mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Shaun Colley" <shaunige@yahoo.co.uk>
To: linux-kernel@vger.kernel.org
Subject: i2c device driver bugs
Date: Sun, 13 Jun 2004 11:31:27 +0100 (BST)	[thread overview]
Message-ID: <20040613103127.57355.qmail@web25103.mail.ukl.yahoo.com> (raw)

Hi list,

I wanted to discuss this a little, so I sent the bug
reports here.  This will avoid me writing a complete
bug report, especially if a bug doesn't exist.  I'd
like your opinions on these bugs.



drivers/i2c/i2c-dev.c
i2cdev_ioctl()
Integer overflow
-----------------------

There seems to be a possible integer overflow, which
can come into play when allocating memory.  See below:

--
case I2C_RDWR:
                if (copy_from_user(&rdwr_arg,
                                   (struct
i2c_rdwr_ioctl_data *)arg,
                                   sizeof(rdwr_arg)))
                        return -EFAULT;

                rdwr_pa = (struct i2c_msg *)
                        kmalloc(rdwr_arg.nmsgs *
sizeof(struct i2c_msg),
                        GFP_KERNEL);

                if (rdwr_pa == NULL) return -ENOMEM;

                res = 0;
                for( i=0; i<rdwr_arg.nmsgs; i++ )
                {

[...]
--

As the code shows, the problem exists when parsing the
I2C_RDWR ioctl option.  It seems like an integer
overflow could occur in the below line:

kmalloc(rdwr_arg.nmsgs * sizeof(struct i2c_msg),
                        GFP_KERNEL);

If rdwr_arg_nmsgs held a number which is not
representable when multiplied by sizeof(struct
i2c_msg), an integer overflow could occur.  Since
rdwr_arg.nmsgs is user-supplied, this could warrant a
problem, especially since the integer overflow occurs
during the allocation in memory.

As far as I can tell, the for() loop following the
memory allocation could cause for data to be written
past the allocated memory, since the integer overflow
is likely to have caused too little memory to have
been allocated -- this could warrant a security
problem, if a bug exists as I've interpreted.


drivers/i2c/i2c-core.c
i2cproc_bus_read()
Integer overflow
-----------------------

There is a possible integer overflow problem when
allocating a chunk of memory:

[...]

if (count > 4096)
                return -EINVAL;

[...]

/* We need a bit of slack in the kernel buffer; this
makes the
                   sprintf safe. */
                        if (! (kbuf = kmalloc(count +
80,GFP_KERNEL)))
                                return -ENOMEM;

[...]

---

Although checks are made to ensure that the 'count'
variable doesn't exceed 4096, no checks are made for
negative numbers.  Since kmalloc() takes it count
argument as an unsigned int, a negative number would
be represented as a very large number.  Then, 80 is
added to this number to allocate a would-be large
chunk of memory, but by adding 80, an integer overflow
can occur.  For example, if -1 was passed as count,
kmalloc() would interpret the number as 0xffffffff +
80, which would definitely cause an integer overflow. 
This could cause too little memory to be allocated --
this would cause a problem, since the following
sprintf() calls will almost definately write past the
allocated memory.  Again, this might be a security
issue.


Are any of these bugs likely to be an issue?  I'd like
to hear your comments please :)

(please CC me, I'm not subscribed to the list)




Thank you for your time.
Shaun.





	
	
		
___________________________________________________________ALL-NEW Yahoo! Messenger - sooooo many all-new ways to express yourself http://uk.messenger.yahoo.com

             reply	other threads:[~2004-06-13 10:31 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-06-13 10:31 Shaun Colley [this message]
2004-06-13 18:41 Shaun Colley
2004-06-14 21:21 ` Greg KH
2004-06-15 15:39   ` Shaun Colley
2004-06-15 16:13     ` Greg KH
2004-06-15 16:33       ` Shaun Colley
     [not found]       ` <20040615163244.10651.qmail@web25103.mail.ukl.yahoo.com>
2004-06-15 16:36         ` Greg KH
2004-06-15 17:09           ` Shaun Colley
2004-06-17 23:56             ` 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=20040613103127.57355.qmail@web25103.mail.ukl.yahoo.com \
    --to=shaunige@yahoo.co.uk \
    --cc=linux-kernel@vger.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®