Script 'mail_helper' called by obssrc
Hello community,

here is the log from the commit of package selinux-sandbox for openSUSE:Factory 
checked in at 2026-12-05 19:09:58
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Comparing /work/SRC/openSUSE:Factory/selinux-sandbox (Old)
 and      /work/SRC/openSUSE:Factory/.selinux-sandbox.new.1340718 (New)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Package is "selinux-sandbox"

Sat Dec  5 19:09:58 2026 rev:4 rq:1402971 version:3.12

Changes:
--------
--- /work/SRC/openSUSE:Factory/selinux-sandbox/selinux-sandbox.changes  
2026-08-06 16:29:02.670746950 +0200
+++ 
/work/SRC/openSUSE:Factory/.selinux-sandbox.new.1340718/selinux-sandbox.changes 
    2026-12-05 19:11:29.875938438 +0100
@@ -1,0 +2,33 @@
+Thu Dec  3 09:00:36 UTC 2026 - Cathy Hu <[email protected]>
+
+- Update to version 3.12
+  https://github.com/SELinuxProject/selinux/releases/tag/v3.12
+  - Fixes security vulnerabilities in seunshare: GHSA-46pq-h6jh-ffhq 
(bsc#1291846), GHSA-xmgc-7fjx-c8mg (bsc#1291845)
+  - Fixes security vulnerabilities in sandbox: GHSA-6f25-hvjj-7gx9 
(bsc#1291842), GHSA-p7vf-vhh6-xqcc (bsc#1291837), GHSA-9cxr-v2wg-qgmg 
(bsc#1291838),
+    GHSA-v55f-vjm7-gvrf (bsc#1291844), GHSA-5rfp-8wvg-3w6q (bsc#1291840), 
GHSA-r2v7-vcw3-q989 (bsc#1291830), GHSA-9x35-cppw-pxhv (bsc#1291831), 
GHSA-5fgx-735h-hgxx (bsc#1291897)
+  - User-visible changes:
+    - Improved sandbox cleanup and command handling, including quoting the
+      command written to .sandboxrc and by sandboxX.sh, and removing temporary
+      directories on error paths.
+    - Hardening of sandbox, libselinux, and libsemanage
+  - Security/hardening changes:
+    - Hardened sandbox, newrole, restorecond and mcstrans handling of
+      commands, temporary files, signals and configuration data, including
+      constant-time comparison of shadow password hashes in newrole, bounded
+      Include nesting depth in mcstrans, a hardened mcstrans systemd service
+      file, and use of openat2() where available in sandbox/seunshare,
+      restorecond and selinux_restorecon(3).
+  - Notable bug fixes:
+    - sandbox/sandbox: do not follow symlinks when shredding sandbox
+      directories
+    - sandbox/seunshare: SIGKILL and drain the child process group
+    - sandbox/seunshare: run the sandbox in its own PID namespace
+- Drop sandbox-fix-cleanup.patch, merged upstream
+- Source URLs: upstream tags are prefixed with "v" now
+
+-------------------------------------------------------------------
+Wed Dec  2 13:07:50 UTC 2026 - Cathy Hu <[email protected]>
+
+- keyring: update bachradsusi.gpg for next release 
+
+-------------------------------------------------------------------

Old:
----
  sandbox-fix-cleanup.patch
  selinux-sandbox-3.11.tar.gz
  selinux-sandbox-3.11.tar.gz.asc

New:
----
  selinux-sandbox-3.12.tar.gz
  selinux-sandbox-3.12.tar.gz.asc

----------(Old B)----------
  Old:    - sandbox/seunshare: run the sandbox in its own PID namespace
- Drop sandbox-fix-cleanup.patch, merged upstream
- Source URLs: upstream tags are prefixed with "v" now
----------(Old E)----------

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Other differences:
------------------
++++++ selinux-sandbox.spec ++++++
--- /var/tmp/diff_new_pack.RhdiDD/_old  2026-12-05 19:11:31.531008186 +0100
+++ /var/tmp/diff_new_pack.RhdiDD/_new  2026-12-05 19:11:31.534008312 +0100
@@ -17,22 +17,20 @@
 
 
 Name:           selinux-sandbox
-Version:        3.11
+Version:        3.12
 Release:        0
 Summary:        SELinux sandbox helper
 License:        GPL-2.0-or-later
 Group:          System/Management
 URL:            https://github.com/SELinuxProject/selinux/wiki
-Source0:        
https://github.com/SELinuxProject/selinux/releases/download/%{version}/%{name}-%{version}.tar.gz
-Source1:        
https://github.com/SELinuxProject/selinux/releases/download/%{version}/%{name}-%{version}.tar.gz.asc
+Source0:        
https://github.com/SELinuxProject/selinux/releases/download/v%{version}/%{name}-%{version}.tar.gz
+Source1:        
https://github.com/SELinuxProject/selinux/releases/download/v%{version}/%{name}-%{version}.tar.gz.asc
 Source2:        selinux-sandbox.keyring
 Source3:        SANDBOX-README.md
 # PATCH-FEATURE-OPENSUSE sandbox_seunshare_move_usr_bin.patch bsc#1268256
 Patch1:         sandbox_seunshare_move_usr_bin.patch
 # PATCH-FEATURE-OPENSUSE man_correct_package_name.patch bsc#1272976
 Patch2:         man_correct_package_name.patch
-# PATCH-FEATURE-NOT-SUBMITTED sandbox-fix-cleanup.patch 
https://bugzilla.redhat.com/show_bug.cgi?id=2481569
-Patch10:        sandbox-fix-cleanup.patch
 BuildRequires:  libcap-ng-devel
 BuildRequires:  libselinux-devel
 Requires:       python3-policycoreutils = %{version}

++++++ selinux-sandbox-3.11.tar.gz -> selinux-sandbox-3.12.tar.gz ++++++
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/selinux-sandbox-3.11/VERSION 
new/selinux-sandbox-3.12/VERSION
--- old/selinux-sandbox-3.11/VERSION    2026-07-01 18:51:05.000000000 +0200
+++ new/selinux-sandbox-3.12/VERSION    2026-12-02 18:39:01.000000000 +0100
@@ -1 +1 @@
-3.11
+3.12
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/selinux-sandbox-3.11/sandbox 
new/selinux-sandbox-3.12/sandbox
--- old/selinux-sandbox-3.11/sandbox    2026-07-01 18:51:05.000000000 +0200
+++ new/selinux-sandbox-3.12/sandbox    2026-12-02 18:39:01.000000000 +0100
@@ -20,6 +20,7 @@
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 #
 
+import errno
 import os
 import stat
 import sys
@@ -27,6 +28,7 @@
 import random
 import fcntl
 import shutil
+import shlex
 import re
 import subprocess
 import selinux
@@ -84,29 +86,125 @@
 
 
 def copyfile(file, srcdir, dest):
-    import re
-    if file.startswith(srcdir):
+    # Only copy what is below srcdir: compare whole path components.
+    srcdir = srcdir.rstrip("/")
+    if file.startswith(srcdir + "/"):
+        # open_nofollow() accepts no symbolic link in the path of the copy
+        dest = os.path.realpath(dest)
         dname = os.path.dirname(file)
         bname = os.path.basename(file)
-        if dname == srcdir:
-            dest = dest + "/" + bname
-        else:
-            newdir = re.sub(srcdir, dest, dname)
-            if not os.path.exists(newdir):
-                os.makedirs(newdir)
-            dest = newdir + "/" + bname
+        subdirs = [name for name in dname[len(srcdir):].split("/") if name]
+        # A name to copy is stored resolved; a relative component in it
+        # would step outside dest before source is even looked at.
+        if bname in (os.curdir, os.pardir) \
+           or os.curdir in subdirs or os.pardir in subdirs:
+            raise ValueError("relative component in %r" % file)
+        nofollow = os.O_RDONLY | os.O_DIRECTORY | os.O_NOFOLLOW
+
+        # With -H or -T, dest was writable for the programs of earlier
+        # sandboxes and any name in it may by now be a symlink that leads
+        # out of it.  Reach the copy through directory file descriptors,
+        # never following a symlink below dest, and create it anew rather
+        # than write to what already has its name.
+        # Read the source through descriptors as well: acquire the
+        # selected name once, then reach everything below it relative
+        # to that descriptor, never following a symbolic link.
+        def copy(sfd, src, name, dirfd):
+            st = os.fstat(sfd)
+            if stat.S_ISDIR(st.st_mode):
+                os.mkdir(name, 0o700, dir_fd=dirfd)
+                fd = os.open(name, nofollow, dir_fd=dirfd)
+                try:
+                    for entry in os.listdir(sfd):
+                        try:
+                            entryfd = os.open(entry,
+                                              os.O_RDONLY | os.O_NOFOLLOW
+                                              | os.O_NONBLOCK,
+                                              dir_fd=sfd)
+                        except OSError as e:
+                            # A symbolic link is copied as a link rather
+                            # than followed.
+                            if e.errno != errno.ELOOP:
+                                raise
+                            target = os.readlink(entry, dir_fd=sfd)
+                            try:
+                                os.unlink(entry, dir_fd=fd)
+                            except FileNotFoundError:
+                                pass
+                            os.symlink(target, entry, dir_fd=fd)
+                            continue
+                        try:
+                            copy(entryfd, src + "/" + entry, entry, fd)
+                        finally:
+                            os.close(entryfd)
+                    shutil.copystat("/proc/self/fd/%d" %sfd,
+                                    "/proc/self/fd/%d" % fd)
+                finally:
+                    os.close(fd)
+            elif not stat.S_ISREG(st.st_mode):
+                raise shutil.SpecialFileError(
+                        "`%s` is not a regular file" % src)
+            else:
+                try:
+                    if os.path.samestat(st, os.stat(name, dir_fd=dirfd,
+                                                    follow_symlinks=False)):
+                        raise shutil.SameFileError(
+                            "%r and %r are the same file" % (src, name))
+                    os.unlink(name, dir_fd=dirfd)
+                except FileNotFoundError:
+                    pass
+                fd = os.open(name, os.O_WRONLY | os.O_CREAT | os.O_EXCL,
+                             0o600, dir_fd=dirfd)
+                try:
+                    shutil.copy2("/proc/self/fd/%d" % sfd,
+                                 "/proc/self/fd/%d" % fd)
+                finally:
+                    os.close(fd)
 
+        dirfd = os.open(dest, os.O_RDONLY | os.O_DIRECTORY)
         try:
-            if os.path.isdir(file):
-                shutil.copytree(file, dest)
-            else:
-                shutil.copy2(file, dest)
+            for name in subdirs:
+                try:
+                    os.mkdir(name, dir_fd=dirfd)
+                except FileExistsError:
+                    pass
+                fd = os.open(name, nofollow, dir_fd=dirfd)
+                os.close(dirfd)
+                dirfd = fd
+            dest = "/".join([dest] + subdirs + [bname])
+            sfd = os.open(file, os.O_RDONLY | os.O_NONBLOCK)
+            try:
+                copy(sfd, file, bname, dirfd)
+            finally:
+                os.close(sfd)
+            mtime = os.stat(bname, dir_fd=dirfd, 
follow_symlinks=False).st_mtime
+        finally:
+            os.close(dirfd)
 
-        except shutil.Error as elist:
-            for e in elist.message:
-                sys.stderr.write(e[2])
+        SAVE_FILES[file] = (dest, mtime)
 
-        SAVE_FILES[file] = (dest, os.path.getmtime(dest))
+
+def create_file(path):
+    try:
+        os.unlink(path)
+    except FileNotFoundError:
+        pass
+    return open(path, "x")
+
+
+def open_nofollow(path, flags):
+    names = [name for name in path.split("/") if name]
+    dirfd = os.open("/", os.O_PATH | os.O_DIRECTORY)
+    try:
+        for name in names[:-1]:
+            fd = os.open(name, os.O_PATH | os.O_DIRECTORY | os.O_NOFOLLOW,
+                         dir_fd=dirfd)
+            os.close(dirfd)
+            dirfd = fd
+        return os.open(names[-1], flags | os.O_NOFOLLOW | os.O_NONBLOCK, 0o600,
+                       dir_fd=dirfd)
+    finally:
+        os.close(dirfd)
 
 
 def savefile(new, orig, X_ind):
@@ -130,13 +228,28 @@
         if re.match(_("[yY]"), ans):
             copy = True
     if copy:
-        shutil.copy2(new, orig)
+        # new is a descriptor of the regular file that open_nofollow() found
+        with open(open_nofollow(orig, os.O_WRONLY | os.O_CREAT), "wb") as dst, 
\
+                open(new, "rb", closefd=False) as src:
+            dst_st = os.fstat(dst.fileno())
+            st = os.fstat(new)
+            if not stat.S_ISREG(dst_st.st_mode):
+                raise OSError(_("not a regular file"))
+            if os.path.samestat(st, dst_st):
+                raise OSError(_("the copy and the original are the same file"))
+            dst.truncate(0)
+            shutil.copyfileobj(src, dst)
+            dst.flush()
+            os.fchmod(dst.fileno(), st.st_mode & 0o777)
+            os.utime(dst.fileno(), ns=(st.st_atime_ns, st.st_mtime_ns))
 
 
 def reserve(level):
     sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
     sock.bind("\0%s" % level)
     fcntl.fcntl(sock.fileno(), fcntl.F_SETFD, fcntl.FD_CLOEXEC)
+    # The level stays reserved only for as long as the socket is open
+    return sock
 
 
 def get_range():
@@ -156,7 +269,6 @@
 def gen_mcs():
     low, high = get_range()
 
-    level = None
     ctr = 0
     total = high - low
     total = (total * (total - 1)) / 2
@@ -172,12 +284,10 @@
             i2 = tmp
         level = "s0:c%d,c%d" % (i1, i2)
         try:
-            reserve(level)
+            sock = reserve(level)
         except socket.error:
             continue
-        break
-    if level:
-        return level
+        return level, sock
     raise ValueError(_("Failed to find any unused category sets.  Consider a 
larger MCS range for this user."))
 
 
@@ -203,6 +313,7 @@
         self.__paths = []
         self.__mount = False
         self.__level = None
+        self.__reservation = None
         self.__homedir = None
         self.__tmpdir = None
         self.__runuserdir = None
@@ -268,16 +379,17 @@
 
     def __setup_sandboxrc(self, wm="/usr/bin/openbox"):
         execfile = self.__homedir + "/.sandboxrc"
-        fd = open(execfile, "w+")
+        fd = create_file(execfile)
         if self.__options.session:
             fd.write("""#!/bin/sh
 #TITLE: /etc/gdm/Xsession
 /etc/gdm/Xsession
 """)
         else:
-            command = self.__paths[0] + " "
-            for p in self.__paths[1:]:
-                command += "'%s' " % p
+            command = shlex.join(self.__paths)
+            # #TITLE: is read back by sandboxX.sh with grep|cut for the
+            # window title; keep it on one line and printable.
+            title = re.sub(r"[^ -~]", " ", " ".join(self.__paths))[:72]
             fd.write("""#! /bin/sh
 #TITLE: %s
 # /usr/bin/test -r ~/.xmodmap && /usr/bin/xmodmap ~/.xmodmap
@@ -286,9 +398,9 @@
 else
     dbus-launch --exit-with-session %s
 fi
-""" % (command, command, command))
+""" % (title, command, command))
+        os.fchmod(fd.fileno(), 0o700)
         fd.close()
-        os.chmod(execfile, 0o700)
 
     def usage(self, message=""):
         error_exit("%s\n%s" % (self.__parser.usage, message))
@@ -430,7 +542,9 @@
         if self.__options.level:
             level = self.__options.level
         else:
-            level = gen_mcs()
+            # Keep the socket open until sandbox exits, so that no
+            # other sandbox is given the same level in the meantime
+            level, self.__reservation = gen_mcs()
 
         con = selinux.getcon()[1].split(":")
         self.__execcon = "%s:%s:%s:%s" % (con[0], con[1], self.setype, level)
@@ -457,16 +571,6 @@
         selinux.chcon(self.__runuserdir, self.__filecon, recursive=True)
         selinux.setfscreatecon(None)
 
-    def __is_wayland_app(self):
-        binary = shutil.which(self.__paths[0])
-        if binary is None:
-            return True
-        output = subprocess.run(['ldd', binary], capture_output=True)
-        for line in str(output.stdout, "utf-8").split('\n'):
-            if line.find("libwayland") != -1:
-                return True
-        return False
-
     def __execute(self):
         try:
             cmds = [SEUNSHARE, "-Z", self.__execcon]
@@ -488,7 +592,7 @@
                         cmds += ["-W", os.environ["WAYLAND_DISPLAY"]]
 
                     xmodmapfile = self.__homedir + "/.xmodmap"
-                    xd = open(xmodmapfile, "w")
+                    xd = create_file(xmodmapfile)
                     try:
                         subprocess.Popen(["/usr/bin/xmodmap", "-pke"], 
stdout=xd).wait()
                     except:
@@ -497,7 +601,7 @@
 
                     self.__setup_sandboxrc(self.__options.wm)
 
-                    if self.__options.Y_ind or self.__is_wayland_app():
+                    if self.__options.Y_ind:
                         WN = "yes"
                     else:
                         WN = "no"
@@ -518,12 +622,35 @@
             return os.WEXITSTATUS(rc[1])
 
         finally:
+            save_failed = False
             for i in self.__paths:
                 if i not in SAVE_FILES:
                     continue
                 (dest, mtime) = SAVE_FILES[i]
-                if os.path.getmtime(dest) > mtime:
-                    savefile(dest, i, self.__options.X_ind)
+                try:
+                    fd = open_nofollow(dest, os.O_RDONLY)
+                except FileNotFoundError as e:
+                    # the program removed its copy: nothing to save
+                    sys.stderr.write(_("Could not save changes to '%s': %s\n") 
% (i, e))
+                    continue
+                except OSError as e:
+                    sys.stderr.write(_("Could not save changes to '%s': %s; 
the edited copy is kept at '%s'\n") % (i, e, dest))
+                    save_failed = True
+                    continue
+                try:
+                    try:
+                        st = os.fstat(fd)
+                        if stat.S_ISREG(st.st_mode) and st.st_mtime > mtime:
+                            savefile(fd, i, self.__options.X_ind)
+                    finally:
+                        os.close(fd)
+                except OSError as e:
+                    sys.stderr.write(_("Could not save changes to '%s': %s; 
the edited copy is kept at '%s'\n") % (i, e, dest))
+                    save_failed = True
+
+            if save_failed:
+                # Keep the directories: they hold the only edited copy.
+                return 1
 
             if self.__homedir and not self.__options.homedir:
                 if self.__options.shred:
@@ -531,14 +658,34 @@
                 shutil.rmtree(self.__homedir)
             if self.__tmpdir and not self.__options.tmpdir:
                 if self.__options.shred:
-                    self.shred(self.__homedir)
+                    self.shred(self.__tmpdir)
                 shutil.rmtree(self.__tmpdir)
+            if self.__runuserdir and not self.__options.runuserdir:
+                if self.__options.shred:
+                    self.shred(self.__runuserdir)
+                shutil.rmtree(self.__runuserdir)
 
     def shred(self, path):
-        for root, dirs, files in os.walk(path):
+        for root, dirs, files, dirfd in os.fwalk(path, follow_symlinks=False):
             for f in files:
-                dest = root + "/" + f
-                subprocess.Popen(["/usr/bin/shred", dest]).wait()
+                try:
+                    fd = os.open(f, os.O_WRONLY | os.O_NOFOLLOW | 
os.O_NONBLOCK,
+                                 dir_fd=dirfd)
+                except OSError:
+                    continue
+                try:
+                    st = os.fstat(fd)
+                    if not stat.S_ISREG(st.st_mode):
+                        continue
+                    remaining = st.st_size
+                    while remaining > 0:
+                        chunk = b"\x00" * min(remaining, 1 << 20)
+                        remaining -= os.write(fd, chunk)
+                    os.fsync(fd)
+                except OSError:
+                    pass
+                finally:
+                    os.close(fd)
 
     def main(self):
         try:
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/selinux-sandbox-3.11/sandboxX.sh 
new/selinux-sandbox-3.12/sandboxX.sh
--- old/selinux-sandbox-3.11/sandboxX.sh        2026-07-01 18:51:05.000000000 
+0200
+++ new/selinux-sandbox-3.12/sandboxX.sh        2026-12-02 18:39:01.000000000 
+0100
@@ -2,9 +2,9 @@
 trap "" TERM
 context=`id -Z | secon -t -l -P`
 export TITLE="Sandbox $context -- `grep ^#TITLE: ~/.sandboxrc | /usr/bin/cut 
-b8-80`"
-[ -z $1 ] && export WAYLAND_NATIVE="no" || export WAYLAND_NATIVE="$1"
-[ -z $2 ] && export SCREENSIZE="1000x700" || export SCREENSIZE="$2"
-[ -z $3 ] && export DPI="96" || export DPI="$3"
+[ -z "$1" ] && export WAYLAND_NATIVE="no" || export WAYLAND_NATIVE="$1"
+[ -z "$2" ] && export SCREENSIZE="1000x700" || export SCREENSIZE="$2"
+[ -z "$3" ] && export DPI="96" || export DPI="$3"
 trap "exit 0" HUP
 
 mkdir -p ~/.config/openbox
@@ -22,16 +22,24 @@
 EOF
 
 if [ "$WAYLAND_NATIVE" == "no" ]; then
+    XAUTH=`mktemp ~/.Xauthority.XXXXXX` || exit 1
+    trap 'rm -f "$XAUTH"' EXIT
+    { printf '\377\377\0\0\0\0\0\022MIT-MAGIC-COOKIE-1\0\020' &&
+      head -c 16 /dev/urandom; } > "$XAUTH" || exit 1
     if [ -z "$WAYLAND_DISPLAY" ]; then
-        DISPLAY_COMMAND='/usr/bin/Xephyr -resizeable -title "$TITLE" 
-terminate -screen $SCREENSIZE -dpi $DPI -nolisten tcp -displayfd 5 5>&1 
2>/dev/null'
+        DISPLAY_COMMAND='/usr/bin/Xephyr -resizeable -title "$TITLE" 
-terminate -screen $SCREENSIZE -dpi $DPI -nolisten tcp -auth "$XAUTH" 
-displayfd 5 5>&1 2>/dev/null'
     else
-        DISPLAY_COMMAND='/usr/bin/Xwayland -terminate -dpi $DPI -retro 
-geometry $SCREENSIZE -decorate -displayfd 5 5>&1 2>/dev/null'
+        DISPLAY_COMMAND='/usr/bin/Xwayland -terminate -dpi $DPI -retro 
-geometry $SCREENSIZE -decorate -auth "$XAUTH" -displayfd 5 5>&1 2>/dev/null'
     fi
     eval $DISPLAY_COMMAND | while read D; do
         export DISPLAY=:$D
+        # Only for the clients of the new server: the server is itself a
+        # client of the user's display and must not present this cookie there.
+        export XAUTHORITY=$XAUTH
         cat > ~/seremote << __EOF
 #!/bin/bash -x
 export DISPLAY=$DISPLAY
+export XAUTHORITY="$XAUTHORITY"
 export WAYLAND_DISPLAY=$WAYLAND_DISPLAY
 "\$@"
 __EOF
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/selinux-sandbox-3.11/seunshare.8 
new/selinux-sandbox-3.12/seunshare.8
--- old/selinux-sandbox-3.11/seunshare.8        2026-07-01 18:51:05.000000000 
+0200
+++ new/selinux-sandbox-3.12/seunshare.8        2026-12-02 18:39:01.000000000 
+0100
@@ -22,7 +22,10 @@
 Use alternate temporary directory to mount on XDG_RUNTIME_DIR 
(/run/user/$UID). runuserdir must be owned by the user
 .TP
 \fB\-C --capabilities\fR
-Allow apps executed within the namespace to use capabilities. Default is no 
capabilities
+Retained for compatibility; has no effect. seunshare always drops all
+capabilities and sets the no-root securebits so setuid-root programs
+run without capabilities, but leaves the bounding set intact so
+programs with file capabilities continue to work.
 .TP
 \fB\-k --kill\fR
 Kill all processes with matching MCS level
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/selinux-sandbox-3.11/seunshare.c 
new/selinux-sandbox-3.12/seunshare.c
--- old/selinux-sandbox-3.11/seunshare.c        2026-07-01 18:51:05.000000000 
+0200
+++ new/selinux-sandbox-3.12/seunshare.c        2026-12-02 18:39:01.000000000 
+0100
@@ -7,12 +7,16 @@
 #include <stdbool.h>
 #include <signal.h>
 #include <sys/fsuid.h>
+#include <time.h>
 #include <sys/stat.h>
 #include <sys/types.h>
 #include <sys/wait.h>
+#include <sys/syscall.h>
 #include <syslog.h>
 #include <sys/mount.h>
-#include <glob.h>
+#ifdef __NR_openat2
+#include <linux/openat2.h>
+#endif
 #include <pwd.h>
 #include <sched.h>
 #include <string.h>
@@ -147,9 +151,10 @@
        } while (0)
 
 /**
- * Spawn external command with dropped privileges.
+ * Spawn external command with dropped privileges. If @cwd_fd is not -1,
+ * the command is run with that directory as its working directory.
  */
-static int spawn_command(char **cmd, uid_t uid)
+static int spawn_command(char **cmd, uid_t uid, int cwd_fd)
 {
        int childpid;
        int status = -1;
@@ -167,6 +172,11 @@
                if (drop_privs(uid) != 0)
                        exit(-1);
 
+               if (cwd_fd >= 0 && fchdir(cwd_fd) < 0) {
+                       perror(_("Unable to change working directory"));
+                       exit(-1);
+               }
+
                status = execv(cmd[0], cmd);
                exit(status);
        }
@@ -219,10 +229,19 @@
  */
 static int pin_dir(const char *dir, struct stat *st_out)
 {
-       int fd;
+       int fd = -1;
        struct stat sb;
 
-       fd = open(dir, O_RDONLY | O_DIRECTORY | O_NOFOLLOW | O_CLOEXEC);
+#ifdef __NR_openat2
+       struct open_how how = {
+               .flags = O_RDONLY | O_DIRECTORY | O_NOFOLLOW | O_CLOEXEC,
+               .resolve = RESOLVE_NO_SYMLINKS | RESOLVE_NO_MAGICLINKS,
+       };
+
+       fd = syscall(__NR_openat2, AT_FDCWD, dir, &how, sizeof(how));
+       if (fd < 0 && (errno == ENOSYS || errno == EINVAL))
+#endif
+               fd = open(dir, O_RDONLY | O_DIRECTORY | O_NOFOLLOW | O_CLOEXEC);
        if (fd < 0) {
                fprintf(stderr, _("Failed to open %s: %m\n"), dir);
                return -1;
@@ -368,33 +387,6 @@
        return rc;
 }
 
-/*
-   If path is empty or ends with  "/." or "/.. return -1 else return 0;
- */
-static int bad_path(const char *path)
-{
-       const char *ptr;
-       ptr = path;
-       while (*ptr)
-               ptr++;
-       if (ptr == path)
-               return -1; // ptr null
-       ptr--;
-       if (ptr != path && *ptr == '.') {
-               ptr--;
-               if (*ptr == '/')
-                       return -1; // path ends in /.
-               if (*ptr == '.') {
-                       if (ptr != path) {
-                               ptr--;
-                               if (*ptr == '/')
-                                       return -1; // path ends in /..
-                       }
-               }
-       }
-       return 0;
-}
-
 static void free_args(char **args)
 {
        char **args_p = args;
@@ -407,34 +399,49 @@
        free(args);
 }
 
-static int rsynccmd(const char *src, const char *dst, char ***cmd)
+/**
+ * Build the rsync command that copies all files in directory @src to @dst.
+ * @src is a name supplied by the user: pin it again, check against @src_st
+ * that it still is the directory that was validated, and list the files
+ * using that fd.
+ */
+static int rsynccmd(const char *src, struct stat *src_st, const char *dst,
+                   char ***cmd)
 {
        char **args;
-       char *buf = NULL;
-       glob_t fglob;
-       fglob.gl_offs = 0;
-       int flags = GLOB_PERIOD;
-       unsigned int i = 0, index;
+       struct dirent *entry;
+       struct stat sb;
+       DIR *dir;
+       int fd;
+       unsigned int count = 0, index;
 
-       /* match glob for all files in src dir */
-       if (asprintf(&buf, "%s/*", src) == -1) {
-               fprintf(stderr, _("Out of memory\n"));
+       fd = pin_dir(src, &sb);
+       if (fd < 0)
+               return -1;
+
+       if (sb.st_dev != src_st->st_dev || sb.st_ino != src_st->st_ino) {
+               fprintf(stderr, _("%s was replaced by a different directory\n"),
+                       src);
+               close(fd);
                return -1;
        }
 
-       if (glob(buf, flags, NULL, &fglob) != 0) {
-               free(buf);
-               buf = NULL;
+       dir = fdopendir(fd);
+       if (!dir) {
+               fprintf(stderr, _("Failed to open %s: %m\n"), src);
+               close(fd);
                return -1;
        }
 
-       free(buf);
-       buf = NULL;
+       while (readdir(dir) != NULL)
+               count++;
+       rewinddir(dir);
 
-       /* rsync -trlHDq -- <glob list> dst NULL */
-       *cmd = calloc(3 + fglob.gl_pathc + 2, sizeof(char *));
+       /* rsync -trlHDq -- <file list> dst NULL */
+       *cmd = calloc(3 + count + 2, sizeof(char *));
        if (!*cmd) {
                fprintf(stderr, _("Out of memory\n"));
+               closedir(dir);
                return -1;
        }
 
@@ -443,20 +450,25 @@
        strdup_or_err(args, 1, "-trlHDq");
        strdup_or_err(args, 2, "--");
 
-       for (i = 0, index = 3; i < fglob.gl_pathc; i++) {
-               const char *path = fglob.gl_pathv[i];
-               if (bad_path(path))
+       /* files created since the count above are left out */
+       index = 3;
+       while (index < 3 + count && (entry = readdir(dir)) != NULL) {
+               if (strcmp(entry->d_name, ".") == 0 ||
+                   strcmp(entry->d_name, "..") == 0)
                        continue;
-               strdup_or_err(args, index, path);
+               if (asprintf(&args[index], "%s/%s", src, entry->d_name) == -1) {
+                       args[index] = NULL;
+                       goto err;
+               }
                index++;
        }
        strdup_or_err(args, index, dst);
        index++;
        args[index] = NULL;
-       globfree(&fglob);
+       closedir(dir);
        return 0;
 err:
-       globfree(&fglob);
+       closedir(dir);
        if (args) {
                free_args(args);
                *cmd = NULL;
@@ -471,7 +483,9 @@
  *         a non-root user: symbolic links to root paths (such as /root) will
  *         not be followed.
  */
-static bool rm_rf(int targetfd, const char *path)
+#define RM_RF_MAXDEPTH 128
+static bool rm_rf(int targetfd, const char *path, unsigned int depth,
+                 bool removetop)
 {
        struct stat statbuf;
 
@@ -484,6 +498,11 @@
        }
 
        if (S_ISDIR(statbuf.st_mode)) {
+               if (depth >= RM_RF_MAXDEPTH) {
+                       fprintf(stderr,
+                               _("rm_rf: directory tree too deep, giving 
up\n"));
+                       return false;
+               }
                const int newfd =
                        openat(targetfd, path,
                               O_RDONLY | O_DIRECTORY | O_NOFOLLOW | O_CLOEXEC);
@@ -507,24 +526,31 @@
                                continue;
                        }
 
-                       if (!rm_rf(dirfd(dir), entry->d_name)) {
+                       if (!rm_rf(dirfd(dir), entry->d_name, depth + 1,
+                                  true)) {
                                rc = false;
                        }
                }
 
                closedir(dir);
 
-               if (unlinkat(targetfd, path, AT_REMOVEDIR) < 0) {
-                       perror("unlinkat");
-                       rc = false;
+               if (removetop) {
+                       if (unlinkat(targetfd, path, AT_REMOVEDIR) < 0) {
+                               perror("unlinkat");
+                               rc = false;
+                       }
                }
 
                return rc;
        }
-       if (unlinkat(targetfd, path, 0) < 0) {
-               perror("unlinkat");
-               return false;
+
+       if (removetop) {
+               if (unlinkat(targetfd, path, 0) < 0) {
+                       perror("unlinkat");
+                       return false;
+               }
        }
+
        return true;
 }
 
@@ -570,9 +596,11 @@
  * Clean up runtime temporary directory.  Returns 0 if no problem was detected,
  * >0 if some error was detected, but errors here are treated as non-fatal and
  * left to tmpwatch to finish incomplete cleanup.
+ * If @copy_content is set, the content is first copied back to the
+ * user-specified directory, which must be passed pinned as @src_fd.
  */
-static int cleanup_tmpdir(const char *tmpdir, const char *src,
-                         struct passwd *pwd, int copy_content)
+static int cleanup_tmpdir(const char *tmpdir, int src_fd, struct passwd *pwd,
+                         int copy_content)
 {
        char **args;
        int rc = 0;
@@ -595,14 +623,10 @@
                        free_args(args);
                        return 1;
                }
-               if (asprintf(&args[6], "%s/", src) == -1) {
-                       fprintf(stderr, _("Out of memory\n"));
-                       free_args(args);
-                       return 1;
-               }
+               strdup_or_err(args, 6, ".");
                args[7] = NULL;
 
-               if (spawn_command(args, pwd->pw_uid) != 0) {
+               if (spawn_command(args, pwd->pw_uid, src_fd) != 0) {
                        fprintf(stderr,
                                _("Failed to copy files from the runtime 
temporary directory\n"));
                        rc++;
@@ -610,20 +634,28 @@
                free_args(args);
        }
 
-       if (setfsuid_checked(0, 0) < 0)
-               rc++;
-
-       /* Recursively remove the runtime temp directory.  */
-       if (!rm_rf(AT_FDCWD, tmpdir)) {
+       /* Remove files under the tmpdir as the user */
+       if (setfsuid_checked(0, pwd->pw_uid) < 0) {
+               fprintf(stderr,
+                       _("unable to switch to user for removing files under 
tmp dir\n"));
+               return ++rc;
+       }
+       if (!rm_rf(AT_FDCWD, tmpdir, 0, false)) {
                fprintf(stderr,
                        _("Failed to recursively remove directory %s\n"),
                        tmpdir);
                rc++;
        }
 
-       if (setfsuid_checked(0, pwd->pw_uid) < 0) {
+       /* Then remove the tmpdir itself as root */
+       if (setfsuid_checked(pwd->pw_uid, 0) < 0) {
                fprintf(stderr,
-                       _("unable to switch back to user after clearing tmp 
dir\n"));
+                       _("unable to switch back to root to delete tmpdir\n"));
+               return ++rc;
+       }
+       if (rmdir(tmpdir) < 0) {
+               fprintf(stderr, _("Failed to remove directory %s: %m\n"),
+                       tmpdir);
                rc++;
        }
 
@@ -649,6 +681,7 @@
        int fd_t = -1, fd_s = -1;
        struct stat tmp_st;
        char *con = NULL;
+       bool created = false;
 
        /* get selinux context of source directory */
        if (execcon) {
@@ -684,6 +717,8 @@
                goto err;
        }
 
+       created = true;
+
        /* temporary directory must be owned by root:user */
        fd_t = pin_dir(tmpdir, out_st);
        if (fd_t < 0)
@@ -721,7 +756,7 @@
        if (setfsuid_checked(0, pwd->pw_uid) < 0)
                goto err;
 
-       if (rsynccmd(src, tmpdir, &cmd) < 0) {
+       if (rsynccmd(src, src_st, tmpdir, &cmd) < 0) {
                goto err;
        }
 
@@ -729,15 +764,26 @@
        if (setfsuid_checked(pwd->pw_uid, 0) < 0)
                goto err;
 
-       if (spawn_command(cmd, pwd->pw_uid) != 0) {
+       if (spawn_command(cmd, pwd->pw_uid, -1) != 0) {
                fprintf(stderr,
                        _("Failed to populate runtime temporary directory\n"));
-               cleanup_tmpdir(tmpdir, src, pwd, 0);
+               cleanup_tmpdir(tmpdir, -1, pwd, 0);
+               created = false;
                goto err;
        }
 
        goto good;
 err:
+       if (created) {
+               /*
+                * Best-effort removal of still-empty tmpdir.
+                * We do not use setfsuid_checked() here
+                * because the fsuid is indeterminate on
+                * some error paths.
+                */
+               (void)setfsuid(0);
+               (void)rmdir(tmpdir);
+       }
        free(tmpdir);
        tmpdir = NULL;
 good:
@@ -773,6 +819,7 @@
        struct stat st_runuserdir_s;
 
        int fd;
+       int fd_tmpdir_s = -1;
 
        const struct option long_options[] = {
                { "homedir", 1, NULL, 'h' },      { "tmpdir", 1, NULL, 't' },
@@ -830,6 +877,12 @@
                        verbose++;
                        break;
                case 'C':
+                       /*
+                        * This is a no-op ever since
+                        * commit 1f0b5bd920c8 switched
+                        * the default to support
+                        * use of file-cap binaries.
+                        */
                        cap_set = CAPNG_SELECT_CAPS;
                        break;
                case 'P':
@@ -847,10 +900,10 @@
                }
        }
 
-       if ((wayland_display &&
-            (strchr(wayland_display, '/') || strstr(wayland_display, ".."))) ||
-           (pipewire_socket &&
-            (strchr(pipewire_socket, '/') || strstr(pipewire_socket, "..")))) {
+       if ((wayland_display && (strchr(wayland_display, '/') ||
+                                !strcmp(wayland_display, ".."))) ||
+           (pipewire_socket && (strchr(pipewire_socket, '/') ||
+                                !strcmp(pipewire_socket, "..")))) {
                fprintf(stderr,
                        _("Error: -W/-P must be a socket name, not a path\n"));
                return -1;
@@ -904,12 +957,11 @@
                close(fd);
        }
        if (tmpdir_s) {
-               fd = pin_dir(tmpdir_s, &st_tmpdir_s);
-               if (fd < 0)
+               fd_tmpdir_s = pin_dir(tmpdir_s, &st_tmpdir_s);
+               if (fd_tmpdir_s < 0)
                        return -1;
                if (check_owner_uid(uid, tmpdir_s, &st_tmpdir_s))
                        return -1;
-               close(fd);
        }
        if (runuserdir_s) {
                fd = pin_dir(runuserdir_s, &st_runuserdir_s);
@@ -952,6 +1004,57 @@
                int fd_runuserdir_s = -1, fd_runtime_dir = -1;
                int fd_tmpdir_r = -1, fd_tmp = -1, fd_var_tmp = -1;
                struct stat sb;
+               pid_t sandbox;
+
+               /*
+                * Put the sandbox in its own PID namespace so that when its
+                * init (the sandboxed command) exits, the kernel SIGKILLs
+                * every remaining descendant regardless of process group,
+                * and does so before the parent's waitpid() can return.
+                * This closes the setsid()/setpgid() escape the post-wait
+                * SIGKILL sweep cannot cover.
+                *
+                * unshare(CLONE_NEWPID) affects subsequent children only,
+                * so fork once more; this intermediate process is what the
+                * parent waits on and just relays the sandbox exit status.
+                * Take a new session first so the parent's kill(-child, ...)
+                * addresses this process group, which the sandbox and its
+                * well-behaved descendants stay in.
+                */
+               if (setsid() == (pid_t)-1) {
+                       perror(_("setsid"));
+                       exit(-1);
+               }
+               if (unshare(CLONE_NEWPID) < 0) {
+                       perror(_("Failed to create PID namespace"));
+                       exit(-1);
+               }
+               sandbox = fork();
+               if (sandbox == -1) {
+                       perror(_("Unable to fork"));
+                       exit(-1);
+               }
+               if (sandbox > 0) {
+                       int st;
+
+                       /*
+                        * Ignore forwarded signals so this process outlives
+                        * the sandbox and the PID namespace guarantee holds;
+                        * the process-group signal reaches the sandbox
+                        * directly.
+                        */
+                       signal(SIGINT, SIG_IGN);
+                       signal(SIGHUP, SIG_IGN);
+                       signal(SIGTERM, SIG_IGN);
+                       signal(SIGQUIT, SIG_IGN);
+
+                       if (waitpid(sandbox, &st, 0) < 0)
+                               exit(-1);
+                       status_to_retval(st, st);
+                       exit(st);
+               }
+
+               /* PID 1 in the new namespace from here on. */
 
                if (unshare(CLONE_NEWNS) < 0) {
                        perror(_("Failed to unshare"));
@@ -1168,7 +1271,6 @@
                        perror(_("Failed to change dir to homedir"));
                        goto childerr;
                }
-               setsid();
 
                /* selinux context */
                if (execcon) {
@@ -1218,8 +1320,27 @@
        waitpid(child, &status, 0);
        status_to_retval(status, status);
 
-       /* Make sure all child processes exit */
-       kill(-child, SIGTERM);
+       /*
+        * Make sure the child process group is gone before cleanup runs.
+        * SIGKILL each iteration so a descendant that fork()s between our
+        * signal and its own exit is caught on the next pass. Zombies keep
+        * the pgid alive until init reaps them, so give this a bounded
+        * budget; with the fd-based shred in sandbox(1), timing out here
+        * only leaves a straggler alongside a race-free cleanup.
+        *
+        * With the PID namespace above, waitpid() returning implies the
+        * namespace has been torn down and no sandbox descendant is
+        * running, so this sweep breaks on the first iteration; kept as
+        * a cheap safety belt.
+        */
+       for (int i = 0; i < 400; i++) {
+               struct timespec ts = { .tv_sec = 0,
+                                      .tv_nsec = 5 * 1000 * 1000 };
+
+               if (kill(-child, SIGKILL) < 0 && errno == ESRCH)
+                       break;
+               nanosleep(&ts, NULL);
+       }
 
        if (execcon && kill_all)
                fprintf(stderr,
@@ -1227,9 +1348,11 @@
                        execcon);
 
        if (tmpdir_r)
-               cleanup_tmpdir(tmpdir_r, tmpdir_s, pwd, 1);
+               cleanup_tmpdir(tmpdir_r, fd_tmpdir_s, pwd, 1);
 
 err:
+       if (fd_tmpdir_s >= 0)
+               close(fd_tmpdir_s);
        free(tmpdir_r);
        return status;
 }

++++++ selinux-sandbox.keyring ++++++
++++ 626 lines (skipped)
++++ between selinux-sandbox.keyring
++++ and 
/work/SRC/openSUSE:Factory/.selinux-sandbox.new.1340718/selinux-sandbox.keyring

Reply via email to