From: Xi Wang <xi.wang@gmail.com>
To: linux-kernel@vger.kernel.org
Cc: Ian Abbott <abbotti@mev.co.uk>,
Mori Hess <fmhess@users.sourceforge.net>,
Greg Kroah-Hartman <gregkh@suse.de>,
Mark Pearson <markpearson_de@yahoo.de>,
Lucas De Marchi <lucas.demarchi@profusion.mobi>,
Greg Dietsche <Gregory.Dietsche@cuw.edu>,
Franky Lin <frankyl@broadcom.com>,
devel@driverdev.osuosl.org, security@kernel.org
Subject: [PATCH] comedi: integer overflow in do_insnlist_ioctl()
Date: Tue, 22 Nov 2011 19:49:29 -0500 [thread overview]
Message-ID: <5C0D372F-F03E-4EB8-8440-83A8D1C95363@gmail.com> (raw)
There is a potential integer overflow in do_insnlist_ioctl() if userspace passes in a large insnlist.n_insns. The call to kmalloc() would allocate a small buffer, which would result in a memory corruption.
Reported-by: Haogang Chen <haogangchen@gmail.com>
Signed-off-by: Xi Wang <xi.wang@gmail.com>
---
drivers/staging/comedi/comedi_fops.c | 7 +++++++
1 files changed, 7 insertions(+), 0 deletions(-)
diff --git a/drivers/staging/comedi/comedi_fops.c b/drivers/staging/comedi/comedi_fops.c
index 21d8c1c..66bb49d 100644
--- a/drivers/staging/comedi/comedi_fops.c
+++ b/drivers/staging/comedi/comedi_fops.c
@@ -650,6 +650,7 @@ static int parse_insn(struct comedi_device *dev, struct comedi_insn *insn,
* data (for reads)
*/
/* arbitrary limits */
+#define MAX_INSNS 256
#define MAX_SAMPLES 256
static int do_insnlist_ioctl(struct comedi_device *dev,
struct comedi_insnlist __user *arg, void *file)
@@ -663,6 +664,12 @@ static int do_insnlist_ioctl(struct comedi_device *dev,
if (copy_from_user(&insnlist, arg, sizeof(struct comedi_insnlist)))
return -EFAULT;
+ if (insnlist.n_insns > MAX_INSNS) {
+ DPRINTK("invalid number of instructions\n");
+ ret = -EINVAL;
+ goto error;
+ }
+
data = kmalloc(sizeof(unsigned int) * MAX_SAMPLES, GFP_KERNEL);
if (!data) {
DPRINTK("kmalloc failed\n");
--
1.7.5.4
next reply other threads:[~2011-11-23 0:49 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-11-23 0:49 Xi Wang [this message]
2011-11-23 6:13 ` Dan Carpenter
2011-11-23 13:59 ` Xi Wang
2011-11-23 14:50 ` Dan Carpenter
2011-11-23 16:06 ` Ian Abbott
2011-11-23 16:53 ` [PATCH v2] " Xi Wang
2011-11-23 21:41 ` [PATCH] " Lars-Peter Clausen
2011-11-23 21:51 ` Dan Carpenter
2011-11-24 19:07 ` Xi Wang
2011-11-25 7:25 ` Dan Carpenter
2011-11-25 21:46 ` [PATCH v3] " Xi Wang
2011-11-27 2:52 ` Greg KH
2011-11-27 11:25 ` Dan Carpenter
2011-11-27 21:24 ` Greg KH
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=5C0D372F-F03E-4EB8-8440-83A8D1C95363@gmail.com \
--to=xi.wang@gmail.com \
--cc=Gregory.Dietsche@cuw.edu \
--cc=abbotti@mev.co.uk \
--cc=devel@driverdev.osuosl.org \
--cc=fmhess@users.sourceforge.net \
--cc=frankyl@broadcom.com \
--cc=gregkh@suse.de \
--cc=linux-kernel@vger.kernel.org \
--cc=lucas.demarchi@profusion.mobi \
--cc=markpearson_de@yahoo.de \
--cc=security@kernel.org \
/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
all inboxes | Powered by JetHome®