Skip to contentSkip to conversation

rapidio: potential overflow in riocm_ch_send()

PATCH New Dan Carpenter 1 participant 1 message Jun 1, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

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.

---
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
index db4c265287ae..5c332b9867e1 100644
@@ -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