CVE-2026-18414
Beschrijving NL
De ADC API vereist dat elke bestuurder een bemonsteringsreeks afwijst waarvan de bestemmingsbuffer te klein is: het buffer_size-veld van struct adc_sequence in include/zephyr/drivers/adc.h documenteert dat "de bestuurder ervoor moet zorgen dat monsters niet over de limiet worden geschreven en een fout moet retourneren als de buffer niet groot genoeg blijkt te zijn". De ADI MAX32-chauffeur kwam dat contract niet na. start_read() in drivers/adc/adc_max32.c buffer_size, een byte-aantal, vergeleken met een steekproefaantal ((1 + extra_samplings) kanalen), waarbij sizeof(uint16_t) werd genegeerd, zodat het een buffer accepteerde die de helft van de vereiste grootte bedroeg. De monsters worden vervolgens opgeslagen via de uint16_t-gegevens- >buffer door Wrap_MXC_ADC_GetData(), die twee bytes per monster schrijft en de aanwijzer met één uint16_t voortzet: in adc_max32_start_channel() voor synchrone leesbewerkingen en in adc_max32_isr() voor asynchrone. Een reeks die twee kanalen selecteert met een buffer van twee bytes, passeert bijvoorbeeld de controle en het tweede monster wordt voorbij het einde van de buffer geschreven. Op een build met CONFIG_USERSPACE zijn adc_read() en adc_read_async() systeemaanroepen. De handler in drivers/adc/adc_handlers.c kopieert de reeks uit het gebruikersgeheugen, verifieert alleen dat [buffer, buffer + buffer_size) beschrijfbaar is door de aanroepende thread en wijst een door de gebruiker geleverde opties->callback af; het laat opzettelijk de grootteberekening over aan de bestuurder. Een thread in gebruikersmodus die toegang heeft gekregen tot een MAX32 ADC-apparaatobject, controleert daarom volledig kanalen, buffer, buffer_size en opties->extra_samplings, en kan de driver twee keer zoveel bytes laten schrijven als de buffer bevat. Omdat de controle schaalt met extra_samplings, is de overschrijding gelijk aan de lengte van de buffer zelf, tot kanalen * 65536 bytes voorbij het einde, omdat de monsteraanwijzer alleen wordt teruggespoeld op een herhalingsbemonstering, nooit op de extra bemonsteringen van een reeks. De resulterende opslag wordt uitgevoerd door het stuurprogramma in de kernelmodus (in de systeemnaam zelf, de ADC-contexttimer of de ADC-interrupthandler voor asynchrone lezingen), waarbij de MPU het geheugendomein van de thread niet beperkt, zodat het schrijven lineair uit de gebruikerspartitie loopt en in het aangrenzende geheugen zoals andere partities, kernelgegevens of threadstacks. De impact is kernel-geheugencorruptie van door de aanvaller gekozen lengte bij een door de aanvaller gekozen offset, een plausibele privilege-escalatie en denial-of-service primitief van een niet-bevoorrechte gebruikersmodus-thread. Builds zonder CONFIG_USERSPACE worden alleen beïnvloed als een robuustheidsfout aan de bellerzijde, omdat de applicatie zelf de buffer levert. De oplossing vervangt het inchecken in start_read() door een oproep naar de nieuwe gedeelde helper adc_sequence_validate_buffer() in drivers/adc/adc_common.c, waarbij de grootte van (uint16_t) als steekproefgrootte wordt doorgegeven. De helper berekent de active_channels sizeof(uint16_t) (1 + extra_samplings) en retourneert -ENOMEM voordat een bemonstering wordt gestart.
Origineel (Engels) tonen
The ADC API requires each driver to reject a sampling sequence whose destination buffer is too small: the buffer_size field of struct adc_sequence in include/zephyr/drivers/adc.h documents that "the driver must ensure that samples are not written beyond the limit and it must return an error if the buffer turns out to be not large enough". The ADI MAX32 driver did not honour that contract. start_read() in drivers/adc/adc_max32.c compared buffer_size, a byte count, against a sample count ((1 + extra_samplings) channels), ignoring sizeof(uint16_t), so it accepted a buffer half the required size. The samples are then stored through the uint16_t data->buffer by Wrap_MXC_ADC_GetData(), which writes two bytes per sample and advances the pointer by one uint16_t: in adc_max32_start_channel() for synchronous reads, and in adc_max32_isr() for asynchronous ones. A sequence selecting two channels with a two-byte buffer, for example, passes the check and has its second sample written past the end of the buffer.
On a build with CONFIG_USERSPACE, adc_read() and adc_read_async() are system calls. The handler in drivers/adc/adc_handlers.c copies the sequence in from user memory, verifies only that [buffer, buffer + buffer_size) is writable by the calling thread, and rejects a user-supplied options->callback; it deliberately leaves the size arithmetic to the driver. A user-mode thread that has been granted access to a MAX32 ADC device object therefore fully controls channels, buffer, buffer_size and options->extra_samplings, and can make the driver write twice as many bytes as its buffer holds. Because the check scales with extra_samplings, the overrun equals the length of the buffer itself, up to channels * 65536 bytes past its end, since the sample pointer is only rewound on a repeat sampling, never on the extra samplings of a sequence.
The resulting stores are performed by the driver in kernel mode (in the system call itself, the ADC context timer, or the ADC interrupt handler for asynchronous reads), where the MPU does not restrict the thread's memory domain, so the write walks linearly out of the user partition and into adjacent memory such as other partitions, kernel data or thread stacks. The impact is kernel-memory corruption of attacker-chosen length at an attacker-chosen offset, a plausible privilege-escalation and denial-of-service primitive from an unprivileged user-mode thread. Builds without CONFIG_USERSPACE are affected only as a caller-side robustness defect, since the application itself supplies the buffer.
The fix replaces that check in start_read() with a call to the new shared helper adc_sequence_validate_buffer() in drivers/adc/adc_common.c, passing sizeof(uint16_t) as the sample size. The helper computes active_channels sizeof(uint16_t) (1 + extra_samplings) and returns -ENOMEM before any sampling is started.