Message ID | 20211025192746.66445-25-krisman@collabora.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | file system-wide error monitoring | expand |
On Mon, Oct 25, 2021 at 10:30 PM Gabriel Krisman Bertazi <krisman@collabora.com> wrote: > > Non-inode errors will reported with an empty file_handle. In > preparation for that, allow some events to print the FID record even if > there isn't any file_handle encoded > > Even though FILEID_ROOT is used internally, make zero-length file > handles be reported as FILEID_INVALID. > > Reviewed-by: Amir Goldstein <amir73il@gmail.com> > Reviewed-by: Jan Kara <jack@suse.cz> > Signed-off-by: Gabriel Krisman Bertazi <krisman@collabora.com> > > --- > Changes since v8: > - Move fanotify_event_has_object_fh check here (jan) Logically, this move is wrong, because after this patch, copy_fid_info_to_user() can theoretically be called with NULL fh in the existing construct of: if (fanotify_event_has_object_fh(event)) { ... ret = copy_fid_info_to_user(fanotify_event_fsid(event), fanotify_event_object_fh(event), The thing that prevents this case in effect is that FAN_FS_ERROR is not yet wired, but I am not sure if leaving this theoretic bisect issue is a good idea. Anyway, that's a very minor theoretic issue and I am sure Jan can decide whether to deal with it and how (no need to post v10 IMO). Thanks, Amir.
On Tue 26-10-21 12:09:19, Amir Goldstein wrote: > On Mon, Oct 25, 2021 at 10:30 PM Gabriel Krisman Bertazi > <krisman@collabora.com> wrote: > > > > Non-inode errors will reported with an empty file_handle. In > > preparation for that, allow some events to print the FID record even if > > there isn't any file_handle encoded > > > > Even though FILEID_ROOT is used internally, make zero-length file > > handles be reported as FILEID_INVALID. > > > > Reviewed-by: Amir Goldstein <amir73il@gmail.com> > > Reviewed-by: Jan Kara <jack@suse.cz> > > Signed-off-by: Gabriel Krisman Bertazi <krisman@collabora.com> > > > > --- > > Changes since v8: > > - Move fanotify_event_has_object_fh check here (jan) > > Logically, this move is wrong, because after this patch, > copy_fid_info_to_user() can theoretically be called with NULL fh in the > existing construct of: > if (fanotify_event_has_object_fh(event)) { > ... > ret = copy_fid_info_to_user(fanotify_event_fsid(event), > > fanotify_event_object_fh(event), > > The thing that prevents this case in effect is that FAN_FS_ERROR > is not yet wired, but I am not sure if leaving this theoretic bisect > issue is a good idea. > > Anyway, that's a very minor theoretic issue and I am sure Jan can > decide whether to deal with it and how (no need to post v10 IMO). Hum, correct. I guess I'll just fold this patch into patch 26. Logically they are very close anyway. Honza
diff --git a/fs/notify/fanotify/fanotify.h b/fs/notify/fanotify/fanotify.h index 80af269eebb8..f51ab6e556e8 100644 --- a/fs/notify/fanotify/fanotify.h +++ b/fs/notify/fanotify/fanotify.h @@ -266,6 +266,9 @@ static inline int fanotify_event_dir_fh_len(struct fanotify_event *event) static inline bool fanotify_event_has_object_fh(struct fanotify_event *event) { + /* For error events, even zeroed fh are reported. */ + if (event->type == FANOTIFY_EVENT_TYPE_FS_ERROR) + return true; return fanotify_event_object_fh_len(event) > 0; } diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c index a9b5c36ee49e..ff4a7373f7a5 100644 --- a/fs/notify/fanotify/fanotify_user.c +++ b/fs/notify/fanotify/fanotify_user.c @@ -339,9 +339,6 @@ static int copy_fid_info_to_user(__kernel_fsid_t *fsid, struct fanotify_fh *fh, pr_debug("%s: fh_len=%zu name_len=%zu, info_len=%zu, count=%zu\n", __func__, fh_len, name_len, info_len, count); - if (!fh_len) - return 0; - if (WARN_ON_ONCE(len < sizeof(info) || len > count)) return -EFAULT; @@ -376,6 +373,11 @@ static int copy_fid_info_to_user(__kernel_fsid_t *fsid, struct fanotify_fh *fh, handle.handle_type = fh->type; handle.handle_bytes = fh_len; + + /* Mangle handle_type for bad file_handle */ + if (!fh_len) + handle.handle_type = FILEID_INVALID; + if (copy_to_user(buf, &handle, sizeof(handle))) return -EFAULT;