From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from sonic311-30.consmr.mail.ne1.yahoo.com (sonic311-30.consmr.mail.ne1.yahoo.com [66.163.188.211]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 522B933F6 for ; Mon, 3 Mar 2025 19:11:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=66.163.188.211 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741029117; cv=none; b=WOukm45+QaAYeWPk7ait+fk6PdKXo/plyUspZGc3Ium+3ZKPDIE+C1BvXkEzhvZQ8C8sI14fBkwsZN1GMXVTE0LS4T4JRIv09wqYnKH5l7xqvoF1dOySQzicmVNUT+ShfGXxX5xJGNsv3VRFmICzBC2sjEnmCgfa6OBV7ZOycfc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741029117; c=relaxed/simple; bh=zttb/KBNS8YrkZTTRzEXOV2zM8d85NRFoEcHxhNsqPI=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=TFkcKhV8XllwlkH1EmljUBQMZ6BX2hq0w9+TkOOfIuUsNh9hC2XyEKf15l41NmjLvkZ6mV+NsK2XU1imyRHSSusACRLfTb+2RiXbwEy3EmCqf1x82hukpokc8B/eKMaISOU1UtcKRlIKL7+k39nffmZKOqj7N4ezN/pASAPBDSU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=schaufler-ca.com; spf=none smtp.mailfrom=schaufler-ca.com; dkim=pass (2048-bit key) header.d=yahoo.com header.i=@yahoo.com header.b=h2M6cWJ+; arc=none smtp.client-ip=66.163.188.211 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=schaufler-ca.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=schaufler-ca.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=yahoo.com header.i=@yahoo.com header.b="h2M6cWJ+" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1741029115; bh=kxho3F4dy7xLzbeT4DOIL9QCojHaIl0A5BraM7FirZA=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From:Subject:Reply-To; b=h2M6cWJ+Ycf2gc5mTu66HIEZwIwKqUR4LTa++oLXcviuHFfqYZ8a3yqumtRL4d1X+paMRw9or9zWjIvldOBgPbzyD18mLlEQkLB71f5od96GBH4y6BWh3Sj2Ym5lwZR2I6UMBAU+hpdJeQfsIkOU+WvJqs0Of/y7MeMPVnZWJvVhL2BBiyZ2ixqgH3ONBQ49VFaWtHFzcT202BHkcE93elOgcdEmmnxIU1zu6t/vhTjMH8MtU134jg1YYsvq0/9BZHnk7/7u7GCu9GuNPSGKFuNlTvpFK2CqklCdZrZUhbi4OlmQ29mXZUdCJpYmhT2xlIBMj2yDiNwcPRL4MwXPbg== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1741029115; bh=Wn44DOLii1NmZiaSBp/MUYjBeOyLAEMtNrNRT0Wh+ZC=; h=X-Sonic-MF:Date:Subject:To:From:From:Subject; b=blzLX2MwCLpMIlYn0YpWf/PUZVVNijpLe3RdQovvMJ98FSEh5SV+uMpF+lF1rQQqNS8jAk8hs1nROpBlVq5jtcmYTWepCoC1AalxFa1FTyBh8st2K8Sfz2sHKivqhG6oKShqLcFxTNQWOPdYOTHZgd/k8+EFQrUqulIJ7WQnLMmOgLMOROL9CRQHMfnxoBETILra7VSIWvnYuo3kQX01i3nybF9stQm3zUbvC6aeh4q+GU42AKzJ9UT0pbMeRYzU6T/byjaJodgX2HYim2nJ/w6YJPieV806ya5MEtouISRvt0tJ0VqTJpAORKwOQcsyDnJ5Vv95eHl5ecC/iUuX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qrbU.l7ehL61q8Asjxqv0h9rfnxWejzRPJtWPt7Sd.zkMtSE9s8pGDfjOpME00twdSMp47F5 UL008WKHvbBK3uvE81JUQLvdVBX9WQMf6wbdNsle3uwqg9sqU9KzdT8LKAXAegMg_e3GzyyVHiZU x6NEyjNYjZAYdnxanLrWhgvd1izkLscoMQv8pwd3SDX2BJf3uD6xvhHLMKwnsJRQ53zoABXrV3xj tr1hkGOnaygVe7gvnlq.5gw2j6Q-- X-Sonic-MF: X-Sonic-ID: 96345618-f8ec-442e-82bc-261f2ecd13a2 Received: from sonic.gate.mail.ne1.yahoo.com by sonic311.consmr.mail.ne1.yahoo.com with HTTP; Mon, 3 Mar 2025 19:11:55 +0000 Received: by hermes--production-gq1-75cc957d6c-bs9kb (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID a55dafe6a07e9ebe5219b5cb6e8d4ed1; Mon, 03 Mar 2025 18:51:38 +0000 (UTC) Message-ID: Date: Mon, 3 Mar 2025 10:51:38 -0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] lsm: rust: mark SecurityCtx methods inline To: Alice Ryhl Cc: Paul Moore , James Morris , "Serge E. Hallyn" , Miguel Ojeda , Boqun Feng , Gary Guo , =?UTF-8?Q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Trevor Gross , rust-for-linux@vger.kernel.org, linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org, Casey Schaufler References: <20250303-inline-securityctx-v1-1-fb7b9b641fdf@google.com> Content-Language: en-US From: Casey Schaufler In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Mailer: WebService/1.1.23040 mail.backend.jedi.jws.acl:role.jedi.acl.token.atz.jws.hermes.yahoo On 3/3/2025 10:40 AM, Alice Ryhl wrote: > On Mon, Mar 3, 2025 at 6:07 PM Casey Schaufler wrote: >> On 3/3/2025 7:29 AM, Alice Ryhl wrote: >>> I'm seeing Binder generating calls to methods on SecurityCtx such as >>> from_secid and drop without inlining. Since these methods are really >>> simple wrappers around C functions, mark the methods to inline to avoid >>> generating these useless small functions. >>> >>> Signed-off-by: Alice Ryhl >>> --- >>> rust/kernel/security.rs | 5 +++++ >>> 1 file changed, 5 insertions(+) >>> >>> diff --git a/rust/kernel/security.rs b/rust/kernel/security.rs >>> index 25d2b1ac3833..243211050526 100644 >>> --- a/rust/kernel/security.rs >>> +++ b/rust/kernel/security.rs >>> @@ -23,6 +23,7 @@ pub struct SecurityCtx { >>> >>> impl SecurityCtx { >>> /// Get the security context given its id. >>> + #[inline] >>> pub fn from_secid(secid: u32) -> Result { >>> // SAFETY: `struct lsm_context` can be initialized to all zeros. >>> let mut ctx: bindings::lsm_context = unsafe { core::mem::zeroed() }; >>> @@ -35,16 +36,19 @@ pub fn from_secid(secid: u32) -> Result { >>> } >>> >>> /// Returns whether the security context is empty. >>> + #[inline] >>> pub fn is_empty(&self) -> bool { >>> self.ctx.len == 0 >>> } >>> >>> /// Returns the length of this security context. >>> + #[inline] >>> pub fn len(&self) -> usize { >>> self.ctx.len as usize >>> } >>> >>> /// Returns the bytes for this security context. >>> + #[inline] >>> pub fn as_bytes(&self) -> &[u8] { >>> let ptr = self.ctx.context; >>> if ptr.is_null() { >>> @@ -61,6 +65,7 @@ pub fn as_bytes(&self) -> &[u8] { >>> } >>> >>> impl Drop for SecurityCtx { >>> + #[inline] >>> fn drop(&mut self) { >>> // SAFETY: By the invariant of `Self`, this frees a context that came from a successful >>> // call to `security_secid_to_secctx` and has not yet been destroyed by >> I don't speak rust (well, yet?) so I can't talk about that, but this comment >> has me concerned. Security contexts (secctx) are not destroyed, they are released. >> While SELinux allocates and frees them, Smack maintains a list of contexts that >> is never freed. A call to security_release_secctx() on SELinux "destroys" the >> secctx, but for Smack does not. > It's just a comment on a call to security_release_secctx, I can reword > from "destroy" to "release". That would do nicely. Thank you. > > Here's the full context: > > // SAFETY: By the invariant of `Self`, this frees a context that came from a > // successful call to `security_secid_to_secctx` and has not yet been destroyed > // by `security_release_secctx`. > unsafe { bindings::security_release_secctx(&mut self.ctx) }; > > Alice >