Skip to contentSkip to conversation

rc: divide by zero bugs in s_tx_carrier()

PATCH Superseded Dan Carpenter 2 participants 2 messages Aug 18, 2012 – Aug 19, 2012

Subsystems (4)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 rc: divide by zero bugs in s_tx_carrier()

"carrier" comes from a get_user() in ir_lirc_ioctl(). We need to test that it's not zero before using it as a divisor.

drivers/media/rc/ene_ir.c +4 -1
index 647dd95..d05ac15 100644
@@ -881,10 +881,13 @@ static int ene_set_tx_mask(struct rc_dev *rdev, u32 tx_mask)
 static int ene_set_tx_carrier(struct rc_dev *rdev, u32 carrier)
 {
 	struct ene_device *dev = rdev->priv;
-	u32 period = 2000000 / carrier;
+	u32 period;
 
 	dbg("TX: attempt to set tx carrier to %d kHz", carrier);
+	if (carrier = 0)
+		return -EINVAL;
 
+	period = 2000000 / carrier;
 	if (period && (period > ENE_CIRMOD_PRD_MAX ||
 			period < ENE_CIRMOD_PRD_MIN)) {
 
drivers/media/rc/nuvoton-cir.c +3 -0
index 699eef3..2ea913a 100644
@@ -517,6 +517,9 @@ static int nvt_set_tx_carrier(struct rc_dev *dev, u32 carrier)
 	struct nvt_dev *nvt = dev->priv;
 	u16 val;
 
+	if (carrier = 0)
+		return -EINVAL;
+
 	nvt_cir_reg_write(nvt, 1, CIR_CP);
 	val = 3000000 / (carrier) - 1;
 	nvt_cir_reg_write(nvt, val & 0xff, CIR_CC);
#1 lore raw
Quoted 2 lines · Dan Carpenter

"carrier" comes from a get_user() in ir_lirc_ioctl(). We need to test that it's not zero before using it as a divisor.

Other RC drivers seem to have the same problem, only more deeply buried. I think it's better to put this check in ir_lirc_ioctl() instead, consistent with LIRC_SET_REC_CARRIER.

Ben.

Quoted 36 lines
drivers/media/rc/ene_ir.c +4 -1
index 647dd95..d05ac15 100644
@@ -881,10 +881,13 @@ static int ene_set_tx_mask(struct rc_dev *rdev, u32 tx_mask)
 static int ene_set_tx_carrier(struct rc_dev *rdev, u32 carrier)
 {
 	struct ene_device *dev = rdev->priv;
-	u32 period = 2000000 / carrier;
+	u32 period;
 
 	dbg("TX: attempt to set tx carrier to %d kHz", carrier);
+	if (carrier == 0)
+		return -EINVAL;
 
+	period = 2000000 / carrier;
 	if (period && (period > ENE_CIRMOD_PRD_MAX ||
 			period < ENE_CIRMOD_PRD_MIN)) {
 
drivers/media/rc/nuvoton-cir.c +3 -0
index 699eef3..2ea913a 100644
@@ -517,6 +517,9 @@ static int nvt_set_tx_carrier(struct rc_dev *dev, u32 carrier)
 	struct nvt_dev *nvt = dev->priv;
 	u16 val;
 
+	if (carrier == 0)
+		return -EINVAL;
+
 	nvt_cir_reg_write(nvt, 1, CIR_CP);
 	val = 3000000 / (carrier) - 1;
 	nvt_cir_reg_write(nvt, val & 0xff, CIR_CC);
Signature · 2 lines
Ben Hutchings
I say we take off; nuke the site from orbit.  It's the only way to be sure.