* [PATCH] x86/selftests: add clobbers for int80 on x86_64
@ 2017-02-10 11:52 Dmitry Safonov
2017-02-10 11:57 ` Dmitry Safonov
2017-02-10 16:13 ` Andy Lutomirski
0 siblings, 2 replies; 6+ messages in thread
From: Dmitry Safonov @ 2017-02-10 11:52 UTC (permalink / raw)
To: linux-kernel
Cc: 0x7f454c46, Dmitry Safonov, Shuah Khan, Thomas Gleixner,
Ingo Molnar, H. Peter Anvin, Andy Lutomirski, Borislav Petkov,
x86, linux-kselftest
Kernel erases R8..R11 registers prior returning to userspace
from int80: https://lkml.org/lkml/2009/10/1/164
GCC can reuse this registers and doesn't expect them to change
during syscall invocation. I met this kind of bug in CRIU once
gcc 6.1 and clang stored local variables in those registers
and the kernel zerofied them during syscall:
https://github.com/xemul/criu/commit/990d33f1a1cdd17bca6c2eb059ab3be2564f7fa2
By that reason I suggest to add those registers to clobbers
in selftests.
Cc: Shuah Khan <shuah@kernel.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Borislav Petkov <bp@suse.de>
Cc: x86@kernel.org
Cc: linux-kselftest@vger.kernel.org
Signed-off-by: Dmitry Safonov <dsafonov@virtuozzo.com>
---
tools/testing/selftests/x86/fsgsbase.c | 2 +-
tools/testing/selftests/x86/iopl.c | 10 ++++++++--
tools/testing/selftests/x86/ldt_gdt.c | 16 +++++++++++-----
tools/testing/selftests/x86/ptrace_syscall.c | 3 ++-
tools/testing/selftests/x86/single_step_syscall.c | 5 ++++-
5 files changed, 26 insertions(+), 10 deletions(-)
diff --git a/tools/testing/selftests/x86/fsgsbase.c b/tools/testing/selftests/x86/fsgsbase.c
index 5b2b4b3c634c..059b06b2d81d 100644
--- a/tools/testing/selftests/x86/fsgsbase.c
+++ b/tools/testing/selftests/x86/fsgsbase.c
@@ -245,7 +245,7 @@ void do_unexpected_base(void)
long ret;
asm volatile ("int $0x80"
: "=a" (ret) : "a" (243), "b" (low_desc)
- : "flags");
+ : "flags", "r8", "r9", "r10", "r11");
memcpy(&desc, low_desc, sizeof(desc));
munmap(low_desc, sizeof(desc));
diff --git a/tools/testing/selftests/x86/iopl.c b/tools/testing/selftests/x86/iopl.c
index c496ca97bc18..98236a233db8 100644
--- a/tools/testing/selftests/x86/iopl.c
+++ b/tools/testing/selftests/x86/iopl.c
@@ -19,6 +19,12 @@
#include <sched.h>
#include <sys/io.h>
+#ifdef __x86_64__
+# define INT80_CLOBBERS "r8", "r9", "r10", "r11"
+#else
+# define INT80_CLOBBERS
+#endif
+
static int nerrs = 0;
static void sethandler(int sig, void (*handler)(int, siginfo_t *, void *),
@@ -70,7 +76,7 @@ int main(void)
err(1, "iopl");
printf("[RUN]\tchild: write to 0x80\n");
- asm volatile ("outb %%al, $0x80" : : "a" (0));
+ asm volatile ("outb %%al, $0x80" : : "a" (0) : INT80_CLOBBERS);
return 0;
} else {
@@ -93,7 +99,7 @@ int main(void)
if (sigsetjmp(jmpbuf, 1) != 0) {
printf("[OK]\twrite was denied\n");
} else {
- asm volatile ("outb %%al, $0x80" : : "a" (0));
+ asm volatile ("outb %%al, $0x80" : : "a" (0) : INT80_CLOBBERS);
printf("[FAIL]\twrite was allowed\n");
nerrs++;
}
diff --git a/tools/testing/selftests/x86/ldt_gdt.c b/tools/testing/selftests/x86/ldt_gdt.c
index 4af47079cf04..dfdabd1f3083 100644
--- a/tools/testing/selftests/x86/ldt_gdt.c
+++ b/tools/testing/selftests/x86/ldt_gdt.c
@@ -45,6 +45,12 @@
#define AR_DB (1 << 22)
#define AR_G (1 << 23)
+#ifdef __x86_64__
+# define INT80_CLOBBERS "flags", "r8", "r9", "r10", "r11"
+#else
+# define INT80_CLOBBERS "flags"
+#endif
+
static int nerrs;
/* Points to an array of 1024 ints, each holding its own index. */
@@ -588,7 +594,7 @@ static int invoke_set_thread_area(void)
asm volatile ("int $0x80"
: "=a" (ret), "+m" (low_user_desc) :
"a" (243), "b" (low_user_desc)
- : "flags");
+ : INT80_CLOBBERS);
return ret;
}
@@ -657,7 +663,7 @@ static void test_gdt_invalidation(void)
"+a" (eax)
: "m" (low_user_desc_clear),
[arg1] "r" ((unsigned int)(unsigned long)low_user_desc_clear)
- : "flags");
+ : INT80_CLOBBERS);
if (sel != 0) {
result = "FAIL";
@@ -688,7 +694,7 @@ static void test_gdt_invalidation(void)
"+a" (eax)
: "m" (low_user_desc_clear),
[arg1] "r" ((unsigned int)(unsigned long)low_user_desc_clear)
- : "flags");
+ : INT80_CLOBBERS);
if (sel != 0) {
result = "FAIL";
@@ -721,7 +727,7 @@ static void test_gdt_invalidation(void)
"+a" (eax)
: "m" (low_user_desc_clear),
[arg1] "r" ((unsigned int)(unsigned long)low_user_desc_clear)
- : "flags");
+ : INT80_CLOBBERS);
#ifdef __x86_64__
syscall(SYS_arch_prctl, ARCH_GET_FS, &new_base);
@@ -774,7 +780,7 @@ static void test_gdt_invalidation(void)
"+a" (eax)
: "m" (low_user_desc_clear),
[arg1] "r" ((unsigned int)(unsigned long)low_user_desc_clear)
- : "flags");
+ : INT80_CLOBBERS);
#ifdef __x86_64__
syscall(SYS_arch_prctl, ARCH_GET_GS, &new_base);
diff --git a/tools/testing/selftests/x86/ptrace_syscall.c b/tools/testing/selftests/x86/ptrace_syscall.c
index b037ce9cf116..eaea92439708 100644
--- a/tools/testing/selftests/x86/ptrace_syscall.c
+++ b/tools/testing/selftests/x86/ptrace_syscall.c
@@ -58,7 +58,8 @@ static void do_full_int80(struct syscall_args32 *args)
asm volatile ("int $0x80"
: "+a" (args->nr),
"+b" (args->arg0), "+c" (args->arg1), "+d" (args->arg2),
- "+S" (args->arg3), "+D" (args->arg4), "+r" (bp));
+ "+S" (args->arg3), "+D" (args->arg4), "+r" (bp)
+ : : "r8", "r9", "r10", "r11");
args->arg5 = bp;
#else
sys32_helper(args, int80_and_ret);
diff --git a/tools/testing/selftests/x86/single_step_syscall.c b/tools/testing/selftests/x86/single_step_syscall.c
index 50c26358e8b7..a48da95c18fd 100644
--- a/tools/testing/selftests/x86/single_step_syscall.c
+++ b/tools/testing/selftests/x86/single_step_syscall.c
@@ -56,9 +56,11 @@ static volatile sig_atomic_t sig_traps;
#ifdef __x86_64__
# define REG_IP REG_RIP
# define WIDTH "q"
+# define INT80_CLOBBERS "r8", "r9", "r10", "r11"
#else
# define REG_IP REG_EIP
# define WIDTH "l"
+# define INT80_CLOBBERS
#endif
static unsigned long get_eflags(void)
@@ -140,7 +142,8 @@ int main()
printf("[RUN]\tSet TF and check int80\n");
set_eflags(get_eflags() | X86_EFLAGS_TF);
- asm volatile ("int $0x80" : "=a" (tmp) : "a" (SYS_getpid));
+ asm volatile ("int $0x80" : "=a" (tmp) : "a" (SYS_getpid)
+ : INT80_CLOBBERS);
check_result();
/*
--
2.11.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] x86/selftests: add clobbers for int80 on x86_64
2017-02-10 11:52 [PATCH] x86/selftests: add clobbers for int80 on x86_64 Dmitry Safonov
@ 2017-02-10 11:57 ` Dmitry Safonov
2017-02-10 16:13 ` Andy Lutomirski
1 sibling, 0 replies; 6+ messages in thread
From: Dmitry Safonov @ 2017-02-10 11:57 UTC (permalink / raw)
To: linux-kernel
Cc: 0x7f454c46, Shuah Khan, Thomas Gleixner, Ingo Molnar,
H. Peter Anvin, Andy Lutomirski, Borislav Petkov, x86,
linux-kselftest
On 02/10/2017 02:52 PM, Dmitry Safonov wrote:
> Kernel erases R8..R11 registers prior returning to userspace
> from int80: https://lkml.org/lkml/2009/10/1/164
>
> GCC can reuse this registers and doesn't expect them to change
> during syscall invocation. I met this kind of bug in CRIU once
> gcc 6.1 and clang stored local variables in those registers
> and the kernel zerofied them during syscall:
> https://github.com/xemul/criu/commit/990d33f1a1cdd17bca6c2eb059ab3be2564f7fa2
>
> By that reason I suggest to add those registers to clobbers
> in selftests.
>
> Cc: Shuah Khan <shuah@kernel.org>
> Cc: Thomas Gleixner <tglx@linutronix.de>
> Cc: Ingo Molnar <mingo@redhat.com>
> Cc: "H. Peter Anvin" <hpa@zytor.com>
> Cc: Andy Lutomirski <luto@kernel.org>
> Cc: Borislav Petkov <bp@suse.de>
> Cc: x86@kernel.org
> Cc: linux-kselftest@vger.kernel.org
> Signed-off-by: Dmitry Safonov <dsafonov@virtuozzo.com>
> ---
> tools/testing/selftests/x86/fsgsbase.c | 2 +-
> tools/testing/selftests/x86/iopl.c | 10 ++++++++--
Drop this one: iopl doesn't do int80 - it's my failure in grepping.
Will resend.
> tools/testing/selftests/x86/ldt_gdt.c | 16 +++++++++++-----
> tools/testing/selftests/x86/ptrace_syscall.c | 3 ++-
> tools/testing/selftests/x86/single_step_syscall.c | 5 ++++-
> 5 files changed, 26 insertions(+), 10 deletions(-)
>
--
Dmitry
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] x86/selftests: add clobbers for int80 on x86_64
2017-02-10 11:52 [PATCH] x86/selftests: add clobbers for int80 on x86_64 Dmitry Safonov
2017-02-10 11:57 ` Dmitry Safonov
@ 2017-02-10 16:13 ` Andy Lutomirski
2017-02-10 16:28 ` Dmitry Safonov
1 sibling, 1 reply; 6+ messages in thread
From: Andy Lutomirski @ 2017-02-10 16:13 UTC (permalink / raw)
To: Dmitry Safonov
Cc: linux-kernel, Dmitry Safonov, Shuah Khan, Thomas Gleixner,
Ingo Molnar, H. Peter Anvin, Andy Lutomirski, Borislav Petkov,
X86 ML, open list:KERNEL SELFTEST FRAMEWORK
On Fri, Feb 10, 2017 at 3:52 AM, Dmitry Safonov <dsafonov@virtuozzo.com> wrote:
> Kernel erases R8..R11 registers prior returning to userspace
> from int80: https://lkml.org/lkml/2009/10/1/164
>
> GCC can reuse this registers and doesn't expect them to change
> during syscall invocation. I met this kind of bug in CRIU once
> gcc 6.1 and clang stored local variables in those registers
> and the kernel zerofied them during syscall:
> https://github.com/xemul/criu/commit/990d33f1a1cdd17bca6c2eb059ab3be2564f7fa2
>
> By that reason I suggest to add those registers to clobbers
> in selftests.
Seems reasonable, but presumably INT80_CLOBBERS should be defined the
same way in all the tests. IOW, if the "flags" clobber is actually
needed, it should be "flags", INT80_CLOBBERS (possibly without the
comma if it's problematic).
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] x86/selftests: add clobbers for int80 on x86_64
2017-02-10 16:13 ` Andy Lutomirski
@ 2017-02-10 16:28 ` Dmitry Safonov
2017-02-10 16:45 ` Andy Lutomirski
0 siblings, 1 reply; 6+ messages in thread
From: Dmitry Safonov @ 2017-02-10 16:28 UTC (permalink / raw)
To: Andy Lutomirski
Cc: linux-kernel, Dmitry Safonov, Shuah Khan, Thomas Gleixner,
Ingo Molnar, H. Peter Anvin, Andy Lutomirski, Borislav Petkov,
X86 ML, open list:KERNEL SELFTEST FRAMEWORK
On 02/10/2017 07:13 PM, Andy Lutomirski wrote:
> On Fri, Feb 10, 2017 at 3:52 AM, Dmitry Safonov <dsafonov@virtuozzo.com> wrote:
>> Kernel erases R8..R11 registers prior returning to userspace
>> from int80: https://lkml.org/lkml/2009/10/1/164
>>
>> GCC can reuse this registers and doesn't expect them to change
>> during syscall invocation. I met this kind of bug in CRIU once
>> gcc 6.1 and clang stored local variables in those registers
>> and the kernel zerofied them during syscall:
>> https://github.com/xemul/criu/commit/990d33f1a1cdd17bca6c2eb059ab3be2564f7fa2
>>
>> By that reason I suggest to add those registers to clobbers
>> in selftests.
>
> Seems reasonable, but presumably INT80_CLOBBERS should be defined the
> same way in all the tests. IOW, if the "flags" clobber is actually
> needed, it should be "flags", INT80_CLOBBERS (possibly without the
> comma if it's problematic).
>
Well, that was my initial attempt: I've defined it as:
+# define INT80_CLOBBERS , "r8", "r9", "r10", "r11"
But that hanging comma looks awful, so I added "flags" there.
And if I do define it without coma and leave it in asm statement,
32-bit version would be unhappy.
So, I found that it's easier to define it with flags included.
--
Dmitry
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] x86/selftests: add clobbers for int80 on x86_64
2017-02-10 16:28 ` Dmitry Safonov
@ 2017-02-10 16:45 ` Andy Lutomirski
2017-02-10 17:11 ` Dmitry Safonov
0 siblings, 1 reply; 6+ messages in thread
From: Andy Lutomirski @ 2017-02-10 16:45 UTC (permalink / raw)
To: Dmitry Safonov
Cc: linux-kernel, Dmitry Safonov, Shuah Khan, Thomas Gleixner,
Ingo Molnar, H. Peter Anvin, Andy Lutomirski, Borislav Petkov,
X86 ML, open list:KERNEL SELFTEST FRAMEWORK
On Fri, Feb 10, 2017 at 8:28 AM, Dmitry Safonov <dsafonov@virtuozzo.com> wrote:
> On 02/10/2017 07:13 PM, Andy Lutomirski wrote:
>>
>> On Fri, Feb 10, 2017 at 3:52 AM, Dmitry Safonov <dsafonov@virtuozzo.com>
>> wrote:
>>>
>>> Kernel erases R8..R11 registers prior returning to userspace
>>> from int80: https://lkml.org/lkml/2009/10/1/164
>>>
>>> GCC can reuse this registers and doesn't expect them to change
>>> during syscall invocation. I met this kind of bug in CRIU once
>>> gcc 6.1 and clang stored local variables in those registers
>>> and the kernel zerofied them during syscall:
>>>
>>> https://github.com/xemul/criu/commit/990d33f1a1cdd17bca6c2eb059ab3be2564f7fa2
>>>
>>> By that reason I suggest to add those registers to clobbers
>>> in selftests.
>>
>>
>> Seems reasonable, but presumably INT80_CLOBBERS should be defined the
>> same way in all the tests. IOW, if the "flags" clobber is actually
>> needed, it should be "flags", INT80_CLOBBERS (possibly without the
>> comma if it's problematic).
>>
>
> Well, that was my initial attempt: I've defined it as:
> +# define INT80_CLOBBERS , "r8", "r9", "r10", "r11"
>
> But that hanging comma looks awful, so I added "flags" there.
> And if I do define it without coma and leave it in asm statement,
> 32-bit version would be unhappy.
> So, I found that it's easier to define it with flags included.
>
Woudl the right answer be to get rid of "flags" in the test where it
appears? I'm not sure it's needed in the first place.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] x86/selftests: add clobbers for int80 on x86_64
2017-02-10 16:45 ` Andy Lutomirski
@ 2017-02-10 17:11 ` Dmitry Safonov
0 siblings, 0 replies; 6+ messages in thread
From: Dmitry Safonov @ 2017-02-10 17:11 UTC (permalink / raw)
To: Andy Lutomirski
Cc: linux-kernel, Dmitry Safonov, Shuah Khan, Thomas Gleixner,
Ingo Molnar, H. Peter Anvin, Andy Lutomirski, Borislav Petkov,
X86 ML, open list:KERNEL SELFTEST FRAMEWORK
On 02/10/2017 07:45 PM, Andy Lutomirski wrote:
> On Fri, Feb 10, 2017 at 8:28 AM, Dmitry Safonov <dsafonov@virtuozzo.com> wrote:
>> On 02/10/2017 07:13 PM, Andy Lutomirski wrote:
>>>
>>> On Fri, Feb 10, 2017 at 3:52 AM, Dmitry Safonov <dsafonov@virtuozzo.com>
>>> wrote:
>>>>
>>>> Kernel erases R8..R11 registers prior returning to userspace
>>>> from int80: https://lkml.org/lkml/2009/10/1/164
>>>>
>>>> GCC can reuse this registers and doesn't expect them to change
>>>> during syscall invocation. I met this kind of bug in CRIU once
>>>> gcc 6.1 and clang stored local variables in those registers
>>>> and the kernel zerofied them during syscall:
>>>>
>>>> https://github.com/xemul/criu/commit/990d33f1a1cdd17bca6c2eb059ab3be2564f7fa2
>>>>
>>>> By that reason I suggest to add those registers to clobbers
>>>> in selftests.
>>>
>>>
>>> Seems reasonable, but presumably INT80_CLOBBERS should be defined the
>>> same way in all the tests. IOW, if the "flags" clobber is actually
>>> needed, it should be "flags", INT80_CLOBBERS (possibly without the
>>> comma if it's problematic).
>>>
>>
>> Well, that was my initial attempt: I've defined it as:
>> +# define INT80_CLOBBERS , "r8", "r9", "r10", "r11"
>>
>> But that hanging comma looks awful, so I added "flags" there.
>> And if I do define it without coma and leave it in asm statement,
>> 32-bit version would be unhappy.
>> So, I found that it's easier to define it with flags included.
>>
>
> Woudl the right answer be to get rid of "flags" in the test where it
> appears? I'm not sure it's needed in the first place.
>
I think it can live without it.
But I didn't want to change it in the same patch and wasn't sure if I
fail to see the reason for it.
So, I'll resend with flags removing, thanks.
--
Dmitry
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2017-02-10 18:54 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-02-10 11:52 [PATCH] x86/selftests: add clobbers for int80 on x86_64 Dmitry Safonov
2017-02-10 11:57 ` Dmitry Safonov
2017-02-10 16:13 ` Andy Lutomirski
2017-02-10 16:28 ` Dmitry Safonov
2017-02-10 16:45 ` Andy Lutomirski
2017-02-10 17:11 ` Dmitry Safonov
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.