From nobody Sat Sep 26 03:11:18 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E04EC2DB7BB; Sat, 5 Sep 2026 02:17:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788574678; cv=none; b=prbCfo131nYcPtRDq6YgZ1eQRbw8hYNk2242fazsnzYpLo0JOsx83QTlfV6o6OUrcBJpHJtAMsl7zsLO9T+PE1AOM8QvKL3nPV+T8OXdiXOrNSJDWXiFgxSpwkzqGZNCjjsuK2WiXRMHPWMAng5Ck3c+vWgV6/iWYq0sAl2MGl8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788574678; c=relaxed/simple; bh=pBfjF5beceQC3GK8orgII7IC2LW//67f1nHLeXHsB20=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To:Cc; b=VkmZmEl/foB6ovx+J+QMCl1unRTqJFkKzMHlbRtj/vpbzOwP9ZVFLsiG50XTL2KwmF21Abq7GSZjzXwjRxxRlKpua7nHW83ciOBGW3v27ZbHdQrnXk5kqJokjV9VLHh7Nm20XoPHuB2T66FXL6k6Byf1KLr2mDZQ8PNdShH4Uco= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=PL+sVWRb; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="PL+sVWRb" Received: by smtp.kernel.org (Postfix) with ESMTPS id 560A8C2BCF5; Sat, 5 Sep 2026 02:17:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1788574677; bh=pBfjF5beceQC3GK8orgII7IC2LW//67f1nHLeXHsB20=; h=From:Date:Subject:To:Cc:Reply-To:From; b=PL+sVWRb9TnwuxBDmNsHlt9HbCDfoaji3iLduI4ymeh/PNZBwGRZyS1nagfnrP5px nY/gVDINhLLHvE5JtG6iPrK6HGl29/kmAjxIxzMusHjRkfxjTz5g2IyQqIPXCBEcX6 nYjE/pzVYJJTG08G8ZByhvrzny8bZym6uiWMRIga51TScfCmAGrDwCbGbrt+gt4H1o 9a4rzzSpkm3W4V//4/uHJE2A2JhanNCw4F14XvPCy7wjyoGP5V0SBTCmDQ7+b3Lxx/ 0GQPLMHnkqNni4f59H4fBDExGWsYM4NpKRDS8Lpic2vu2xNWGg/rBIidkH3EmMSIW0 DQDiVirKbaIlw== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2DF84C79F89; Sat, 5 Sep 2026 02:17:57 +0000 (UTC) From: Younes Akhouayri via B4 Relay Date: Sat, 05 Sep 2026 04:17:45 +0200 Subject: [PATCH] rust: num: seal Integer Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260905-feature-rust-num-seal-integer-v1-1-83096115ad64@younes.io> X-B4-Tracking: v=1; b=H4sIAAAAAAAC/yXM0Q7CIAyF4VdZuLYRcSGZr2K8ANaxGmWmBWOy7 N2F7fJver5VCTKhqFu3KsYvCS2pxuXUqTC7FBForK2MNlYP+goTulwYgYtkSOUNgu4FlDJGZHC 9sWacejMEq6rxYZzot/v3x9FS/BNDbmj78E4QPLsU5nZamCKl864fy237A9lWeQilAAAA X-Change-ID: 20260903-feature-rust-num-seal-integer-a4262df429c6 To: Alexandre Courbot , Yury Norov , Miguel Ojeda , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Danilo Krummrich , Daniel Almeida , Tamir Duberstein , =?utf-8?q?Onur_=C3=96zkan?= Cc: rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org, Younes Akhouayri X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1788574676; l=1759; i=git@younes.io; s=20260712; h=from:subject:message-id; bh=bVjKmsDC3xyhPHxsbELDrHtf25N1qLrwIDkcTJtI+Hw=; b=tn6YSXWPvKIjGWNXFsc+QIj5PzBOLQzeokvmPUB666OHKjbnHLWLMM+YIRl87t9+YEYlqeFkH UOZmavqYAaJCk/4Rs0Jf1qgDYBfLRIG6qyvjqPfVMPOiB4TA55gUurs X-Developer-Key: i=git@younes.io; a=ed25519; pk=1DRfzPrQ04RQHHgGK28t+vjIAPv5oISPiAdLMU6J5dE= X-Endpoint-Received: by B4 Relay for git@younes.io/20260712 with auth_id=866 X-Original-From: Younes Akhouayri Reply-To: git@younes.io From: Younes Akhouayri Bounded relies on Integer implementations to describe primitive integer semantics correctly. In particular, it uses Integer::BITS and Signedness to justify unchecked operations. Integer is currently safe and externally implementable, so an implementation can violate those assumptions and make safe Bounded operations reach undefined behavior. Seal Integer so only the primitive implementations provided by the kernel crate can satisfy it. Fixes: 01e345e82ec3 ("rust: num: add Bounded integer wrapping type") Closes: https://lore.kernel.org/rust-for-linux/CANiq72mOfR33s4y+Ueivd5NrC5y= re+Pcp57ZOBz0msw9A4AP1Q@mail.gmail.com/ Cc: stable@vger.kernel.org Suggested-by: Miguel Ojeda Signed-off-by: Younes Akhouayri Reported-by: usually precedes the Closes tag, e.g. --- rust/kernel/num.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/rust/kernel/num.rs b/rust/kernel/num.rs index dbe848e30efe..de589792a77a 100644 --- a/rust/kernel/num.rs +++ b/rust/kernel/num.rs @@ -15,9 +15,14 @@ pub enum Unsigned {} /// Designates signed primitive types. pub enum Signed {} =20 +mod private { + pub trait Sealed {} +} + /// Describes core properties of integer types. pub trait Integer: - Sized + private::Sealed + + Sized + Copy + Clone + PartialEq @@ -56,6 +61,8 @@ pub trait Integer: macro_rules! impl_integer { ($($type:ty: $signedness:ty), *) =3D> { $( + impl private::Sealed for $type {} + impl Integer for $type { type Signedness =3D $signedness; =20 --- base-commit: e510334fbaeaa016ac76d80b4c5f47611c5f7860 change-id: 20260903-feature-rust-num-seal-integer-a4262df429c6 Best regards, -- =20 Younes Akhouayri