[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <d51d8e60-cb5f-fa97-a00c-9c6a2e42b42b@linuxfoundation.org>
Date: Fri, 29 May 2020 08:40:42 -0600
From: Shuah Khan <skhan@...uxfoundation.org>
To: Sasha Levin <sashal@...nel.org>, tglx@...utronix.de,
luto@...nel.org, ak@...ux.intel.com
Cc: corbet@....net, mingo@...hat.com, bp@...en8.de, x86@...nel.org,
shuah@...nel.org, gregkh@...uxfoundation.org, tony.luck@...el.com,
chang.seok.bae@...el.com, dave.hansen@...ux.intel.com,
peterz@...radead.org, linux-doc@...r.kernel.org,
linux-kernel@...r.kernel.org, jarkko.sakkinen@...ux.intel.com,
"H . Peter Anvin" <hpa@...or.com>,
Dave Hansen <dave.hansen@...el.com>,
Shuah Khan <skhan@...uxfoundation.org>
Subject: Re: [PATCH v13 15/16] selftests/x86/fsgsbase: Test GS selector on
ptracer-induced GS base write
On 5/28/20 2:14 PM, Sasha Levin wrote:
> From: "Chang S. Bae" <chang.seok.bae@...el.com>
>
> The test validates that the selector is not changed when a ptracer writes
> the ptracee's GS base.
>
> Originally-by: Andy Lutomirski <luto@...nel.org>
> Signed-off-by: Chang S. Bae <chang.seok.bae@...el.com>
> Reviewed-by: Tony Luck <tony.luck@...el.com>
> Cc: Thomas Gleixner <tglx@...utronix.de>
> Cc: Borislav Petkov <bp@...en8.de>
> Cc: Andy Lutomirski <luto@...nel.org>
> Cc: H. Peter Anvin <hpa@...or.com>
> Cc: Dave Hansen <dave.hansen@...el.com>
> Cc: Tony Luck <tony.luck@...el.com>
> Cc: Andi Kleen <ak@...ux.intel.com>
> Signed-off-by: Sasha Levin <sashal@...nel.org>
> ---
> tools/testing/selftests/x86/fsgsbase.c | 21 +++++++++++++++------
> 1 file changed, 15 insertions(+), 6 deletions(-)
>
> diff --git a/tools/testing/selftests/x86/fsgsbase.c b/tools/testing/selftests/x86/fsgsbase.c
> index 15a329da59fa..950a48b2e366 100644
> --- a/tools/testing/selftests/x86/fsgsbase.c
> +++ b/tools/testing/selftests/x86/fsgsbase.c
> @@ -465,7 +465,7 @@ static void test_ptrace_write_gsbase(void)
> wait(&status);
>
> if (WSTOPSIG(status) == SIGTRAP) {
> - unsigned long gs, base;
> + unsigned long gs;
> unsigned long gs_offset = USER_REGS_OFFSET(gs);
> unsigned long base_offset = USER_REGS_OFFSET(gs_base);
>
> @@ -481,7 +481,6 @@ static void test_ptrace_write_gsbase(void)
> err(1, "PTRACE_POKEUSER");
>
> gs = ptrace(PTRACE_PEEKUSER, child, gs_offset, NULL);
> - base = ptrace(PTRACE_PEEKUSER, child, base_offset, NULL);
>
> /*
> * In a non-FSGSBASE system, the nonzero selector will load
> @@ -489,11 +488,21 @@ static void test_ptrace_write_gsbase(void)
> * selector value is changed or not by the GSBASE write in
> * a ptracer.
> */
> - if (gs == 0 && base == 0xFF) {
> - printf("[OK]\tGS was reset as expected\n");
> - } else {
> + if (gs != *shared_scratch) {
> nerrs++;
> - printf("[FAIL]\tGS=0x%lx, GSBASE=0x%lx (should be 0, 0xFF)\n", gs, base);
> + printf("[FAIL]\tGS changed to %lx\n", gs);
> +
> + /*
> + * On older kernels, poking a nonzero value into the
> + * base would zero the selector. On newer kernels,
> + * this behavior has changed -- poking the base
> + * changes only the base and, if FSGSBASE is not
> + * available, this may not effect.
> + */
> + if (gs == 0)
> + printf("\tNote: this is expected behavior on older kernels.\n");
Let's add what is "this" for context in this message.
> + } else {
> + printf("[OK]\tGS remained 0x%hx\n", *shared_scratch);
> }
> }
>
>
thanks,
-- Shuah
Powered by blists - more mailing lists