Re: [PATCH] rust: num: seal Integer

From: Alexandre Courbot

Date: Sat Sep 05 2026 - 20:18:24 EST


On Sat Sep 5, 2026 at 11:22 PM JST, Gary Guo wrote:
> On Sat Sep 5, 2026 at 3:17 AM BST, Younes Akhouayri via B4 Relay wrote:
>> From: Younes Akhouayri <git@xxxxxxxxx>
>>
>> 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+Ueivd5NrC5yre+Pcp57ZOBz0msw9A4AP1Q@xxxxxxxxxxxxxx/
>> Cc: stable@xxxxxxxxxxxxxxx
>> Suggested-by: Miguel Ojeda <ojeda@xxxxxxxxxx>
>> Signed-off-by: Younes Akhouayri <git@xxxxxxxxx>
>> ---
>> 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 {}
>>
>> +mod private {
>> + pub trait Sealed {}
>> +}
>
> I feel that it's time to add an attribute macro for sealing.

+1, this is going to be a really common pattern.