mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] selinux: use explicit 64-bit division
@ 2026-09-15 19:56 Arnd Bergmann
  2026-09-15 20:36 ` Paul Moore
  0 siblings, 1 reply; 4+ messages in thread
From: Arnd Bergmann @ 2026-09-15 19:56 UTC (permalink / raw)
  To: Paul Moore, Stephen Smalley
  Cc: Arnd Bergmann, Ondrej Mosnáček, selinux, linux-kernel

From: Arnd Bergmann <arnd@arndb.de>

On 32-bit targets, the division of a 64-bit integer by 33 causes a
function call:

arm-linux-gnueabi-ld: security/selinux/selinuxfs.o: in function `sel_read_class':
selinuxfs.c:(.text+0xdcc): undefined reference to `__aeabi_uldivmod'
arm-linux-gnueabi-ld: security/selinux/selinuxfs.o: in function `sel_read_perm':
selinuxfs.c:(.text+0xed0): undefined reference to `__aeabi_uldivmod'

Replace this with an explicit call to div_u64() and div_u64_rem() to
annotate that these are potentially very slow.

Fixes: fc68b6a45f16 ("selinux: convert selinuxfs inode numbers from unsigned long to u64")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 security/selinux/selinuxfs.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/security/selinux/selinuxfs.c b/security/selinux/selinuxfs.c
index f60f92e2ac34..7894a2f480f7 100644
--- a/security/selinux/selinuxfs.c
+++ b/security/selinux/selinuxfs.c
@@ -1573,7 +1573,7 @@ static inline u64 sel_class_to_ino(u16 class)
 
 static inline u16 sel_ino_to_class(u64 ino)
 {
-	return (ino & SEL_INO_MASK) / (SEL_VEC_MAX + 1);
+	return div_u64(ino & SEL_INO_MASK, SEL_VEC_MAX + 1);
 }
 
 static inline u64 sel_perm_to_ino(u16 class, u32 perm)
@@ -1583,7 +1583,11 @@ static inline u64 sel_perm_to_ino(u16 class, u32 perm)
 
 static inline u32 sel_ino_to_perm(u64 ino)
 {
-	return (ino & SEL_INO_MASK) % (SEL_VEC_MAX + 1);
+	u32 rem;
+
+	div_u64_rem(ino & SEL_INO_MASK, SEL_VEC_MAX + 1, &rem);
+
+	return rem;
 }
 
 static ssize_t sel_read_class(struct file *file, char __user *buf,
-- 
2.53.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] selinux: use explicit 64-bit division
  2026-09-15 19:56 [PATCH] selinux: use explicit 64-bit division Arnd Bergmann
@ 2026-09-15 20:36 ` Paul Moore
  2026-09-15 20:42   ` Arnd Bergmann
  0 siblings, 1 reply; 4+ messages in thread
From: Paul Moore @ 2026-09-15 20:36 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Stephen Smalley, Arnd Bergmann, Ondrej Mosnáček,
	selinux, linux-kernel

On Tue, Sep 15, 2026 at 3:57 PM Arnd Bergmann <arnd@kernel.org> wrote:
>
> From: Arnd Bergmann <arnd@arndb.de>
>
> On 32-bit targets, the division of a 64-bit integer by 33 causes a
> function call:
>
> arm-linux-gnueabi-ld: security/selinux/selinuxfs.o: in function `sel_read_class':
> selinuxfs.c:(.text+0xdcc): undefined reference to `__aeabi_uldivmod'
> arm-linux-gnueabi-ld: security/selinux/selinuxfs.o: in function `sel_read_perm':
> selinuxfs.c:(.text+0xed0): undefined reference to `__aeabi_uldivmod'
>
> Replace this with an explicit call to div_u64() and div_u64_rem() to
> annotate that these are potentially very slow.
>
> Fixes: fc68b6a45f16 ("selinux: convert selinuxfs inode numbers from unsigned long to u64")
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> ---
>  security/selinux/selinuxfs.c | 8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)

Thanks Arnd.

As sashiko pointed out[1], since we don't really use the full 64-bit
inode space, what do you think about the following fix instead?

diff --git a/security/selinux/selinuxfs.c b/security/selinux/selinuxfs.c
index 292302eb60f3..d864c314c873 100644
--- a/security/selinux/selinuxfs.c
+++ b/security/selinux/selinuxfs.c
@@ -1574,7 +1574,8 @@ static inline u64 sel_class_to_ino(u16 class)

 static inline u16 sel_ino_to_class(u64 ino)
 {
-       return (ino & SEL_INO_MASK) / (SEL_VEC_MAX + 1);
+       u32 ino_masked = ino & SEL_INO_MASK;
+       return ino_masked / (SEL_VEC_MAX + 1);
 }

 static inline u64 sel_perm_to_ino(u16 class, u32 perm)
@@ -1584,7 +1585,8 @@ static inline u64 sel_perm_to_ino(u16 class, u32 perm)

 static inline u32 sel_ino_to_perm(u64 ino)
 {
-       return (ino & SEL_INO_MASK) % (SEL_VEC_MAX + 1);
+       u32 ino_masked = ino & SEL_INO_MASK;
+       return ino_masked % (SEL_VEC_MAX + 1);
 }

[1] https://lore.kernel.org/selinux/20260915200522.BBC8A1F000FF@smtp.kernel.org/

-- 
paul-moore.com

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] selinux: use explicit 64-bit division
  2026-09-15 20:36 ` Paul Moore
@ 2026-09-15 20:42   ` Arnd Bergmann
  2026-09-15 21:40     ` Paul Moore
  0 siblings, 1 reply; 4+ messages in thread
From: Arnd Bergmann @ 2026-09-15 20:42 UTC (permalink / raw)
  To: Paul Moore, Arnd Bergmann
  Cc: Stephen Smalley, Ondrej Mosnáček, selinux, linux-kernel

On Tue, Sep 15, 2026, at 22:36, Paul Moore wrote:
> On Tue, Sep 15, 2026 at 3:57 PM Arnd Bergmann <arnd@kernel.org> wrote:
>>
>> From: Arnd Bergmann <arnd@arndb.de>
>>
>> On 32-bit targets, the division of a 64-bit integer by 33 causes a
>> function call:
>>
>> arm-linux-gnueabi-ld: security/selinux/selinuxfs.o: in function `sel_read_class':
>> selinuxfs.c:(.text+0xdcc): undefined reference to `__aeabi_uldivmod'
>> arm-linux-gnueabi-ld: security/selinux/selinuxfs.o: in function `sel_read_perm':
>> selinuxfs.c:(.text+0xed0): undefined reference to `__aeabi_uldivmod'
>>
>> Replace this with an explicit call to div_u64() and div_u64_rem() to
>> annotate that these are potentially very slow.
>>
>> Fixes: fc68b6a45f16 ("selinux: convert selinuxfs inode numbers from unsigned long to u64")
>> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
>> ---
>>  security/selinux/selinuxfs.c | 8 ++++++--
>>  1 file changed, 6 insertions(+), 2 deletions(-)
>
> Thanks Arnd.
>
> As sashiko pointed out[1], since we don't really use the full 64-bit
> inode space, what do you think about the following fix instead?

Ah right, I hadn't checked the actual value of SEL_INO_MASK, and the
description of your patch made it sound like the 64-bit space
was actually required.

Your patch is better then, you can treat my mail as Reported-by.

     Arnd

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] selinux: use explicit 64-bit division
  2026-09-15 20:42   ` Arnd Bergmann
@ 2026-09-15 21:40     ` Paul Moore
  0 siblings, 0 replies; 4+ messages in thread
From: Paul Moore @ 2026-09-15 21:40 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Arnd Bergmann, Stephen Smalley, Ondrej Mosnáček,
	selinux, linux-kernel

On Tue, Sep 15, 2026 at 4:43 PM Arnd Bergmann <arnd@arndb.de> wrote:
> On Tue, Sep 15, 2026, at 22:36, Paul Moore wrote:
> > On Tue, Sep 15, 2026 at 3:57 PM Arnd Bergmann <arnd@kernel.org> wrote:
> >>
> >> From: Arnd Bergmann <arnd@arndb.de>
> >>
> >> On 32-bit targets, the division of a 64-bit integer by 33 causes a
> >> function call:
> >>
> >> arm-linux-gnueabi-ld: security/selinux/selinuxfs.o: in function `sel_read_class':
> >> selinuxfs.c:(.text+0xdcc): undefined reference to `__aeabi_uldivmod'
> >> arm-linux-gnueabi-ld: security/selinux/selinuxfs.o: in function `sel_read_perm':
> >> selinuxfs.c:(.text+0xed0): undefined reference to `__aeabi_uldivmod'
> >>
> >> Replace this with an explicit call to div_u64() and div_u64_rem() to
> >> annotate that these are potentially very slow.
> >>
> >> Fixes: fc68b6a45f16 ("selinux: convert selinuxfs inode numbers from unsigned long to u64")
> >> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> >> ---
> >>  security/selinux/selinuxfs.c | 8 ++++++--
> >>  1 file changed, 6 insertions(+), 2 deletions(-)
> >
> > Thanks Arnd.
> >
> > As sashiko pointed out[1], since we don't really use the full 64-bit
> > inode space, what do you think about the following fix instead?
>
> Ah right, I hadn't checked the actual value of SEL_INO_MASK, and the
> description of your patch made it sound like the 64-bit space
> was actually required.

No worries, selinuxfs is a bit odd sometimes.

> Your patch is better then, you can treat my mail as Reported-by.

Done, patch link below.  Thanks again!

https://lore.kernel.org/selinux/20260915213807.481355-2-paul@paul-moore.com

-- 
paul-moore.com

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-09-15 21:40 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-15 19:56 [PATCH] selinux: use explicit 64-bit division Arnd Bergmann
2026-09-15 20:36 ` Paul Moore
2026-09-15 20:42   ` Arnd Bergmann
2026-09-15 21:40     ` Paul Moore

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®