linux-stable/fs/notify
Amir Goldstein 522249f05c fanotify: allow reporting errors on failure to open fd
When working in "fd mode", fanotify_read() needs to open an fd
from a dentry to report event->fd to userspace.

Opening an fd from dentry can fail for several reasons.
For example, when tasks are gone and we try to open their
/proc files or we try to open a WRONLY file like in sysfs
or when trying to open a file that was deleted on the
remote network server.

Add a new flag FAN_REPORT_FD_ERROR for fanotify_init().
For a group with FAN_REPORT_FD_ERROR, we will send the
event with the error instead of the open fd, otherwise
userspace may not get the error at all.

For an overflow event, we report -EBADF to avoid confusing FAN_NOFD
with -EPERM.  Similarly for pidfd open errors we report either -ESRCH
or the open error instead of FAN_NOPIDFD and FAN_EPIDFD.

In any case, userspace will not know which file failed to
open, so add a debug print for further investigation.

Reported-by: Krishna Vivek Vitta <kvitta@microsoft.com>
Link: https://lore.kernel.org/linux-fsdevel/SI2P153MB07182F3424619EDDD1F393EED46D2@SI2P153MB0718.APCP153.PROD.OUTLOOK.COM/
Signed-off-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Jan Kara <jack@suse.cz>
Link: https://patch.msgid.link/20241003142922.111539-1-amir73il@gmail.com
2024-10-16 17:43:05 +02:00
..
dnotify inotify: Fix possible deadlock in fsnotify_destroy_mark 2024-10-02 15:14:29 +02:00
fanotify fanotify: allow reporting errors on failure to open fd 2024-10-16 17:43:05 +02:00
inotify fsnotify: Avoid data race between fsnotify_recalc_mask() and fsnotify_object_watched() 2024-10-02 15:11:40 +02:00
fdinfo.c fsnotify: Avoid -Wflex-array-member-not-at-end warning 2024-03-26 10:53:32 +01:00
fdinfo.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
fsnotify.c fsnotify: Avoid data race between fsnotify_recalc_mask() and fsnotify_object_watched() 2024-10-02 15:11:40 +02:00
fsnotify.h fsnotify: clear PARENT_WATCHED flags lazily 2024-06-05 09:52:38 +02:00
group.c inotify: Fix possible deadlock in fsnotify_destroy_mark 2024-10-02 15:14:29 +02:00
Kconfig fs/notify: Remove "select SRCU" 2023-02-02 16:26:06 -08:00
Makefile License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
mark.c fsnotify: Avoid data race between fsnotify_recalc_mask() and fsnotify_object_watched() 2024-10-02 15:11:40 +02:00
notification.c fsnotify: Pass group argument to free_event 2021-10-27 12:34:18 +02:00