From: Firo Yang <firogm@gmail.com>
To: t.sailer@alumni.ethz.ch, wharms@bfs.de, andreyknvl@google.com
Cc: linux-hams@vger.kernel.org, davem@davemloft.net,
gregkh@linuxfoundation.org, netdev@vger.kernel.org,
Firo Yang <firogm@gmail.com>
Subject: [PATCH v2] hdlcdrv: fix divide error bug if bitrate is 0
Date: Fri, 19 May 2017 21:21:46 +0800 [thread overview]
Message-ID: <20170519132146.744-1-firogm@gmail.com> (raw)
In-Reply-To: <CAAeHK+ya2sAtLmJ0VyP6e=13OXUw98dp1WdRFU=o5+xGFGPtbQ@mail.gmail.com>
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
next prev parent reply other threads:[~2017-05-19 13:21 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-05-16 15:05 drivers/net/hamradio: divide error in hdlcdrv_ioctl Andrey Konovalov
2017-05-16 15:05 ` Andrey Konovalov
2017-05-17 20:07 ` Alan Cox
2017-05-19 0:29 ` Andrey Konovalov
2017-05-19 13:21 ` Firo Yang [this message]
2017-05-19 21:41 ` [PATCH v2] hdlcdrv: fix divide error bug if bitrate is 0 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170519132146.744-1-firogm@gmail.com \
--to=firogm@gmail.com \
--cc=andreyknvl@google.com \
--cc=davem@davemloft.net \
--cc=gregkh@linuxfoundation.org \
--cc=linux-hams@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=t.sailer@alumni.ethz.ch \
--cc=wharms@bfs.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).