0012-don-t-pass-AT_SYMLINK_NOFOLLOW-flag-to-faccessat.patch 4.4 KB

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