Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp2467187rdb; Fri, 8 Dec 2023 08:57:57 -0800 (PST) X-Google-Smtp-Source: AGHT+IFLr8eq4yvmwGDYayQzRUlBxvwhMg4JVdQCAozJN/mI7UWfGCasiH6tfOjckk0B4/HsMPTR X-Received: by 2002:a05:6a20:3d84:b0:190:16bb:4f5f with SMTP id s4-20020a056a203d8400b0019016bb4f5fmr422100pzi.10.1702054677251; Fri, 08 Dec 2023 08:57:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702054677; cv=none; d=google.com; s=arc-20160816; b=EmnCccN33I+CQmIYRaX1r/fo6Nc99EIKbS+Hfkq0tS9HmEndX4iajC30qlHnoow4pR 8zo/LYKs0qxb9suYA0tWGrnnuBVUPgS/r9UMHZtGFG2xwsw1TF4ar3R8/mG84F5Kkm6J mo6eveaFRnpROOnctghkT6EnHvONFfZDoBuH2761fzJIWPjUwBuJR/zBLMEN0QplZI4F BJnyW/tTHXtmqpGaAAvwrd0zZ1zgC5PkJ+5tcFLGDhExYVVKWMWG7HoLALf9x54PdBWo Yz2dotn7XipNiJB36EweLjeEryL7WhRSEdyP73rDglNl4Nq7sEZKBgpVUhzZi6ALM+ty UP0Q== 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=+bKWbY0TFFFJG7vCNdsapguiWXk5Tcdbxhr2FyThgV4=; fh=bIzMNiPPz3+kNsIZoOsWyvcnPBV7bb4MpvoaM27HP70=; b=Ok6eZfmbJKYJ/fLfYXFdzuyypnC/N9S9z9BuSzKBI7Lh68GlDv/3ydFpI2xIRpAlZS sxcgiFqMUGW9+hSvmPyE+Fh0veYhEK1CgWh5NGTNJsS1H9HJpeAvYZDswFhU8qQZZOdP 0gPL/yGzNxT+hIWNYj7GRuDrp3+KNSUxXQmug1iI8ASi/R8hFoXN1UhitznPEZmXuP8U azf6NkVBNOY3CdSMJ2jY5IDtdtXAGd/4sQj/xs7C2Z5OE1BM/diH6n9H+3XFir3nac5B abcO6M1BZSPtYxmEUDfUXnu+6WwXIqBnYh6g6JZrZvYM62YhaMHiDUJP1SuJC90rX104 xysA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=IlOPMzwG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id m12-20020a056a00080c00b006ce5b632ff6si1887928pfk.54.2023.12.08.08.57.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Dec 2023 08:57:57 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=IlOPMzwG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 6CE0E84A84DC; Fri, 8 Dec 2023 08:57:54 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233651AbjLHQ5j (ORCPT + 99 others); Fri, 8 Dec 2023 11:57:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43326 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232094AbjLHQ5h (ORCPT ); Fri, 8 Dec 2023 11:57:37 -0500 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C0DA998; Fri, 8 Dec 2023 08:57:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Transfer-Encoding: Content-Type:MIME-Version:References:Message-ID:Subject:Cc:To:From:Date: Sender:Reply-To:Content-ID:Content-Description; bh=+bKWbY0TFFFJG7vCNdsapguiWXk5Tcdbxhr2FyThgV4=; b=IlOPMzwGrh/jGe5Kiyfmvz91r2 DMe8pUz8Wq3s7w2GLz1XHY4A9XDGCfk8/cVEQOmWA48/RiYZAMXOFYmmFcYkZDbQ5h502Wb3TteF8 J+eVsnXCtfTIqVDaqmNfQaeBL86u5r2eivNqXVdqQpxBYVdwzmBs1BA8ZCzTCsdSRbxTyZ1USB4J9 WncYy/GVXmd4+KowpHmPKlrXohHcN4yI5nLjOt0B0uwCa+az5Q3b1GwQobVLUap62blhtXCZj5CqS L1pdQEwmXmBrsIwdIpFqU3ZwVZtB7ZPqAn6DPNNDcZ9YYoiHW7fcc5aBqNppVII1H9it+czae4xK0 Ekm1eL/w==; Received: from j130084.upc-j.chello.nl ([24.132.130.84] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1rBe9v-0066Wi-1l; Fri, 08 Dec 2023 16:57:03 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 1000) id 2652A3003F0; Fri, 8 Dec 2023 17:57:02 +0100 (CET) Date: Fri, 8 Dec 2023 17:57:02 +0100 From: Peter Zijlstra To: Miguel Ojeda Cc: 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 , Kees Cook , 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: <20231208165702.GI28727@noisy.programming.kicks-ass.net> 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> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Spam-Status: No, score=-0.9 required=5.0 tests=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 howler.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 (howler.vger.email [0.0.0.0]); Fri, 08 Dec 2023 08:57:54 -0800 (PST) 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. > - Is this a kernel rule everybody should follow now? i.e. "no (new?) > short, exported symbols that just dereference their pointer args". If > so, could this please be documented? Or is it already somewhere? Gadget scanners are ever evolving and I think there's a bunch of groups running them against Linux, but most of us don't have spare time beyond trying to plug the latest hole. > - Are we checking for this in some way already, e.g. via `objtool`? > Especially if this is a rule, then it would be nice to have a way to > double-check if we are getting rid of (most of) these "dangerous" > symbols (or at least not introduce new ones, and not just in Rust but > C too). Objtool does not look for these (gadget scanners are quite complicated by now and I don't think I want to go there with objtool). At the moment I'm simply fixing whatever gets reported from 3rd parties when and where time permits. The thing at hand was just me eyeballing it. > > That would be good, but how are you going to do that without duplicating > > the horror that is struct task_struct ? > > As Alice pointed out, `bindgen` "solves" that, but it is nevertheless > extra maintenance effort. > > > Well, I really wish the Rust community would address the C > > interoperability in a hurry. Basically make it a requirement for > > in-kernel Rust. > > Yeah, some of us have advocated for more integrated C support within > Rust (or within `rustc` at least). \o/ > > I mean, how hard can it be to have clang parse the C headers and inject > > them into the Rust IR as if they're external FFI things. > > That is what `bindgen` does (it uses Clang as a library), except it > does not create Rust IR, it outputs normal Rust code, i.e. similar to > C declarations. Right, but then you get into the problem that Rust simply cannot express a fair amount of the things we already do, like asm-goto, or even simple asm with memops apparently. > But note that using Clang does not solve the issue of `#define`s in > the general case. That is why we would still need "helpers" like these > so that the compiler knows how to expand the macro in a C context, > which then can be inlined as LLVM IR or similar (which is what I > suspect you were actually thinking about, rather than "Rust IR"?). Yeah, LLVM-IR. And urgh yeah, CPP, this is another down-side of Rust not being in the C language family, you can't sanely run CPP on it. Someone really should do a Rust like language in the C family, then perhaps it will stop looking like line noise to me :-) I suppose converting things to enum and inline functions where possible might help a bit with that, but things like tracepoints, which are built from a giant pile of CPP are just not going to be happy :/ Anyway, I think it would be a giant step forwards from where we are today. > That "mix the LLVM IRs from Clang and `rustc`" ("local LTO hack") > approach is something we have been discussing in the past for > performance reasons (i.e. to inline these small C functions that Rust > needs, cross-language, even in non-LTO builds). And if it helps to > avoid certain attacks around speculation, then even better. So if the > LLVM folks do not have any major concerns about it, then I think we > should go ahead with that (please see also my reply to comex). But does LTO make any guarantees about inlining? The thing is, with actual LLVM-IR you can express the __always_inline attribute and inlining becomes guaranteed, I don't think you can rely on LTO for the same level of guarantees. And you still need to create these C functions by hand in this local-LTO scenario, which is less than ideal.