[Bug] RT-Thread Bouffalo ADC reads outside its DMA sample buffer
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 72/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- c
- Ambito
- embedded-iot, security
Direzione di ricerca
Leggi bsp/bouffalo_lab/libraries/rt_drivers/drv_adc.c nei punti indicati e segui come i canali ADC configurati vengono associati agli slot dei risultati DMA. Controlla components/drivers/misc/adc.c per comprendere il percorso di lettura pubblico, quindi esamina la configurazione ADC della scheda e i test pertinenti. Il lavoro è concluso quando i canali non supportati o fuori intervallo vengono rifiutati prima dell’indicizzazione e i canali validi vengono associati agli slot campionati.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
RT-Thread Version
v5.3.0
Affected area
Other / Not sure
Hardware/BSP vendor
Not applicable / Other
Architecture
Not applicable / Other
Board and hardware details
Bouffalo ADC
Develop Toolchain
Other
Describe the bug
RT-Thread Bouffalo ADC reads outside its DMA sample buffer
Affected version
RT-Thread v5.3.0.
Describe the bug
bl_adc_get_value() reads raw_data[10 + channel] without checking the channel. raw_data has 26 words. A channel of 22 selects word 32, past the end of the buffer.
static volatile uint32_t raw_data[16 + 10];
rt_sem_take(_adc->sem, RT_WAITING_FOREVER);
*value = (rt_uint32_t)raw_data[10 + channel];
rt_adc_read() does not validate the channel either. The semaphore is created with an initial count of zero and released from the DMA completion handler, so the read runs after that wait returns. A channel below -10 selects before the start of raw_data.
Staying inside the 26-word array is only the memory bound. A supported channel also has to be one the board actually samples, with a defined slot in the DMA result.
Locations:
bsp/bouffalo_lab/libraries/rt_drivers/drv_adc.c:26
bsp/bouffalo_lab/libraries/rt_drivers/drv_adc.c:155
bsp/bouffalo_lab/libraries/rt_drivers/drv_adc.c:166
bsp/bouffalo_lab/libraries/rt_drivers/drv_adc.c:177
bsp/bouffalo_lab/libraries/rt_drivers/drv_adc.c:201
components/drivers/misc/adc.c:118
Threat model
The boundary is a caller of the public ADC API. This report does not treat a network or physical-bus peer as the attacker. The value that caller controls is the channel argument of rt_adc_read(dev, channel). dev only selects the ADC instance. raw_data is a driver buffer; the caller does not supply its address or length.
channel has type rt_int8_t, so the values defined by the API are -128 through 127. The read uses index 10 + channel. Channels 0 through 15 stay inside the 26-word array. Channel 22, which fits in rt_int8_t, selects word 32. A channel below -10 selects before the array. The negative constants RT_ADC_INTERN_CH_TEMPER, RT_ADC_INTERN_CH_VREF, and RT_ADC_INTERN_CH_VBAT (-1, -2, and -3) are inside the array by this formula, but that does not make them valid sample slots.
With RT_USING_FINSH, adc read <channel> passes atoi(argv[2]) into rt_adc_read(). The shell is an entry point only when an untrusted user can reach it. A product task that forwards an untrusted channel into the same API is the same boundary. The read still waits on the ADC semaphore, which starts at zero and is released by the DMA completion handler.
Steps to reproduce
I have not reproduced this on Bouffalo hardware. The reduced check keeps the array length and the 10 + channel index. It does not model the semaphore or DMA.
#include <stdint.h>
static volatile uint32_t raw_data[16 + 10];
static uint32_t read_channel(int8_t channel)
{
return raw_data[10 + channel];
}
int main(void)
{
return (int)read_channel(22);
}
Compile it with a bounds sanitizer, for example:
clang -fsanitize=address,undefined -g -O1 repro.c -o repro && ./repro
Rejecting the channel before the index avoids the report. Channel -11 is also out of range; channels 0 and 10 stay inside this array.
Relevant log output
runtime error: index 32 out of bounds for type 'volatile uint32_t[26]'
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior
Impact
The callback returns the loaded word through rt_adc_read(). A caller that can supply the channel, including the adc shell command when FinSH is enabled, can request a word outside raw_data once the DMA wait has completed. The reduced check shows the out-of-bounds read. It does not show which adjacent data a product would return, or a network entry point.
This is a read. raw_data is the source, and the store is to the caller's output pointer.
Suggested fix
Validate the channel against the configured channel list before waiting on the semaphore. Map that channel to a documented sample slot and check the slot against the DMA buffer length. Reject negative and unsupported channels. Keep the DMA producer and the reader on the same result layout.
Other additional context
No response
- Lingua principale
- C
- Stelle
- 12.3k
- Fork
- 5.5k
- Merge medio
- 4g 9h
- PR unite (30g)
- 37
Preparare l'ambiente
Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di RT-Thread/rt-thread
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 67/100
RT-Thread/rt-thread#11951 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
[Bug] RT-Thread AB32 ADC uses an unchecked channel as a register indexForse già presa @usualtreee l’ha presa 3 giorni fa. Apertabug Component component: drivers
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
RT-Thread/rt-thread#11948 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
[Bug] [libc] timer_gettime 拆秒前将总纳秒截断为 uint32_t,剩余时间查询错误Forse già presa @Yunlk l’ha presa 10 giorni fa. Apertain progress
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
RT-Thread/rt-thread#11924 · 7 commenti · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
[Bug] dfs_v2 tmpfs: ftruncate(fd, 0) frees the file buffer but reports success — use-after-free read/write and double free from a legal POSIX callForse già presa @remukisama l’ha presa 14 giorni fa. Apertain progress
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
RT-Thread/rt-thread#11902 · 4 commenti · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
[bsp][stm32][bluepill] README「快速上手」缺少重新生成 MDK 工程这一步,按文档操作无法编译通过Forse di nuovo libera @moment-NEW l’ha presa 31 giorni fa e non c’è nessuna pull request aperta. Apertain progress
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
RT-Thread/rt-thread#11818 · 4 commenti · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di RT-Thread/rt-thread
Issue simili
-
Bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 66/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
meshcore-dev/MeshCore#3760 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
ly05010419/MacNativeGames#1697 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
colbymchenry/codegraph#3228 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
FujiNetWIFI/fujinet-config#372 ·
I maintainer di solito rispondono entro 1 giorno