Skip to content

Don't inject matchpathcon_filespec_add64() ifdef __x86_64__ (#463, Debian#1098481) #464

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

nabijaczleweli
Copy link
Contributor

As the code notes, it wants to add an

/* ABI backwards-compatible shim for non-LFS 32-bit systems */

it tries to detect these with

#if defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS == 64 && __BITS_PER_LONG < 64

which is correct with the added precondition that the ino_t without
-D_FILE_OFFSET_BITS=64 was actually u32 (i.e. it conflates all ILP32 systems into being non-LFS).

This is not the case on x32, for example, which is LFS; thus, the

static_assert(sizeof(unsigned long) == sizeof(__ino_t), "inode size mismatch");

assertion fails (__ino_t is the "kernel ino_t" type, which generally corresponds to the kernel's ulong, which is u64 on x32).

The correct spelling of the test for this is

#if ... && sizeof(__ino_t) == 4

but this is not statically solvable with the preprocessor.

Thus, we need to explicitly special-case this. __x86_64__ indicates one of two ABIs (LP64 (amd64) or ILP32 (x32)), both of which have ino_t=u64, and is the macro used for defining __INO_T_TYPE in the system headers, so it's the best fit here.

Fixes: commit 9395cc0 ("Always build for LFS mode on 32-bit archs.")
Closes: #463
Closes: Debian#1098481
Cc: @kainz


Insert -I../../libselinux/include and -L../../libselinux/src into subprograms where needed

These subprograms (sublibraries) use plain

#include <selinux/selinux.h>
cc ... -lselinux ...

&c. which includes/links to the system libselinux.

Naturally, this doesn't work if you don't have one.

These all came out of a plain build on x32.

@bachradsusi
Copy link
Member

Hello, thanks for the patch!

In order to get the patch reviewed and accepted, it's necessary to send it to [email protected] mailing list. The best way is to use git send-email command, e.g.:

 git send-email --from='Your Name <[email protected]>' [email protected] --smtp-server=my.smtp.server --confirm=auto -1

See https://github.com/SELinuxProject/selinux/blob/main/CONTRIBUTING.md

@mildsunrise
Copy link

mildsunrise commented Mar 18, 2025

@nabijaczleweli thank you for the patch, I was about to submit a very similar one for RV32. unfortunately this one doesn't fully fix the issue for all 32-bit LFS platforms, and I'm not sure what would be the best way to do that

@mildsunrise
Copy link

mildsunrise commented Mar 18, 2025

The definition is using __ino_t which is, as far as I can see, glibc specific. If using glibc-specific macros is acceptable, then the right criteria would be:

-#if defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS == 64 && __BITS_PER_LONG < 64
+#if defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS == 64 && __TIMESIZE < 64

or also

#ifndef __INO_T_MATCHES_INO64_T

@nabijaczleweli
Copy link
Contributor Author

I think you nailed it actually yeah

@nabijaczleweli
Copy link
Contributor Author

@mildsunrise
Copy link

perfect, thank you :)

@mildsunrise
Copy link

hi sorry to bother you again, just wanted to note that (if I'm not mistaken) this patch breaks builds with USE_LFS=n on non-LFS 32-bit systems. I think nobody should be building with USE_LFS=n but since it's just a default, wanted to raise it just in case.

of course, the previous assertion

static_assert(sizeof(unsigned long) == sizeof(ino_t), "inode size mismatch");

was also wrong... I'd suggest a third clause, e.g.:

#if (defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS == 64) && !defined(__INO_T_MATCHES_INO64_T)
/*...*/
#elif (defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS == 64) || !defined(__INO_T_MATCHES_INO64_T)

static_assert(sizeof(uint64_t) == sizeof(ino_t), "inode size mismatch");

#else

static_assert(sizeof(uint32_t) == sizeof(ino_t), "inode size mismatch");

#endif

…4_T) instead of using __BITS_PER_LONG < 64 as proxy

The __INO_T_MATCHES_INO64_T is defined
if ino_t would be the same size as ino64_t
if -D_FILE_OFFSET_BITS=64 were not defined.

This is /exactly/ what
  /* ABI backwards-compatible shim for non-LFS 32-bit systems */
  #if defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS == 64 && __BITS_PER_LONG < 64
is trying to get at, but currently fails because x32/RV32 are "LFS"
with 32-bit longs and 64-bit time_ts natively.

Thus, the
  static_assert(sizeof(unsigned long) == sizeof(__ino_t), "inode size mismatch");
assertion fails (__ino_t is the "kernel ino_t" type,
which generally corresponds to the kernel's ulong, which is u64 on x32).

glibc headers allow us to check the condition we care about directly.

Fixes: commit 9395cc0 ("Always build for LFS mode on 32-bit archs.")
Closes: SELinuxProject#463
Closes: Debian#1098481
Signed-off-by: наб <[email protected]>
Cc: Alba Mendez <[email protected]>
…programs where needed

These subprograms (sublibraries) use plain
  #include <selinux/selinux.h>
  cc ... -lselinux ...
&c. which includes/links to the system libselinux.

Naturally, this doesn't work if you don't have one.

All of these fell out of a plain make invocation,
yielding errors like
  cc  -O2 -Werror -Wall -Wextra -Wfloat-equal -Wformat=2 -Winit-self -Wmissing-format-attribute -Wmissing-noreturn -Wmissing-prototypes -Wnull-dereference -Wpointer-arith -Wshadow -Wstrict-prototypes -Wundef -Wunused -Wwrite-strings -fno-common -I../include -D_GNU_SOURCE -c -o boolean_record.o boolean_record.c
  boolean_record.c:26:10: fatal error: selinux/selinux.h: No such file or directory
     26 | #include <selinux/selinux.h>
        |          ^~~~~~~~~~~~~~~~~~~
  compilation terminated.

  make[2]: Entering directory '/tmp/selinux/policycoreutils/sestatus'
  cc -O2 -Werror -Wall -Wextra -Wfloat-equal -Wformat=2 -Winit-self -Wmissing-format-attribute -Wmissing-noreturn -Wmissing-prototypes -Wnull-dereference -Wpointer-arith -Wshadow -Wstrict-prototypes -Wundef -Wunused -Wwrite-strings -fno-common -D_FILE_OFFSET_BITS=64   -c -o sestatus.o sestatus.c
  sestatus.c:12:10: fatal error: selinux/selinux.h: No such file or directory
     12 | #include <selinux/selinux.h>
        |          ^~~~~~~~~~~~~~~~~~~
  compilation terminated.

Signed-off-by: наб <[email protected]>
@nabijaczleweli
Copy link
Contributor Author

@mildsunrise
Copy link

perfect, thanks again!

@mildsunrise
Copy link

It seems that before this patch, libselinux didn't compile with musl for 32-bit platforms, and this patch further broke the build for 64-bit platforms too. @alyssais has posted an improved version of this patch which should fix the build for both 32-bit and 64-bit platforms :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

selinux 3.8 build fails on x32 due to (erroneous?) asserts in matchpathcon.c
3 participants