Skip to contentSkip to conversation

media: rc: validate that "rc_proto" is reasonable

PATCH In review Dan Carpenter 2 participants 2 messages Oct 30, 2020 – Nov 1, 2020

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

PATCH 1/1 media: rc: validate that "rc_proto" is reasonable

Smatch complains that "rc_proto" comes from the user and it can result in shift wrapping in ir_raw_encode_scancode()

drivers/media/rc/rc-ir-raw.c:526 ir_raw_encode_scancode()
error: undefined (user controlled) shift '1 << protocol'

This is true, but I reviewed the surrounding code and it appears harmless. Anyway, let's verify that "rc_proto" is valid as a kernel hardenning measure.

---
 drivers/media/rc/lirc_dev.c | 3 ++-
 include/uapi/linux/lirc.h   | 1 +
 2 files changed, 3 insertions(+), 1 deletion(-)
include/uapi/linux/lirc.h +1 -0
index f99d9dcae667..c1eb960adde3 100644
@@ -226,6 +226,7 @@ enum rc_proto {
 	RC_PROTO_RCMM24		= 25,
 	RC_PROTO_RCMM32		= 26,
 	RC_PROTO_XBOX_DVD	= 27,
+	RC_PROTO_MAX		= RC_PROTO_XBOX_DVD,
 };
 
 #endif
drivers/media/rc/lirc_dev.c +2 -1
index 220363b9a868..116daf90c858 100644
@@ -263,7 +263,8 @@ static ssize_t lirc_transmit(struct file *file, const char __user *buf,
 			goto out_unlock;
 		}
 
-		if (scan.flags || scan.keycode || scan.timestamp) {
+		if (scan.flags || scan.keycode || scan.timestamp ||
+		    scan.rc_proto > RC_PROTO_MAX) {
 			ret = -EINVAL;
 			goto out_unlock;
 		}
Signature · 1 line
2.28.0
maintainer
#1 lore raw

Hi Dan,

Quoted 9 lines · Dan Carpenter

Smatch complains that "rc_proto" comes from the user and it can result in shift wrapping in ir_raw_encode_scancode()

drivers/media/rc/rc-ir-raw.c:526 ir_raw_encode_scancode()
error: undefined (user controlled) shift '1 << protocol'

This is true, but I reviewed the surrounding code and it appears harmless. Anyway, let's verify that "rc_proto" is valid as a kernel hardenning measure.

It would mean that suddenly an invalid rc proto could become valid; also like you say, this is a good hardening measure.

Good catch, thank you.

Regards,

Sean

Quoted 35 lines
---
 drivers/media/rc/lirc_dev.c | 3 ++-
 include/uapi/linux/lirc.h   | 1 +
 2 files changed, 3 insertions(+), 1 deletion(-)
include/uapi/linux/lirc.h +1 -0
index f99d9dcae667..c1eb960adde3 100644
@@ -226,6 +226,7 @@ enum rc_proto {
 	RC_PROTO_RCMM24		= 25,
 	RC_PROTO_RCMM32		= 26,
 	RC_PROTO_XBOX_DVD	= 27,
+	RC_PROTO_MAX		= RC_PROTO_XBOX_DVD,
 };
 
 #endif
drivers/media/rc/lirc_dev.c +2 -1
index 220363b9a868..116daf90c858 100644
@@ -263,7 +263,8 @@ static ssize_t lirc_transmit(struct file *file, const char __user *buf,
 			goto out_unlock;
 		}
 
-		if (scan.flags || scan.keycode || scan.timestamp) {
+		if (scan.flags || scan.keycode || scan.timestamp ||
+		    scan.rc_proto > RC_PROTO_MAX) {
 			ret = -EINVAL;
 			goto out_unlock;
 		}
Signature · 1 line
2.28.0