Skip to contentSkip to conversation

9pfs: local: Do not follow symlink in _nofollow

PATCH In review Akihiko Odaki 3 participants 4 messages Apr 27, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 9pfs: local: Do not follow symlink in _nofollow

---
 hw/9pfs/9p-local.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/9pfs/9p-local.c +1 -1
index d42ce6d8b82..def8afdb4d6 100644
@@ -365,7 +365,7 @@ static int fchmodat_nofollow(int dirfd, const char *name, mode_t mode)
     if (fd == -1) {
         /* In case the file is writable-only and isn't a directory. */
         if (errno == EACCES) {
-            fd = openat_file(dirfd, name, O_WRONLY, 0);
+            fd = openat_file(dirfd, name, O_WRONLY | O_NOFOLLOW, 0);
         }
         if (fd == -1 && errno == EISDIR) {
             errno = EACCES;
Signature · 1 line
2.32.0 (Apple Git-132)
#1 lore raw
Quoted 10 lines · On Mittwoch, 27. April 2022 04:45:45 CEST Akihiko Odaki wrote:
---
 hw/9pfs/9p-local.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/9pfs/9p-local.c +0 -0
index d42ce6d8b82..def8afdb4d6 100644

hw/9pfs/9p-local.c static int fchmodat_nofollow(int dirfd, const char · line 368

Quoted 5 lines
hw/9pfs/9p-local.c +1 -1
@@ -365,7 +365,7 @@ static int fchmodat_nofollow(int dirfd, const char
 *name, mode_t mode) if (fd == -1) {
         /* In case the file is writable-only and isn't a directory. */
         if (errno == EACCES) {
-            fd = openat_file(dirfd, name, O_WRONLY, 0);
+            fd = openat_file(dirfd, name, O_WRONLY | O_NOFOLLOW, 0);

O_NOFOLLOW flag is always added inside openat_file() implementation:

https://github.com/qemu/qemu/blob/master/hw/9pfs/9p-util.h#L60

So this change is not necessary AFAICS.

Quoted 3 lines
hw/9pfs/9p-local.c +0 -0
         }
         if (fd == -1 && errno == EISDIR) {
             errno = EACCES;
#2 lore raw
Quoted 19 lines · On Wed, 27 Apr 2022 10:46:31 +0200 Christian Schoenebeck…
Quoted 10 lines · On Mittwoch, 27. April 2022 04:45:45 CEST Akihiko Odaki wrote:
---
 hw/9pfs/9p-local.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/9pfs/9p-local.c +0 -0
index d42ce6d8b82..def8afdb4d6 100644

hw/9pfs/9p-local.c static int fchmodat_nofollow(int dirfd, const char · line 368

Quoted 5 lines
hw/9pfs/9p-local.c +1 -1
@@ -365,7 +365,7 @@ static int fchmodat_nofollow(int dirfd, const char
 *name, mode_t mode) if (fd == -1) {
         /* In case the file is writable-only and isn't a directory. */
         if (errno == EACCES) {
-            fd = openat_file(dirfd, name, O_WRONLY, 0);
+            fd = openat_file(dirfd, name, O_WRONLY | O_NOFOLLOW, 0);

O_NOFOLLOW flag is always added inside openat_file() implementation:

Quoted 4 lines

https://github.com/qemu/qemu/blob/master/hw/9pfs/9p-util.h#L60

So this change is not necessary AFAICS.

Right, and with macOS in mind, maybe fchmodat(AT_SYMLINK_NOFOLLOW) just works unlike with linux ?

Quoted 5 lines
Quoted 3 lines
hw/9pfs/9p-local.c +0 -0
         }
         if (fd == -1 && errno == EISDIR) {
             errno = EACCES;
#3 lore raw
Quoted 25 lines · On Mittwoch, 27. April 2022 12:21:51 CEST Greg Kurz wrote:

On Wed, 27 Apr 2022 10:46:31 +0200

Quoted 22 lines · Christian Schoenebeck
Quoted 11 lines · On Mittwoch, 27. April 2022 04:45:45 CEST Akihiko Odaki wrote:

---

 hw/9pfs/9p-local.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/9pfs/9p-local.c +0 -0
index d42ce6d8b82..def8afdb4d6 100644

hw/9pfs/9p-local.c static int fchmodat_nofollow(int dirfd, const char · line 370

Quoted 7 lines
hw/9pfs/9p-local.c +1 -1
@@ -365,7 +365,7 @@ static int fchmodat_nofollow(int dirfd, const char
 *name, mode_t mode) if (fd == -1) {
 
         /* In case the file is writable-only and isn't a directory. */
         if (errno == EACCES) {
 
-            fd = openat_file(dirfd, name, O_WRONLY, 0);
+            fd = openat_file(dirfd, name, O_WRONLY | O_NOFOLLOW, 0);

O_NOFOLLOW flag is always added inside openat_file() implementation:

Quoted 6 lines
Quoted 3 lines

https://github.com/qemu/qemu/blob/master/hw/9pfs/9p-util.h#L60

So this change is not necessary AFAICS.

Right, and with macOS in mind, maybe fchmodat(AT_SYMLINK_NOFOLLOW) just works unlike with linux ?

Yep, fchmodat(AT_SYMLINK_NOFOLLOW) seems to work on macOS! Like you already suggested on the other thread, it would make sense to move current implementation of fchmodat_nofollow() to 9p-util-linux.h/.c and let macOS just use fchmodat(AT_SYMLINK_NOFOLLOW) instead.

Best regards,
Christian Schoenebeck