Skip to content

Commit

Permalink
Always build for LFS mode on 32-bit archs.
Browse files Browse the repository at this point in the history
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>
Acked-by: James Carter <jwcart2@gmail.com>
  • Loading branch information
vorlonofportland authored and jwcart2 committed Dec 17, 2024
1 parent 2fc29ae commit 9395cc0
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 0 deletions.
6 changes: 6 additions & 0 deletions libselinux/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 5 additions & 0 deletions libselinux/include/selinux/selinux.h
Original file line number Diff line number Diff line change
@@ -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" {
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions libselinux/src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions libselinux/src/libselinux.map
Original file line number Diff line number Diff line change
Expand Up @@ -252,3 +252,8 @@ LIBSELINUX_3.5 {
getpidprevcon;
getpidprevcon_raw;
} LIBSELINUX_3.4;

LIBSELINUX_3.8 {
global:
matchpathcon_filespec_add64;
} LIBSELINUX_3.5;
26 changes: 26 additions & 0 deletions libselinux/src/matchpathcon.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <assert.h>
#include <sys/stat.h>
#include <string.h>
#include <errno.h>
Expand Down Expand Up @@ -260,6 +261,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.
*/
Expand Down
2 changes: 2 additions & 0 deletions libselinux/utils/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 9395cc0

Please sign in to comment.