LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH 1/2] x86: signal_32: introduce retcode and rt_retcode
@ 2008-11-12  3:09 Hiroshi Shimamoto
  2008-11-12  3:11 ` [PATCH 2/2] x86: ia32_signal: remove unnecessary padding Hiroshi Shimamoto
  0 siblings, 1 reply; 11+ messages in thread
From: Hiroshi Shimamoto @ 2008-11-12  3:09 UTC (permalink / raw)
  To: Ingo Molnar, Thomas Gleixner, H. Peter Anvin; +Cc: linux-kernel

From: Hiroshi Shimamoto <h-shimamoto@ct.jp.nec.com>

Impact: cleanup

Introduce retcode and rt_retcode to replace setting up frame->retcode.

Signed-off-by: Hiroshi Shimamoto <h-shimamoto@ct.jp.nec.com>
---
 arch/x86/kernel/signal_32.c |   30 ++++++++++++++++++++++++------
 1 files changed, 24 insertions(+), 6 deletions(-)

diff --git a/arch/x86/kernel/signal_32.c b/arch/x86/kernel/signal_32.c
index 27a5c81..514171a 100644
--- a/arch/x86/kernel/signal_32.c
+++ b/arch/x86/kernel/signal_32.c
@@ -45,6 +45,28 @@
 # define FIX_EFLAGS	__FIX_EFLAGS
 #endif
 
+static const struct {
+	u16 poplmovl;
+	u32 val;
+	u16 int80;
+} __attribute__((packed)) retcode = {
+	0xb858,		/* popl %eax; movl $..., %eax */
+	__NR_sigreturn,
+	0x80cd,		/* int $0x80 */
+};
+
+static const struct {
+	u8  movl;
+	u32 val;
+	u16 int80;
+	u8  pad;
+} __attribute__((packed)) rt_retcode = {
+	0xb8,		/* movl $..., %eax */
+	__NR_rt_sigreturn,
+	0x80cd,		/* int $0x80 */
+	0
+};
+
 /*
  * Atomically swap in the new signal mask, and wait for a signal.
  */
@@ -427,9 +449,7 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
 	 * reasons and because gdb uses it as a signature to notice
 	 * signal handler stack frames.
 	 */
-	err |= __put_user(0xb858, (short __user *)(frame->retcode+0));
-	err |= __put_user(__NR_sigreturn, (int __user *)(frame->retcode+2));
-	err |= __put_user(0x80cd, (short __user *)(frame->retcode+6));
+	err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
 
 	if (err)
 		return -EFAULT;
@@ -498,9 +518,7 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
 	 * reasons and because gdb uses it as a signature to notice
 	 * signal handler stack frames.
 	 */
-	err |= __put_user(0xb8, (char __user *)(frame->retcode+0));
-	err |= __put_user(__NR_rt_sigreturn, (int __user *)(frame->retcode+1));
-	err |= __put_user(0x80cd, (short __user *)(frame->retcode+5));
+	err |= __put_user(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
 
 	if (err)
 		return -EFAULT;
-- 
1.5.6


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

* [PATCH 2/2] x86: ia32_signal: remove unnecessary padding
  2008-11-12  3:09 [PATCH 1/2] x86: signal_32: introduce retcode and rt_retcode Hiroshi Shimamoto
@ 2008-11-12  3:11 ` Hiroshi Shimamoto
  2008-11-12 11:29   ` Ingo Molnar
  2008-11-12 12:56   ` Andi Kleen
  0 siblings, 2 replies; 11+ messages in thread
From: Hiroshi Shimamoto @ 2008-11-12  3:11 UTC (permalink / raw)
  To: Ingo Molnar, Thomas Gleixner, H. Peter Anvin; +Cc: linux-kernel

From: Hiroshi Shimamoto <h-shimamoto@ct.jp.nec.com>

Impact: cleanup

Remove unnecessary paddings, this saves 4 bytes.

Signed-off-by: Hiroshi Shimamoto <h-shimamoto@ct.jp.nec.com>
---
 arch/x86/ia32/ia32_signal.c |    5 +----
 1 files changed, 1 insertions(+), 4 deletions(-)

diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
index bafc0b4..e886907 100644
--- a/arch/x86/ia32/ia32_signal.c
+++ b/arch/x86/ia32/ia32_signal.c
@@ -427,12 +427,10 @@ int ia32_setup_frame(int sig, struct k_sigaction *ka,
 		u16 poplmovl;
 		u32 val;
 		u16 int80;
-		u16 pad;
 	} __attribute__((packed)) code = {
 		0xb858,		 /* popl %eax ; movl $...,%eax */
 		__NR_ia32_sigreturn,
 		0x80cd,		/* int $0x80 */
-		0,
 	};
 
 	frame = get_sigframe(ka, regs, sizeof(*frame), &fpstate);
@@ -508,8 +506,7 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
 		u8 movl;
 		u32 val;
 		u16 int80;
-		u16 pad;
-		u8  pad2;
+		u8  pad;
 	} __attribute__((packed)) code = {
 		0xb8,
 		__NR_ia32_rt_sigreturn,
-- 
1.5.6


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

* Re: [PATCH 2/2] x86: ia32_signal: remove unnecessary padding
  2008-11-12  3:11 ` [PATCH 2/2] x86: ia32_signal: remove unnecessary padding Hiroshi Shimamoto
@ 2008-11-12 11:29   ` Ingo Molnar
  2008-11-12 12:33     ` Mikael Pettersson
  2008-11-12 12:56   ` Andi Kleen
  1 sibling, 1 reply; 11+ messages in thread
From: Ingo Molnar @ 2008-11-12 11:29 UTC (permalink / raw)
  To: Hiroshi Shimamoto; +Cc: Thomas Gleixner, H. Peter Anvin, linux-kernel


* Hiroshi Shimamoto <h-shimamoto@ct.jp.nec.com> wrote:

> From: Hiroshi Shimamoto <h-shimamoto@ct.jp.nec.com>
> 
> Impact: cleanup
> 
> Remove unnecessary paddings, this saves 4 bytes.
> 
> Signed-off-by: Hiroshi Shimamoto <h-shimamoto@ct.jp.nec.com>
> ---
>  arch/x86/ia32/ia32_signal.c |    5 +----
>  1 files changed, 1 insertions(+), 4 deletions(-)

applied your patches to tip/x86/signal:

 9cc3c49: x86: ia32_signal: remove unnecessary padding
 4a61204: x86: signal_32: introduce retcode and rt_retcode

thanks!

A question - this change:

> @@ -427,12 +427,10 @@ int ia32_setup_frame(int sig, struct k_sigaction *ka,
>  		u16 poplmovl;
>  		u32 val;
>  		u16 int80;
> -		u16 pad;
>  	} __attribute__((packed)) code = {
>  		0xb858,		 /* popl %eax ; movl $...,%eax */
>  		__NR_ia32_sigreturn,
>  		0x80cd,		/* int $0x80 */
> -		0,
>  	};
>  
>  	frame = get_sigframe(ka, regs, sizeof(*frame), &fpstate);
> @@ -508,8 +506,7 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
>  		u8 movl;
>  		u32 val;
>  		u16 int80;
> -		u16 pad;
> -		u8  pad2;
> +		u8  pad;
>  	} __attribute__((packed)) code = {
>  		0xb8,
>  		__NR_ia32_rt_sigreturn,

does not impact any ABI, because it's only about the signal trampoline 
the kernel pushes to the user-space stack - not about any 
userspace-visible signal frame detail, right?

	Ingo

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

* Re: [PATCH 2/2] x86: ia32_signal: remove unnecessary padding
  2008-11-12 11:29   ` Ingo Molnar
@ 2008-11-12 12:33     ` Mikael Pettersson
  2008-11-12 17:12       ` H. Peter Anvin
  0 siblings, 1 reply; 11+ messages in thread
From: Mikael Pettersson @ 2008-11-12 12:33 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: Hiroshi Shimamoto, Thomas Gleixner, H. Peter Anvin, linux-kernel

Ingo Molnar writes:
 > 
 > * Hiroshi Shimamoto <h-shimamoto@ct.jp.nec.com> wrote:
 > 
 > > From: Hiroshi Shimamoto <h-shimamoto@ct.jp.nec.com>
 > > 
 > > Impact: cleanup
 > > 
 > > Remove unnecessary paddings, this saves 4 bytes.
 > > 
 > > Signed-off-by: Hiroshi Shimamoto <h-shimamoto@ct.jp.nec.com>
 > > ---
 > >  arch/x86/ia32/ia32_signal.c |    5 +----
 > >  1 files changed, 1 insertions(+), 4 deletions(-)
 > 
 > applied your patches to tip/x86/signal:
 > 
 >  9cc3c49: x86: ia32_signal: remove unnecessary padding
 >  4a61204: x86: signal_32: introduce retcode and rt_retcode
 > 
 > thanks!
 > 
 > A question - this change:
 > 
 > > @@ -427,12 +427,10 @@ int ia32_setup_frame(int sig, struct k_sigaction *ka,
 > >  		u16 poplmovl;
 > >  		u32 val;
 > >  		u16 int80;
 > > -		u16 pad;
 > >  	} __attribute__((packed)) code = {
 > >  		0xb858,		 /* popl %eax ; movl $...,%eax */
 > >  		__NR_ia32_sigreturn,
 > >  		0x80cd,		/* int $0x80 */
 > > -		0,
 > >  	};
 > >  
 > >  	frame = get_sigframe(ka, regs, sizeof(*frame), &fpstate);
 > > @@ -508,8 +506,7 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
 > >  		u8 movl;
 > >  		u32 val;
 > >  		u16 int80;
 > > -		u16 pad;
 > > -		u8  pad2;
 > > +		u8  pad;
 > >  	} __attribute__((packed)) code = {
 > >  		0xb8,
 > >  		__NR_ia32_rt_sigreturn,
 > 
 > does not impact any ABI, because it's only about the signal trampoline 
 > the kernel pushes to the user-space stack - not about any 
 > userspace-visible signal frame detail, right?

As long as the 'char retcode[8]' field isn't reduced in size
(you can _never_ do that!), and the initial instruction
sequence up to the 'int $0x80' isn't changed (you can't change
that either), I believe this is safe.

It does cause each signal delivery to leak 2 uninitialised
kernel bytes to the end of retcode[], which seems unnecessary.

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

* Re: [PATCH 2/2] x86: ia32_signal: remove unnecessary padding
  2008-11-12  3:11 ` [PATCH 2/2] x86: ia32_signal: remove unnecessary padding Hiroshi Shimamoto
  2008-11-12 11:29   ` Ingo Molnar
@ 2008-11-12 12:56   ` Andi Kleen
  2008-11-12 18:34     ` Hiroshi Shimamoto
  1 sibling, 1 reply; 11+ messages in thread
From: Andi Kleen @ 2008-11-12 12:56 UTC (permalink / raw)
  To: Hiroshi Shimamoto
  Cc: Ingo Molnar, Thomas Gleixner, H. Peter Anvin, linux-kernel

Hiroshi Shimamoto <h-shimamoto@ct.jp.nec.com> writes:

> From: Hiroshi Shimamoto <h-shimamoto@ct.jp.nec.com>
>
> Impact: cleanup

Actually it's not a cleanup.

> Remove unnecessary paddings, this saves 4 bytes.

This might actually break code. The code is not actually used,
but only kept around because some old gdb versions used this
code as a marker for detecting signals.

I don't know if they require the padding or not, but it seems
somewhat risky to change a legacy marker like this.

-Andi

-- 
ak@linux.intel.com

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

* Re: [PATCH 2/2] x86: ia32_signal: remove unnecessary padding
  2008-11-12 12:33     ` Mikael Pettersson
@ 2008-11-12 17:12       ` H. Peter Anvin
  2008-11-12 18:02         ` Hiroshi Shimamoto
  0 siblings, 1 reply; 11+ messages in thread
From: H. Peter Anvin @ 2008-11-12 17:12 UTC (permalink / raw)
  To: Mikael Pettersson
  Cc: Ingo Molnar, Hiroshi Shimamoto, Thomas Gleixner, linux-kernel

Mikael Pettersson wrote:
> It does cause each signal delivery to leak 2 uninitialised
> kernel bytes to the end of retcode[], which seems unnecessary.

Not just unnecessary, it is a huge no-no for security.

NAK on this.

	-hpa

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

* Re: [PATCH 2/2] x86: ia32_signal: remove unnecessary padding
  2008-11-12 17:12       ` H. Peter Anvin
@ 2008-11-12 18:02         ` Hiroshi Shimamoto
  2008-11-12 18:12           ` H. Peter Anvin
  0 siblings, 1 reply; 11+ messages in thread
From: Hiroshi Shimamoto @ 2008-11-12 18:02 UTC (permalink / raw)
  To: H. Peter Anvin
  Cc: Mikael Pettersson, Ingo Molnar, Thomas Gleixner, linux-kernel

H. Peter Anvin wrote:
> Mikael Pettersson wrote:
>> It does cause each signal delivery to leak 2 uninitialised
>> kernel bytes to the end of retcode[], which seems unnecessary.
> 
> Not just unnecessary, it is a huge no-no for security.

Am I missing important thing?
The frame->retcode is 8 bytes and packed structure with padding
is 10 bytes each, and the code is copied to user stack 8 bytes only.

err |= __copy_to_user(frame->retcode, &code, 8);

I don't think the behavior is changed.

thanks,
Hiroshi Shimamoto

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


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

* Re: [PATCH 2/2] x86: ia32_signal: remove unnecessary padding
  2008-11-12 18:02         ` Hiroshi Shimamoto
@ 2008-11-12 18:12           ` H. Peter Anvin
  2008-11-13  8:45             ` Mikael Pettersson
  0 siblings, 1 reply; 11+ messages in thread
From: H. Peter Anvin @ 2008-11-12 18:12 UTC (permalink / raw)
  To: Hiroshi Shimamoto
  Cc: Mikael Pettersson, Ingo Molnar, Thomas Gleixner, linux-kernel

Hiroshi Shimamoto wrote:
> H. Peter Anvin wrote:
>> Mikael Pettersson wrote:
>>> It does cause each signal delivery to leak 2 uninitialised
>>> kernel bytes to the end of retcode[], which seems unnecessary.
>> Not just unnecessary, it is a huge no-no for security.
> 
> Am I missing important thing?
> The frame->retcode is 8 bytes and packed structure with padding
> is 10 bytes each, and the code is copied to user stack 8 bytes only.
> 
> err |= __copy_to_user(frame->retcode, &code, 8);
> 
> I don't think the behavior is changed.
> 

Ah, nevermind, then.  Then it fine, obviously.

	-hpa

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

* Re: [PATCH 2/2] x86: ia32_signal: remove unnecessary padding
  2008-11-12 12:56   ` Andi Kleen
@ 2008-11-12 18:34     ` Hiroshi Shimamoto
  0 siblings, 0 replies; 11+ messages in thread
From: Hiroshi Shimamoto @ 2008-11-12 18:34 UTC (permalink / raw)
  To: Andi Kleen; +Cc: Ingo Molnar, Thomas Gleixner, H. Peter Anvin, linux-kernel

Andi Kleen wrote:
> Hiroshi Shimamoto <h-shimamoto@ct.jp.nec.com> writes:
> 
>> From: Hiroshi Shimamoto <h-shimamoto@ct.jp.nec.com>
>>
>> Impact: cleanup
> 
> Actually it's not a cleanup.
> 
>> Remove unnecessary paddings, this saves 4 bytes.
> 
> This might actually break code. The code is not actually used,
> but only kept around because some old gdb versions used this
> code as a marker for detecting signals.

I think, this cleanup doesn't change the code copied to user stack.
It removes additional 2 bytes from each struct, and these had not
been copied to user stack, because the structures were 10 bytes and
frame->retcode is 8 bytes.

Thanks,
Hiroshi Shimamoto

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

* Re: [PATCH 2/2] x86: ia32_signal: remove unnecessary padding
  2008-11-12 18:12           ` H. Peter Anvin
@ 2008-11-13  8:45             ` Mikael Pettersson
  2008-11-13 17:38               ` H. Peter Anvin
  0 siblings, 1 reply; 11+ messages in thread
From: Mikael Pettersson @ 2008-11-13  8:45 UTC (permalink / raw)
  To: H. Peter Anvin
  Cc: Hiroshi Shimamoto, Mikael Pettersson, Ingo Molnar,
	Thomas Gleixner, linux-kernel

H. Peter Anvin writes:
 > Hiroshi Shimamoto wrote:
 > > H. Peter Anvin wrote:
 > >> Mikael Pettersson wrote:
 > >>> It does cause each signal delivery to leak 2 uninitialised
 > >>> kernel bytes to the end of retcode[], which seems unnecessary.
 > >> Not just unnecessary, it is a huge no-no for security.
 > > 
 > > Am I missing important thing?
 > > The frame->retcode is 8 bytes and packed structure with padding
 > > is 10 bytes each, and the code is copied to user stack 8 bytes only.
 > > 
 > > err |= __copy_to_user(frame->retcode, &code, 8);
 > > 
 > > I don't think the behavior is changed.
 > > 
 > 
 > Ah, nevermind, then.  Then it fine, obviously.

Agreed. I wonder how on earth those templates ended
up as 10 bytes large when retcode[] always has been
8 bytes.

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

* Re: [PATCH 2/2] x86: ia32_signal: remove unnecessary padding
  2008-11-13  8:45             ` Mikael Pettersson
@ 2008-11-13 17:38               ` H. Peter Anvin
  0 siblings, 0 replies; 11+ messages in thread
From: H. Peter Anvin @ 2008-11-13 17:38 UTC (permalink / raw)
  To: Mikael Pettersson
  Cc: Hiroshi Shimamoto, Ingo Molnar, Thomas Gleixner, linux-kernel

Mikael Pettersson wrote:
>  > 
>  > Ah, nevermind, then.  Then it fine, obviously.
> 
> Agreed. I wonder how on earth those templates ended
> up as 10 bytes large when retcode[] always has been
> 8 bytes.

Probably someone added something and didn't adjust the padding.

	-hpa

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

end of thread, other threads:[~2008-11-13 17:39 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-11-12  3:09 [PATCH 1/2] x86: signal_32: introduce retcode and rt_retcode Hiroshi Shimamoto
2008-11-12  3:11 ` [PATCH 2/2] x86: ia32_signal: remove unnecessary padding Hiroshi Shimamoto
2008-11-12 11:29   ` Ingo Molnar
2008-11-12 12:33     ` Mikael Pettersson
2008-11-12 17:12       ` H. Peter Anvin
2008-11-12 18:02         ` Hiroshi Shimamoto
2008-11-12 18:12           ` H. Peter Anvin
2008-11-13  8:45             ` Mikael Pettersson
2008-11-13 17:38               ` H. Peter Anvin
2008-11-12 12:56   ` Andi Kleen
2008-11-12 18:34     ` Hiroshi Shimamoto

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).