From: Mitchell Blank Jr <mitch@sfgoth.com>
To: Jes Sorensen <jes@sgi.com>
Cc: Andi Kleen <ak@suse.de>, Linus Torvalds <torvalds@osdl.org>,
Andrew Morton <akpm@osdl.org>,
linux-kernel@vger.kernel.org, linux-ia64@vger.kernel.org
Subject: Re: [patch] avoid unaligned access when accessing poll stack
Date: Sat, 01 Apr 2006 02:35:38 +0000 [thread overview]
Message-ID: <20060401023538.GB3157@gaz.sfgoth.com> (raw)
In-Reply-To: <yq0odzmtwni.fsf@jaguar.mkp.net>
Jes Sorensen wrote:
> I assume you mean select().
>
> Updated patch attached.
This fixes a few problems introduced by this patch.
* Fixes two warnings caused by mixing "char *" and "long *" pointers
* If SELECT_STACK_ALLOC is not a multiple of sizeof(long) then stack_fds[]
would be less than SELECT_STACK_ALLOC bytes and could overflow later in
the function. Fixed by simply rearranging the test later to work on
sizeof(stack_fds)
Currently SELECT_STACK_ALLOC is 256 so this doesn't happen, but it's
nasty to have things like this hidden in the code. What if later
someone decides to change SELECT_STACK_ALLOC to 300?
* I also changed "size" to be unsigned since that makes more sense and
is less prone to overflow bugs. I'm also a little scared by the
"kmalloc(6 * size)" since that type of call is a classic multiply-overflow
security hole (hence libc's calloc() API). However "size" is constrained
by fdt->max_fdset so I think it isn't exploitable. The kernel doesn't
have an overflow-safe API for kmalloc'ing arrays, does it?
Patch is vs current git HEAD. Only compile/boot tested.
Signed-off-by: Mitchell Blank Jr <mitch@sfgoth.com>
diff --git a/fs/select.c b/fs/select.c
index 071660f..bd9c7db 100644
--- a/fs/select.c
+++ b/fs/select.c
@@ -311,7 +311,8 @@ static int core_sys_select(int n, fd_set
{
fd_set_bits fds;
char *bits;
- int ret, size, max_fdset;
+ int ret, max_fdset;
+ unsigned int size;
struct fdtable *fdt;
/* Allocate small arguments on the stack to save memory and be faster */
long stack_fds[SELECT_STACK_ALLOC/sizeof(long)];
@@ -335,8 +336,8 @@ static int core_sys_select(int n, fd_set
*/
ret = -ENOMEM;
size = FDS_BYTES(n);
- if (6*size < SELECT_STACK_ALLOC)
- bits = stack_fds;
+ if (size < sizeof(stack_fds) / 6)
+ bits = (char *) stack_fds;
else
bits = kmalloc(6 * size, GFP_KERNEL);
if (!bits)
@@ -373,7 +374,7 @@ static int core_sys_select(int n, fd_set
ret = -EFAULT;
out:
- if (bits != stack_fds)
+ if (bits != (char *) stack_fds)
kfree(bits);
out_nofds:
return ret;
next prev parent reply other threads:[~2006-04-01 2:35 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-03-31 15:38 [patch] avoid unaligned access when accessing poll stack Jes Sorensen
2006-03-31 16:00 ` Andi Kleen
2006-03-31 16:18 ` Jes Sorensen
2006-04-01 2:35 ` Mitchell Blank Jr [this message]
2006-04-01 2:44 ` Andi Kleen
2006-04-01 3:39 ` Mitchell Blank Jr
2006-03-31 16:37 ` OGAWA Hirofumi
2006-03-31 16:53 ` Andi Kleen
2006-03-31 17:16 ` OGAWA Hirofumi
2006-03-31 17:18 ` Andi Kleen
2006-03-31 17:40 ` OGAWA Hirofumi
2006-03-31 17:19 ` OGAWA Hirofumi
2006-03-31 18:20 ` Andrew Morton
2006-04-02 14:49 ` Jes Sorensen
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=20060401023538.GB3157@gaz.sfgoth.com \
--to=mitch@sfgoth.com \
--cc=ak@suse.de \
--cc=akpm@osdl.org \
--cc=jes@sgi.com \
--cc=linux-ia64@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=torvalds@osdl.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