hdlcdrv: fix divide error bug if bitrate is 0
Subsystems (2)
PATCH 1/1 hdlcdrv: fix divide error bug if bitrate is 0
The divisor s->par.bitrate will always be 0 until initialized by ndo_open() and hdlcdrv_open().
In order to fix this divide zero error, check whether the netdevice was opened by ndo_open() before performing divide.
--- drivers/net/hamradio/hdlcdrv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/hamradio/hdlcdrv.c +1 -1
@@ -574,7 +574,7 @@ static int hdlcdrv_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)break ;case HDLCDRVCTL_CALIBRATE : -if (!capable (CAP_SYS_RAWIO )) +if (!capable (CAP_SYS_RAWIO ) || !netif_running (dev))return -EPERM ;if (bi.data.calibrate >INT_MAX / s->par.bitrate)return -EINVAL ;
Signature · 1 line
2.9.4
Am 17.05.2017 14:35, schrieb Firo Yang:
Quoted 17 lines
The divisor
s->par.bitratewill always be 0 until initialized byndo_open()andhdlcdrv_open().In order to fix this divide zero error, check whether the netdevice was opened by
ndo_open()before performing divide.Reported-by Dmitry Vyukov <[email protected]>Signed-off-by Firo Yang <[email protected]>--- drivers/net/hamradio/hdlcdrv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/net/hamradio/hdlcdrv.c +0
-0
drivers/net/hamradio/hdlcdrv.c static int hdlcdrv_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) · line 580
Quoted 8 lines
drivers/net/hamradio/hdlcdrv.c +1
-1@@ -574,7 +574,7 @@ static int hdlcdrv_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)break ;case HDLCDRVCTL_CALIBRATE : -if (!capable (CAP_SYS_RAWIO )) +if (!capable (CAP_SYS_RAWIO ) || !netif_running (dev))return -EPERM ;if (bi.data.calibrate >INT_MAX / s->par.bitrate)return -EINVAL ;
I would still check for s->par.bitrate > 0 later changes may affect the setting of it and it is much more obvious.
Also perhaps !netif_running(dev) should better return ENODEV.
just my 2 cents,
re,
wh
Quoted 22 lines · walter harms
Am 17.05.2017 14:35, schrieb Firo Yang:
Quoted 19 lines
The divisor
s->par.bitratewill always be 0 until initialized byndo_open()andhdlcdrv_open().In order to fix this divide zero error, check whether the netdevice was opened by
ndo_open()before performing divide.Reported-by Dmitry Vyukov <[email protected]>Signed-off-by Firo Yang <[email protected]>--- drivers/net/hamradio/hdlcdrv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/net/hamradio/hdlcdrv.c +0
-0@@ -574,7 +574,7 @@ static int hdlcdrv_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)break ;
Quoted 9 lines
drivers/net/hamradio/hdlcdrv.c static int hdlcdrv_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) · line 580
Quoted 6 lines
drivers/net/hamradio/hdlcdrv.c +1
-1case HDLCDRVCTL_CALIBRATE : -if (!capable (CAP_SYS_RAWIO )) +if (!capable (CAP_SYS_RAWIO ) || !netif_running (dev))return -EPERM ;if (bi.data.calibrate >INT_MAX / s->par.bitrate)return -EINVAL ;I would still check for
s->par.bitrate> 0 later changes may affect the setting of it and it is much more obvious.
I think 0 is not valid value for bitrate, so we should check it in other places, like what ser12_open() did:
429 if (bc->baud < 300 || bc->baud > 4800) {
430 printk(KERN_INFO "baycom_ser_fdx: invalid baudrate "
431 "(300...4800)\n");
432 return -EINVAL;
433 }
...
440 bc->hdrv.par.bitrate = bc->baud;
Quoted 2 lines
Also perhaps !netif_running(dev) should better return ENODEV.
However, the 'dev' truly exists in this circumstance.
Thanks,
Firo
Quoted 6 lines
just my 2 cents,
re,
wh
Am 17.05.2017 15:42, schrieb Firo Yang:
Quoted 33 lines · walter harms
Quoted 22 lines
Am 17.05.2017 14:35, schrieb Firo Yang:
Quoted 19 lines
The divisor
s->par.bitratewill always be 0 until initialized byndo_open()andhdlcdrv_open().In order to fix this divide zero error, check whether the netdevice was opened by
ndo_open()before performing divide.Reported-by Dmitry Vyukov <[email protected]>Signed-off-by Firo Yang <[email protected]>--- drivers/net/hamradio/hdlcdrv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/net/hamradio/hdlcdrv.c +0
-0@@ -574,7 +574,7 @@ static int hdlcdrv_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)break ;Quoted 9 lines
drivers/net/hamradio/hdlcdrv.c static int hdlcdrv_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) · line 580
Quoted 6 lines
drivers/net/hamradio/hdlcdrv.c +1
-1case HDLCDRVCTL_CALIBRATE : -if (!capable (CAP_SYS_RAWIO )) +if (!capable (CAP_SYS_RAWIO ) || !netif_running (dev))return -EPERM ;if (bi.data.calibrate >INT_MAX / s->par.bitrate)return -EINVAL ;I would still check for
s->par.bitrate> 0 later changes may affect the setting of it and it is much more obvious.
Quoted 9 lines
I think 0 is not valid value for bitrate, so we should check it in other places, like what
ser12_open()did:
429 if (bc->baud< 300 ||bc->baud> 4800) {
430 printk(KERN_INFO "baycom_ser_fdx: invalid baudrate "
431 "(300...4800)\n");
432 return-EINVAL;
433 }
...
440bc->hdrv.par.bitrate=bc->baud;
I do not want to say you change is not valid but i have learned that it is better to have an obvious check that to rely on hidden knowledge.
Quoted 6 lines
Quoted 3 lines
Also perhaps !netif_running(dev) should better return ENODEV.
However, the 'dev' truly exists in this circumstance.
yes and i do not feel good with that but "no permission" will lead any enduser into a search for user rights.
re,
wh
Quoted 9 lines
Thanks,
FiroQuoted 6 lines
just my 2 cents,
re,
wh
Quoted 47 lines · walter harms
Am 17.05.2017 15:42, schrieb Firo Yang:
Quoted 33 lines · walter harms
Quoted 22 lines
Am 17.05.2017 14:35, schrieb Firo Yang:
Quoted 19 lines
The divisor
s->par.bitratewill always be 0 until initialized byndo_open()andhdlcdrv_open().In order to fix this divide zero error, check whether the netdevice was opened by
ndo_open()before performing divide.Reported-by Dmitry Vyukov <[email protected]>Signed-off-by Firo Yang <[email protected]>--- drivers/net/hamradio/hdlcdrv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/net/hamradio/hdlcdrv.c +0
-0@@ -574,7 +574,7 @@ static int hdlcdrv_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)break ;Quoted 9 lines
drivers/net/hamradio/hdlcdrv.c static int hdlcdrv_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) · line 580
Quoted 6 lines
drivers/net/hamradio/hdlcdrv.c +1
-1case HDLCDRVCTL_CALIBRATE : -if (!capable (CAP_SYS_RAWIO )) +if (!capable (CAP_SYS_RAWIO ) || !netif_running (dev))return -EPERM ;if (bi.data.calibrate >INT_MAX / s->par.bitrate)return -EINVAL ;I would still check for
s->par.bitrate> 0 later changes may affect the setting of it and it is much more obvious.Quoted 9 lines
I think 0 is not valid value for bitrate, so we should check it in other places, like what
ser12_open()did:
429 if (bc->baud< 300 ||bc->baud> 4800) {
430 printk(KERN_INFO "baycom_ser_fdx: invalid baudrate "
431 "(300...4800)\n");
432 return-EINVAL;
433 }
...
440bc->hdrv.par.bitrate=bc->baud;
Quoted 2 lines
I do not want to say you change is not valid but i have learned that it is better to have an obvious check that to rely on hidden knowledge.
I agree with this.
Quoted 11 lines
Quoted 8 lines
Quoted 5 lines
Also perhaps !netif_running(dev) should better return ENODEV.
However, the 'dev' truly exists in this circumstance.
yes and i do not feel good with that but "no permission" will lead any enduser into a search for user rights.
Indeed, ENODEV is more informative to enduser.
I will send a update patch.
Thanks,
Firo
Quoted 16 lines
re,
whQuoted 9 lines
Thanks,
FiroQuoted 6 lines
just my 2 cents,
re,
wh