rapidio: potential overflow in riocm_ch_send()
Subsystems (2)
PATCH 1/1 rapidio: potential overflow in riocm_ch_send()
The "buf" variable has "len" bytes, and the size is controlled by the user in cm_chan_msg_send(). If the length is fewer than sizeof(*hdr) then it could lead to memory corruption.
Signed-off-by Dan Carpenter <[email protected]>
---
Strictly speaking the last two bytes of length are reserved and not written to but it's simpler and better to check "< sizeof(*hdr)" instead of "< sizeof(*hdr) - 2". This is better for future proofing.
drivers/rapidio/rio_cm.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/rapidio/rio_cm.c +2 -1
@@ -784,7 +784,8 @@ static int riocm_ch_send(u16 ch_id, void *buf, int len)struct rio_ch_chan_hdr *hdr;int ret; -if (buf ==NULL || ch_id ==0 || len ==0 || len >RIO_MAX_MSG_SIZE ) +if (buf ==NULL || ch_id ==0 || + len <sizeof (*hdr) || len >RIO_MAX_MSG_SIZE )return -EINVAL ; ch =riocm_get_channel (ch_id);
Signature · 1 line
2.30.2