[packages/libselinux] Rel 3. SWIG 4.5 build fix
arekm
arekm at pld-linux.org
Sat Oct 24 10:47:31 CEST 2026
commit 8fe1174a3b0ccec1fdd18fb76ca0e6fef82626b6
Author: Arkadiusz Miśkiewicz <arekm at maven.pl>
Date: Sat Oct 24 10:46:51 2026 +0200
Rel 3. SWIG 4.5 build fix
libselinux-restorecon-xattr-uaf.patch | 56 +++++++++++++++++++++++++++++++++++
libselinux-swig4.5.patch | 53 +++++++++++++++++++++++++++++++++
libselinux.spec | 10 +++++--
3 files changed, 117 insertions(+), 2 deletions(-)
---
diff --git a/libselinux.spec b/libselinux.spec
index a012ec4..235a47d 100644
--- a/libselinux.spec
+++ b/libselinux.spec
@@ -8,13 +8,17 @@ Summary: SELinux library and simple utilities
Summary(pl.UTF-8): Biblioteka SELinux i proste narzędzia
Name: libselinux
Version: 3.11
-Release: 2
+Release: 3
License: Public Domain
Group: Libraries
#Source0Download: https://github.com/SELinuxProject/selinux/wiki/Releases
Source0: https://github.com/SELinuxProject/selinux/releases/download/%{version}/%{name}-%{version}.tar.gz
# Source0-md5: 14c406813dc389a9c9a0d70a05b8be65
Patch0: %{name}-no-pip.patch
+# https://github.com/SELinuxProject/selinux/commit/fb518ff492; SWIG 4.5 dropped PyString_* macros
+Patch1: %{name}-swig4.5.patch
+# https://github.com/SELinuxProject/selinux/commit/15e0901f9b
+Patch2: %{name}-restorecon-xattr-uaf.patch
URL: https://github.com/SELinuxProject/selinux/wiki
%ifarch ppc ppc64 sparc sparcv9 sparc64
BuildRequires: gcc >= 5:3.4
@@ -143,11 +147,13 @@ Wiązania języka Ruby do biblioteki SELinux.
%prep
%setup -q
%patch -P0 -p1
+%patch -P1 -p2
+%patch -P2 -p2
%build
%{__make} -j1 all %{?with_python:pywrap} %{?with_ruby:rubywrap} \
CC="%{__cc}" \
- CFLAGS="%{rpmcppflags} %{rpmcflags} -D_FILE_OFFSET_BITS=64 -Wno-incompatible-pointer-types" \
+ CFLAGS="%{rpmcppflags} %{rpmcflags} -D_FILE_OFFSET_BITS=64" \
LDFLAGS="%{rpmldflags}" \
LIBDIR=%{_libdir} \
PYPREFIX=python3 \
diff --git a/libselinux-restorecon-xattr-uaf.patch b/libselinux-restorecon-xattr-uaf.patch
new file mode 100644
index 0000000..2924d33
--- /dev/null
+++ b/libselinux-restorecon-xattr-uaf.patch
@@ -0,0 +1,56 @@
+From 15e0901f9baef42254d24e64c1ef5fd9084f5dc0 Mon Sep 17 00:00:00 2001
+From: Vit Mojzis <vmojzis at redhat.com>
+Date: Thu, 6 Aug 2026 21:37:35 +0200
+Subject: [PATCH] libselinux: restorecon_xattr: reset dir_xattr_list on every
+ call
+
+selinux_restorecon_xattr(3) documents that "xattr_list must be set to
+NULL before calling selinux_restorecon_xattr(3). The caller is
+responsible for freeing the returned xattr_list entries." Commit
+b5a23d7f30c1 ("libselinux: restorecon_xattr: clear dir_xattr_* after
+freeing") reset the dir_xattr_list/dir_xattr_last statics after
+freeing them on the internal error-cleanup path of the recursive
+walk, but not on the normal success path.
+
+After a successful call, dir_xattr_list/dir_xattr_last are left
+pointing at the just-returned, now caller-owned list. Once the caller
+frees it as required and calls the function again, add_xattr_entry()
+finds dir_xattr_list non-NULL and appends the next entry through
+dir_xattr_last->next, a dangling pointer into memory the caller has
+already freed - a use-after-free write.
+
+Reset both pointers to NULL at the top of every call instead of only
+in the error path: by the API description, any list from a prior call
+is not valid.
+
+Co-Authored-By: Claude Sonnet 5 <noreply at anthropic.com>
+
+Signed-off-by: Vit Mojzis <vmojzis at redhat.com>
+Acked-by: Stephen Smalley <stephen.smalley.work at gmail.com>
+---
+ libselinux/src/selinux_restorecon.c | 12 ++++++++++++
+ 1 file changed, 12 insertions(+)
+
+diff --git a/libselinux/src/selinux_restorecon.c b/libselinux/src/selinux_restorecon.c
+index 4233ba6539..49b8ff7ed4 100644
+--- a/libselinux/src/selinux_restorecon.c
++++ b/libselinux/src/selinux_restorecon.c
+@@ -1968,6 +1968,18 @@ int selinux_restorecon_xattr(const char *pathname, unsigned int xattr_flags,
+ if (!fc_sehandle)
+ return -1;
+
++ /*
++ * The API contract requires the caller to have already freed any
++ * xattr_list returned by a previous call before calling again.
++ * Forget our own head/tail pointers to that now caller-owned memory
++ * here instead of carrying them over: leaving them set would make
++ * the next add_xattr_entry() append a new entry through
++ * dir_xattr_last, which would be dangling once the caller has freed
++ * it, resulting in a use-after-free.
++ */
++ dir_xattr_list = NULL;
++ dir_xattr_last = NULL;
++
+ if (lstat(pathname, &sb) < 0) {
+ if (errno == ENOENT)
+ return 0;
diff --git a/libselinux-swig4.5.patch b/libselinux-swig4.5.patch
new file mode 100644
index 0000000..bbcd722
--- /dev/null
+++ b/libselinux-swig4.5.patch
@@ -0,0 +1,53 @@
+From fb518ff492cd6a286f35b415cbd7fd0f6e3faedb Mon Sep 17 00:00:00 2001
+From: Petr Lautrbach <lautrbach at redhat.com>
+Date: Thu, 6 Aug 2026 16:30:44 +0200
+Subject: [PATCH] libselinux: Replace PyString_FromString with
+ PyUnicode_FromString for SWIG 4.5.0 compatibility
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+SWIG 4.5.0 removed Python 2 C API compatibility macros (PyInt_*,
+PyString_*, SWIG_Python_str_*) from its runtime header pyhead.swg.
+These macros previously mapped deprecated Python 2 C API names to their
+Python 3 equivalents.
+
+Fixes: https://github.com/SELinuxProject/selinux/issues/538
+Authored-by: Jitka Plesníková <jplesnik at redhat.com>
+Signed-off-by: Petr Lautrbach <lautrbach at redhat.com>
+Acked-by: Stephen Smalley <stephen.smalley.work at gmail.com>
+---
+ libselinux/src/selinuxswig_python.i | 6 +++---
+ 1 file changed, 3 insertions(+), 3 deletions(-)
+
+diff --git a/libselinux/src/selinuxswig_python.i b/libselinux/src/selinuxswig_python.i
+index c8c08a4070..74d923e427 100644
+--- a/libselinux/src/selinuxswig_python.i
++++ b/libselinux/src/selinuxswig_python.i
+@@ -69,7 +69,7 @@ def install(src, dest):
+ PyObject* list = PyList_New(*$2);
+ int i;
+ for (i = 0; i < *$2; i++) {
+- PyList_SetItem(list, i, PyString_FromString((*$1)[i]));
++ PyList_SetItem(list, i, PyUnicode_FromString((*$1)[i]));
+ }
+ $result = SWIG_AppendOutput($result, list);
+ }
+@@ -123,7 +123,7 @@ def install(src, dest):
+ len++;
+ plist = PyList_New(len);
+ for (i = 0; i < len; i++) {
+- PyList_SetItem(plist, i, PyString_FromString((*$1)[i]));
++ PyList_SetItem(plist, i, PyUnicode_FromString((*$1)[i]));
+ }
+ } else {
+ plist = PyList_New(0);
+@@ -140,7 +140,7 @@ def install(src, dest):
+ if (*$1) {
+ plist = PyList_New(result);
+ for (i = 0; i < result; i++) {
+- PyList_SetItem(plist, i, PyString_FromString((*$1)[i]));
++ PyList_SetItem(plist, i, PyUnicode_FromString((*$1)[i]));
+ }
+ } else {
+ plist = PyList_New(0);
================================================================
---- gitweb:
http://git.pld-linux.org/gitweb.cgi/packages/libselinux.git/commitdiff/8fe1174a3b0ccec1fdd18fb76ca0e6fef82626b6
More information about the pld-cvs-commit
mailing list