0001-Inject-matchpathcon_filespec_add64-if-defined-__INO_.patch 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. From 5c3fcbd931b7f9752b5ce29cec3b6813991d61c0 Mon Sep 17 00:00:00 2001
  2. From: =?UTF-8?q?=D0=BD=D0=B0=D0=B1?= <[email protected]>
  3. Date: Thu, 20 Mar 2025 16:55:17 +0100
  4. Subject: [PATCH] Inject matchpathcon_filespec_add64() if
  5. !defined(__INO_T_MATCHES_INO64_T) instead of using __BITS_PER_LONG < 64 as
  6. proxy
  7. MIME-Version: 1.0
  8. Content-Type: text/plain; charset=UTF-8
  9. Content-Transfer-Encoding: 8bit
  10. The __INO_T_MATCHES_INO64_T is defined
  11. if ino_t would be the same size as ino64_t
  12. if -D_FILE_OFFSET_BITS=64 were not defined.
  13. This is /exactly/ what
  14. /* ABI backwards-compatible shim for non-LFS 32-bit systems */
  15. #if defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS == 64 && __BITS_PER_LONG < 64
  16. is trying to get at, but currently fails because x32/RV32 are "LFS"
  17. with 32-bit longs and 64-bit time_ts natively.
  18. Thus, the
  19. static_assert(sizeof(unsigned long) == sizeof(__ino_t), "inode size mismatch");
  20. assertion fails (__ino_t is the "kernel ino_t" type,
  21. which generally corresponds to the kernel's ulong, which is u64 on x32).
  22. glibc headers allow us to check the condition we care about directly.
  23. Fixes: commit 9395cc0322 ("Always build for LFS mode on 32-bit archs.")
  24. Closes: #463
  25. Closes: Debian#1098481
  26. Signed-off-by: наб <[email protected]>
  27. Cc: Alba Mendez <[email protected]>
  28. Acked-by: James Carter <[email protected]>
  29. ---
  30. include/selinux/selinux.h | 2 +-
  31. src/matchpathcon.c | 8 ++++++--
  32. 2 files changed, 7 insertions(+), 3 deletions(-)
  33. --- a/include/selinux/selinux.h
  34. +++ b/include/selinux/selinux.h
  35. @@ -537,7 +537,7 @@ extern int matchpathcon_index(const char
  36. with the same inode (e.g. due to multiple hard links). If so, then
  37. use the latter of the two specifications based on their order in the
  38. file contexts configuration. Return the used specification index. */
  39. -#if defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS == 64 && __BITS_PER_LONG < 64
  40. +#if defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS == 64 && !defined(__INO_T_MATCHES_INO64_T)
  41. #define matchpathcon_filespec_add matchpathcon_filespec_add64
  42. #endif
  43. extern int matchpathcon_filespec_add(ino_t ino, int specind, const char *file);
  44. --- a/src/matchpathcon.c
  45. +++ b/src/matchpathcon.c
  46. @@ -261,7 +261,7 @@ int matchpathcon_filespec_add(ino_t ino,
  47. return -1;
  48. }
  49. -#if defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS == 64 && __BITS_PER_LONG < 64
  50. +#if (defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS == 64) && !defined(__INO_T_MATCHES_INO64_T)
  51. /* alias defined in the public header but we undefine it here */
  52. #undef matchpathcon_filespec_add
  53. @@ -280,9 +280,13 @@ int matchpathcon_filespec_add(unsigned l
  54. {
  55. return matchpathcon_filespec_add64(ino, specind, file);
  56. }
  57. +#elif (defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS == 64) || defined(__INO_T_MATCHES_INO64_T)
  58. +
  59. +static_assert(sizeof(uint64_t) == sizeof(ino_t), "inode size mismatch");
  60. +
  61. #else
  62. -static_assert(sizeof(unsigned long) == sizeof(ino_t), "inode size mismatch");
  63. +static_assert(sizeof(uint32_t) == sizeof(ino_t), "inode size mismatch");
  64. #endif