linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] fanotify: fix copy_event_to_user() fid error clean up
@ 2021-06-11  3:32 Matthew Bobrowski
  2021-06-11  7:04 ` Amir Goldstein
  0 siblings, 1 reply; 8+ messages in thread
From: Matthew Bobrowski @ 2021-06-11  3:32 UTC (permalink / raw)
  To: amir73il, jack; +Cc: linux-fsdevel

Ensure that clean up is performed on the allocated file descriptor and
struct file object in the event that an error is encountered while copying
fid info objects. Currently, we return directly to the caller when an error
is experienced in the fid info copying helper, which isn't ideal given that
the listener process could be left with a dangling file descriptor in their
fdtable.

Fixes: 44d705b0370b1 ("fanotify: report name info for FAN_DIR_MODIFY event")
Fixes: 5e469c830fdb5 ("fanotify: copy event fid info to user")
Link: https://lore.kernel.org/linux-fsdevel/YMKv1U7tNPK955ho@google.com/T/#m15361cd6399dad4396aad650de25dbf6b312288e

Signed-off-by: Matthew Bobrowski <repnop@google.com>
---

Hey Amir/Jan,

I wasn't 100% sure what specific commit hash I should be referencing in the
fix tags, so please let me know if that needs to be changed.

Should we also be CC'ing <stable@vger.kernel.org> so this gets backported?

 fs/notify/fanotify/fanotify_user.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
index be5b6d2c01e7..64864fb40b40 100644
--- a/fs/notify/fanotify/fanotify_user.c
+++ b/fs/notify/fanotify/fanotify_user.c
@@ -471,7 +471,7 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
 					info_type, fanotify_info_name(info),
 					info->name_len, buf, count);
 		if (ret < 0)
-			return ret;
+			goto out_close_fd;
 
 		buf += ret;
 		count -= ret;
@@ -519,7 +519,7 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
 					fanotify_event_object_fh(event),
 					info_type, dot, dot_len, buf, count);
 		if (ret < 0)
-			return ret;
+			goto out_close_fd;
 
 		buf += ret;
 		count -= ret;
-- 
2.32.0.272.g935e593368-goog

/M

^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2021-06-15 11:11 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-11  3:32 [PATCH] fanotify: fix copy_event_to_user() fid error clean up Matthew Bobrowski
2021-06-11  7:04 ` Amir Goldstein
2021-06-11  7:24   ` Greg KH
2021-06-14 10:28   ` Jan Kara
2021-06-15  9:24     ` Matthew Bobrowski
2021-06-15  9:41       ` Greg KH
2021-06-15 10:23         ` Jan Kara
2021-06-15 11:11           ` Greg KH

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).