* [PATCH v2] hdlcdrv: fix divide error bug if bitrate is 0
[not found] <CAAeHK+ya2sAtLmJ0VyP6e=13OXUw98dp1WdRFU=o5+xGFGPtbQ@mail.gmail.com>
@ 2017-05-19 13:21 ` Firo Yang
2017-05-19 21:41 ` David Miller
2017-05-26 14:37 ` [PATCH v3] hdlcdrv: Fix divide by zero in hdlcdrv_ioctl Firo Yang
1 sibling, 1 reply; 4+ messages in thread
From: Firo Yang @ 2017-05-19 13:21 UTC (permalink / raw)
To: t.sailer, wharms, andreyknvl; +Cc: linux-hams, davem, gregkh, netdev, Firo Yang
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.And we also check the the
value of bitrate in case of bad setting of it.
Reported-by: Andrey Konovalov <andreyknvl@google.com>
Signed-off-by: Firo Yang <firogm@gmail.com>
---
v1->v2:
Change Reported-by to Andrey Konovalov.
Send it to original report thread.
v0->v1:
Reviewed by walter harms <wharms@bfs.de>.
Return ENODEV instead of EPERM if !netif_running(dev)
Check if s->par.bitrate > 0.
drivers/net/hamradio/hdlcdrv.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/drivers/net/hamradio/hdlcdrv.c b/drivers/net/hamradio/hdlcdrv.c
index 8c3633c..b0f417f 100644
--- a/drivers/net/hamradio/hdlcdrv.c
+++ b/drivers/net/hamradio/hdlcdrv.c
@@ -576,6 +576,10 @@ static int hdlcdrv_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
case HDLCDRVCTL_CALIBRATE:
if(!capable(CAP_SYS_RAWIO))
return -EPERM;
+ if (!netif_running(dev))
+ return -ENODEV;
+ if (!(s->par.bitrate > 0))
+ return -EINVAL;
if (bi.data.calibrate > INT_MAX / s->par.bitrate)
return -EINVAL;
s->hdlctx.calibrate = bi.data.calibrate * s->par.bitrate / 16;
--
2.9.4
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v2] hdlcdrv: fix divide error bug if bitrate is 0
2017-05-19 13:21 ` [PATCH v2] hdlcdrv: fix divide error bug if bitrate is 0 Firo Yang
@ 2017-05-19 21:41 ` David Miller
0 siblings, 0 replies; 4+ messages in thread
From: David Miller @ 2017-05-19 21:41 UTC (permalink / raw)
To: firogm; +Cc: t.sailer, wharms, andreyknvl, linux-hams, gregkh, netdev
From: Firo Yang <firogm@gmail.com>
Date: Fri, 19 May 2017 21:21:46 +0800
> @@ -576,6 +576,10 @@ static int hdlcdrv_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
> case HDLCDRVCTL_CALIBRATE:
> if(!capable(CAP_SYS_RAWIO))
> return -EPERM;
> + if (!netif_running(dev))
> + return -ENODEV;
> + if (!(s->par.bitrate > 0))
> + return -EINVAL;
This test is so un-canonical and convoluted.
Please use something more straightforward. I really think Alan
Cox's patch handled this more cleanly. Make the test something
like "if (x <= 0) return -EINVAL;".
I also am not convinced about the netif_running() test and at
best it is a separate change from this divide by zero bug fix
so belongs in a separate patch.
Thank you.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v3] hdlcdrv: Fix divide by zero in hdlcdrv_ioctl
[not found] <CAAeHK+ya2sAtLmJ0VyP6e=13OXUw98dp1WdRFU=o5+xGFGPtbQ@mail.gmail.com>
2017-05-19 13:21 ` [PATCH v2] hdlcdrv: fix divide error bug if bitrate is 0 Firo Yang
@ 2017-05-26 14:37 ` Firo Yang
2017-05-27 22:45 ` David Miller
1 sibling, 1 reply; 4+ messages in thread
From: Firo Yang @ 2017-05-26 14:37 UTC (permalink / raw)
To: davem, alan
Cc: t.sailer, wharms, andreyknvl, linux-hams, gregkh, netdev, thomas,
javier, dhowells, geliangtang, linux-kernel, Firo Yang
syszkaller fuzzer triggered a divide by zero, when set calibration
through ioctl().
To fix it, test 'bitrate' if it is negative or 0, just return -EINVAL.
Reported-by: Andrey Konovalov <andreyknvl@google.com>
Signed-off-by: Firo Yang <firogm@gmail.com>
---
v2->v3:
Just fix divide error and remove netif_running() test.
Refine the testing code as David Miller suggested.
v1->v2:
Change Reported-by to Andrey Konovalov.
Send it to original report thread.
v0->v1:
Reviewed by walter harms <wharms@bfs.de>.
Return ENODEV instead of EPERM if !netif_running(dev)
Check if s->par.bitrate > 0.
drivers/net/hamradio/hdlcdrv.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/net/hamradio/hdlcdrv.c b/drivers/net/hamradio/hdlcdrv.c
index 8c3633c..97e3bc6 100644
--- a/drivers/net/hamradio/hdlcdrv.c
+++ b/drivers/net/hamradio/hdlcdrv.c
@@ -576,6 +576,8 @@ static int hdlcdrv_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
case HDLCDRVCTL_CALIBRATE:
if(!capable(CAP_SYS_RAWIO))
return -EPERM;
+ if (s->par.bitrate <= 0)
+ return -EINVAL;
if (bi.data.calibrate > INT_MAX / s->par.bitrate)
return -EINVAL;
s->hdlctx.calibrate = bi.data.calibrate * s->par.bitrate / 16;
--
2.9.4
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v3] hdlcdrv: Fix divide by zero in hdlcdrv_ioctl
2017-05-26 14:37 ` [PATCH v3] hdlcdrv: Fix divide by zero in hdlcdrv_ioctl Firo Yang
@ 2017-05-27 22:45 ` David Miller
0 siblings, 0 replies; 4+ messages in thread
From: David Miller @ 2017-05-27 22:45 UTC (permalink / raw)
To: firogm
Cc: alan, t.sailer, wharms, andreyknvl, linux-hams, gregkh, netdev,
thomas, javier, dhowells, geliangtang, linux-kernel
From: Firo Yang <firogm@gmail.com>
Date: Fri, 26 May 2017 22:37:38 +0800
> syszkaller fuzzer triggered a divide by zero, when set calibration
> through ioctl().
>
> To fix it, test 'bitrate' if it is negative or 0, just return -EINVAL.
>
> Reported-by: Andrey Konovalov <andreyknvl@google.com>
> Signed-off-by: Firo Yang <firogm@gmail.com>
Applied, thank you.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2017-05-27 22:45 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <CAAeHK+ya2sAtLmJ0VyP6e=13OXUw98dp1WdRFU=o5+xGFGPtbQ@mail.gmail.com>
2017-05-19 13:21 ` [PATCH v2] hdlcdrv: fix divide error bug if bitrate is 0 Firo Yang
2017-05-19 21:41 ` David Miller
2017-05-26 14:37 ` [PATCH v3] hdlcdrv: Fix divide by zero in hdlcdrv_ioctl Firo Yang
2017-05-27 22:45 ` David Miller
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).