systemd: try AT_EMPTY_PATH for access_fd() first

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.

(From OE-Core rev: 14c332ddf39650bb089dca1ea19642c7449e8af4)

Signed-off-by: Suresh H A <Suresh.HA@bmwtechworks.in>
Signed-off-by: Yoann Congal <yoann.congal@smile.fr>
[YC: More details available at:
https://lore.kernel.org/all/MAXP287MB42404C1A7233A3D773FFA7DFEE802@MAXP287MB4240.INDP287.PROD.OUTLOOK.COM/ ]
Signed-off-by: Paul Barker <paul@pbarker.dev>
This commit is contained in:
Suresh H A authored and Paul Barker committed 2026-11-04 10:20:39 +00:00
1 parent f513188495
commit b5ccd67e78
2 files changed
+35

No files matched your search

@@ -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
@@ -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