Received: by 10.223.164.202 with SMTP id h10csp4659887wrb; Wed, 29 Nov 2017 09:44:10 -0800 (PST) X-Google-Smtp-Source: AGs4zMb2h7WU7pJHG+m2gdD4flF5KnJuHIjt0a8A62Mxxc2xnmXxdOqcieeQ/N8bBGlnqSVHZOjv X-Received: by 10.98.219.198 with SMTP id f189mr3859223pfg.44.1511977450691; Wed, 29 Nov 2017 09:44:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1511977450; cv=none; d=google.com; s=arc-20160816; b=Iq4GQMyzSVuF32308foPHyYd2JGzCdh3kpiBZenBwwmHz7cXFvFfrsIcW8L6mvuC05 aLWCcWCodrg7HyQ0ks0koL6UJa59uqW+ViF67MgaU3tvoIX3XVMgcUy9S8/81znD/B9y QGV/sFRTSZ84akdbDhRx20j1i9e6KJWcVLNONLbPTJHQGNDiVWDeBpIjqp1P1YxbwZnf G0sqVLOUhrQPg0tjuDzH6gEv2rI0hGytEfw/yTYumjSrv/edH7XpkMzVlmITvsl+xu8T K+V8YGlXfKrrX4E6xvSLiysI7YEsofehTeUFjdbmmPTqz5hJbPylnxjw4JmfaAzd4Ndg 26FQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=DzMXvz9V+syMGmEeV9/f5+OlMg0/RuIererx68f0/RE=; b=IKo/UTw2aTlLAdJv4s1i1SZLdLeRMGIBW6aOFoc7traAjNwcG/piS9PNJutwE7t8A3 1ZFjP6iFexQJg+NH76u104hclVANMVS0Aqw8k+l+AyveQGcYzdMdvJSG38tm461aJcwb UnMRaH8ofvnDpNWrROtpObqHoHabl3OG26eW28HO8+OQDoC7ZLHplWVl5/UFJbgWjuOa hHW4n+ISIia0UCiD61H6QdKvjPVid4bkEVLhQUBiLdNmI8a3yaNkXC/8OeOK6IZZk5Iv hZxsKk0nWdSoXr2aryxBsYggk6VZ3xMpDO17novz0ADgEpIgtYSSxLwx6kUDRAT+quSg FWBw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=oAOFEPDc; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f129si1541690pgc.792.2017.11.29.09.44.00; Wed, 29 Nov 2017 09:44:10 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=oAOFEPDc; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934763AbdK2Rmw (ORCPT + 70 others); Wed, 29 Nov 2017 12:42:52 -0500 Received: from mail-wm0-f66.google.com ([74.125.82.66]:46312 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934532AbdK2Rmr (ORCPT ); Wed, 29 Nov 2017 12:42:47 -0500 Received: by mail-wm0-f66.google.com with SMTP id r78so7997784wme.5; Wed, 29 Nov 2017 09:42:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=DzMXvz9V+syMGmEeV9/f5+OlMg0/RuIererx68f0/RE=; b=oAOFEPDcz8jlosW+w7RvxmgdGL5sVvqYynpGDd0mRr2xc7qth9hGGogZrem0hx1Y9g NTsCMJ37tnCYXqRNkcpNUpEfFLFL1s3pdFUOX/K5eImvPAvU65BJUsOCcQUruFlqZgC/ b6yR5nJfLpF1n2KZagMiS5/GrKTw4cKEqi0VbvDAHnMd5Jpj3COVBx5QVfUkX3D9/xBb ahLZ7kySqZLger/g9ayYbXeCZInCVkDL29G/s+Whu+dpecKb6SPTZa3hB9HElc+teypD 1rOlvvW2QLb5VWrqzZtbq/fSCfJfSX5eaU84uCNid+wiKWJS5wfcpcC1NyF5bvQVP0j4 WHcg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=DzMXvz9V+syMGmEeV9/f5+OlMg0/RuIererx68f0/RE=; b=eylAlOXPb5D51xL4Lq3/TyW8LgdaFEbCwF/laBB0fVTp+/QUVTELeXChGG0J2W2QUJ bCLQJIMzpQGSzvdI3ntIzOsCqDANKSrwQyN1S+6HCRTKyFE0vp6qO9l5XLnyQGicuCrP T1bnrO4ACXDup1uCsNhZk64NFVP5fNxgRfvswwHVkDq1JsVugThm+XndlCdJd6n7j8e1 JFuaQZ273AVQEaZNzxQdsIEbTUMmhlYBQd3ivHEpxshNRp+/Yz5O/rH7dYtymZRL37Hi jlZOI/1JOLOmtb10BT6gUfuHSZkd1mRcm2snTkZbXLaOEYs1Q/S3trKooNCuJMC8fS5C hVRQ== X-Gm-Message-State: AJaThX72Okx58eM6xrljZ0ToRK+NaGUcezG9VdEDc+HSD75kolsKmMHp wjoe5wcfKCAuu1W85pg1p1DZaDZk1Rm5YNHPosc= X-Received: by 10.80.144.112 with SMTP id z45mr8672351edz.185.1511977365510; Wed, 29 Nov 2017 09:42:45 -0800 (PST) MIME-Version: 1.0 Received: by 10.80.166.135 with HTTP; Wed, 29 Nov 2017 09:42:25 -0800 (PST) In-Reply-To: <20171129172100.28819-4-alexander.levin@verizon.com> References: <20171129172100.28819-1-alexander.levin@verizon.com> <20171129172100.28819-4-alexander.levin@verizon.com> From: Dmitry Safonov <0x7f454c46@gmail.com> Date: Wed, 29 Nov 2017 17:42:25 +0000 Message-ID: Subject: Re: [PATCH AUTOSEL for 4.9 04/52] x86/selftests: Add clobbers for int80 on x86_64 To: alexander.levin@verizon.com Cc: "linux-kernel@vger.kernel.org" , "stable@vger.kernel.org" , Dmitry Safonov , Borislav Petkov , Borislav Petkov , Brian Gerst , Denys Vlasenko , "H . Peter Anvin" , Josh Poimboeuf , Linus Torvalds , Peter Zijlstra , Shuah Khan , Thomas Gleixner , "linux-kselftest@vger.kernel.org" , Ingo Molnar Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Sasha, I would object including this to stable tree: 1. It's selftest fixup 2. I have never saw selftests failing because of it (but it's possible) I saw this in CRIU (Checkpoint Restore In Userspace) project triggering, so I've fixed the selftests, mostly for documentation reasons - as people in userspace can reuse this code and think it's good and will just work after copy-paste (which is not the case). So, this patch doesn't look urgent to include it in -stable kernel. Thanks, Dmitry 2017-11-29 17:21 GMT+00:00 : > From: Dmitry Safonov > > [ Upstream commit 2a4d0c627f5374f365a873dea4e10ae0bb437680 ] > > Kernel erases R8..R11 registers prior returning to userspace > from int80: > > https://lkml.org/lkml/2009/10/1/164 > > GCC can reuse these 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. Also, as noted by Andy - removed unneeded clobber > for flags in INT $0x80 inline asm. > > Signed-off-by: Dmitry Safonov > Acked-by: Andy Lutomirski > Cc: 0x7f454c46@gmail.com > Cc: Borislav Petkov > Cc: Borislav Petkov > Cc: Brian Gerst > Cc: Denys Vlasenko > Cc: H. Peter Anvin > Cc: Josh Poimboeuf > Cc: Linus Torvalds > Cc: Peter Zijlstra > Cc: Shuah Khan > Cc: Thomas Gleixner > Cc: linux-kselftest@vger.kernel.org > Link: http://lkml.kernel.org/r/20170213101336.20486-1-dsafonov@virtuozzo.com > Signed-off-by: Ingo Molnar > Signed-off-by: Sasha Levin > --- > tools/testing/selftests/x86/fsgsbase.c | 2 +- > 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 ++++- > 4 files changed, 18 insertions(+), 8 deletions(-) > > diff --git a/tools/testing/selftests/x86/fsgsbase.c b/tools/testing/selftests/x86/fsgsbase.c > index 9b4610c6d3fb..f249e042b3b5 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"); > + : "r8", "r9", "r10", "r11"); > memcpy(&desc, low_desc, sizeof(desc)); > munmap(low_desc, sizeof(desc)); > > diff --git a/tools/testing/selftests/x86/ldt_gdt.c b/tools/testing/selftests/x86/ldt_gdt.c > index e717fed80219..b9a22f18566a 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 "r8", "r9", "r10", "r11" > +#else > +# define INT80_CLOBBERS > +#endif > + > static int nerrs; > > /* Points to an array of 1024 ints, each holding its own index. */ > @@ -634,7 +640,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; > } > > @@ -703,7 +709,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"; > @@ -734,7 +740,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"; > @@ -767,7 +773,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); > @@ -820,7 +826,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.0 From 1591200310008017748@xxx Thu Feb 01 12:07:47 +0000 2018 X-GM-THRID: 1585583382079019320 X-Gmail-Labels: Inbox,Category Forums,Downloaded_2018-02