Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp1648973ybi; Sat, 27 Jul 2019 15:00:58 -0700 (PDT) X-Google-Smtp-Source: APXvYqzJKWJnosesAJ6dM6XLXCmjBNYyxUA3e+z2t4cuctJblxnp3ersFTPsIG5XZRKj+XaTTKVb X-Received: by 2002:a17:902:4683:: with SMTP id p3mr94944394pld.31.1564264858341; Sat, 27 Jul 2019 15:00:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564264858; cv=none; d=google.com; s=arc-20160816; b=OeP0WsTeaGR67V5cjc1+esQtq0lx58fw+5gXgYPyk9q9kE6+PvYW1H6d0bm24Xrhei qoAR871DI4/f+upztllwRlATkl0zfIctsir8JameuJagUmIfuHlt9CXZ/HnzAWuYEbPM iwmdwARdgIHv6SuXY3s4NWB6nhZO2Y4w4twx5Q4wu5SlfM6UL/SDStAR0pJoLIUteTPC I572Tdcslc2LbyQtIKQy9Indr1SVsGEjaAi+Gyk4Qho/IAJ7FgSBPYzh1SCdhjCu3mfs wxXYA1ElKx0bBgT3Bnd67VF+eYEgPo/FSHig9x9VOke+HXpl7JJ/3FCACAYC9614vLFj GhYQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :message-id:in-reply-to:subject:cc:to:from:date; bh=c2DftF+Y4VQMITAd+ParBGjGysAulSdD9KFfeFkaGTQ=; b=N76wYHDUkDc2aAx26Es4+HJvZm1WYryCNQ3S9Sc4BSqVrMeCMyEhTDHLyWKZLzjH0f I29LDBuTOkqajYHJXrgSIgXtBvTepH87Qg3gl16uKnDKMxWppF7KqHp4kIcy8z0WKU6c 19l12afL1YVzHUvGBK/A+QyhCljs1nx7/oFRkqnI36HuzBkLtkwkAk6JlXn3ZCgKoJ3j f1r9Hn1yKzS1gHJ6CiQTvAUZmujARABbcT0FTiW/g+tcQnouZOSfWybZvD623z3gQ5m/ b1zoWl6fdFiXgXFO6O6eAn5k6oJmYEK7uldwbPivVL12HiVy1DQRnMSWoww/HThFc9di EvHA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l44si25667487pjb.23.2019.07.27.15.00.43; Sat, 27 Jul 2019 15:00:58 -0700 (PDT) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726546AbfG0Vwm (ORCPT + 99 others); Sat, 27 Jul 2019 17:52:42 -0400 Received: from Galois.linutronix.de ([193.142.43.55]:51199 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725265AbfG0Vwm (ORCPT ); Sat, 27 Jul 2019 17:52:42 -0400 Received: from pd9ef1cb8.dip0.t-ipconnect.de ([217.239.28.184] helo=nanos) by Galois.linutronix.de with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1hrUcE-0001Yp-1b; Sat, 27 Jul 2019 23:52:34 +0200 Date: Sat, 27 Jul 2019 23:52:32 +0200 (CEST) From: Thomas Gleixner To: Andy Lutomirski cc: Sean Christopherson , Kees Cook , Vincenzo Frascino , X86 ML , LKML , Paul Bolle , Arnd Bergmann Subject: Re: [5.2 REGRESSION] Generic vDSO breaks seccomp-enabled userspace on i386 In-Reply-To: Message-ID: References: <201907221012.41504DCD@keescook> <201907221135.2C2D262D8@keescook> <201907221620.F31B9A082@keescook> <201907231437.DB20BEBD3@keescook> <201907231636.AD3ED717D@keescook> <20190726180103.GE3188@linux.intel.com> User-Agent: Alpine 2.21 (DEB 202 2017-01-01) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Linutronix-Spam-Score: -1.0 X-Linutronix-Spam-Level: - X-Linutronix-Spam-Status: No , -1.0 points, 5.0 required, ALL_TRUSTED=-1,SHORTCIRCUIT=-0.0001 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, 27 Jul 2019, Thomas Gleixner wrote: > On Sat, 27 Jul 2019, Andy Lutomirski wrote: > > > > I think it's getting quite late to start inventing new seccomp > > features to fix this. I think the right solution for 5.3 is to change > > the 32-bit vdso fallback to use the old clock_gettime, i.e. > > clock_gettime32. This is obviously not an acceptable long-term > > solution. > > Sigh. I'll have a look.... Completely untested patch below. For the record: I have to say that I hate it. Just to be clear. Once a clever seccomp admin decides to enforce Y2038 compliance by filtering out the legacy syscalls this will force glibc into the syscall slowpath directly because __vdso_clock_gettime64() is gone. So this needs a proper secccomp solution soener than later. The fallback change to the legacy syscall is on purpose conditional on CONFIG_SECCOMP so those people who care can get access to __vdso_clock_gettime64() nevertheless. Thanks, tglx 8<----------------- --- a/arch/x86/entry/vdso/vdso32/vdso32.lds.S +++ b/arch/x86/entry/vdso/vdso32/vdso32.lds.S @@ -27,7 +27,9 @@ VERSION __vdso_gettimeofday; __vdso_time; __vdso_clock_getres; +#ifndef CONFIG_SECCOMP __vdso_clock_gettime64; +#endif }; LINUX_2.5 { --- a/arch/x86/include/asm/vdso/gettimeofday.h +++ b/arch/x86/include/asm/vdso/gettimeofday.h @@ -101,6 +101,7 @@ long clock_gettime_fallback(clockid_t _c { long ret; +#ifndef CONFIG_SECCOMP asm ( "mov %%ebx, %%edx \n" "mov %[clock], %%ebx \n" @@ -110,6 +111,36 @@ long clock_gettime_fallback(clockid_t _c : "0" (__NR_clock_gettime64), [clock] "g" (_clkid), "c" (_ts) : "edx"); +#else + struct old_timespec32 tmpts; + + /* + * Using clock_gettime and not clock_gettime64 here is a + * temporary workaround to pacify seccomp filters which are + * unaware of the Y2038 safe variant. + */ + + asm ( + "mov %%ebx, %%edx \n" + "mov %[clock], %%ebx \n" + "call __kernel_vsyscall \n" + "mov %%edx, %%ebx \n" + : "=a" (ret), "=m" (tmpts) + : "0" (__NR_clock_gettime), [clock] "g" (_clkid), "c" (&tmpts) + : "edx"); + + /* + * The core code will have to convert that back. A smart compiler + * should notice and avoid the double conversion. If not, bad luck; + * we we are not going to change the core code just to make seccomp + * happy. + */ + + if (!ret) { + _ts->tv_sec = tmpts.tv_sec; + _ts->tv_nsec = tmpts.tv_nsec; + } +#endif return ret; } @@ -136,6 +167,7 @@ clock_getres_fallback(clockid_t _clkid, { long ret; +#ifndef CONFIG_SECCOMP asm ( "mov %%ebx, %%edx \n" "mov %[clock], %%ebx \n" @@ -144,7 +176,32 @@ clock_getres_fallback(clockid_t _clkid, : "=a" (ret), "=m" (*_ts) : "0" (__NR_clock_getres_time64), [clock] "g" (_clkid), "c" (_ts) : "edx"); +#else + struct old_timespec32 tmpts; + + /* + * Using clock_getres and not clock_getres_time64 here is a + * temporary workaround to pacify seccomp filters which are unaware + * of the time64 variants. Technically there is no requirement to + * use the 64bit variant here as the resolution is definitely not + * affected by Y2038, but the end goal of Y2038 is to utilize the + * new 64bit timespec variants for everything. + */ + + asm ( + "mov %%ebx, %%edx \n" + "mov %[clock], %%ebx \n" + "call __kernel_vsyscall \n" + "mov %%edx, %%ebx \n" + : "=a" (ret), "=m" (tmpts) + : "0" (__NR_clock_getres), [clock] "g" (_clkid), "c" (&tmpts) + : "edx"); + if (!ret) { + _ts->tv_sec = tmpts.tv_sec; + _ts->tv_nsec = tmpts.tv_nsec; + } +#endif return ret; }