Skip to contentSkip to conversation

libselinux: be careful with non-portable LFS macro

PATCH In review Alyssa Ross 2 participants 3 messages Apr 26, 2025 – May 6, 2025 SELinux security module

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 libselinux: be careful with non-portable LFS macro

musl does not provide the obsolete LFS64 APIs (like ino64_t) — ino_t has always been 64-bit on all platforms there. That means there's also no __INO_T_MATCHES_INO64_T macro, meaning the check would pass and reach the static asserts for the shim, which would fail due to there being no ino64_t to check the size of. Fix this by only assuming the absense of __INO_T_MATCHES_INO64_t is meaningful when another non-portable Glibc macro, __INO64_T_TYPE, is defined. If both are missing, that probably just means there is no ino64_t.

Fixes 5c3fcbd9 ("Inject matchpathcon_filespec_add64() if !defined(__INO_T_MATCHES_INO64_T) instead of using __BITS_PER_LONG < 64 as proxy")

---
v2: Made the same change to the condition in the header, as suggested
in a GitHub comment. The omission didn't seem to break anything, but it makes sense to change it there too.
https://github.com/NixOS/nixpkgs/pull/391728#issuecomment-2832282846

 libselinux/include/selinux/selinux.h | 2 +-
 libselinux/src/matchpathcon.c        | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
libselinux/include/selinux/selinux.h +1 -1
index f64896b7..b1431e5d 100644
@@ -537,7 +537,7 @@ extern int matchpathcon_index(const char *path,
    with the same inode (e.g. due to multiple hard links).  If so, then
    use the latter of the two specifications based on their order in the 
    file contexts configuration.  Return the used specification index. */
-#if defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS == 64 && !defined(__INO_T_MATCHES_INO64_T)
+#if defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS == 64 && defined(__INO64_T_TYPE) && !defined(__INO_T_MATCHES_INO64_T)
 #define matchpathcon_filespec_add matchpathcon_filespec_add64
 #endif
 extern int matchpathcon_filespec_add(ino_t ino, int specind, const char *file);
libselinux/src/matchpathcon.c +1 -1
index a4f65045..240c9fa7 100644
@@ -261,7 +261,7 @@ int matchpathcon_filespec_add(ino_t ino, int specind, const char *file)
 	return -1;
 }
 
-#if (defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS == 64) && !defined(__INO_T_MATCHES_INO64_T)
+#if (defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS == 64) && defined(__INO64_T_TYPE) && !defined(__INO_T_MATCHES_INO64_T)
 /* alias defined in the public header but we undefine it here */
 #undef matchpathcon_filespec_add
 

base-commit: 2647cc0fdca326b81ee3c08718cbe19b7866b53a

Signature · 1 line
2.47.2
Acked-by on v2 1/1
#1 lore raw
Quoted 10 lines · Alyssa Ross

musl does not provide the obsolete LFS64 APIs (like ino64_t) — ino_t has always been 64-bit on all platforms there. That means there's also no __INO_T_MATCHES_INO64_T macro, meaning the check would pass and reach the static asserts for the shim, which would fail due to there being no ino64_t to check the size of. Fix this by only assuming the absense of __INO_T_MATCHES_INO64_t is meaningful when another non-portable Glibc macro, __INO64_T_TYPE, is defined. If both are missing, that probably just means there is no ino64_t.

Quoted 2 lines
Fixes 5c3fcbd9 ("Inject matchpathcon_filespec_add64() if !defined(__INO_T_MATCHES_INO64_T) instead of using __BITS_PER_LONG < 64 as proxy")
Quoted 41 lines

---
v2: Made the same change to the condition in the header, as suggested
in a GitHub comment. The omission didn't seem to break anything, but it makes sense to change it there too.
https://github.com/NixOS/nixpkgs/pull/391728#issuecomment-2832282846

 libselinux/include/selinux/selinux.h | 2 +-
 libselinux/src/matchpathcon.c        | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
libselinux/include/selinux/selinux.h +1 -1
index f64896b7..b1431e5d 100644
@@ -537,7 +537,7 @@ extern int matchpathcon_index(const char *path,
    with the same inode (e.g. due to multiple hard links).  If so, then
    use the latter of the two specifications based on their order in the
    file contexts configuration.  Return the used specification index. */
-#if defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS == 64 && !defined(__INO_T_MATCHES_INO64_T)
+#if defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS == 64 && defined(__INO64_T_TYPE) && !defined(__INO_T_MATCHES_INO64_T)
 #define matchpathcon_filespec_add matchpathcon_filespec_add64
 #endif
 extern int matchpathcon_filespec_add(ino_t ino, int specind, const char *file);
libselinux/src/matchpathcon.c +1 -1
index a4f65045..240c9fa7 100644
@@ -261,7 +261,7 @@ int matchpathcon_filespec_add(ino_t ino, int specind, const char *file)
        return -1;
 }
 
-#if (defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS == 64) && !defined(__INO_T_MATCHES_INO64_T)
+#if (defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS == 64) && defined(__INO64_T_TYPE) && !defined(__INO_T_MATCHES_INO64_T)
 /* alias defined in the public header but we undefine it here */
 #undef matchpathcon_filespec_add
 

base-commit: 2647cc0fdca326b81ee3c08718cbe19b7866b53a --
2.47.2

#2 lore raw
Quoted 12 lines · James Carter
Quoted 10 lines · Alyssa Ross

musl does not provide the obsolete LFS64 APIs (like ino64_t) — ino_t has always been 64-bit on all platforms there. That means there's also no __INO_T_MATCHES_INO64_T macro, meaning the check would pass and reach the static asserts for the shim, which would fail due to there being no ino64_t to check the size of. Fix this by only assuming the absense of __INO_T_MATCHES_INO64_t is meaningful when another non-portable Glibc macro, __INO64_T_TYPE, is defined. If both are missing, that probably just means there is no ino64_t.

Quoted 5 lines
Quoted 2 lines
Fixes 5c3fcbd9 ("Inject matchpathcon_filespec_add64() if !defined(__INO_T_MATCHES_INO64_T) instead of using __BITS_PER_LONG < 64 as proxy")

Merged.
Thanks,
Jim

Quoted 41 lines
Quoted 41 lines

---
v2: Made the same change to the condition in the header, as suggested
in a GitHub comment. The omission didn't seem to break anything, but it makes sense to change it there too.
https://github.com/NixOS/nixpkgs/pull/391728#issuecomment-2832282846

 libselinux/include/selinux/selinux.h | 2 +-
 libselinux/src/matchpathcon.c        | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
libselinux/include/selinux/selinux.h +1 -1
index f64896b7..b1431e5d 100644
@@ -537,7 +537,7 @@ extern int matchpathcon_index(const char *path,
    with the same inode (e.g. due to multiple hard links).  If so, then
    use the latter of the two specifications based on their order in the
    file contexts configuration.  Return the used specification index. */
-#if defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS == 64 && !defined(__INO_T_MATCHES_INO64_T)
+#if defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS == 64 && defined(__INO64_T_TYPE) && !defined(__INO_T_MATCHES_INO64_T)
 #define matchpathcon_filespec_add matchpathcon_filespec_add64
 #endif
 extern int matchpathcon_filespec_add(ino_t ino, int specind, const char *file);
libselinux/src/matchpathcon.c +1 -1
index a4f65045..240c9fa7 100644
@@ -261,7 +261,7 @@ int matchpathcon_filespec_add(ino_t ino, int specind, const char *file)
        return -1;
 }
 
-#if (defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS == 64) && !defined(__INO_T_MATCHES_INO64_T)
+#if (defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS == 64) && defined(__INO64_T_TYPE) && !defined(__INO_T_MATCHES_INO64_T)
 /* alias defined in the public header but we undefine it here */
 #undef matchpathcon_filespec_add
 

base-commit: 2647cc0fdca326b81ee3c08718cbe19b7866b53a --
2.47.2