Skip to contentSkip to conversation

fanotify: do not allow setting FAN_RENAME on non-dir

PATCH In review Amir Goldstein 3 participants 6 messages May 6, 2022 – May 9, 2022

Subsystems (3)
lore
Share & tools
lore

Amir Goldstein

author reviewer
#0 lore raw

PATCH 1/1 fanotify: do not allow setting FAN_RENAME on non-dir

The desired sematics of this action are not clear, so for now deny this action. We may relax it when we decide on the semantics and implement them.

Fixes 8cc3b1ccd930 ("fanotify: wire up FAN_RENAME event")
---
 fs/notify/fanotify/fanotify_user.c | 5 +++++
 1 file changed, 5 insertions(+)
fs/notify/fanotify/fanotify_user.c +5 -0
index edad67d674dc..ae0c27fac651 100644
@@ -1695,6 +1695,11 @@ static int do_fanotify_mark(int fanotify_fd, unsigned int flags, __u64 mask,
 	else
 		mnt = path.mnt;
 
+	/* FAN_RENAME is not allowed on non-dir (for now) */
+	ret = -EINVAL;
+	if (inode && (mask & FAN_RENAME) && !S_ISDIR(inode->i_mode))
+		goto path_put_and_out;
+
 	/* Mask out FAN_EVENT_ON_CHILD flag for sb/mount/non-dir marks */
 	if (mnt || !S_ISDIR(inode->i_mode)) {
 		mask &= ~FAN_EVENT_ON_CHILD;
Signature · 1 line
2.25.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · Amir Goldstein

The desired sematics of this action are not clear, so for now deny this action. We may relax it when we decide on the semantics and implement them.

Fixes 8cc3b1ccd930 ("fanotify: wire up FAN_RENAME event")

Thanks for sending this patch through Amir, LGTM.

Feel free to add:

Quoted 22 lines
---
 fs/notify/fanotify/fanotify_user.c | 5 +++++
 1 file changed, 5 insertions(+)
fs/notify/fanotify/fanotify_user.c +5 -0
index edad67d674dc..ae0c27fac651 100644
@@ -1695,6 +1695,11 @@ static int do_fanotify_mark(int fanotify_fd, unsigned int flags, __u64 mask,
 	else
 		mnt = path.mnt;
 
+	/* FAN_RENAME is not allowed on non-dir (for now) */
+	ret = -EINVAL;
+	if (inode && (mask & FAN_RENAME) && !S_ISDIR(inode->i_mode))
+		goto path_put_and_out;
+
 	/* Mask out FAN_EVENT_ON_CHILD flag for sb/mount/non-dir marks */
 	if (mnt || !S_ISDIR(inode->i_mode)) {
 		mask &= ~FAN_EVENT_ON_CHILD;
Signature · 1 line
2.25.1

/M

maintainer
#2 lore raw
In reply to Amir Goldstein
Quoted 7 lines · Amir Goldstein

The desired sematics of this action are not clear, so for now deny this action. We may relax it when we decide on the semantics and implement them.

Fixes 8cc3b1ccd930 ("fanotify: wire up FAN_RENAME event")

Thanks guys. I've merged the fix to my tree (fast_track branch) and will push it to Linus on Monday once it gets at least some exposure to auto-testers.

Honza

Quoted 23 lines
---
 fs/notify/fanotify/fanotify_user.c | 5 +++++
 1 file changed, 5 insertions(+)
fs/notify/fanotify/fanotify_user.c +5 -0
index edad67d674dc..ae0c27fac651 100644
@@ -1695,6 +1695,11 @@ static int do_fanotify_mark(int fanotify_fd, unsigned int flags, __u64 mask,
 	else
 		mnt = path.mnt;
 
+	/* FAN_RENAME is not allowed on non-dir (for now) */
+	ret = -EINVAL;
+	if (inode && (mask & FAN_RENAME) && !S_ISDIR(inode->i_mode))
+		goto path_put_and_out;
+
 	/* Mask out FAN_EVENT_ON_CHILD flag for sb/mount/non-dir marks */
 	if (mnt || !S_ISDIR(inode->i_mode)) {
 		mask &= ~FAN_EVENT_ON_CHILD;
Signature · 1 line
2.25.1
Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR
author reviewer
#3 lore raw
Quoted 6 lines · Jan Kara
Quoted 4 lines · Amir Goldstein

The desired sematics of this action are not clear, so for now deny this action. We may relax it when we decide on the semantics and implement them.

Quoted 7 lines
Quoted 3 lines
Fixes 8cc3b1ccd930 ("fanotify: wire up FAN_RENAME event")

Thanks guys. I've merged the fix to my tree (fast_track branch) and will push it to Linus on Monday once it gets at least some exposure to auto-testers.

Actually, I made a mistake.
It should not return -EINVAL, it should return -ENOTDIR, because the error is the object not the syscall argument values.

Going forward, when Matthew implements FAN_RENAME on non-dir, the error should be changed to -EPERM (for unpriv caller). This will allow better documentation of behavior in kernel 5.17 and newer kernels.

Can you please fix that before sending to Linus?

Thanks,
Amir.

author reviewer
#4 lore raw
Quoted 20 lines · Amir Goldstein
Quoted 6 lines · Jan Kara
Quoted 4 lines · Amir Goldstein

The desired sematics of this action are not clear, so for now deny this action. We may relax it when we decide on the semantics and implement them.

Quoted 7 lines
Quoted 3 lines
Fixes 8cc3b1ccd930 ("fanotify: wire up FAN_RENAME event")

Thanks guys. I've merged the fix to my tree (fast_track branch) and will push it to Linus on Monday once it gets at least some exposure to auto-testers.

Actually, I made a mistake.
It should not return -EINVAL, it should return -ENOTDIR, because the error is the object not the syscall argument values.

Quoted 7 lines

Going forward, when Matthew implements FAN_RENAME on non-dir, the error should be changed to -EPERM (for unpriv caller). This will allow better documentation of behavior in kernel 5.17 and newer kernels.

Can you please fix that before sending to Linus?

Actually, nevermind, I have thought of another issue so posting v2. I think we should deny all dirent events on non-dir with FAN_REPORT_TARGET_FID.

This is what happens when posting patches from airports :-P

Thanks,
Amir.

maintainer
#5 lore raw
In reply to Amir Goldstein
Quoted 11 lines · Amir Goldstein
Quoted 10 lines · Jan Kara
Quoted 7 lines · Amir Goldstein

The desired sematics of this action are not clear, so for now deny this action. We may relax it when we decide on the semantics and implement them.

Fixes 8cc3b1ccd930 ("fanotify: wire up FAN_RENAME event")
Quoted 7 lines
Quoted 3 lines

Thanks guys. I've merged the fix to my tree (fast_track branch) and will push it to Linus on Monday once it gets at least some exposure to auto-testers.

Actually, I made a mistake.
It should not return -EINVAL, it should return -ENOTDIR, because the error is the object not the syscall argument values.

Yeah, makes sense.

Quoted 6 lines

Going forward, when Matthew implements FAN_RENAME on non-dir, the error should be changed to -EPERM (for unpriv caller). This will allow better documentation of behavior in kernel 5.17 and newer kernels.

Can you please fix that before sending to Linus?

Yup, I'll update that.

Honza

Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR