staging: axis-fifo: validate tx_fifo_depth in axis_fifo_parse_dt()
PATCH 1/1 staging: axis-fifo: validate tx_fifo_depth in axis_fifo_parse_dt()
tx_fifo_depth is read from the device tree as an unsigned int and later used in axis_fifo_write() as:
words_to_write > (fifo->tx_fifo_depth - 4)
If tx_fifo_depth is <= 4, the unsigned subtraction wraps around to a very large value, making the bounds check ineffective. This can cause the calling process to block indefinitely waiting for a FIFO vacancy that will never be reached.
Add a validation check in axis_fifo_parse_dt() to reject invalid values at probe time with a clear error message.
Compile-tested with:
make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- \
drivers/staging/axis-fifo/axis-fifo.o
--- drivers/staging/axis-fifo/axis-fifo.c | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/staging/axis-fifo/axis-fifo.c +7 -0
@@ -413,6 +413,13 @@ static int axis_fifo_parse_dt(struct axis_fifo *fifo)if (ret)return ret; +if (fifo->tx_fifo_depth <=4 ) { +dev_err (fifo->dt_device, +"invalid xlnx,tx-fifo-depth (%u), must be > 4\n" , + fifo->tx_fifo_depth); +return -EINVAL ; + } + ret =of_property_read_u32 (node,"xlnx,use-rx-data" , &fifo->has_rx_fifo);if (ret)
Signature · 1 line
2.53.0
Greg KH
maintainerQuoted 5 lines · User
tx_fifo_depthis read from the device tree as an unsigned int and later used inaxis_fifo_write()as:words_to_write > (fifo->tx_fifo_depth - 4)
Quoted 7 lines
If
tx_fifo_depthis <= 4, the unsigned subtraction wraps around to a very large value, making the bounds check ineffective. This can cause the calling process to block indefinitely waiting for a FIFO vacancy that will never be reached.Add a validation check in
axis_fifo_parse_dt()to reject invalid values at probe time with a clear error message.
Please tell your LLM script that device tree values are "trusted".
Quoted 6 lines
Compile-tested with:
make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- \
drivers/staging/axis-fifo/axis-fifo.oSigned-off-by User <[email protected]>
Not a valid name, sorry.
And again, don't use LLMs on drivers/staging/ without reading the email archives first.
thanks,
greg k-h