]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
libfrog: pass mode to xfrog_file_setattr
authorDarrick J. Wong <djwong@kernel.org>
Tue, 23 Sep 2025 17:10:27 +0000 (10:10 -0700)
committerAndrey Albershteyn <aalbersh@kernel.org>
Thu, 25 Sep 2025 09:18:10 +0000 (11:18 +0200)
xfs/633 crashes rdump_fileattrs_path passes a NULL struct stat pointer
and then the fallback code dereferences it to get the file mode.
Instead, let's just pass the stat mode directly to it, because that's
the only piece of information that it needs.

Fixes: 128ac4dadbd633 ("xfs_db: use file_setattr to copy attributes on special files with rdump")
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Andrey Albershteyn <aalbersh@kernel.org>
db/rdump.c
io/attr.c
libfrog/file_attr.c
libfrog/file_attr.h
quota/project.c

index 82520e37d713e58bf8b0ff19d093e59ecf5026f1..a50df4b8c72302901cd07d636b7971b443111e88 100644 (file)
@@ -188,8 +188,8 @@ rdump_fileattrs_path(
                        return 1;
        }
 
-       ret = xfrog_file_setattr(destdir->fd, pbuf->path, NULL, &fa,
-                       AT_SYMLINK_NOFOLLOW);
+       ret = xfrog_file_setattr(destdir->fd, pbuf->path, VFS_I(ip)->i_mode,
+                       &fa, AT_SYMLINK_NOFOLLOW);
        if (ret) {
                if (errno == EOPNOTSUPP || errno == EPERM || errno == ENOTTY)
                        lost_mask |= LOST_FSXATTR;
index 022ca5f1df1b7c8bbc54517f69a5d9812e74e896..9563ff74e44777a4d9d4d588f6ce2757fd17e91d 100644 (file)
--- a/io/attr.c
+++ b/io/attr.c
@@ -261,7 +261,7 @@ chattr_callback(
 
        attr.fa_xflags |= orflags;
        attr.fa_xflags &= ~andflags;
-       error = xfrog_file_setattr(AT_FDCWD, path, stat, &attr,
+       error = xfrog_file_setattr(AT_FDCWD, path, stat->st_mode, &attr,
                                   AT_SYMLINK_NOFOLLOW);
        if (error) {
                fprintf(stderr, _("%s: cannot set flags on %s: %s\n"),
@@ -357,7 +357,7 @@ chattr_f(
 
        attr.fa_xflags |= orflags;
        attr.fa_xflags &= ~andflags;
-       error = xfrog_file_setattr(AT_FDCWD, name, &st, &attr,
+       error = xfrog_file_setattr(AT_FDCWD, name, st.st_mode, &attr,
                                   AT_SYMLINK_NOFOLLOW);
        if (error) {
                fprintf(stderr, _("%s: cannot set flags on %s: %s\n"),
index bb51ac6eb2ef95d872b1abce82e4b14adc0c4c0c..c2cbcb4e14659c6db5f673b684b39ad758f92ffd 100644 (file)
@@ -85,7 +85,7 @@ int
 xfrog_file_setattr(
        const int               dfd,
        const char              *path,
-       const struct stat       *stat,
+       const mode_t            mode,
        struct file_attr        *fa,
        const unsigned int      at_flags)
 {
@@ -103,7 +103,7 @@ xfrog_file_setattr(
                return error;
 #endif
 
-       if (SPECIAL_FILE(stat->st_mode)) {
+       if (SPECIAL_FILE(mode)) {
                errno = EOPNOTSUPP;
                return -1;
        }
index df9b6181d52cf928e4cd05adc44dc4a88e79406b..2a1c0d42d0a7711993ccd065bbaf0a48169a0a5b 100644 (file)
@@ -24,12 +24,7 @@ xfrog_file_getattr(
        struct file_attr        *fa,
        const unsigned int      at_flags);
 
-int
-xfrog_file_setattr(
-       const int               dfd,
-       const char              *path,
-       const struct stat       *stat,
-       struct file_attr        *fa,
-       const unsigned int      at_flags);
+int xfrog_file_setattr(const int dfd, const char *path, const mode_t mode,
+               struct file_attr *fa, const unsigned int at_flags);
 
 #endif /* __LIBFROG_FILE_ATTR_H__ */
index 5832e1474e2549d61c652de543f98d69e9c2b866..33449e01ef4dbb4afffbc28a925d6c9350591ea8 100644 (file)
@@ -157,7 +157,8 @@ clear_project(
        fa.fa_projid = 0;
        fa.fa_xflags &= ~FS_XFLAG_PROJINHERIT;
 
-       error = xfrog_file_setattr(dfd, path, stat, &fa, AT_SYMLINK_NOFOLLOW);
+       error = xfrog_file_setattr(dfd, path, stat->st_mode, &fa,
+                       AT_SYMLINK_NOFOLLOW);
        if (error) {
                fprintf(stderr, _("%s: cannot clear project on %s: %s\n"),
                        progname, path, strerror(errno));
@@ -205,7 +206,8 @@ setup_project(
        if (S_ISDIR(stat->st_mode))
                fa.fa_xflags |= FS_XFLAG_PROJINHERIT;
 
-       error = xfrog_file_setattr(dfd, path, stat, &fa, AT_SYMLINK_NOFOLLOW);
+       error = xfrog_file_setattr(dfd, path, stat->st_mode, &fa,
+                       AT_SYMLINK_NOFOLLOW);
        if (error) {
                fprintf(stderr, _("%s: cannot set project on %s: %s\n"),
                        progname, path, strerror(errno));