selinux: avoid 64-bit division of inode numbers
Paul Moore
maintainerPATCH 1/1 selinux: avoid 64-bit division of inode numbers
As reported by Arnd, a previous change to convert the selinuxfs inode numbers to u64 to match the rest of the kernel caused a problem on 32-bit systems:
arm-linux-gnueabi-ld: .../selinuxfs.o: in function `sel_read_class':
selinuxfs.c:(.text+0xdcc): undefined reference to `__aeabi_uldivmod'
arm-linux-gnueabi-ld: .../selinuxfs.o: in function `sel_read_perm':
selinuxfs.c:(.text+0xed0): undefined reference to `__aeabi_uldivmod'
Since we don't currently use more than 24-bits in the selinuxfs inodes (see SEL_INO_MASK), fix this by applying the SEL_INO_MASK to the selinuxfs inode numbers and casting to a u32 before performing any division operations.
--- security/selinux/selinuxfs.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
security/selinux/selinuxfs.c +4 -2
@@ -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 ); } static ssize_t sel_read_class(struct file *file, char __user *buf,
Signature · 1 line
2.55.0
[email protected]
AI reviewSashiko has reviewed this patch and found no issues. It looks great!
Quoted 9 lines
As reported by Arnd, a previous change to convert the selinuxfs inode numbers to u64 to match the rest of the kernel caused a problem on 32-bit systems:
arm-linux-gnueabi-ld:
.../selinuxfs.o: in function `sel_read_class':selinuxfs.c:(.text+0xdcc): undefined reference to `__aeabi_uldivmod' arm-linux-gnueabi-ld: .../selinuxfs.o: in function `sel_read_perm': selinuxfs.c:(.text+0xed0): undefined reference to `__aeabi_uldivmod'
Quoted 8 lines
Since we don't currently use more than 24-bits in the selinuxfs inodes (see
SEL_INO_MASK), fix this by applying theSEL_INO_MASKto the selinuxfs inode numbers and casting to a u32 before performing any division operations.Fixes fc68b6a45f16 ("selinux: convert selinuxfs inode numbers from unsigned long to u64")Reported-by Arnd Bergmann <[email protected]>Signed-off-by Paul Moore <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Quoted 15 lines · Paul Moore
As reported by Arnd, a previous change to convert the selinuxfs inode numbers to u64 to match the rest of the kernel caused a problem on 32-bit systems:
arm-linux-gnueabi-ld:
.../selinuxfs.o: in function `sel_read_class':selinuxfs.c:(.text+0xdcc): undefined reference to `__aeabi_uldivmod' arm-linux-gnueabi-ld: .../selinuxfs.o: in function `sel_read_perm': selinuxfs.c:(.text+0xed0): undefined reference to `__aeabi_uldivmod'Since we don't currently use more than 24-bits in the selinuxfs inodes (see
SEL_INO_MASK), fix this by applying theSEL_INO_MASKto the selinuxfs inode numbers and casting to a u32 before performing any division operations.
Quoted 6 lines
Fixes fc68b6a45f16 ("selinux: convert selinuxfs inode numbers from unsigned long to u64")Reported-by Arnd Bergmann <[email protected]>Signed-off-by Paul Moore <[email protected]>--- security/selinux/selinuxfs.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
Merged into selinux/dev.
Signature · 1 line
paul-moore.com