diff mbox series

[poky,scarthgap,v2] systemd: try AT_EMPTY_PATH for access_fd() first

Message ID 20261028175112.1623080-1-UpStream_IP-SH@bmwtechworks.in
State Under Review
Delegated to: Yoann Congal
Headers show
Series [poky,scarthgap,v2] systemd: try AT_EMPTY_PATH for access_fd() first | expand

Commit Message

Suresh H A Oct. 28, 2026, 5:51 p.m. UTC
From: Suresh H A <Suresh.HA@bmwtechworks.in>

Backport a fix to try AT_EMPTY_PATH which changes access_fd() to use
faccessat(..., AT_EMPTY_PATH) instead of validating access through
/proc/self/fd/<fd>.

This fixes a reproducible race during service startup. On
Linux 6.6 / systemd 255 (Scarthgap) based platform, affected
services may fail to start when systemd-remount-fs.service runs
concurrently and remounts procfs. In this window, access_fd()
can fail with -ESRCH while resolving /proc/self/fd/<fd>, causing
systemd to report that the executable cannot be located.

The upstream implementation performs the access check directly on
the file descriptor, avoiding dependence on procfs path resolution
and eliminating the observed race.

Signed-off-by: Suresh H A <Suresh.HA@bmwtechworks.in>
---
 ...ry-AT_EMPTY_PATH-for-access_fd-first.patch | 34 +++++++++++++++++++
 meta/recipes-core/systemd/systemd_255.22.bb   |  1 +
 2 files changed, 35 insertions(+)
 create mode 100644 meta/recipes-core/systemd/systemd/0024-fs-util-try-AT_EMPTY_PATH-for-access_fd-first.patch
diff mbox series

Patch

diff --git a/meta/recipes-core/systemd/systemd/0024-fs-util-try-AT_EMPTY_PATH-for-access_fd-first.patch b/meta/recipes-core/systemd/systemd/0024-fs-util-try-AT_EMPTY_PATH-for-access_fd-first.patch
new file mode 100644
index 0000000000..268ace04c4
--- /dev/null
+++ b/meta/recipes-core/systemd/systemd/0024-fs-util-try-AT_EMPTY_PATH-for-access_fd-first.patch
@@ -0,0 +1,34 @@ 
+From 228d4c63102367a757ba4f31c49a148975607a72 Mon Sep 17 00:00:00 2001
+From: Mike Yuan <me@yhndnzj.com>
+Date: Mon, 20 May 2024 19:33:26 +0800
+Subject: [PATCH] fs-util: try AT_EMPTY_PATH for access_fd() first
+
+Upstream-Status: Backport [https://github.com/systemd/systemd/pull/32933/commits/c675851d5fd503c1ae5d244f041d43ae9e3ab79b]
+
+Signed-off-by: Suresh H A <Suresh.HA@bmwtechworks.in>
+---
+ src/basic/fs-util.c | 8 ++++++++
+ 1 file changed, 8 insertions(+)
+
+diff --git a/src/basic/fs-util.c b/src/basic/fs-util.c
+index 5bc7d2f..3a7ebd2 100644
+--- a/src/basic/fs-util.c
++++ b/src/basic/fs-util.c
+@@ -668,6 +668,14 @@ int unlink_or_warn(const char *filename) {
+ int access_fd(int fd, int mode) {
+         /* Like access() but operates on an already open fd */
+ 
++        if (faccessat(fd, "", mode, AT_EMPTY_PATH) >= 0)
++                return 0;
++        if (errno != EINVAL)
++                return -errno;
++
++        /* Support for AT_EMPTY_PATH is added rather late (kernel 5.8), so fall back to going through /proc/
++         * if unavailable. */
++
+         if (access(FORMAT_PROC_FD_PATH(fd), mode) < 0) {
+                 if (errno != ENOENT)
+                         return -errno;
+-- 
+2.43.0
+
diff --git a/meta/recipes-core/systemd/systemd_255.22.bb b/meta/recipes-core/systemd/systemd_255.22.bb
index 84d41a86c9..1bdeb551fd 100644
--- a/meta/recipes-core/systemd/systemd_255.22.bb
+++ b/meta/recipes-core/systemd/systemd_255.22.bb
@@ -39,6 +39,7 @@  SRC_URI += " \
            file://CVE-2026-29111-04.patch \
            file://CVE-2026-4105.patch \
            file://0023-journal-replace-a-bunch-of-assert-with-friendlier-ch.patch \
+           file://0024-fs-util-try-AT_EMPTY_PATH-for-access_fd-first.patch \
            "
 
 # patches needed by musl