linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] x86/signal: fix restart_syscall number for x32 tasks
@ 2015-11-30 21:54 Dmitry V. Levin
  2015-12-05 17:55 ` [tip:x86/urgent] x86/signal: Fix " tip-bot for Dmitry V. Levin
  0 siblings, 1 reply; 5+ messages in thread
From: Dmitry V. Levin @ 2015-11-30 21:54 UTC (permalink / raw)
  To: Thomas Gleixner, Ingo Molnar, H. Peter Anvin
  Cc: Elvira Khabirova, x86, linux-kernel

When restarting a syscall with regs->ax == -ERESTART_RESTARTBLOCK,
regs->ax is assigned to a restart_syscall number.  For x32 tasks,
this syscall number must have __X32_SYSCALL_BIT set, otherwise it
will be an x86_64 syscall number instead of a valid x32 syscall number.

Reported-by: strace/tests/restart_syscall.test
Reported-and-tested-by: Elvira Khabirova <lineprinter0@gmail.com>
Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
Cc: stable@vger.kernel.org
---
 arch/x86/kernel/signal.c | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
index b7ffb7c..cb6282c 100644
--- a/arch/x86/kernel/signal.c
+++ b/arch/x86/kernel/signal.c
@@ -690,12 +690,15 @@ handle_signal(struct ksignal *ksig, struct pt_regs *regs)
 	signal_setup_done(failed, ksig, stepping);
 }
 
-#ifdef CONFIG_X86_32
-#define NR_restart_syscall	__NR_restart_syscall
-#else /* !CONFIG_X86_32 */
-#define NR_restart_syscall	\
-	test_thread_flag(TIF_IA32) ? __NR_ia32_restart_syscall : __NR_restart_syscall
-#endif /* CONFIG_X86_32 */
+static inline unsigned long get_nr_restart_syscall(const struct pt_regs *regs)
+{
+#if defined(CONFIG_X86_32) || !defined(CONFIG_X86_64)
+	return __NR_restart_syscall;
+#else /* !CONFIG_X86_32 && CONFIG_X86_64 */
+	return test_thread_flag(TIF_IA32) ? __NR_ia32_restart_syscall :
+		__NR_restart_syscall | (regs->orig_ax & __X32_SYSCALL_BIT);
+#endif /* CONFIG_X86_32 || !CONFIG_X86_64 */
+}
 
 /*
  * Note that 'init' is a special process: it doesn't get signals it doesn't
@@ -724,7 +727,7 @@ void do_signal(struct pt_regs *regs)
 			break;
 
 		case -ERESTART_RESTARTBLOCK:
-			regs->ax = NR_restart_syscall;
+			regs->ax = get_nr_restart_syscall(regs);
 			regs->ip -= 2;
 			break;
 		}
-- 
ldv

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

* [tip:x86/urgent] x86/signal: Fix restart_syscall number for x32 tasks
  2015-11-30 21:54 [PATCH] x86/signal: fix restart_syscall number for x32 tasks Dmitry V. Levin
@ 2015-12-05 17:55 ` tip-bot for Dmitry V. Levin
  0 siblings, 0 replies; 5+ messages in thread
From: tip-bot for Dmitry V. Levin @ 2015-12-05 17:55 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: mingo, ldv, hpa, tglx, linux-kernel, lineprinter0

Commit-ID:  22eab1108781eff09961ae7001704f7bd8fb1dce
Gitweb:     http://git.kernel.org/tip/22eab1108781eff09961ae7001704f7bd8fb1dce
Author:     Dmitry V. Levin <ldv@altlinux.org>
AuthorDate: Tue, 1 Dec 2015 00:54:36 +0300
Committer:  Thomas Gleixner <tglx@linutronix.de>
CommitDate: Sat, 5 Dec 2015 18:52:14 +0100

x86/signal: Fix restart_syscall number for x32 tasks

When restarting a syscall with regs->ax == -ERESTART_RESTARTBLOCK,
regs->ax is assigned to a restart_syscall number.  For x32 tasks, this
syscall number must have __X32_SYSCALL_BIT set, otherwise it will be
an x86_64 syscall number instead of a valid x32 syscall number. This
issue has been there since the introduction of x32.

Reported-by: strace/tests/restart_syscall.test
Reported-and-tested-by: Elvira Khabirova <lineprinter0@gmail.com>
Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
Cc: Elvira Khabirova <lineprinter0@gmail.com>
Cc: stable@vger.kernel.org
Link: http://lkml.kernel.org/r/20151130215436.GA25996@altlinux.org
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
---
 arch/x86/kernel/signal.c | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
index b7ffb7c..cb6282c 100644
--- a/arch/x86/kernel/signal.c
+++ b/arch/x86/kernel/signal.c
@@ -690,12 +690,15 @@ handle_signal(struct ksignal *ksig, struct pt_regs *regs)
 	signal_setup_done(failed, ksig, stepping);
 }
 
-#ifdef CONFIG_X86_32
-#define NR_restart_syscall	__NR_restart_syscall
-#else /* !CONFIG_X86_32 */
-#define NR_restart_syscall	\
-	test_thread_flag(TIF_IA32) ? __NR_ia32_restart_syscall : __NR_restart_syscall
-#endif /* CONFIG_X86_32 */
+static inline unsigned long get_nr_restart_syscall(const struct pt_regs *regs)
+{
+#if defined(CONFIG_X86_32) || !defined(CONFIG_X86_64)
+	return __NR_restart_syscall;
+#else /* !CONFIG_X86_32 && CONFIG_X86_64 */
+	return test_thread_flag(TIF_IA32) ? __NR_ia32_restart_syscall :
+		__NR_restart_syscall | (regs->orig_ax & __X32_SYSCALL_BIT);
+#endif /* CONFIG_X86_32 || !CONFIG_X86_64 */
+}
 
 /*
  * Note that 'init' is a special process: it doesn't get signals it doesn't
@@ -724,7 +727,7 @@ void do_signal(struct pt_regs *regs)
 			break;
 
 		case -ERESTART_RESTARTBLOCK:
-			regs->ax = NR_restart_syscall;
+			regs->ax = get_nr_restart_syscall(regs);
 			regs->ip -= 2;
 			break;
 		}

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

* Re: [PATCH] x86/signal: fix restart_syscall number for x32 tasks
  2015-12-13  3:44 ` Dmitry V. Levin
@ 2015-12-17 20:27   ` Andy Lutomirski
  0 siblings, 0 replies; 5+ messages in thread
From: Andy Lutomirski @ 2015-12-17 20:27 UTC (permalink / raw)
  To: Dmitry V. Levin; +Cc: X86 ML, linux-kernel, Elvira Khabirova

On Sat, Dec 12, 2015 at 7:44 PM, Dmitry V. Levin <ldv@altlinux.org> wrote:
> On Mon, Dec 07, 2015 at 03:22:06PM -0800, Andy Lutomirski wrote:
>> [not real reply because I'm using a bad internet connection right now
>> and I'm not set up with my usual Gmane reply hack right now]
>>
>> The new code is (whitespace-damaged):
>>
>> static inline unsigned long get_nr_restart_syscall(const struct pt_regs *regs)
>> {
>> #if defined(CONFIG_X86_32) || !defined(CONFIG_X86_64)
>>  return __NR_restart_syscall;
>> #else /* !CONFIG_X86_32 && CONFIG_X86_64 */
>>  return test_thread_flag(TIF_IA32) ? __NR_ia32_restart_syscall :
>>  __NR_restart_syscall | (regs->orig_ax & __X32_SYSCALL_BIT);
>> #endif /* CONFIG_X86_32 || !CONFIG_X86_64 */
>> }
>>
>> This is IMO awful.  This use of TIF_IA32 is wrong, and this is
>> otherwise gross.  Can we do it for real:
>>
>> if (is_ia32_task())
>>   return __NR_ia32_restart_syscall;
>> else
>>   return __NR_restart_syscall | (regs->orig_ax & __X32_SYSCALL_BIT);
>> /* preserve x32 bit */
>>
>> I'd send the patch myself, but you apparently have a good test case
>> for this, and I don't.
>
> Unfortunately, this won't compile on CONFIG_X86_32 because
> __NR_ia32_restart_syscall is defined for CONFIG_X86_64 only.
>
> Something like this should work:
>
> static inline unsigned long get_nr_restart_syscall(const struct pt_regs *regs)
> {
> #ifdef CONFIG_X86_64
>         if (is_ia32_task())
>                 return __NR_ia32_restart_syscall;
> # ifdef CONFIG_X86_X32_ABI
>         if (regs->orig_ax & __X32_SYSCALL_BIT)
>                 return __NR_restart_syscall | __X32_SYSCALL_BIT;
> # endif
> #endif
>         return __NR_restart_syscall;
> }

Looks good to me.  Want to send a patch?

--Andy

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

* Re: [PATCH] x86/signal: fix restart_syscall number for x32 tasks
  2015-12-07 23:22 [PATCH] x86/signal: fix " Andy Lutomirski
@ 2015-12-13  3:44 ` Dmitry V. Levin
  2015-12-17 20:27   ` Andy Lutomirski
  0 siblings, 1 reply; 5+ messages in thread
From: Dmitry V. Levin @ 2015-12-13  3:44 UTC (permalink / raw)
  To: Andy Lutomirski; +Cc: X86 ML, linux-kernel, Elvira Khabirova

On Mon, Dec 07, 2015 at 03:22:06PM -0800, Andy Lutomirski wrote:
> [not real reply because I'm using a bad internet connection right now
> and I'm not set up with my usual Gmane reply hack right now]
> 
> The new code is (whitespace-damaged):
> 
> static inline unsigned long get_nr_restart_syscall(const struct pt_regs *regs)
> {
> #if defined(CONFIG_X86_32) || !defined(CONFIG_X86_64)
>  return __NR_restart_syscall;
> #else /* !CONFIG_X86_32 && CONFIG_X86_64 */
>  return test_thread_flag(TIF_IA32) ? __NR_ia32_restart_syscall :
>  __NR_restart_syscall | (regs->orig_ax & __X32_SYSCALL_BIT);
> #endif /* CONFIG_X86_32 || !CONFIG_X86_64 */
> }
> 
> This is IMO awful.  This use of TIF_IA32 is wrong, and this is
> otherwise gross.  Can we do it for real:
> 
> if (is_ia32_task())
>   return __NR_ia32_restart_syscall;
> else
>   return __NR_restart_syscall | (regs->orig_ax & __X32_SYSCALL_BIT);
> /* preserve x32 bit */
> 
> I'd send the patch myself, but you apparently have a good test case
> for this, and I don't.

Unfortunately, this won't compile on CONFIG_X86_32 because
__NR_ia32_restart_syscall is defined for CONFIG_X86_64 only.

Something like this should work:

static inline unsigned long get_nr_restart_syscall(const struct pt_regs *regs)
{
#ifdef CONFIG_X86_64
	if (is_ia32_task())
		return __NR_ia32_restart_syscall;
# ifdef CONFIG_X86_X32_ABI
	if (regs->orig_ax & __X32_SYSCALL_BIT)
		return __NR_restart_syscall | __X32_SYSCALL_BIT;
# endif
#endif
	return __NR_restart_syscall;
}

I don't see any way to avoid ifdefs here, sorry.


-- 
ldv

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

* Re: [PATCH] x86/signal: fix restart_syscall number for x32 tasks
@ 2015-12-07 23:22 Andy Lutomirski
  2015-12-13  3:44 ` Dmitry V. Levin
  0 siblings, 1 reply; 5+ messages in thread
From: Andy Lutomirski @ 2015-12-07 23:22 UTC (permalink / raw)
  To: X86 ML, linux-kernel, Dmitry V. Levin, lvira Khabirova

[not real reply because I'm using a bad internet connection right now
and I'm not set up with my usual Gmane reply hack right now]

The new code is (whitespace-damaged):

static inline unsigned long get_nr_restart_syscall(const struct pt_regs *regs)
{
#if defined(CONFIG_X86_32) || !defined(CONFIG_X86_64)
 return __NR_restart_syscall;
#else /* !CONFIG_X86_32 && CONFIG_X86_64 */
 return test_thread_flag(TIF_IA32) ? __NR_ia32_restart_syscall :
 __NR_restart_syscall | (regs->orig_ax & __X32_SYSCALL_BIT);
#endif /* CONFIG_X86_32 || !CONFIG_X86_64 */
}

This is IMO awful.  This use of TIF_IA32 is wrong, and this is
otherwise gross.  Can we do it for real:

if (is_ia32_task())
  return __NR_ia32_restart_syscall;
else
  return __NR_restart_syscall | (regs->orig_ax & __X32_SYSCALL_BIT);
/* preserve x32 bit */

I'd send the patch myself, but you apparently have a good test case
for this, and I don't.

(this isn't a regression, and I'm not suggesting any change for 4.4 or
for stable.  But for 4.5, can we do it right, please?)

And yes, I'll send a patch to rename is_ia32_task, but that's orthogonal.

--Andy

P.S. I'm still hoping to kill TIF_IA32 entirely some time soon.

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

end of thread, other threads:[~2015-12-17 20:27 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-11-30 21:54 [PATCH] x86/signal: fix restart_syscall number for x32 tasks Dmitry V. Levin
2015-12-05 17:55 ` [tip:x86/urgent] x86/signal: Fix " tip-bot for Dmitry V. Levin
2015-12-07 23:22 [PATCH] x86/signal: fix " Andy Lutomirski
2015-12-13  3:44 ` Dmitry V. Levin
2015-12-17 20:27   ` Andy Lutomirski

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).