Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

fs: get rid of __FMODE_NONOTIFY kludge

All it takes to get rid of the __FMODE_NONOTIFY kludge is switching
fanotify from anon_inode_getfd() to anon_inode_getfile_fmode() and adding
a dentry_open_nonotify() helper to be used by fanotify on the other path.
That's it - no more weird shit in OPEN_FMODE(), etc.

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Link: https://lore.kernel.org/linux-fsdevel/20241113043003.GH3387508@ZenIV/
Signed-off-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Jan Kara <jack@suse.cz>
Link: https://patch.msgid.link/d1231137e7b661a382459e79a764259509a4115d.1731684329.git.josef@toxicpanda.com

authored by

Al Viro and committed by
Jan Kara
ebe55960 b86545e0

+40 -19
+2 -2
fs/fcntl.c
··· 1158 1158 * Exceptions: O_NONBLOCK is a two bit define on parisc; O_NDELAY 1159 1159 * is defined as O_NONBLOCK on some platforms and not on others. 1160 1160 */ 1161 - BUILD_BUG_ON(21 - 1 /* for O_RDONLY being 0 */ != 1161 + BUILD_BUG_ON(20 - 1 /* for O_RDONLY being 0 */ != 1162 1162 HWEIGHT32( 1163 1163 (VALID_OPEN_FLAGS & ~(O_NONBLOCK | O_NDELAY)) | 1164 - __FMODE_EXEC | __FMODE_NONOTIFY)); 1164 + __FMODE_EXEC)); 1165 1165 1166 1166 fasync_cache = kmem_cache_create("fasync_cache", 1167 1167 sizeof(struct fasync_struct), 0,
+16 -9
fs/notify/fanotify/fanotify_user.c
··· 100 100 * 101 101 * Internal and external open flags are stored together in field f_flags of 102 102 * struct file. Only external open flags shall be allowed in event_f_flags. 103 - * Internal flags like FMODE_NONOTIFY, FMODE_EXEC, FMODE_NOCMTIME shall be 104 - * excluded. 103 + * Internal flags like FMODE_EXEC shall be excluded. 105 104 */ 106 105 #define FANOTIFY_INIT_ALL_EVENT_F_BITS ( \ 107 106 O_ACCMODE | O_APPEND | O_NONBLOCK | \ ··· 257 258 return client_fd; 258 259 259 260 /* 260 - * we need a new file handle for the userspace program so it can read even if it was 261 - * originally opened O_WRONLY. 261 + * We provide an fd for the userspace program, so it could access the 262 + * file without generating fanotify events itself. 262 263 */ 263 - new_file = dentry_open(path, 264 - group->fanotify_data.f_flags | __FMODE_NONOTIFY, 265 - current_cred()); 264 + new_file = dentry_open_nonotify(path, group->fanotify_data.f_flags, 265 + current_cred()); 266 266 if (IS_ERR(new_file)) { 267 267 put_unused_fd(client_fd); 268 268 client_fd = PTR_ERR(new_file); ··· 1407 1409 unsigned int fid_mode = flags & FANOTIFY_FID_BITS; 1408 1410 unsigned int class = flags & FANOTIFY_CLASS_BITS; 1409 1411 unsigned int internal_flags = 0; 1412 + struct file *file; 1410 1413 1411 1414 pr_debug("%s: flags=%x event_f_flags=%x\n", 1412 1415 __func__, flags, event_f_flags); ··· 1476 1477 (!(fid_mode & FAN_REPORT_NAME) || !(fid_mode & FAN_REPORT_FID))) 1477 1478 return -EINVAL; 1478 1479 1479 - f_flags = O_RDWR | __FMODE_NONOTIFY; 1480 + f_flags = O_RDWR; 1480 1481 if (flags & FAN_CLOEXEC) 1481 1482 f_flags |= O_CLOEXEC; 1482 1483 if (flags & FAN_NONBLOCK) ··· 1554 1555 goto out_destroy_group; 1555 1556 } 1556 1557 1557 - fd = anon_inode_getfd("[fanotify]", &fanotify_fops, group, f_flags); 1558 + fd = get_unused_fd_flags(f_flags); 1558 1559 if (fd < 0) 1559 1560 goto out_destroy_group; 1560 1561 1562 + file = anon_inode_getfile_fmode("[fanotify]", &fanotify_fops, group, 1563 + f_flags, FMODE_NONOTIFY); 1564 + if (IS_ERR(file)) { 1565 + fd = PTR_ERR(file); 1566 + put_unused_fd(fd); 1567 + goto out_destroy_group; 1568 + } 1569 + fd_install(fd, file); 1561 1570 return fd; 1562 1571 1563 1572 out_destroy_group:
+19 -4
fs/open.c
··· 1105 1105 } 1106 1106 EXPORT_SYMBOL(dentry_open); 1107 1107 1108 + struct file *dentry_open_nonotify(const struct path *path, int flags, 1109 + const struct cred *cred) 1110 + { 1111 + struct file *f = alloc_empty_file(flags, cred); 1112 + if (!IS_ERR(f)) { 1113 + int error; 1114 + 1115 + f->f_mode |= FMODE_NONOTIFY; 1116 + error = vfs_open(path, f); 1117 + if (error) { 1118 + fput(f); 1119 + f = ERR_PTR(error); 1120 + } 1121 + } 1122 + return f; 1123 + } 1124 + 1108 1125 /** 1109 1126 * dentry_create - Create and open a file 1110 1127 * @path: path to create ··· 1219 1202 inline int build_open_flags(const struct open_how *how, struct open_flags *op) 1220 1203 { 1221 1204 u64 flags = how->flags; 1222 - u64 strip = __FMODE_NONOTIFY | O_CLOEXEC; 1205 + u64 strip = O_CLOEXEC; 1223 1206 int lookup_flags = 0; 1224 1207 int acc_mode = ACC_MODE(flags); 1225 1208 ··· 1227 1210 "struct open_flags doesn't yet handle flags > 32 bits"); 1228 1211 1229 1212 /* 1230 - * Strip flags that either shouldn't be set by userspace like 1231 - * FMODE_NONOTIFY or that aren't relevant in determining struct 1232 - * open_flags like O_CLOEXEC. 1213 + * Strip flags that aren't relevant in determining struct open_flags. 1233 1214 */ 1234 1215 flags &= ~strip; 1235 1216
+3 -3
include/linux/fs.h
··· 2751 2751 } 2752 2752 struct file *dentry_open(const struct path *path, int flags, 2753 2753 const struct cred *creds); 2754 + struct file *dentry_open_nonotify(const struct path *path, int flags, 2755 + const struct cred *cred); 2754 2756 struct file *dentry_create(const struct path *path, int flags, umode_t mode, 2755 2757 const struct cred *cred); 2756 2758 struct path *backing_file_user_path(struct file *f); ··· 3709 3707 int __init list_bdev_fs_names(char *buf, size_t size); 3710 3708 3711 3709 #define __FMODE_EXEC ((__force int) FMODE_EXEC) 3712 - #define __FMODE_NONOTIFY ((__force int) FMODE_NONOTIFY) 3713 3710 3714 3711 #define ACC_MODE(x) ("\004\002\006\006"[(x)&O_ACCMODE]) 3715 - #define OPEN_FMODE(flag) ((__force fmode_t)(((flag + 1) & O_ACCMODE) | \ 3716 - (flag & __FMODE_NONOTIFY))) 3712 + #define OPEN_FMODE(flag) ((__force fmode_t)((flag + 1) & O_ACCMODE)) 3717 3713 3718 3714 static inline bool is_sxid(umode_t mode) 3719 3715 {
-1
include/uapi/asm-generic/fcntl.h
··· 6 6 7 7 /* 8 8 * FMODE_EXEC is 0x20 9 - * FMODE_NONOTIFY is 0x4000000 10 9 * These cannot be used by userspace O_* until internal and external open 11 10 * flags are split. 12 11 * -Eric Paris