Received: by 2002:a05:7412:b10a:b0:f3:1519:9f41 with SMTP id az10csp448172rdb; Thu, 30 Nov 2023 08:49:08 -0800 (PST) X-Google-Smtp-Source: AGHT+IFR4QeXXiqNRZjg1eU0YggDP76YvKfcCp8tbKq1PX+jMmV66cnEdNHJbbZ0FGSUYIIOK93P X-Received: by 2002:a17:902:e54e:b0:1cf:d660:5b00 with SMTP id n14-20020a170902e54e00b001cfd6605b00mr15242570plf.28.1701362947651; Thu, 30 Nov 2023 08:49:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701362947; cv=none; d=google.com; s=arc-20160816; b=IDTAixvY2wyJEeX0Ar+88+3416vkr0Xbk4Hq3HhbOsfAtgTFO5pNId9eon0WVyVCEN bM+1Ie/G7LWkfwOCvY1VU+no6fiy2OoIsPIOE5B6FDTVI87w6I/sLtHXedDApg56HYhy eCe985Tj3zjHUOyAkhqNdBuKIDkya9scPPl88xJFEkQk1Xd8u1RMOGQgF9bQYGd7gQr1 bHWln0iZWvwrW//IcxiC/BBBjLB2gUJKcFLzrM6JFjJPX2RVHphnYm4WF2ag3hHLNR8k cgijh9b3uP4YXRARROSRBDfbAFRF9miSLujK7FbYx3pbccA+5HRYXRpVyb2aT5TymqK0 CFjw== 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 :feedback-id:references:in-reply-to:message-id:subject:cc:from:to :date:dkim-signature; bh=ma6iKXmyJ476bBrogFjyVSkUY7XrgEHkL0/Xftslrt4=; fh=yGC6hLtEKxG/qAMK6tCmLY72Pr3WjPw6U6qgCoktHOQ=; b=gBDedtYouCE2pj2uKyw56WIBlEud8AD3haW0dLtbRdoWHxVnxiFdf7KlaoiM43/Pj5 9b5LVL46F5JuVJmK0B5JZ+J1F01nhu736lYrToc97tzeub0YORejTZPRjYy2oNuBnRBr 1choCDSJXGpuYcS0ZeHo0WwxkAvRDHFlsSPFtY/3aEukNiy/1bxnigOZhNH+PTnxjady 82f96xNuSErSRO85VLoHViLV9E5yxULqr/WkjX10YJT9KSMQiQjY/sC9BFNA9kh0fmX+ G86baDKU9KN/tOyJPcGF6HcSGkblPfeqDKsxx+3ZNP6AHth28IMWEnuINSbqA8L91IjL GChw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@proton.me header.s=protonmail header.b=SmOdraL9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=proton.me Return-Path: Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id x20-20020a170902821400b001d00a86c9dbsi1434080pln.400.2023.11.30.08.49.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Nov 2023 08:49:07 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@proton.me header.s=protonmail header.b=SmOdraL9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=proton.me Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 35EDB80D6A1B; Thu, 30 Nov 2023 08:49:05 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345697AbjK3Qsu (ORCPT + 99 others); Thu, 30 Nov 2023 11:48:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37518 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232402AbjK3Qss (ORCPT ); Thu, 30 Nov 2023 11:48:48 -0500 Received: from mail-4322.protonmail.ch (mail-4322.protonmail.ch [185.70.43.22]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 540D410F8; Thu, 30 Nov 2023 08:48:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=proton.me; s=protonmail; t=1701362933; x=1701622133; bh=ma6iKXmyJ476bBrogFjyVSkUY7XrgEHkL0/Xftslrt4=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector; b=SmOdraL93gFqTu2k/5T2ohP1ZJp2b+CgRREaU2e5H1ZUq4x+EQvILLt2aSngvbMa6 PuK9x5xisRVyi5GJs6FPfdfzAX85fwq8Xrl5f6AnTNOgFSBCQzSrvkP5g4+EGQDsHL EDBFtQ/XfIaDvnkhJpKS55tbPYn/LRm42eGm3PN6XQjcfWymtg7hYZG97eEo82RFCS DhIXHhEsObboS66pGMYvBvB+X7350grHi5wzpZmkhB6NTESy/2TtQQClKyerIxp0qL RQT4giTnYFEp7mYhmjHeCd9EKaUCvyy8q3Cqe1rdbp4PpCBmDq+9ZX4rAFkBo0Sd5R Gasrmyqv2pBdw== Date: Thu, 30 Nov 2023 16:48:29 +0000 To: Alice Ryhl From: Benno Lossin Cc: Miguel Ojeda , Alex Gaynor , Wedson Almeida Filho , Boqun Feng , Gary Guo , =?utf-8?Q?Bj=C3=B6rn_Roy_Baron?= , Andreas Hindborg , Peter Zijlstra , Alexander Viro , Christian Brauner , Greg Kroah-Hartman , =?utf-8?Q?Arve_Hj=C3=B8nnev=C3=A5g?= , 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 5/7] rust: file: add `Kuid` wrapper Message-ID: <1fDBLge_kImhS4koYYda8t5pmIAeA9Zxo8haE_x1zKgxqGtrQd3wHhOgTbV8db3exz-Q6kXoDh3XWMyX4aox0oGTDSX2udA6ZDSV3r3D1_U=@proton.me> In-Reply-To: <20231129-alice-file-v1-5-f81afe8c7261@google.com> References: <20231129-alice-file-v1-0-f81afe8c7261@google.com> <20231129-alice-file-v1-5-f81afe8c7261@google.com> Feedback-ID: 71780778:user:proton MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable 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 groat.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 (groat.vger.email [0.0.0.0]); Thu, 30 Nov 2023 08:49:05 -0800 (PST) On 11/29/23 14:12, Alice Ryhl wrote: > + /// Returns the given task's pid in the current pid namespace. > + pub fn pid_in_current_ns(&self) -> Pid { > + // SAFETY: We know that `self.0.get()` is valid by the type inva= riant. The rest is just FFI > + // calls. > + unsafe { > + let namespace =3D bindings::task_active_pid_ns(bindings::get= _current()); > + bindings::task_tgid_nr_ns(self.0.get(), namespace) > + } I would split this into two `unsafe` blocks. > + } > + > /// Wakes up the task. > pub fn wake_up(&self) { > // SAFETY: By the type invariant, we know that `self.0.get()` is= non-null and valid. > @@ -147,6 +180,42 @@ pub fn wake_up(&self) { > } > } >=20 > +impl Kuid { > + /// Get the current euid. > + pub fn current_euid() -> Kuid { > + // SAFETY: Just an FFI call. > + Self { > + kuid: unsafe { bindings::current_euid() }, > + } Would expect a call to `from_raw` here instead of `Self {}`. > + } > + > + /// Create a `Kuid` given the raw C type. > + pub fn from_raw(kuid: bindings::kuid_t) -> Self { > + Self { kuid } > + } Is there a reason that this is named `from_raw` and not just a normal `From` impl? AFAICT any `bindings::kuid_t` is a valid `Kuid`. > + > + /// Turn this kuid into the raw C type. > + pub fn into_raw(self) -> bindings::kuid_t { > + self.kuid > + } > + > + /// Converts this kernel UID into a UID that userspace understands. = Uses the namespace of the > + /// current task. Why not: /// Converts this kernel UID into a userspace UID. /// /// Uses the namespace of the current task. --=20 Cheers, Benno > + pub fn into_uid_in_current_ns(self) -> bindings::uid_t { > + // SAFETY: Just an FFI call. > + unsafe { bindings::from_kuid(bindings::current_user_ns(), self.k= uid) } > + } > +}