Skip to contentSkip to conversation

media: dvb-usb-v2: ec168: Reject zero-length I2C reads

PATCH In review Andi Shyti 3 participants 3 messages Oct 19

Subsystems (4)
lore
Share & tools
lore

Andi Shyti

author
#0 lore raw

PATCH 1/1 media: dvb-usb-v2: ec168: Reject zero-length I2C reads

ec168_i2c_xfer() checks the length of the register-address message in a combined demodulator read, but does not validate the read message length. Userspace can supply a zero-length read through I2C_RDWR.

This reaches ec168_ctrl_msg(), which selects an IN control pipe for READ_DEMOD with wLength set to zero. The USB core treats control requests without a data stage as OUT(*), triggering the "BOGUS control dir" warning in usb_submit_urb().

Reject zero-length read messages with -EOPNOTSUPP before issuing the USB request, using the existing exit path to release the I2C mutex.

(*) is_out = ... || !setup->wLength;

Fixes 2bf290be4f3e ("V4L/DVB (13364): ec168: add new driver for E3C EC168 DVB USB")
Reported-by [email protected]
Cc <[email protected]> # v2.6.33+
---
 drivers/media/usb/dvb-usb-v2/ec168.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/usb/dvb-usb-v2/ec168.c +1 -1
index 973b32356b17..f6b98c7d3704 100644
@@ -115,7 +115,7 @@ static int ec168_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[],
 	while (i < num) {
 		if (num > i + 1 && (msg[i+1].flags & I2C_M_RD)) {
 			if (msg[i].addr == ec168_ec100_config.demod_address) {
-				if (msg[i].len < 1) {
+				if (msg[i].len < 1 || msg[i+1].len < 1) {
 					i = -EOPNOTSUPP;
 					break;
 				}
Signature · 1 line
2.55.0
#1 lore raw
Sashiko has reviewed this patch and found no issues.
Quoted 14 lines

ec168_i2c_xfer() checks the length of the register-address message in a combined demodulator read, but does not validate the read message length. Userspace can supply a zero-length read through I2C_RDWR.

This reaches ec168_ctrl_msg(), which selects an IN control pipe for READ_DEMOD with wLength set to zero. The USB core treats control requests without a data stage as OUT(*), triggering the "BOGUS control dir" warning in usb_submit_urb().

Reject zero-length read messages with -EOPNOTSUPP before issuing the USB request, using the existing exit path to release the I2C mutex.

Quoted 6 lines

(*) is_out = ... || !setup->wLength;

Fixes 2bf290be4f3e ("V4L/DVB (13364): ec168: add new driver for E3C EC168 DVB USB")
Reported-by [email protected]

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#2 lore raw
In reply to Andi Shyti
Quoted 30 lines · Andi Shyti

ec168_i2c_xfer() checks the length of the register-address message in a combined demodulator read, but does not validate the read message length. Userspace can supply a zero-length read through I2C_RDWR.

This reaches ec168_ctrl_msg(), which selects an IN control pipe for READ_DEMOD with wLength set to zero. The USB core treats control requests without a data stage as OUT(*), triggering the "BOGUS control dir" warning in usb_submit_urb().

Reject zero-length read messages with -EOPNOTSUPP before issuing the USB request, using the existing exit path to release the I2C mutex.

(*) is_out = ... || !setup->wLength;

Fixes 2bf290be4f3e ("V4L/DVB (13364): ec168: add new driver for E3C EC168 DVB USB")
Reported-by [email protected]
Cc <[email protected]> # v2.6.33+
---
 drivers/media/usb/dvb-usb-v2/ec168.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/usb/dvb-usb-v2/ec168.c +0 -0
index 973b32356b17..f6b98c7d3704 100644

drivers/media/usb/dvb-usb-v2/ec168.c static int ec168_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[], · line 121

Quoted 8 lines
drivers/media/usb/dvb-usb-v2/ec168.c +1 -1
@@ -115,7 +115,7 @@ static int ec168_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[],
 	while (i < num) {
 		if (num > i + 1 && (msg[i+1].flags & I2C_M_RD)) {
 			if (msg[i].addr == ec168_ec100_config.demod_address) {
-				if (msg[i].len < 1) {
+				if (msg[i].len < 1 || msg[i+1].len < 1) {
 					i = -EOPNOTSUPP;
 					break;
 				}

Isn't there an I2C quirks flag to indicate that 0-length reads aren't allowed? Setting that flag would be more understandable than this test.

Alan Stern