1 ext4: ioctl: fix erroneous return value
3 From: Anton Protopopov <a.s.protopopov@gmail.com>
5 The ext4_ioctl_setflags() function which is used in the ioctls
6 EXT4_IOC_SETFLAGS and EXT4_IOC_FSSETXATTR may return the positive value
7 EPERM instead of -EPERM in case of error. This bug was introduced by a
8 recent commit 9b7365fc.
10 The following program can be used to illustrate the wrong behavior:
12 #include <sys/types.h>
13 #include <sys/ioctl.h>
18 #define FS_IOC_GETFLAGS _IOR('f', 1, long)
19 #define FS_IOC_SETFLAGS _IOW('f', 2, long)
20 #define FS_IMMUTABLE_FL 0x00000010
27 fd = open("file", O_RDWR|O_CREAT, 0600);
31 if (ioctl(fd, FS_IOC_GETFLAGS, &flags) < 0)
32 err(1, "ioctl: FS_IOC_GETFLAGS");
34 flags |= FS_IMMUTABLE_FL;
36 if (ioctl(fd, FS_IOC_SETFLAGS, &flags) < 0)
37 err(1, "ioctl: FS_IOC_SETFLAGS");
39 warnx("ioctl returned no error");
44 Running it gives the following result:
46 $ strace -e ioctl ./test
47 ioctl(3, FS_IOC_GETFLAGS, 0x7ffdbd8bfd38) = 0
48 ioctl(3, FS_IOC_SETFLAGS, 0x7ffdbd8bfd38) = 1
49 test: ioctl returned no error
52 Running the program on a kernel with the bug fixed gives the proper result:
54 $ strace -e ioctl ./test
55 ioctl(3, FS_IOC_GETFLAGS, 0x7ffdd2768258) = 0
56 ioctl(3, FS_IOC_SETFLAGS, 0x7ffdd2768258) = -1 EPERM (Operation not permitted)
57 test: ioctl: FS_IOC_SETFLAGS: Operation not permitted
60 Signed-off-by: Anton Protopopov <a.s.protopopov@gmail.com>
61 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
63 fs/ext4/ioctl.c | 2 +-
64 1 file changed, 1 insertion(+), 1 deletion(-)
66 diff --git a/fs/ext4/ioctl.c b/fs/ext4/ioctl.c
67 index 0f6c369..a99b010 100644
70 @@ -208,7 +208,7 @@ static int ext4_ioctl_setflags(struct inode *inode,
72 struct ext4_inode_info *ei = EXT4_I(inode);
73 handle_t *handle = NULL;
74 - int err = EPERM, migrate = 0;
75 + int err = -EPERM, migrate = 0;
76 struct ext4_iloc iloc;
77 unsigned int oldflags, mask, i;
83 To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
84 the body of a message to majordomo@vger.kernel.org
85 More majordomo info at http://vger.kernel.org/majordomo-info.html