netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Firo Yang <firogm@gmail.com>
To: t.sailer@alumni.ethz.ch, wharms@bfs.de
Cc: linux-hams@vger.kernel.org, netdev@vger.kernel.org,
	dvyukov@google.com, syzkaller@googlegroups.com,
	davem@davemloft.net, gregkh@linuxfoundation.org,
	Firo Yang <firogm@gmail.com>
Subject: [[PATCH v1]] hdlcdrv: fix divide error bug if bitrate is 0
Date: Thu, 18 May 2017 12:02:18 +0800	[thread overview]
Message-ID: <1495080138-21695-1-git-send-email-firogm@gmail.com> (raw)

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: Dmitry Vyukov <dvyukov@google.com>
Signed-off-by: Firo Yang <firogm@gmail.com>
---
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.7.4


             reply	other threads:[~2017-05-18  4:02 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-18  4:02 Firo Yang [this message]
2017-05-19  0:31 ` [[PATCH v1]] hdlcdrv: fix divide error bug if bitrate is 0 Andrey Konovalov

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=1495080138-21695-1-git-send-email-firogm@gmail.com \
    --to=firogm@gmail.com \
    --cc=davem@davemloft.net \
    --cc=dvyukov@google.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-hams@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=syzkaller@googlegroups.com \
    --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).