update commit description for fix-memleak-in-ext4_readdir
[ext4-patch-queue.git] / fix-erroneus-return-value
blob564c53cf3f8c9d34a46504a639f539d25a73241e
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>
14     #include <sys/stat.h>
15     #include <fcntl.h>
16     #include <err.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
22     int main(void)
23     {
24         int fd;
25         long flags;
27         fd = open("file", O_RDWR|O_CREAT, 0600);
28         if (fd < 0)
29             err(1, "open");
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");
41         return 0;
42     }
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
50     +++ exited with 0 +++
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
58     +++ exited with 1 +++
60 Signed-off-by: Anton Protopopov <a.s.protopopov@gmail.com>
61 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
62 ---
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
68 --- a/fs/ext4/ioctl.c
69 +++ b/fs/ext4/ioctl.c
70 @@ -208,7 +208,7 @@ static int ext4_ioctl_setflags(struct inode *inode,
71  {
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;
78         unsigned int jflag;
79 -- 
80 2.6.5
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