Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp68111imm; Thu, 11 Oct 2018 15:35:09 -0700 (PDT) X-Google-Smtp-Source: ACcGV62PLoIJi6mnp4CIG+CkRrd5kPMRV0/Hl/V4G6DiVMXZ6nCaSUx38NkgHa0f4+6yTrNE7TnL X-Received: by 2002:a63:5d03:: with SMTP id r3-v6mr3118764pgb.445.1539297309482; Thu, 11 Oct 2018 15:35:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539297309; cv=none; d=google.com; s=arc-20160816; b=H17w9gibZENOz+4Zxs8MvZXHKJrlYAV7ER2GhYwTdV6JUgMKqvunJhel8H+C0EjuPd zb2g7pKhyTIcvzqf4ggvdCoClvOP0s4UGM8EAqiOLG+ISBMmRIR2IR8LSgQMspud+Uni Js54UUANc/St2r1Z31/7ZJZfKvDk7dvcRX55AlnvAFh0N8yD6Cyn5eQZfG1QOSvvGqOh yGoqpBXLQTQcAe8J3lNi3eAO+dmwLB5IQrbGeL5DeecvRxyn97kQomDyEyIGv5V2gpYa O06/MK53rz8flZHax58jcGjbTjvcxDv50g3G6XXbvcghtzaipBKnYfBDjefM/ss5Yoia w5jA== 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=EqLujneTdnmTQ5hKSLWCKROAtig3zD/J87RP5C3+z50=; b=LabGHqKe0SW4hE4An647g8is1yEuFsV23tB7TP3Sqm4s1kfdpRJplAY8S8QoHgDasD JiD0j4hatdkCpYqIBU5l3DsrQTCiOOjGB4kUKqxqVPOvRdUtzW+duyCYNORMKqsBYeUG kpqyPvSbHKy1cN0nzP1Gp/iTUP52OA+30DlDDJLnh4PXDTqrDx91GEuErEbYbypASKVs MoKl1B74InSxsKehAK6FcpreYWykCy1jgQ90XZ/AM6jrOajwbIbi0FxCE9iTH9HWh7/I ijNNQoBPSZgG7VOb8EMtkSvH61lsJ9yZ2RIxzzXyte5hTNWrIcWqlGvIu7/9D9uJbq6s aFUA== 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 u12-v6si3485394pls.150.2018.10.11.15.34.45; Thu, 11 Oct 2018 15:35:09 -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 S1726887AbeJLGDc (ORCPT + 99 others); Fri, 12 Oct 2018 02:03:32 -0400 Received: from Galois.linutronix.de ([146.0.238.70]:48756 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725919AbeJLGDc (ORCPT ); Fri, 12 Oct 2018 02:03:32 -0400 Received: from p5492fe24.dip0.t-ipconnect.de ([84.146.254.36] helo=nanos) by Galois.linutronix.de with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1gAjWl-0003XH-Cb; Fri, 12 Oct 2018 00:33:55 +0200 Date: Fri, 12 Oct 2018 00:33:54 +0200 (CEST) From: Thomas Gleixner To: Kees Cook cc: Andy Lutomirski , Kristen Carlson Accardi , Kernel Hardening , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , X86 ML , LKML Subject: Re: [PATCH] x86: entry: flush the cache if syscall error In-Reply-To: Message-ID: References: <20181011185458.10186-1-kristen@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 Thu, 11 Oct 2018, Kees Cook wrote: > On Thu, Oct 11, 2018 at 1:48 PM, Andy Lutomirski wrote: > > On Thu, Oct 11, 2018 at 11:55 AM Kristen Carlson Accardi > >> +__visible inline void l1_cache_flush(struct pt_regs *regs) > >> +{ > >> + if (IS_ENABLED(CONFIG_SYSCALL_FLUSH) && > >> + static_cpu_has(X86_FEATURE_FLUSH_L1D)) { > >> + if (regs->ax == 0 || regs->ax == -EAGAIN || > >> + regs->ax == -EEXIST || regs->ax == -ENOENT || > >> + regs->ax == -EXDEV || regs->ax == -ETIMEDOUT || > >> + regs->ax == -ENOTCONN || regs->ax == -EINPROGRESS) > > > > What about ax > 0? (Or more generally, any ax outside the range of -1 > > .. -4095 or whatever the error range is.) As it stands, it looks like > > you'll flush on successful read(), write(), recv(), etc, and that > > could seriously hurt performance on real workloads. > > Seems like just changing this with "ax == 0" into "ax >= 0" would solve that? > > I think this looks like a good idea. It might be worth adding a > comment about the checks to explain why those errors are whitelisted. > It's a cheap and effective mitigation for "unknown future problems" > that doesn't degrade normal workloads. pt_regs->ax is unsigned long, so you want to check this with IS_ERR_VALUE() first. if (!IS_ERR_VALUE(regs->ax)) return; and then you really want to have something smarter than a gazillion of whitelisted error value checks, which effectively compile into a gazillion conditonal branches. Thanks, tglx