Blob Blame History Raw
From: Colin Ian King <colin.king@canonical.com>
Subject: media: dvb_ca_en50221: sanity check slot number from userspace
Git-commit: a24e6348e5a0e8562ad64d760c25907ed088611c
Patch-mainline: v4.16
References: bsc#1192802
Acked-by: Jiri Bohac <jbohac@suse.cz>

Currently a user can pass in an unsanitized slot number which
will lead to and out of range index into ca->slot_info. Fix this
by checking that the slot number is no more than the allowed
maximum number of slots. Seems that this bug has been in the driver
forever.

Detected by CoverityScan, CID#139381 ("Untrusted pointer read")

Signed-off-by: Colin Ian King <colin.king@canonical.com>
Reviewed-by: Dan Carpenter <dan.carpenter@oracle.com>
Reviewed-by: Jasmin Jessich <jasmin@anw.at>
Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>

diff --git a/drivers/media/dvb-core/dvb_ca_en50221.c b/drivers/media/dvb-core/dvb_ca_en50221.c
index d48b61eb01f4..a3b2754e7124 100644
--- a/drivers/media/dvb-core/dvb_ca_en50221.c
+++ b/drivers/media/dvb-core/dvb_ca_en50221.c
@@ -1371,6 +1371,9 @@ static ssize_t dvb_ca_en50221_io_write(struct file *file,
 	buf += 2;
 	count -= 2;
 
+	if (slot >= ca->slot_count)
+		return -EINVAL;
+
 	/* check if the slot is actually running */
 	if (ca->slot_info[slot].slot_state != DVB_CA_SLOTSTATE_RUNNING)
 		return -EINVAL;
-- 
2.33.0