Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp2585120imm; Thu, 11 Oct 2018 12:40:22 -0700 (PDT) X-Google-Smtp-Source: ACcGV61vtBAoRszg/Dj4ucGw5YV9CnMGuUXvKyXP4r954GZlaaLlyAhLtJKUj1isim73u/pq7bpb X-Received: by 2002:a17:902:7842:: with SMTP id e2-v6mr2833047pln.104.1539286822200; Thu, 11 Oct 2018 12:40:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539286822; cv=none; d=google.com; s=arc-20160816; b=kEqL8NEN4gZRozicfOOQXw3dtvWswCpWn1PXP0idJSyzqwzVw4mcAtOxd0SLOzk7LB gD08Oe+Zwbq1YB8xkdN08+uDaFl61sRQMgp9TValoX0DV/rwuhyFgiQjVcM5dwhnlVvf M280TLMusKz+m+hgDpc6Jcjz/78+9ruKKzOsGlaamfGCR9GvK14rm9DDCYDLyNZ53q0j 2TlU7lFryFlrXyyCTqS3QO57/O54SQ02myw8qQ9KRHHfKqO2SJpWtEanczGc3VPCsKiT p10UAdUQC7iFr2b1hBiFLdhV+GvF5sJHeRKiL7nHCHubiFaQUCbcog0gHxVAFm6zuBgF AM1Q== 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 :in-reply-to:references:mime-version:dkim-signature; bh=UxsTRqCwGVc/2uRbvHxAGmyi9A1utpFpzeNLnYTwFq4=; b=z46meaR0J71kiAI2lQd/i72WGIEjuqcssRsr4ZuCz5vWBB20nn7aZLRFhSlt/JlfX/ LwYnecWTck8JKJeCp6nsLXhGEzF6+g4PUnW5IobfxLNNBuPImzR7/p5xEl7U06HoD8+9 zzDjiB+3BguoKek1lnITJAYIvuyWyBIZUIoF3S9Vlv84FXv9jA0Mfusxfp1AGtL7S8Gu FesDDmWMdoK2EPtSxKJOG43saYtnEoRQLz3kmiZL10N78CpkVbltzy16RrXWmJdRUHtl MEGCKyskLgC9Ev5lA6RMpBzqVWwxnkhQzAWRMsMj9wgt60xDyfCP+OkUVK/Y2JoksCvD 93kQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=vD4yB7Lm; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f35-v6si29386912plh.33.2018.10.11.12.40.07; Thu, 11 Oct 2018 12:40:22 -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; dkim=pass header.i=@kernel.org header.s=default header.b=vD4yB7Lm; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729993AbeJLCyJ (ORCPT + 99 others); Thu, 11 Oct 2018 22:54:09 -0400 Received: from mail.kernel.org ([198.145.29.99]:38872 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726861AbeJLCyJ (ORCPT ); Thu, 11 Oct 2018 22:54:09 -0400 Received: from mail-wr1-f45.google.com (mail-wr1-f45.google.com [209.85.221.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 6C1E221470 for ; Thu, 11 Oct 2018 19:25:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1539285932; bh=YJo/qxuGm+DW/D8051DkEp1KmIgUQc8LeJ4cGi/xPBg=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=vD4yB7LmdaqYAPUJlz+e2T7pHKpb2ucjCK40MFMXPd78r5a4zZ9CqLRsEGL6kWwFl OUQJXsHTeiiYnM3qZQkGxR+xcRM7h3mJMPhdD5tD+TcqrAx821c48BOMpHHRzG5+I5 s3VAiD5WtChGgeRFCs4Q5gqvrjq+4ghIX23OC8Ls= Received: by mail-wr1-f45.google.com with SMTP id a13-v6so10933284wrt.5 for ; Thu, 11 Oct 2018 12:25:32 -0700 (PDT) X-Gm-Message-State: ABuFfojxe/SPYj6Gt8BIYUgbQdrV3HFLaNFMUUtCSiUbO9TumabfBRTS brxDuDKCoFxnMbo9+6n4lfGYqKhkuMsQzWy/2k9WFA== X-Received: by 2002:adf:9792:: with SMTP id s18-v6mr2857469wrb.283.1539285930778; Thu, 11 Oct 2018 12:25:30 -0700 (PDT) MIME-Version: 1.0 References: <20181011185458.10186-1-kristen@linux.intel.com> In-Reply-To: <20181011185458.10186-1-kristen@linux.intel.com> From: Andy Lutomirski Date: Thu, 11 Oct 2018 12:25:18 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] x86: entry: flush the cache if syscall error To: Kristen Carlson Accardi Cc: Kernel Hardening , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , X86 ML , Andrew Lutomirski , LKML 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 On Thu, Oct 11, 2018 at 11:55 AM Kristen Carlson Accardi wrote: > > This patch aims to make it harder to perform cache timing attacks on data > left behind by system calls. If we have an error returned from a syscall, > flush the L1 cache. > > It's important to note that this patch is not addressing any specific > exploit, nor is it intended to be a complete defense against anything. > It is intended to be a low cost way of eliminating some of side effects > of a failed system call. > > A performance test using sysbench on one hyperthread and a script which > attempts to repeatedly access files it does not have permission to access > on the other hyperthread found no significant performance impact. > > +__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) > + return; > + > + wrmsrl(MSR_IA32_FLUSH_CMD, L1D_FLUSH); > + } > +} Ugh. What exactly is this trying to protect against? And how many cycles should we expect L1D_FLUSH to take? ISTM that, if we have a situation where the L1D can be read by user code, we lose, via hyperthreading, successful syscalls, /dev/random, and may other vectors. This seems like a small mitigation at a rather large cost.