Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp2518586rdb; Fri, 8 Dec 2023 10:19:00 -0800 (PST) X-Google-Smtp-Source: AGHT+IGARtGfljIVTzYfAg/Q8a1Vmgkk7/75kumwrq0i9MjB4kQg3BqkXrmJL5Nh+Y2Vg2LsY1SC X-Received: by 2002:a05:6a20:9497:b0:18b:950d:de3b with SMTP id hs23-20020a056a20949700b0018b950dde3bmr401408pzb.38.1702059540356; Fri, 08 Dec 2023 10:19:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702059540; cv=none; d=google.com; s=arc-20160816; b=C6YVN0jQRincqDV7IrxEPmdJdCLzG7K0XWRBC4FGtWGn1d7BxHb37x5ZfTjnyPaSXq NKMWT5nQBHt1pv7cSwmi/dWBzUmO8xBZJOe0F+MvDSIzE5D4qWcu7cY0oKnu1gHEJk6q vtS5ol4WRabbK0L5byBQX37nMYe2YD0F8wVruLkaxBG85brfwseW2y9pW9yA3kOL6luX JGc1haC4ffGzS8U/dqrPOWKMzfGSg+KZqrVIA5NEkCOVkPSCa//lpyXgbcvsY9k/sgeW uBCFOQ2Wufzq7+uV6yJ8EswebhURM1RdAZIukf96N9veth5VJCk0f+4iB7i1fdTlHSJG QfDQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=xrT35L8MTIhLwpdhO3H/c+pqRQCxCg0MNTO7FGS/OpU=; fh=c86rcRO1j7y4kn4imfboshpxx8QGmszEaj04vicKbfI=; b=WToftPcMFit2ZWvxkLMCtDKmhkxaFvE4s9yCLTm5fJ/sWd05xCC8c8twl+QVYF315t 8hFQ4ohIfjyi87YRjf5znSZpQSP2mJn6w29XPCMSVuSE7vPvXRIJPyBb/9WPl9eXC57i UVG6ec84Xuc6i95C4P0+h3qGZdRLtF/X5IN/K5s4a5T6h59xjr1Hpxmb4hSLwtiqAz1g SnD46+q/5XHVFFqzpdof4mdBkZ+a4+OeONL0eHqpYPEZxFPREgVvrI+8MEb2+NlXbod+ wQfj+q8Jvg33uGZcpsexN+ga3mO6OXclCaArt9yCqZod3HFmXd38yfXBExs4v4e9UvcX lHGw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=Srx7Lw7d; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id n2-20020a632702000000b00578b63123desi1921304pgn.789.2023.12.08.10.18.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Dec 2023 10:19:00 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=Srx7Lw7d; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id CFFC483B1E87; Fri, 8 Dec 2023 10:18:57 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1574486AbjLHSSn (ORCPT + 99 others); Fri, 8 Dec 2023 13:18:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43202 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229811AbjLHSSm (ORCPT ); Fri, 8 Dec 2023 13:18:42 -0500 Received: from mail-pf1-x430.google.com (mail-pf1-x430.google.com [IPv6:2607:f8b0:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BDDCDA3 for ; Fri, 8 Dec 2023 10:18:48 -0800 (PST) Received: by mail-pf1-x430.google.com with SMTP id d2e1a72fcca58-6cecb004339so1141928b3a.3 for ; Fri, 08 Dec 2023 10:18:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1702059528; x=1702664328; darn=vger.kernel.org; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=xrT35L8MTIhLwpdhO3H/c+pqRQCxCg0MNTO7FGS/OpU=; b=Srx7Lw7dfmby6qUy+IUZE6TayrZzauBxi67HlNAZ31Q6wc6z9lGZzYS5WsHOkqYG0C 7kamCrAc8j+ZwlcOzVOqSbsK2jeXX/4eSe6NzJfp8MHf18llAeSUKM/VPZ5G+6o0FY9u CKEFjCink5viuqFDz+3ldtNywPMi+tECXnXRo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702059528; x=1702664328; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=xrT35L8MTIhLwpdhO3H/c+pqRQCxCg0MNTO7FGS/OpU=; b=rbTVXbXFKi5cAOfLEKWLpseGiuRrlgniFNhzBFm0kteQcVypwHMKLYNfmESEYwcajH fyEt6siiG9+BUPd+lmpi6bS+++wsVKdHVi4xG0m98RDNJFQtNgjaAV+WybV3UwVkWCYX mpbs1bOvCbHt2swDJzPtQcZCxV/Faat1N6EZTSw06rW+jtU7Yvlai4AGK91jju7wWVsb bDkFSsQyXP/OH84EaK20qjakMJBav28dfgDjLpS/csMmEcs/OYE/q96i4DozWEAxFlHQ Wrx2m4UHK37qFWaDHlsw718bIY1j1ir08Z1QgD+FUX6onMcEx9/AmubkkHLkHpxLk9On Q+Tw== X-Gm-Message-State: AOJu0YwfCVr2HgizAOJSJFf++6ru/VNFIOCmEY23LTz2BguI6QI+ZTzo R6YWExMfGUNtBKWGL9LXoF+gAQ== X-Received: by 2002:a05:6a20:8c1b:b0:190:20d:5b94 with SMTP id j27-20020a056a208c1b00b00190020d5b94mr372175pzh.27.1702059528236; Fri, 08 Dec 2023 10:18:48 -0800 (PST) Received: from www.outflux.net (198-0-35-241-static.hfc.comcastbusiness.net. [198.0.35.241]) by smtp.gmail.com with ESMTPSA id s7-20020a63f047000000b005c67dd98b15sm1867436pgj.74.2023.12.08.10.18.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Dec 2023 10:18:47 -0800 (PST) Date: Fri, 8 Dec 2023 10:18:47 -0800 From: Kees Cook To: Peter Zijlstra Cc: Miguel Ojeda , Alice Ryhl , Miguel Ojeda , Alex Gaynor , Wedson Almeida Filho , Boqun Feng , Gary Guo , =?iso-8859-1?Q?Bj=F6rn?= Roy Baron , Benno Lossin , Andreas Hindborg , Alexander Viro , Christian Brauner , Greg Kroah-Hartman , Arve =?iso-8859-1?B?SGr4bm5lduVn?= , Todd Kjos , Martijn Coenen , Joel Fernandes , Carlos Llamas , Suren Baghdasaryan , Dan Williams , Matthew Wilcox , Thomas Gleixner , Daniel Xu , linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: Re: [PATCH v2 5/7] rust: file: add `Kuid` wrapper Message-ID: <202312080947.674CD2DC7@keescook> References: <20231206-alice-file-v2-0-af617c0d9d94@google.com> <20231206-alice-file-v2-5-af617c0d9d94@google.com> <20231206123402.GE30174@noisy.programming.kicks-ass.net> <20231206134041.GG30174@noisy.programming.kicks-ass.net> <20231208165702.GI28727@noisy.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20231208165702.GI28727@noisy.programming.kicks-ass.net> X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Fri, 08 Dec 2023 10:18:58 -0800 (PST) On Fri, Dec 08, 2023 at 05:57:02PM +0100, Peter Zijlstra wrote: > On Fri, Dec 08, 2023 at 05:31:59PM +0100, Miguel Ojeda wrote: > > On Wed, Dec 6, 2023 at 2:41 PM Peter Zijlstra wrote: > > > > > > Anywhoo, the longer a function is, the harder it becomes, since you need > > > to deal with everything a function does and consider the specuation > > > window length. So trivial functions like the above that do an immediate > > > dereference and are (and must be) a valid indirect target (because > > > EXPORT) are ideal. > > > > We discussed this in our weekly meeting, and we would like to ask a > > few questions: > > > > - Could you please describe an example attack that you are thinking > > of? (i.e. a "full" attack, rather than just Spectre itself). For > > instance, would it rely on other vulnerabilities? > > There's a fairly large amount of that on github, google spectre poc and > stuff like that. tl;dr: I don't think the introduction of speculation gadgets is a sufficient reason to block Rust interfaces like this. Long version: I think the question here is "what is the threat model?" If I break down the objection, I understand it as: 1) The trivial wrappers-of-inlines are speculation gadgets. 2) They're exported, so callable by anything. If the threat model is "something can call these to trigger speculation", I think this is pretty strongly mitigated already; 1) These aren't syscall definitions, so their "reachability" is pretty limited. In fact, they're already going to be used in places, logically, where the inline would be used, so the speculation window is going to be same (or longer, given the addition of the direct call and return). 2) If an attacker is in a position to directly call these helpers, they're not going to use them: if an attacker already has arbitrary execution, they're not going to bother with speculation. Fundamentally I don't see added risk here. From the security hardening perspective we have two goals: kill bug classes and block exploitation techniques, and the former is a much more powerful defensive strategy since without the bugs, there's no chance to perform an exploit. In general, I think we should prioritize bug class elimination over exploit technique foiling. In this case, we're adding a potential weakness to the image of the kernel of fairly limited scope in support of stronger bug elimination goals. Even if we look at the prerequisites for mounting an attack here, we've already got things in place to help mitigate arbitrary code execution (KCFI, BTI, etc). Nothing is perfect, but speculation gadgets are pretty far down on the list of concerns, IMO. We have no real x86 ROP defense right now in the kernel, so that's a much lower hanging fruit for attackers. As another comparison, on x86 there are so many direct execution gadgets present in middle-of-instruction code patterns that worrying about a speculation gadget seems silly to me. > [...] > The thing at hand was just me eyeballing it. I can understand the point you and Greg have both expressed here: "this is known to be an anti-pattern, we need to do something else". I generally agree with this, but in this case, I don't think it's the right call. This is an area we'll naturally see improvement from on the Rust side since these calls are a _performance_ concern too, so it's not like this will be "forgotten" about. But blocking it until there is a complete and perfect solution feels like we're letting perfect be the enemy of good. All of our development is evolutionary, so I think we'd be in a much better position to take these (currently ugly) work-arounds (visible only in Rust builds) so that we gain the ability to evolve towards more memory safe code. -Kees -- Kees Cook