From 257d904bd45998551164fa9483fa0f6befc2f116 Mon Sep 17 00:00:00 2001 From: Giuseppe Scrivano Date: Fri, 29 Jul 2022 10:45:07 +0200 Subject: [PATCH] direct: use /proc/self/fd to read xattrs instead of using the lgetxattr and llistxattr system calls on the entire file path, use the /proc/self/fd/$FD/$RELATIVE_PATH path instead so that the lookup is relative to the lower dir file descriptor that is already open. Closes: https://github.com/containers/fuse-overlayfs/issues/364 Signed-off-by: Giuseppe Scrivano --- direct.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/direct.c b/direct.c index a796e14..3a8f387 100644 --- a/direct.c +++ b/direct.c @@ -44,8 +44,13 @@ static int direct_listxattr (struct ovl_layer *l, const char *path, char *buf, size_t size) { char full_path[PATH_MAX]; - - strconcat3 (full_path, PATH_MAX, l->path, "/", path); + int ret; + ret = snprintf (full_path, sizeof (full_path), "/proc/self/fd/%d/%s", l->fd, path); + if (ret >= sizeof (full_path)) + { + errno = ENAMETOOLONG; + return -1; + } return llistxattr (full_path, buf, size); } @@ -54,9 +59,13 @@ static int direct_getxattr (struct ovl_layer *l, const char *path, const char *name, char *buf, size_t size) { char full_path[PATH_MAX]; - - strconcat3 (full_path, PATH_MAX, l->path, "/", path); - + int ret; + ret = snprintf (full_path, sizeof (full_path), "/proc/self/fd/%d/%s", l->fd, path); + if (ret >= sizeof (full_path)) + { + errno = ENAMETOOLONG; + return -1; + } return lgetxattr (full_path, name, buf, size); }