diff mbox series

fanotify: don't skip extra event info if no info_mode is set

Message ID adfd31f369528c9958922d901fbe8eba48dfe496.1721403041.git.josef@toxicpanda.com (mailing list archive)
State New
Headers show
Series fanotify: don't skip extra event info if no info_mode is set | expand

Commit Message

Josef Bacik July 19, 2024, 3:30 p.m. UTC
Previously we would only include optional information if you requested
it via an FAN_ flag at fanotify_init time (FAN_REPORT_FID for example).
However this isn't necessary as the event length is encoded in the
metadata, and if the user doesn't want to consume the information they
don't have to.  With the PRE_ACCESS events we will always generate range
information, so drop this check in order to allow this extra
information to be exported without needing to have another flag.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
 fs/notify/fanotify/fanotify_user.c | 13 ++++---------
 1 file changed, 4 insertions(+), 9 deletions(-)

Comments

Amir Goldstein July 20, 2024, 7:44 a.m. UTC | #1
On Fri, Jul 19, 2024 at 6:31 PM Josef Bacik <josef@toxicpanda.com> wrote:
>
> Previously we would only include optional information if you requested
> it via an FAN_ flag at fanotify_init time (FAN_REPORT_FID for example).
> However this isn't necessary as the event length is encoded in the
> metadata, and if the user doesn't want to consume the information they
> don't have to.  With the PRE_ACCESS events we will always generate range
> information, so drop this check in order to allow this extra
> information to be exported without needing to have another flag.
>
> Signed-off-by: Josef Bacik <josef@toxicpanda.com>

Looks sane, you may add:
Reviewed-by: Amir Goldstein <amir73il@gmail.com>

I think it would be best to re-post this one along with the pre-content
events series for better context.

Thanks,
Amir.

> ---
>  fs/notify/fanotify/fanotify_user.c | 13 ++++---------
>  1 file changed, 4 insertions(+), 9 deletions(-)
>
> diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
> index 9ec313e9f6e1..2e2fba8a9d20 100644
> --- a/fs/notify/fanotify/fanotify_user.c
> +++ b/fs/notify/fanotify/fanotify_user.c
> @@ -160,9 +160,6 @@ static size_t fanotify_event_len(unsigned int info_mode,
>         int fh_len;
>         int dot_len = 0;
>
> -       if (!info_mode)
> -               return event_len;
> -
>         if (fanotify_is_error_event(event->mask))
>                 event_len += FANOTIFY_ERROR_INFO_LEN;
>
> @@ -740,12 +737,10 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
>         if (fanotify_is_perm_event(event->mask))
>                 FANOTIFY_PERM(event)->fd = fd;
>
> -       if (info_mode) {
> -               ret = copy_info_records_to_user(event, info, info_mode, pidfd,
> -                                               buf, count);
> -               if (ret < 0)
> -                       goto out_close_fd;
> -       }
> +       ret = copy_info_records_to_user(event, info, info_mode, pidfd,
> +                                       buf, count);
> +       if (ret < 0)
> +               goto out_close_fd;
>
>         if (f)
>                 fd_install(fd, f);
> --
> 2.43.0
>
diff mbox series

Patch

diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
index 9ec313e9f6e1..2e2fba8a9d20 100644
--- a/fs/notify/fanotify/fanotify_user.c
+++ b/fs/notify/fanotify/fanotify_user.c
@@ -160,9 +160,6 @@  static size_t fanotify_event_len(unsigned int info_mode,
 	int fh_len;
 	int dot_len = 0;
 
-	if (!info_mode)
-		return event_len;
-
 	if (fanotify_is_error_event(event->mask))
 		event_len += FANOTIFY_ERROR_INFO_LEN;
 
@@ -740,12 +737,10 @@  static ssize_t copy_event_to_user(struct fsnotify_group *group,
 	if (fanotify_is_perm_event(event->mask))
 		FANOTIFY_PERM(event)->fd = fd;
 
-	if (info_mode) {
-		ret = copy_info_records_to_user(event, info, info_mode, pidfd,
-						buf, count);
-		if (ret < 0)
-			goto out_close_fd;
-	}
+	ret = copy_info_records_to_user(event, info, info_mode, pidfd,
+					buf, count);
+	if (ret < 0)
+		goto out_close_fd;
 
 	if (f)
 		fd_install(fd, f);