All of lore.kernel.org
 help / color / mirror / Atom feed
* 64bit kernel/N32 userspace - shmctl corrupts userspace memory
@ 2006-07-26  0:32 Chad Reese
  2006-07-26  2:04 ` Ralf Baechle
  2006-07-26  2:07 ` Ralf Baechle
  0 siblings, 2 replies; 5+ messages in thread
From: Chad Reese @ 2006-07-26  0:32 UTC (permalink / raw)
  To: linux-mips

[-- Attachment #1: Type: text/plain, Size: 464 bytes --]

If you're running a 64bit kernel with N32 userspace, shmctl will corrupt
memory in userspace. When copy_shmid_to_user() is called, it copies the
entire kernel shmid_ds into userspace. For a 64bit kernel, this is 88
bytes. In N32 userspace it is 76 bytes.

My hack to get around the problem is attached, but I expect someone here
will be able to come up with a better fix. shmid_ds contains a lot of
members that are marked unused. Are these really useless?

Chad


[-- Attachment #2: shared_memory_shmctl_fix.patch --]
[-- Type: text/x-patch, Size: 810 bytes --]

Index: linux/ipc/shm.c
===================================================================
RCS file: /repository/octsw/linux/kernel_2.6/linux/ipc/shm.c,v
retrieving revision 1.1.1.6
retrieving revision 1.2
diff -u -r1.1.1.6 -r1.2
--- linux/ipc/shm.c	7 Jun 2006 19:19:51 -0000	1.1.1.6
+++ linux/ipc/shm.c	22 Jul 2006 02:26:11 -0000	1.2
@@ -321,7 +321,11 @@
 		out.shm_lpid	= in->shm_lpid;
 		out.shm_nattch	= in->shm_nattch;
 
-		return copy_to_user(buf, &out, sizeof(out));
+		/* Use offsetof() instead of sizeof() since N32 userspace has a 
+		    different size including the unused fields. This just copies 
+		    what is used. The old method would corrupt data after the 
+		    structure */
+		return copy_to_user(buf, &out, offsetof(struct shmid_ds, shm_unused2));
 	    }
 	default:
 		return -EINVAL;

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

* Re: 64bit kernel/N32 userspace - shmctl corrupts userspace memory
  2006-07-26  0:32 64bit kernel/N32 userspace - shmctl corrupts userspace memory Chad Reese
@ 2006-07-26  2:04 ` Ralf Baechle
  2006-07-26  2:30   ` Chad Reese
  2006-07-26  2:07 ` Ralf Baechle
  1 sibling, 1 reply; 5+ messages in thread
From: Ralf Baechle @ 2006-07-26  2:04 UTC (permalink / raw)
  To: Chad Reese; +Cc: linux-mips

On Tue, Jul 25, 2006 at 05:32:41PM -0700, Chad Reese wrote:

> If you're running a 64bit kernel with N32 userspace, shmctl will corrupt
> memory in userspace. When copy_shmid_to_user() is called, it copies the
> entire kernel shmid_ds into userspace. For a 64bit kernel, this is 88
> bytes. In N32 userspace it is 76 bytes.
> 
> My hack to get around the problem is attached, but I expect someone here
> will be able to come up with a better fix. shmid_ds contains a lot of
> members that are marked unused. Are these really useless?

Can you try below patch?

  Ralf

diff --git a/arch/mips/kernel/scall64-n32.S b/arch/mips/kernel/scall64-n32.S
index 98abbc5..605d393 100644
--- a/arch/mips/kernel/scall64-n32.S
+++ b/arch/mips/kernel/scall64-n32.S
@@ -150,7 +150,7 @@ EXPORT(sysn32_call_table)
 	PTR	sys_madvise
 	PTR	sys_shmget
 	PTR	sys32_shmat
-	PTR	sys_shmctl			/* 6030 */
+	PTR	compat_sys_shmctl		/* 6030 */
 	PTR	sys_dup
 	PTR	sys_dup2
 	PTR	sys_pause

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

* Re: 64bit kernel/N32 userspace - shmctl corrupts userspace memory
  2006-07-26  0:32 64bit kernel/N32 userspace - shmctl corrupts userspace memory Chad Reese
  2006-07-26  2:04 ` Ralf Baechle
@ 2006-07-26  2:07 ` Ralf Baechle
  1 sibling, 0 replies; 5+ messages in thread
From: Ralf Baechle @ 2006-07-26  2:07 UTC (permalink / raw)
  To: Chad Reese; +Cc: linux-mips

On Tue, Jul 25, 2006 at 05:32:41PM -0700, Chad Reese wrote:

> If you're running a 64bit kernel with N32 userspace, shmctl will corrupt
> memory in userspace. When copy_shmid_to_user() is called, it copies the
> entire kernel shmid_ds into userspace. For a 64bit kernel, this is 88
> bytes. In N32 userspace it is 76 bytes.
> 
> My hack to get around the problem is attached, but I expect someone here
> will be able to come up with a better fix. shmid_ds contains a lot of
> members that are marked unused. Are these really useless?

They need to be there for compatibility with older revisions of the
structure - we can increase the size of the structure but not decrease.

Talking about compatibility, you change breaks N64 compatibility ...

  Ralf

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

* Re: 64bit kernel/N32 userspace - shmctl corrupts userspace memory
  2006-07-26  2:04 ` Ralf Baechle
@ 2006-07-26  2:30   ` Chad Reese
  2006-07-26  3:13     ` Atsushi Nemoto
  0 siblings, 1 reply; 5+ messages in thread
From: Chad Reese @ 2006-07-26  2:30 UTC (permalink / raw)
  To: Ralf Baechle; +Cc: linux-mips

compat.c is only included if CONFIG_SYSVIPC_COMPAT is defined. This
isn't anywhere in 2.6.16.26. Is this what you're refering to?

Chad

Ralf Baechle wrote:
> On Tue, Jul 25, 2006 at 05:32:41PM -0700, Chad Reese wrote:
> 
> 
>>If you're running a 64bit kernel with N32 userspace, shmctl will corrupt
>>memory in userspace. When copy_shmid_to_user() is called, it copies the
>>entire kernel shmid_ds into userspace. For a 64bit kernel, this is 88
>>bytes. In N32 userspace it is 76 bytes.
>>
>>My hack to get around the problem is attached, but I expect someone here
>>will be able to come up with a better fix. shmid_ds contains a lot of
>>members that are marked unused. Are these really useless?
> 
> 
> Can you try below patch?
> 
>   Ralf
> 
> diff --git a/arch/mips/kernel/scall64-n32.S b/arch/mips/kernel/scall64-n32.S
> index 98abbc5..605d393 100644
> --- a/arch/mips/kernel/scall64-n32.S
> +++ b/arch/mips/kernel/scall64-n32.S
> @@ -150,7 +150,7 @@ EXPORT(sysn32_call_table)
>  	PTR	sys_madvise
>  	PTR	sys_shmget
>  	PTR	sys32_shmat
> -	PTR	sys_shmctl			/* 6030 */
> +	PTR	compat_sys_shmctl		/* 6030 */
>  	PTR	sys_dup
>  	PTR	sys_dup2
>  	PTR	sys_pause
> 

-- 

Chad Reese <kreese@caviumnetworks.com>
Cavium Networks
Phone: 650 - 623 - 7038
Cell: 321 - 438 - 7753

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

* Re: 64bit kernel/N32 userspace - shmctl corrupts userspace memory
  2006-07-26  2:30   ` Chad Reese
@ 2006-07-26  3:13     ` Atsushi Nemoto
  0 siblings, 0 replies; 5+ messages in thread
From: Atsushi Nemoto @ 2006-07-26  3:13 UTC (permalink / raw)
  To: creese; +Cc: ralf, linux-mips

On Tue, 25 Jul 2006 19:30:45 -0700, Chad Reese <creese@caviumnetworks.com> wrote:
> compat.c is only included if CONFIG_SYSVIPC_COMPAT is defined. This
> isn't anywhere in 2.6.16.26. Is this what you're refering to?

You can add this to arch/mips/Kconfig:

config SYSVIPC_COMPAT
	bool
	depends on COMPAT && SYSVIPC
	default y

BTW, it seems many SYSVIPC functions in arch/mips/kernel/linux32.c can
be replaced by this common code.

---
Atsushi Nemoto

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

end of thread, other threads:[~2006-07-26  3:13 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-07-26  0:32 64bit kernel/N32 userspace - shmctl corrupts userspace memory Chad Reese
2006-07-26  2:04 ` Ralf Baechle
2006-07-26  2:30   ` Chad Reese
2006-07-26  3:13     ` Atsushi Nemoto
2006-07-26  2:07 ` Ralf Baechle

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.