Received: by 10.223.176.5 with SMTP id f5csp393100wra; Tue, 30 Jan 2018 13:16:29 -0800 (PST) X-Google-Smtp-Source: AH8x2262VkMNi0M8A3cTnBv2FisgNF2WhFcAMUzW5J4Z6h0o2dX76PWkTgmRwXRepsbpJRZPnoJu X-Received: by 10.98.11.17 with SMTP id t17mr31614960pfi.201.1517346988972; Tue, 30 Jan 2018 13:16:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517346988; cv=none; d=google.com; s=arc-20160816; b=rp3+UxMbd8bPFtk6nqqoi40C+1h7KlwyXrQgGGXYy6eTuu6dG1w/8CHxfBdQuyeY2J QlgRQaJ58d/TEuV3OqQ5Lv7tCi2/dvVTvnMZ3P8ZgEs0jL+gjILpEGjOmeSu/BlBC2UV fo1yfA0DMixa+QNY0nQNssCPqRAF+b2w2S4St8ZKj3Rov32VW8xP42TFuxfDl/b6ce9S YL5/OmgvqSSNxyWHmTJ9duF89+6XgkY/MaeideU380+cs/orRAJ18FU/qfdQUth3AWGq gOrzQ9yn1iHxHHLzMjdTdSEru+61BfoenbzgPxtI9b+JDsHpEm8zooPe8N5ILd3jOmUM peSw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:arc-authentication-results; bh=+TvFVOIhVuIWDqfv4T6l/goGBtIny5Hh8z1vyoDGMe8=; b=qbv+Sp9P531J5F+bwGJtqD6yy0k/J2iKwMDJwRCITfaNsL1ggUJrhgUl+JA1t8QMzl vrjhTtz5fR5FDCRMe+3EjVpTVfAjSnjwTiKg90IEhtFHK/Zw49IOpMJJtWHZgEw74QTQ 4pLtpQIjpnA4p1qc6cByAL/JQy7ES+sz0ufMAAE3CJpsUo21TjR5km0BxkW8tXLnD+JA vC85SkWQ7shBY2IsIor+OHVGChWTdU9MyYvvD5DtJ0TPz2F9nMwVXz9FgUp1x7SFjIdk MGeT1ANzTwiN/oreycl0AbLctxCmhoALtQcww66M6do1KT316Xd+sUAp33SXhDA/2MHo 3LOQ== 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 t71si1993316pgb.396.2018.01.30.13.16.14; Tue, 30 Jan 2018 13:16:28 -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; 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 S932087AbeA3VDW (ORCPT + 99 others); Tue, 30 Jan 2018 16:03:22 -0500 Received: from mga02.intel.com ([134.134.136.20]:51401 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932070AbeA3VDV (ORCPT ); Tue, 30 Jan 2018 16:03:21 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 30 Jan 2018 13:03:21 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.46,436,1511856000"; d="scan'208";a="14662647" Received: from schen9-desk3.jf.intel.com (HELO [10.54.74.42]) ([10.54.74.42]) by orsmga006.jf.intel.com with ESMTP; 30 Jan 2018 13:03:21 -0800 Subject: Re: [PATCH] x86/speculation: Use Indirect Branch Prediction Barrier in context switch To: Borislav Petkov , David Woodhouse Cc: arjan@linux.intel.com, tglx@linutronix.de, karahmed@amazon.de, x86@kernel.org, linux-kernel@vger.kernel.org, peterz@infradead.org, pbonzini@redhat.com, ak@linux.intel.com, torvalds@linux-foundation.org, gregkh@linux-foundation.org, mingo@kernel.org, luto@kernel.org, linux@dominikbrodowski.net References: <1517263487-3708-1-git-send-email-dwmw@amazon.co.uk> <20180130203836.bsgme6kf6hstgbrx@pd.tnic> From: Tim Chen Message-ID: <024dd53b-1912-34fa-deb8-550c111df521@linux.intel.com> Date: Tue, 30 Jan 2018 13:03:20 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.1.0 MIME-Version: 1.0 In-Reply-To: <20180130203836.bsgme6kf6hstgbrx@pd.tnic> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 01/30/2018 12:38 PM, Borislav Petkov wrote: > On Mon, Jan 29, 2018 at 10:04:47PM +0000, David Woodhouse wrote: >> + if (tsk && tsk->mm && >> + tsk->mm->context.ctx_id != last_ctx_id && >> + get_dumpable(tsk->mm) != SUID_DUMP_USER) >> + indirect_branch_prediction_barrier(); > > Ok, so while staring at this, someone just came up with the following > sequence: > > 1. Malicious process runs with UID=A, does BTB poisoning > 2. Sensitive process (e.g. gpg) starts also with UID=A, no IBPB flush occurs since task is initially dumpable > 3. gpg now does prctl(PR_SET_DUMPABLE, ...) to clear the dumpable flag > 4. gpg now does sensitive stuff that it thinks is protected > 5. gpg does indirect branches that shouldn't be influenced by the malicious process > > Now, if you switch between steps 3. and 4., you're good because gpg > became non-dumpable. But if you *don't* switch, the bad BTB entries are > still there. The attacker has to guarantee itself to run right before victim. And the window of attack is very small, as only the first context switch to victim may be vulnerable. The victim will be immune on the next switch. For timing attack, the attacker needs to scan one bit at a time. So probably the attacker could glean 1 bit of information on the switch back to the attacker and then the attacker could not scan further. So it doesn't seem to be very practical attack if the victim has set itself to be non-dumpable. Tim > > So, *actually*, we need to flush IBPB in set_dumpable() too, when we > clear SUID_DUMP_USER. > > Or, are we missing something obvious here and that is not needed because > of reasons I haven't thought about? > > I know, gpg doesn't do prctl() but disables core dumping with > setrlimit() but there might be other processes who do that... > > Thx. >