Message ID | cover.1666651511.git.pawan.kumar.gupta@linux.intel.com |
---|---|
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp725535wru; Mon, 24 Oct 2022 17:34:20 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7g45z2m9joB0IV1fMYKHyuDJuOJB8EYVishNK+kFvncsjWSAyUOzd79kaWpI7YbjDp5hBO X-Received: by 2002:a17:906:ee8e:b0:730:3646:d178 with SMTP id wt14-20020a170906ee8e00b007303646d178mr30415223ejb.426.1666658060591; Mon, 24 Oct 2022 17:34:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666658060; cv=none; d=google.com; s=arc-20160816; b=0CcQ1AZ15opgIDzHguC/+DtJYyHUg8fzG1qSePYImDPA88t6vbKKi8GhUSWplWF3Jj jn8vcBdi68aP5NGQ3b9UoUi9GWRoR/vWOuNIoJ8yamR1i0bRGsPlVRt9aa3NfrzFtgvD bJMkyFIMM8xJ+e4KE4pAFX2UoxG2w0yDqleybIHZ4jI4z9K2bLkbpC5G524jJUikiLO5 7dsMLmxEl11E93Y447tan3sQWzUlSTQldyeUmqIK7pFFy6ItCCOwB/6GvTp4s4vmcSA7 mgooQKW/Toyb7V/aa2IvQTJXEAebJtbh7g100ixFf01kU/kjKi7Ib1TbT6Y5O7E9kmY7 SbVA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=zoKGiUvkYB4zOzXNO7fRF02dU96WAXoiMKIBfy+bRME=; b=rqk4q2nhpp/h6ajH8cDZNlIxIhmAtGUxvETpX4iCu/9GWQnKR0081N8tiPGxXfQyDu f7u3M6UuP2YYh7YLJP2JsgAx3EEZL/r510WQzYY07xY2R8nq+MByMrSkvmxGS5ZmBK+z Ypt05xNILpk1R53FyhdSPB6ChSqKtrOclnqBn0doJwl2YQbxtaZZbbezhqqqJlXSl+DV xlS44Tpio1BTJ8CjTtXIX9GkOeXPfwcbsimBK5Et/GRH6HInHEK9lwZ8FT7XeeTG1Pkp VCgSnUEehLAp7AVDoPMLb4u2OQ61WZI/8sAy/TB8c2Da1p/m5RNgXhsvMW0xbi5YpyJj raPA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=IphW3CK6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hr42-20020a1709073faa00b007832bdf1856si1189410ejc.740.2022.10.24.17.33.56; Mon, 24 Oct 2022 17:34:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=IphW3CK6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229588AbiJYAdf (ORCPT <rfc822;pwkd43@gmail.com> + 99 others); Mon, 24 Oct 2022 20:33:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57736 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230381AbiJYAdJ (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 24 Oct 2022 20:33:09 -0400 Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3060820347; Mon, 24 Oct 2022 15:57:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1666652281; x=1698188281; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=/QFYcqzzhog465CEp7hJCINJC63rwNPJ/l0XxVVSM6g=; b=IphW3CK6tjTAbqJpyvEU5yD+tVjeukfE0aGA9BR5AnSK/KieuDcM1yT8 5ebACnvzZEQ4A4odoBErIgAmiIuTzSLVj6oF28kClfGeOrIX39sYggBeZ tIP/09DEy6WgTrX29qzOIEi1GXRNgnP2x9u0ypx24JpCdddvoyhEfz9SJ MQ/Nc30R4B4Vz/x6Jfw8o1DtKcZvFGmLhrO7GmJNXdIVs8ugOpUy2ZZ+j pHTSvedNCrVFEYZ3yLIi2hXt/0dmT4SxE3L5dLyHxerecemflRhzJDEk5 yjyDN6y4zwx7NzCftQUKAmVhb6f2IJfmpSfw9HgPmj9Y8ca7OrLfHtxOR w==; X-IronPort-AV: E=McAfee;i="6500,9779,10510"; a="308633271" X-IronPort-AV: E=Sophos;i="5.95,210,1661842800"; d="scan'208";a="308633271" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Oct 2022 15:57:56 -0700 X-IronPort-AV: E=McAfee;i="6500,9779,10510"; a="609363400" X-IronPort-AV: E=Sophos;i="5.95,210,1661842800"; d="scan'208";a="609363400" Received: from pkearns-mobl1.amr.corp.intel.com (HELO guptapa-desk.intel.com) ([10.252.131.64]) by orsmga006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Oct 2022 15:57:55 -0700 From: Pawan Gupta <pawan.kumar.gupta@linux.intel.com> To: scott.d.constable@intel.com, daniel.sneddon@linux.intel.com, Jakub Kicinski <kuba@kernel.org>, dave.hansen@intel.com, Johannes Berg <johannes@sipsolutions.net>, Paolo Abeni <pabeni@redhat.com>, antonio.gomez.iglesias@linux.intel.com, "David S. Miller" <davem@davemloft.net>, Eric Dumazet <edumazet@google.com> Cc: linux-wireless@vger.kernel.org, linux-kernel@vger.kernel.org, x86@kernel.org, gregkh@linuxfoundation.org, netdev@vger.kernel.org Subject: [RFC PATCH 0/2] Branch Target Injection (BTI) gadget in minstrel Date: Mon, 24 Oct 2022 15:57:45 -0700 Message-Id: <cover.1666651511.git.pawan.kumar.gupta@linux.intel.com> X-Mailer: git-send-email 2.37.3 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.5 required=5.0 tests=AC_FROM_MANY_DOTS,BAYES_00, DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747617642331496467?= X-GMAIL-MSGID: =?utf-8?q?1747617642331496467?= |
Series |
Branch Target Injection (BTI) gadget in minstrel
|
|
Message
Pawan Gupta
Oct. 24, 2022, 10:57 p.m. UTC
Hi, There is a theoretical possibility of using minstrel_ht_get_expected_throughput() as a disclosure gadget for Branch History Injection (BHI)/Intra-mode Branch Target Injection (IMBTI) [1]. Requesting feedback on the couple of patches that mitigates this. First patch adds a generic speculation barrier. Second patch uses the speculation barrier to mitigate BHI/IMBTI. The other goal of this series is to start a discussion on whether such hard to exploit, but theoretical possible attacks deems to be mitigated. In general Branch Target Injection class of attacks involves an adversary controlling an indirect branch target to misspeculate to a disclosure gadget. For a successful attack an adversary also needs to control the register contents used by the disclosure gadget. Assuming preconditions are met, a disclosure gadget would transiently do below: 1. Loads an attacker chosen data from memory. 2. Based on the data, modifies cache state that is observable by an attacker. Although both these operations are architecturally invisible, the cache state changes could be used to infer the data. Disclosure gadget is mitigated by adding a speculation barrier. Thanks, Pawan [1] https://www.intel.com/content/www/us/en/developer/articles/technical/software-security-guidance/technical-documentation/branch-history-injection.html Pawan Gupta (2): nospec: Add a generic barrier_nospec() minstrel_ht: Mitigate BTI gadget minstrel_ht_get_expected_throughput() include/linux/nospec.h | 4 ++++ net/mac80211/rc80211_minstrel_ht.c | 9 +++++++++ 2 files changed, 13 insertions(+)
Comments
On Mon, Oct 24, 2022 at 03:57:45PM -0700, Pawan Gupta wrote: > The other goal of this series is to start a discussion on whether such > hard to exploit, but theoretical possible attacks deems to be mitigated. > > In general Branch Target Injection class of attacks involves an adversary > controlling an indirect branch target to misspeculate to a disclosure gadget. > For a successful attack an adversary also needs to control the register > contents used by the disclosure gadget. I'm thinking this is going about it wrong. You're going to be randomly sprinking LFENCEs around forever if you go down this path making stuff slower and slower. Not to mention that it's going to bitrot; the function might change but the LFENCE will stay, protecting nothing but still being slow. I think the focus should be on finding the source sites, not protecting the target sites. Where can an attacker control the register content and have an indirect jump/call. Also, things like FineIBT will severely limit the viability of all this. And how is sprinking random LFENCEs around better than running with spectre_v2=eibrs,retpoline which is the current recommended mitigation against all this IIRC (or even eibrs,lfence for lesser values of paranoia).
On Tue, Oct 25, 2022 at 01:07:52PM +0200, Peter Zijlstra wrote: >On Mon, Oct 24, 2022 at 03:57:45PM -0700, Pawan Gupta wrote: > >> The other goal of this series is to start a discussion on whether such >> hard to exploit, but theoretical possible attacks deems to be mitigated. >> >> In general Branch Target Injection class of attacks involves an adversary >> controlling an indirect branch target to misspeculate to a disclosure gadget. >> For a successful attack an adversary also needs to control the register >> contents used by the disclosure gadget. > >I'm thinking this is going about it wrong. You're going to be randomly >sprinking LFENCEs around forever if you go down this path making stuff >slower and slower. Right, an alternative to LFENCE is to mask the indexes(wherever possible) for gadgets that are called frequently. But still its not a clean solution. >Not to mention that it's going to bitrot; the function might change but >the LFENCE will stay, protecting nothing but still being slow. Totally agree with this. >I think the focus should be on finding the source sites, not protecting >the target sites. Where can an attacker control the register content and >have an indirect jump/call. That is an interesting approach. I am wondering what mitigation can be applied at source? LFENCE before an indirect branch can greatly reduce the speculation window, but will not completely eliminate it. Also LFENCE at sources could be costlier than masking the indexes at targets or LFENCE at the targets. >Also, things like FineIBT will severely limit the viability of all this. Yes. >And how is sprinking random LFENCEs around better than running with >spectre_v2=eibrs,retpoline which is the current recommended mitigation >against all this IIRC (or even eibrs,lfence for lesser values of >paranoia). Its a trade-off between performance and spot fixing (hopefully handful of) gadgets. Even the gadget in question here is not demonstrated to be exploitable. If this scenario changes, polluting the kernel all over is definitely not the right approach.
On Tue, 2022-10-25 at 12:38 -0700, Pawan Gupta wrote: > > > And how is sprinking random LFENCEs around better than running with > > spectre_v2=eibrs,retpoline which is the current recommended mitigation > > against all this IIRC (or even eibrs,lfence for lesser values of > > paranoia). > > Its a trade-off between performance and spot fixing (hopefully handful > of) gadgets. Even the gadget in question here is not demonstrated to be > exploitable. If this scenario changes, polluting the kernel all over is > definitely not the right approach. > Btw, now I'm wondering - you were detecting these with the compiler based something, could there be a compiler pass to insert appropriate things, perhaps as a gcc plugin or something? Now honestly I have no idea if it's feasible, but since you're detecting it that way, and presumably then we'd have to maintain the detection and run it regularly to make sure that (a) things didn't bitrot and the gadget is still there, and (b) no new places show up ... perhaps the better way would be to combine both? johannes
On Tue, Oct 25, 2022 at 12:38:45PM -0700, Pawan Gupta wrote: > > I think the focus should be on finding the source sites, not protecting > > the target sites. Where can an attacker control the register content and > > have an indirect jump/call. > > That is an interesting approach. I am wondering what mitigation can > be applied at source? Limiting the value ranges for example. Or straight up killing the values if they go unused -- like how we clear the registers in entry. > LFENCE before an indirect branch can greatly > reduce the speculation window, but will not completely eliminate it. Depends on the part; there's a whole bunch of parts where LFENCE is sufficient.
On 10/25/22 04:07, Peter Zijlstra wrote: > I think the focus should be on finding the source sites, not protecting > the target sites. Where can an attacker control the register content and > have an indirect jump/call. How would this work with something like 'struct file_operations' which provide a rich set of indirect calls that frequently have fully user-controlled values in registers? It certainly wouldn't *hurt* to be zeroing out the registers that are unused at indirect call sites. But, the majority of gadgets in this case used rdi and rsi, which are the least likely to be able to be zapped at call sites.
On Tue, Oct 25, 2022 at 09:56:21PM +0200, Johannes Berg wrote: >On Tue, 2022-10-25 at 12:38 -0700, Pawan Gupta wrote: >> >> > And how is sprinking random LFENCEs around better than running with >> > spectre_v2=eibrs,retpoline which is the current recommended mitigation >> > against all this IIRC (or even eibrs,lfence for lesser values of >> > paranoia). >> >> Its a trade-off between performance and spot fixing (hopefully handful >> of) gadgets. Even the gadget in question here is not demonstrated to be >> exploitable. If this scenario changes, polluting the kernel all over is >> definitely not the right approach. >> >Btw, now I'm wondering - you were detecting these with the compiler >based something, could there be a compiler pass to insert appropriate >things, perhaps as a gcc plugin or something? I hear it could be a lot of work for gcc. I am not sure if its worth especially when we can't establish the exploitability of these gadgets. There are some other challenges like, hot-path sites would prefer to mask the indexes instead of using a speculation barrier for performance reasons. I assume adding this intelligence to compilers would be extremely hard. Also hardware controls and features in newer processors will make the software mitigations redundant.
On Tue, Oct 25, 2022 at 03:00:35PM -0700, Dave Hansen wrote: > On 10/25/22 04:07, Peter Zijlstra wrote: > > I think the focus should be on finding the source sites, not protecting > > the target sites. Where can an attacker control the register content and > > have an indirect jump/call. > > How would this work with something like 'struct file_operations' which > provide a rich set of indirect calls that frequently have fully > user-controlled values in registers? > > It certainly wouldn't *hurt* to be zeroing out the registers that are > unused at indirect call sites. But, the majority of gadgets in this > case used rdi and rsi, which are the least likely to be able to be > zapped at call sites. Right; so FineIBT will limit the targets to the right set of functions, and those functions must already assume the values are user controlled and take appropriate measures. If you really truly care about the old hardware, then one solution would be to de-virtualize the call using LTO or something (yes, it will need some compiler work and you might need to annotate the code a bit and even have a fixed/predetermined set of loadable modules, but meh). Barring that, you could perhaps put {min,max} range information next to the function pointer such that you can impose value ranges before doing the indirect call. But given this is all theoretical and FineIBT solves a lot of it I can't find myself to care too much.