You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
According to the documentation for struct spi_buf in spi.h, when setting buf member to a null-pointer, dummy bytes should be sent on MOSI line.
/**
* @brief SPI buffer structure
*
* @param buf is a valid pointer on a data buffer, or NULL otherwise.
* @param len is the length of the buffer or, if buf is NULL, will be the
* length which as to be sent as dummy bytes (as TX buffer) or
* the length of bytes that should be skipped (as RX buffer).
*/
struct spi_buf {
void *buf;
size_t len;
};
But when using STM32 driver spi_ll_stm32.c, setting buf to a null pointer results in a null-pointer de-reference (e.g. line 100):
if (SPI_WORD_SIZE_GET(data->ctx.config->operation) == 8) {
if (spi_context_tx_on(&data->ctx)) {
/****** HERE ******/ tx_frame = UNALIGNED_GET((u8_t *)(data->ctx.tx_buf));
}
LL_SPI_TransmitData8(spi, tx_frame);
/* The update is ignored if TX is off. */
spi_context_update_tx(&data->ctx, 1, 1);
} else {
if (spi_context_tx_on(&data->ctx)) {
tx_frame = UNALIGNED_GET((u16_t *)(data->ctx.tx_buf));
}
LL_SPI_TransmitData16(spi, tx_frame);
/* The update is ignored if TX is off. */
spi_context_update_tx(&data->ctx, 2, 1);
}
The cause for the problem stems from #20948 and later from #21772
These commits replaced the call to spi_context_tx_buf_on() with a call to spi_context_tx_on().
While spi_context_tx_buf_on() is checking for the validity of tx buf pointer, spi_context_tx_on() does not, and so a null-pointer de-reference occurs.
To Reproduce
A test case was added to the spi_loopback test under tests/drivers/spi/ which makes an SPI spi_transceive() call with a null tx buffer.
Here is a patch for this test case + a configuration file for running on the nucleo_f413zh board:
Describe the bug
According to the documentation for
struct spi_buf
inspi.h
, when settingbuf
member to a null-pointer, dummy bytes should be sent on MOSI line.But when using STM32 driver
spi_ll_stm32.c
, settingbuf
to a null pointer results in a null-pointer de-reference (e.g. line 100):The cause for the problem stems from #20948 and later from #21772
These commits replaced the call to
spi_context_tx_buf_on()
with a call tospi_context_tx_on()
.While
spi_context_tx_buf_on()
is checking for the validity of tx buf pointer,spi_context_tx_on()
does not, and so a null-pointer de-reference occurs.To Reproduce
A test case was added to the spi_loopback test under tests/drivers/spi/ which makes an SPI
spi_transceive()
call with a null tx buffer.Here is a patch for this test case + a configuration file for running on the nucleo_f413zh board:
Steps to reproduce the behavior
Expected behavior
Test should pass: RX buffer should contain all zeros.
Impact
This is a showstopper! null pointer de-reference can lead to serious issues.
Environment
Additional context
Proposed fix patch (go back to using
spi_context_tx_buf_on()
):The text was updated successfully, but these errors were encountered: