All of lore.kernel.org
 help / color / mirror / Atom feed
* Unaligned accesses in compat_sys_msgrcv and sys_msgrcv
@ 2006-10-21  4:11 Jurij Smakov
  2006-10-21  6:35 ` David Miller
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Jurij Smakov @ 2006-10-21  4:11 UTC (permalink / raw)
  To: sparclinux

Hi,

Every time I compile anything on my box running 2.6.18, I get these 
messages in dmesg every 5 seconds:

Kernel unaligned access at TPC[4ec2f0] sys_msgrcv+0x2dc/0x32c
Kernel unaligned access at TPC[4e9f6c] compat_sys_msgrcv+0xbc/0x124
Kernel unaligned access at TPC[4ec2f0] sys_msgrcv+0x2dc/0x32c
Kernel unaligned access at TPC[4e9f6c] compat_sys_msgrcv+0xbc/0x124
Kernel unaligned access at TPC[4ec2f0] sys_msgrcv+0x2dc/0x32c

Decoding the addresses indicates that the unaligned accesses are 
generated by get_user call in compat_sys_msgrcv at ipc/compat.c:357 
and put_user in sys_msgrcv at ipc/msg.c:836. As far as I can tell, the 
problem stems from the fact that allocating memory with 

p = compat_alloc_user_space(second + sizeof(struct msgbuf));

at ipc/compat.c:352 does not guarantee alignment of p, so when we 
later try to ldxa from the address &p->mtype (in get_user) or stxa 
to &msgp->mtype (in put_user), we catch an exception.

As I'm not sure what would be the correct fix here, I'd appreciate any 
advice on how to deal with that.

Best regards,
-- 
Jurij Smakov                                           jurij@wooyd.org
Key: http://www.wooyd.org/pgpkey/                      KeyID: C99E03CC

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Unaligned accesses in compat_sys_msgrcv and sys_msgrcv
  2006-10-21  4:11 Unaligned accesses in compat_sys_msgrcv and sys_msgrcv Jurij Smakov
@ 2006-10-21  6:35 ` David Miller
  2006-10-23  4:54 ` David Miller
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: David Miller @ 2006-10-21  6:35 UTC (permalink / raw)
  To: sparclinux

From: Jurij Smakov <jurij@wooyd.org>
Date: Fri, 20 Oct 2006 21:11:08 -0700

> p = compat_alloc_user_space(second + sizeof(struct msgbuf));
> 
> at ipc/compat.c:352 does not guarantee alignment of p, so when we 
> later try to ldxa from the address &p->mtype (in get_user) or stxa 
> to &msgp->mtype (in put_user), we catch an exception.
> 
> As I'm not sure what would be the correct fix here, I'd appreciate any 
> advice on how to deal with that.

compat_alloc_user_space() should round down the pointer it returns
to be 8-byte aligned.

Thanks for catching this, I'll cook up a patch over the weekend.

What application is calling sys_msgrev() during a compile btw?

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Unaligned accesses in compat_sys_msgrcv and sys_msgrcv
  2006-10-21  4:11 Unaligned accesses in compat_sys_msgrcv and sys_msgrcv Jurij Smakov
  2006-10-21  6:35 ` David Miller
@ 2006-10-23  4:54 ` David Miller
  2006-10-23 16:52 ` Jurij Smakov
  2006-10-23 21:01 ` David Miller
  3 siblings, 0 replies; 5+ messages in thread
From: David Miller @ 2006-10-23  4:54 UTC (permalink / raw)
  To: sparclinux

From: Jurij Smakov <jurij@wooyd.org>
Date: Fri, 20 Oct 2006 21:11:08 -0700

> p = compat_alloc_user_space(second + sizeof(struct msgbuf));

Thanks again for this report Jurij, this patch should fix it up.

commit a94b1d1fd7ca3129e1d38d38167779fa6ee69780
Author: David S. Miller <davem@sunset.davemloft.net>
Date:   Sun Oct 22 21:53:30 2006 -0700

    [SPARC64]: 8-byte align return value from compat_alloc_user_space()
    
    Otherwise we get a ton of unaligned exceptions, for cases such
    as compat_sys_msgrcv() which go:
    
    	p = compat_alloc_user_space(second + sizeof(struct msgbuf));
    
    and here 'second' can for example be an arbitrary odd value.
    
    Based upon a bug report from Jurij Smakov.
    
    Signed-off-by: David S. Miller <davem@davemloft.net>

diff --git a/include/asm-sparc64/compat.h b/include/asm-sparc64/compat.h
index c73935d..36511ca 100644
--- a/include/asm-sparc64/compat.h
+++ b/include/asm-sparc64/compat.h
@@ -164,7 +164,7 @@ static inline compat_uptr_t ptr_to_compa
 	return (u32)(unsigned long)uptr;
 }
 
-static __inline__ void __user *compat_alloc_user_space(long len)
+static inline void __user *compat_alloc_user_space(long len)
 {
 	struct pt_regs *regs = current_thread_info()->kregs;
 	unsigned long usp = regs->u_regs[UREG_I6];
@@ -174,7 +174,10 @@ static __inline__ void __user *compat_al
 	else
 		usp &= 0xffffffffUL;
 
-	return (void __user *) (usp - len);
+	usp -= len;
+	usp &= ~0x7UL;
+
+	return (void __user *) usp;
 }
 
 struct compat_ipc64_perm {

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: Unaligned accesses in compat_sys_msgrcv and sys_msgrcv
  2006-10-21  4:11 Unaligned accesses in compat_sys_msgrcv and sys_msgrcv Jurij Smakov
  2006-10-21  6:35 ` David Miller
  2006-10-23  4:54 ` David Miller
@ 2006-10-23 16:52 ` Jurij Smakov
  2006-10-23 21:01 ` David Miller
  3 siblings, 0 replies; 5+ messages in thread
From: Jurij Smakov @ 2006-10-23 16:52 UTC (permalink / raw)
  To: sparclinux

On Sun, Oct 22, 2006 at 09:54:19PM -0700, David Miller wrote:
> From: Jurij Smakov <jurij@wooyd.org>
> Date: Fri, 20 Oct 2006 21:11:08 -0700
> 
> > p = compat_alloc_user_space(second + sizeof(struct msgbuf));
> 
> Thanks again for this report Jurij, this patch should fix it up.
> 
> commit a94b1d1fd7ca3129e1d38d38167779fa6ee69780
> Author: David S. Miller <davem@sunset.davemloft.net>
> Date:   Sun Oct 22 21:53:30 2006 -0700

Thanks, that took care of the unaligned accesses nicely.

It turned out that the source of these messages was fakeroot - a 
Debian utility which wraps a few system calls to create an illusion 
that the process is running with root privileges. It is commonly used 
during package builds and uses IPC to communicate with the daemon 
which tracks the (fake) information about file ownership and 
permissions.

Best regards, 
-- 
Jurij Smakov                                           jurij@wooyd.org
Key: http://www.wooyd.org/pgpkey/                      KeyID: C99E03CC

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Unaligned accesses in compat_sys_msgrcv and sys_msgrcv
  2006-10-21  4:11 Unaligned accesses in compat_sys_msgrcv and sys_msgrcv Jurij Smakov
                   ` (2 preceding siblings ...)
  2006-10-23 16:52 ` Jurij Smakov
@ 2006-10-23 21:01 ` David Miller
  3 siblings, 0 replies; 5+ messages in thread
From: David Miller @ 2006-10-23 21:01 UTC (permalink / raw)
  To: sparclinux

From: Jurij Smakov <jurij@wooyd.org>
Date: Mon, 23 Oct 2006 09:52:00 -0700

> It turned out that the source of these messages was fakeroot - a 
> Debian utility which wraps a few system calls to create an illusion 
> that the process is running with root privileges. It is commonly used 
> during package builds and uses IPC to communicate with the daemon 
> which tracks the (fake) information about file ownership and 
> permissions.

Thanks Jurij, I knew about fakeroot but not that it used
sysv IPC :-)

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2006-10-23 21:01 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-10-21  4:11 Unaligned accesses in compat_sys_msgrcv and sys_msgrcv Jurij Smakov
2006-10-21  6:35 ` David Miller
2006-10-23  4:54 ` David Miller
2006-10-23 16:52 ` Jurij Smakov
2006-10-23 21:01 ` David Miller

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.