Re: [Stable-review] [patch 31/38] ARM: 6891/1: prevent heap corruptionin OABI semtimedop

From: Jesper Juhl
Date: Mon May 09 2011 - 16:16:23 EST


On Sat, 7 May 2011, Ben Hutchings wrote:

> On Thu, 2011-05-05 at 17:11 -0700, Greg KH wrote:
> > 2.6.38-stable review patch. If anyone has any objections, please let us know.
> >
> > ------------------
> >
> > From: Dan Rosenberg <drosenberg@xxxxxxxxxxxxx>
> >
> > commit 0f22072ab50cac7983f9660d33974b45184da4f9 upstream.
> >
> > When CONFIG_OABI_COMPAT is set, the wrapper for semtimedop does not
> > bound the nsops argument. A sufficiently large value will cause an
> > integer overflow in allocation size, followed by copying too much data
> > into the allocated buffer. Fix this by restricting nsops to SEMOPM.
> > Untested.
> >
> > Signed-off-by: Dan Rosenberg <drosenberg@xxxxxxxxxxxxx>
> > Signed-off-by: Russell King <rmk+kernel@xxxxxxxxxxxxxxxx>
> > Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxx>
> >
> > ---
> > arch/arm/kernel/sys_oabi-compat.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > --- a/arch/arm/kernel/sys_oabi-compat.c
> > +++ b/arch/arm/kernel/sys_oabi-compat.c
> > @@ -311,7 +311,7 @@ asmlinkage long sys_oabi_semtimedop(int
> > long err;
> > int i;
> >
> > - if (nsops < 1)
> > + if (nsops < 1 || nsops > SEMOPM)
> > return -EINVAL;
>
> It's not that important, but the manual page says the error code should
> E2BIG in the latter case.
>

So something like this...

Return correct error (E2BIG) when nsops is greater than SEMOPM in
sys_oabi_semtimedop. The man page (semtimedop(2)) lists this as the proper
error in ths case:
"E2BIG The argument nsops is greater than SEMOPM, the maximum number of
operations allowed per system call."

Signed-off-by: Jesper Juhl <jj@xxxxxxxxxxxxx>
Reported-by: Ben Hutchings <ben@xxxxxxxxxxxxxxx>
--
sys_oabi-compat.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/arch/arm/kernel/sys_oabi-compat.c b/arch/arm/kernel/sys_oabi-compat.c
index af0aaeb..c196ad7 100644
--- a/arch/arm/kernel/sys_oabi-compat.c
+++ b/arch/arm/kernel/sys_oabi-compat.c
@@ -311,8 +311,10 @@ asmlinkage long sys_oabi_semtimedop(int semid,
long err;
int i;

- if (nsops < 1 || nsops > SEMOPM)
+ if (nsops < 1)
return -EINVAL;
+ else if (nsops > SEMOPM)
+ return -E2BIG;
sops = kmalloc(sizeof(*sops) * nsops, GFP_KERNEL);
if (!sops)
return -ENOMEM;



--
Jesper Juhl <jj@xxxxxxxxxxxxx> http://www.chaosbits.net/
Don't top-post http://www.catb.org/jargon/html/T/top-post.html
Plain text mails only, please.

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/