blob: 0a7594c068077ffb9c6eaaf492b38d7342565274 [file] [log] [blame]
Andrew Geissler82c905d2020-04-13 13:39:40 -05001From e6f871078d8d6f076c84f908fa57af15417ab87d Mon Sep 17 00:00:00 2001
Brad Bishop19323692019-04-05 15:28:33 -04002From: Andre McCurdy <armccurdy@gmail.com>
3Date: Tue, 10 Oct 2017 14:33:30 -0700
Andrew Geissler82c905d2020-04-13 13:39:40 -05004Subject: [PATCH] don't pass AT_SYMLINK_NOFOLLOW flag to faccessat()
Brad Bishop19323692019-04-05 15:28:33 -04005
6Avoid using AT_SYMLINK_NOFOLLOW flag. It doesn't seem like the right
7thing to do and it's not portable (not supported by musl). See:
8
9 http://lists.landley.net/pipermail/toybox-landley.net/2014-September/003610.html
10 http://www.openwall.com/lists/musl/2015/02/05/2
11
12Note that laccess() is never passing AT_EACCESS so a lot of the
13discussion in the links above doesn't apply. Note also that
14(currently) all systemd callers of laccess() pass mode as F_OK, so
15only check for existence of a file, not access permissions.
16Therefore, in this case, the only distiction between faccessat()
17with (flag == 0) and (flag == AT_SYMLINK_NOFOLLOW) is the behaviour
18for broken symlinks; laccess() on a broken symlink will succeed with
19(flag == AT_SYMLINK_NOFOLLOW) and fail (flag == 0).
20
21The laccess() macros was added to systemd some time ago and it's not
22clear if or why it needs to return success for broken symlinks. Maybe
23just historical and not actually necessary or desired behaviour?
24
25Upstream-Status: Inappropriate [musl specific]
26
27Signed-off-by: Andre McCurdy <armccurdy@gmail.com>
Andrew Geissler82c905d2020-04-13 13:39:40 -050028
Brad Bishop19323692019-04-05 15:28:33 -040029---
30 src/basic/fs-util.h | 22 +++++++++++++++++++++-
31 src/shared/base-filesystem.c | 6 +++---
32 2 files changed, 24 insertions(+), 4 deletions(-)
33
Andrew Geissler635e0e42020-08-21 15:58:33 -050034Index: systemd-stable/src/basic/fs-util.h
35===================================================================
36--- systemd-stable.orig/src/basic/fs-util.h
37+++ systemd-stable/src/basic/fs-util.h
38@@ -42,7 +42,27 @@ int fchmod_opath(int fd, mode_t m);
Brad Bishop19323692019-04-05 15:28:33 -040039 int fd_warn_permissions(const char *path, int fd);
Andrew Geissler635e0e42020-08-21 15:58:33 -050040 int stat_warn_permissions(const char *path, const struct stat *st);
Brad Bishop19323692019-04-05 15:28:33 -040041
42-#define laccess(path, mode) faccessat(AT_FDCWD, (path), (mode), AT_SYMLINK_NOFOLLOW)
43+/*
44+ Avoid using AT_SYMLINK_NOFOLLOW flag. It doesn't seem like the right thing to
45+ do and it's not portable (not supported by musl). See:
46+
47+ http://lists.landley.net/pipermail/toybox-landley.net/2014-September/003610.html
48+ http://www.openwall.com/lists/musl/2015/02/05/2
49+
50+ Note that laccess() is never passing AT_EACCESS so a lot of the discussion in
51+ the links above doesn't apply. Note also that (currently) all systemd callers
52+ of laccess() pass mode as F_OK, so only check for existence of a file, not
53+ access permissions. Therefore, in this case, the only distiction between
54+ faccessat() with (flag == 0) and (flag == AT_SYMLINK_NOFOLLOW) is the
55+ behaviour for broken symlinks; laccess() on a broken symlink will succeed
56+ with (flag == AT_SYMLINK_NOFOLLOW) and fail (flag == 0).
57+
58+ The laccess() macros was added to systemd some time ago and it's not clear if
59+ or why it needs to return success for broken symlinks. Maybe just historical
60+ and not actually necessary or desired behaviour?
61+*/
62+
63+#define laccess(path, mode) faccessat(AT_FDCWD, (path), (mode), 0)
64
65 int touch_file(const char *path, bool parents, usec_t stamp, uid_t uid, gid_t gid, mode_t mode);
66 int touch(const char *path);
Andrew Geissler635e0e42020-08-21 15:58:33 -050067Index: systemd-stable/src/shared/base-filesystem.c
68===================================================================
69--- systemd-stable.orig/src/shared/base-filesystem.c
70+++ systemd-stable/src/shared/base-filesystem.c
71@@ -54,7 +54,7 @@ int base_filesystem_create(const char *r
Brad Bishop19323692019-04-05 15:28:33 -040072 return log_error_errno(errno, "Failed to open root file system: %m");
73
74 for (i = 0; i < ELEMENTSOF(table); i ++) {
75- if (faccessat(fd, table[i].dir, F_OK, AT_SYMLINK_NOFOLLOW) >= 0)
76+ if (faccessat(fd, table[i].dir, F_OK, 0) >= 0)
77 continue;
78
79 if (table[i].target) {
Andrew Geissler635e0e42020-08-21 15:58:33 -050080@@ -62,7 +62,7 @@ int base_filesystem_create(const char *r
Brad Bishop19323692019-04-05 15:28:33 -040081
82 /* check if one of the targets exists */
83 NULSTR_FOREACH(s, table[i].target) {
84- if (faccessat(fd, s, F_OK, AT_SYMLINK_NOFOLLOW) < 0)
85+ if (faccessat(fd, s, F_OK, 0) < 0)
86 continue;
87
88 /* check if a specific file exists at the target path */
Andrew Geissler635e0e42020-08-21 15:58:33 -050089@@ -73,7 +73,7 @@ int base_filesystem_create(const char *r
Brad Bishop19323692019-04-05 15:28:33 -040090 if (!p)
91 return log_oom();
92
93- if (faccessat(fd, p, F_OK, AT_SYMLINK_NOFOLLOW) < 0)
94+ if (faccessat(fd, p, F_OK, 0) < 0)
95 continue;
96 }
97