All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Always build for LFS mode on 32-bit archs.
@ 2024-02-16  0:32 Steve Langasek
  2024-02-16  0:35 ` Steve Langasek
  0 siblings, 1 reply; 16+ messages in thread
From: Steve Langasek @ 2024-02-16  0:32 UTC (permalink / raw)
  To: selinux

Hello,

In Debian and Ubuntu, we are working to move future releases of the OS on
32-bit architectures (predominantly: armhf AKA arm-linux-gnueabihf) to use
64-bit time_t natively in anticipation of the y2038 event horizon.

While for most libraries we are taking the approach to rebuild in-place with
changed compiler flags and declaring incompatibility with previous package
builds via the package manager, libselinux is a sufficiently core part of
the OS (as a dependency of the package manager itself) that this is not
tenable.

Therefore I propose the following patch to libselinux to make it dual-ABI
for the single LFS-sensitive entry point, congruent to the way glibc itself
handles such changes.

The particular implementation doesn't use as many asm extension / symbol
version map tricks as glibc to make "nice" symbol names in the resulting
binary, it just gives us matchpathcon_filespec_add() and
matchpathcon_filespec_add64() as entrypoints.  If there is a preference for
more glibc-style handling with symbol versions I am happy to rework to
accomodate.

As this problem has been discovered rather late in our transition process, I
have a bit of a time crunch on my side which is not your problem, but I
would ask that whether or not the patch is ready to land, we reach a
consensus ASAP on:

  - whether it is acceptable to introduce a new entry point for this on
    32-bit architectures
  - the name this new entry point should use (including symbol version)
  - that it is acceptable to upstream that we proceed on implementing this
    at the distro level in advance of the patch landing upstream.

Thanks!




^ permalink raw reply	[flat|nested] 16+ messages in thread
* [PATCH] Always build for LFS mode on 32-bit archs.
@ 2024-11-28 16:54 Christian Göttsche
  2024-12-16 21:26 ` James Carter
  0 siblings, 1 reply; 16+ messages in thread
From: Christian Göttsche @ 2024-11-28 16:54 UTC (permalink / raw)
  To: selinux; +Cc: Steve Langasek, Christian Göttsche

From: Steve Langasek <steve.langasek@canonical.com>

Maintains the type signature of the existing matchpathcon_filespec_add()
entry point on 32-bit archs but maps the API to a new
matchpathcon_filespec_add64() entry point that takes a 64-bit ino_t argument
instead.

Software on 32-bit Linux ports which historically use a 32-bit time_t (thus
affected by the y2038 problem) have, as a precondition of migrating to
64-bit time_t, that they also migrate to large filesystem support because
glibc does not provide entry points for the cross-product of
(LFS: yes, LFS: no) x (time_t: 32, time_t: 64).

In order to support smooth migration of such operating systems from 32-bit
time_t to 64-bit time_t, it is useful for libselinux to:

- provide entry points on 32-bit systems for both LFS and non-LFS variants
  of the API (as glibc itself does)
- use LFS internally for all filesystem calls (just in case)
- map the API call to the correct implementation based on the build
  environment of the caller.

Signed-off-by: Steve Langasek <steve.langasek@canonical.com>
Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
---
Originally posted https://lore.kernel.org/selinux/ZeQuOBwQ2eSbkUAS@homer.dodds.net/1.2-0001-Always-build-for-LFS-mode-on-32-bit-archs.patch

v2:
 - Adjusted version in libselinux.map
 - check for __BITS_PER_LONG availability in matchpathcon.c similar to
   selinux.h
 - add static asserts, it's better to fail hard at compile time instead
   of having a silent ABI break
Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
---
 libselinux/Makefile                  |  6 ++++++
 libselinux/include/selinux/selinux.h |  5 +++++
 libselinux/src/Makefile              |  2 ++
 libselinux/src/libselinux.map        |  5 +++++
 libselinux/src/matchpathcon.c        | 26 ++++++++++++++++++++++++++
 libselinux/utils/Makefile            |  2 ++
 6 files changed, 46 insertions(+)

diff --git a/libselinux/Makefile b/libselinux/Makefile
index 6d9e2736..a50b6491 100644
--- a/libselinux/Makefile
+++ b/libselinux/Makefile
@@ -34,6 +34,12 @@ PCRE_CFLAGS += $(shell $(PKG_CONFIG) --cflags $(PCRE_MODULE))
 PCRE_LDLIBS := $(shell $(PKG_CONFIG) --libs $(PCRE_MODULE))
 export PCRE_MODULE PCRE_CFLAGS PCRE_LDLIBS
 
+USE_LFS ?= y
+ifeq ($(USE_LFS),y)
+	LFS_CFLAGS := -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64
+endif
+export LFS_CFLAGS
+
 OS := $(shell uname)
 export OS
 
diff --git a/libselinux/include/selinux/selinux.h b/libselinux/include/selinux/selinux.h
index 50419a7c..f3cf5a20 100644
--- a/libselinux/include/selinux/selinux.h
+++ b/libselinux/include/selinux/selinux.h
@@ -1,8 +1,10 @@
 #ifndef _SELINUX_H_
 #define _SELINUX_H_
 
+#include <stdint.h>
 #include <sys/types.h>
 #include <stdarg.h>
+#include <asm/bitsperlong.h>
 
 #ifdef __cplusplus
 extern "C" {
@@ -535,6 +537,9 @@ 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 && __BITS_PER_LONG < 64
+#define matchpathcon_filespec_add matchpathcon_filespec_add64
+#endif
 extern int matchpathcon_filespec_add(ino_t ino, int specind, const char *file);
 
 /* Destroy any inode associations that have been added, e.g. to restart
diff --git a/libselinux/src/Makefile b/libselinux/src/Makefile
index 41cfbdca..9909eb40 100644
--- a/libselinux/src/Makefile
+++ b/libselinux/src/Makefile
@@ -89,6 +89,8 @@ CFLAGS ?= -O -Wall -W -Wundef -Wformat-y2k -Wformat-security -Winit-self -Wmissi
           -Werror -Wno-aggregate-return \
           $(EXTRA_CFLAGS)
 
+override CFLAGS += $(LFS_CFLAGS)
+
 LD_SONAME_FLAGS=-soname,$(LIBSO),--version-script=libselinux.map,-z,defs,-z,relro
 
 ifeq ($(OS), Darwin)
diff --git a/libselinux/src/libselinux.map b/libselinux/src/libselinux.map
index 5e00f45b..02f5b761 100644
--- a/libselinux/src/libselinux.map
+++ b/libselinux/src/libselinux.map
@@ -252,3 +252,8 @@ LIBSELINUX_3.5 {
     getpidprevcon;
     getpidprevcon_raw;
 } LIBSELINUX_3.4;
+
+LIBSELINUX_3.8 {
+  global:
+    matchpathcon_filespec_add64;
+} LIBSELINUX_3.5;
diff --git a/libselinux/src/matchpathcon.c b/libselinux/src/matchpathcon.c
index 967520e4..15f9353d 100644
--- a/libselinux/src/matchpathcon.c
+++ b/libselinux/src/matchpathcon.c
@@ -1,3 +1,4 @@
+#include <assert.h>
 #include <sys/stat.h>
 #include <string.h>
 #include <errno.h>
@@ -261,6 +262,31 @@ int matchpathcon_filespec_add(ino_t ino, int specind, const char *file)
 	return -1;
 }
 
+#if defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS == 64 && __BITS_PER_LONG < 64
+/* alias defined in the public header but we undefine it here */
+#undef matchpathcon_filespec_add
+
+/* ABI backwards-compatible shim for non-LFS 32-bit systems */
+
+static_assert(sizeof(unsigned long) == sizeof(__ino_t), "inode size mismatch");
+static_assert(sizeof(unsigned long) == sizeof(uint32_t), "inode size mismatch");
+static_assert(sizeof(ino_t) == sizeof(ino64_t), "inode size mismatch");
+static_assert(sizeof(ino64_t) == sizeof(uint64_t), "inode size mismatch");
+
+extern int matchpathcon_filespec_add(unsigned long ino, int specind,
+                                     const char *file);
+
+int matchpathcon_filespec_add(unsigned long ino, int specind,
+                              const char *file)
+{
+	return matchpathcon_filespec_add64(ino, specind, file);
+}
+#else
+
+static_assert(sizeof(unsigned long) == sizeof(ino_t), "inode size mismatch");
+
+#endif
+
 /*
  * Evaluate the association hash table distribution.
  */
diff --git a/libselinux/utils/Makefile b/libselinux/utils/Makefile
index f3cedc11..0d7095b1 100644
--- a/libselinux/utils/Makefile
+++ b/libselinux/utils/Makefile
@@ -36,6 +36,8 @@ CFLAGS ?= -O -Wall -W -Wundef -Wformat-y2k -Wformat-security -Winit-self -Wmissi
           -Werror -Wno-aggregate-return -Wno-redundant-decls -Wstrict-overflow=5 \
           $(EXTRA_CFLAGS)
 
+override CFLAGS += $(LFS_CFLAGS)
+
 ifeq ($(OS), Darwin)
 override CFLAGS += -I/opt/local/include -I../../libsepol/include
 override LDFLAGS += -L../../libsepol/src -undefined dynamic_lookup
-- 
2.45.2


^ permalink raw reply related	[flat|nested] 16+ messages in thread
* [PATCH] Always build for LFS mode on 32-bit archs.
@ 2024-02-16  0:18 Steve Langasek
  0 siblings, 0 replies; 16+ messages in thread
From: Steve Langasek @ 2024-02-16  0:18 UTC (permalink / raw)
  To: selinux

Hello,

In Debian and Ubuntu, we are working to move future releases of the OS on
32-bit architectures (predominantly: armhf AKA arm-linux-gnueabihf) to use
64-bit time_t natively in anticipation of the y2038 event horizon.

While for most libraries we are taking the approach to rebuild in-place with
changed compiler flags and declaring incompatibility with previous package
builds via the package manager, libselinux is a sufficiently core part of
the OS (as a dependency of the package manager itself) that this is not
tenable.

Therefore I propose the following patch to libselinux to make it dual-ABI
for the single LFS-sensitive entry point, congruent to the way glibc itself
handles such changes.

The particular implementation doesn't use as many asm extension / symbol
version map tricks as glibc to make "nice" symbol names in the resulting
binary, it just gives us matchpathcon_filespec_add() and
matchpathcon_filespec_add64() as entrypoints.  If there is a preference for
more glibc-style handling with symbol versions I am happy to rework to
accomodate.

As this problem has been discovered rather late in our transition process, I
have a bit of a time crunch on my side which is not your problem, but I
would ask that whether or not the patch is ready to land, we reach a
consensus ASAP on:

  - whether it is acceptable to introduce a new entry point for this on
    32-bit architectures
  - the name this new entry point should use (including symbol version)
  - that it is acceptable to upstream that we proceed on implementing this
    at the distro level in advance of the patch landing upstream.

Thanks!


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

end of thread, other threads:[~2024-12-17 20:25 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-02-16  0:32 [PATCH] Always build for LFS mode on 32-bit archs Steve Langasek
2024-02-16  0:35 ` Steve Langasek
2024-02-17 21:54   ` Kees Cook
2024-02-18  3:08     ` Steve Langasek
2024-02-25  6:45       ` Steve Langasek
2024-02-26 17:52         ` Christian Göttsche
2024-02-27  7:00           ` Steve Langasek
2024-02-27 17:13             ` Christian Göttsche
2024-02-28  6:11               ` Steve Langasek
2024-02-28  9:20                 ` Petr Lautrbach
2024-03-03  8:00                   ` Steve Langasek
2024-06-02 16:40                     ` Chris Hofstaedtler
  -- strict thread matches above, loose matches on Subject: below --
2024-11-28 16:54 Christian Göttsche
2024-12-16 21:26 ` James Carter
2024-12-17 20:25   ` James Carter
2024-02-16  0:18 Steve Langasek

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.