Skip to content

Commit 130a3c7

Browse files
krisman-at-collaborajankara
authored andcommitted
fanotify: Emit generic error info for error event
The error info is a record sent to users on FAN_FS_ERROR events documenting the type of error. It also carries an error count, documenting how many errors were observed since the last reporting. Link: https://lore.kernel.org/r/[email protected] Reviewed-by: Amir Goldstein <[email protected]> Reviewed-by: Jan Kara <[email protected]> Signed-off-by: Gabriel Krisman Bertazi <[email protected]> Signed-off-by: Jan Kara <[email protected]>
1 parent 936d6a3 commit 130a3c7

File tree

4 files changed

+45
-0
lines changed

4 files changed

+45
-0
lines changed

fs/notify/fanotify/fanotify.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -621,6 +621,7 @@ static struct fanotify_event *fanotify_alloc_error_event(
621621
return NULL;
622622

623623
fee->fae.type = FANOTIFY_EVENT_TYPE_FS_ERROR;
624+
fee->error = report->error;
624625
fee->err_count = 1;
625626
fee->fsid = *fsid;
626627

fs/notify/fanotify/fanotify.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ FANOTIFY_NE(struct fanotify_event *event)
205205

206206
struct fanotify_error_event {
207207
struct fanotify_event fae;
208+
s32 error; /* Error reported by the Filesystem. */
208209
u32 err_count; /* Suppressed errors count */
209210

210211
__kernel_fsid_t fsid; /* FSID this error refers to. */

fs/notify/fanotify/fanotify_user.c

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ struct kmem_cache *fanotify_perm_event_cachep __read_mostly;
115115
(sizeof(struct fanotify_event_info_fid) + sizeof(struct file_handle))
116116
#define FANOTIFY_PIDFD_INFO_HDR_LEN \
117117
sizeof(struct fanotify_event_info_pidfd)
118+
#define FANOTIFY_ERROR_INFO_LEN \
119+
(sizeof(struct fanotify_event_info_error))
118120

119121
static int fanotify_fid_info_len(int fh_len, int name_len)
120122
{
@@ -139,6 +141,9 @@ static size_t fanotify_event_len(unsigned int info_mode,
139141
if (!info_mode)
140142
return event_len;
141143

144+
if (fanotify_is_error_event(event->mask))
145+
event_len += FANOTIFY_ERROR_INFO_LEN;
146+
142147
info = fanotify_event_info(event);
143148

144149
if (fanotify_event_has_dir_fh(event)) {
@@ -324,6 +329,28 @@ static int process_access_response(struct fsnotify_group *group,
324329
return -ENOENT;
325330
}
326331

332+
static size_t copy_error_info_to_user(struct fanotify_event *event,
333+
char __user *buf, int count)
334+
{
335+
struct fanotify_event_info_error info;
336+
struct fanotify_error_event *fee = FANOTIFY_EE(event);
337+
338+
info.hdr.info_type = FAN_EVENT_INFO_TYPE_ERROR;
339+
info.hdr.pad = 0;
340+
info.hdr.len = FANOTIFY_ERROR_INFO_LEN;
341+
342+
if (WARN_ON(count < info.hdr.len))
343+
return -EFAULT;
344+
345+
info.error = fee->error;
346+
info.error_count = fee->err_count;
347+
348+
if (copy_to_user(buf, &info, sizeof(info)))
349+
return -EFAULT;
350+
351+
return info.hdr.len;
352+
}
353+
327354
static int copy_fid_info_to_user(__kernel_fsid_t *fsid, struct fanotify_fh *fh,
328355
int info_type, const char *name,
329356
size_t name_len,
@@ -530,6 +557,15 @@ static int copy_info_records_to_user(struct fanotify_event *event,
530557
total_bytes += ret;
531558
}
532559

560+
if (fanotify_is_error_event(event->mask)) {
561+
ret = copy_error_info_to_user(event, buf, count);
562+
if (ret < 0)
563+
return ret;
564+
buf += ret;
565+
count -= ret;
566+
total_bytes += ret;
567+
}
568+
533569
return total_bytes;
534570
}
535571

include/uapi/linux/fanotify.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ struct fanotify_event_metadata {
126126
#define FAN_EVENT_INFO_TYPE_DFID_NAME 2
127127
#define FAN_EVENT_INFO_TYPE_DFID 3
128128
#define FAN_EVENT_INFO_TYPE_PIDFD 4
129+
#define FAN_EVENT_INFO_TYPE_ERROR 5
129130

130131
/* Variable length info record following event metadata */
131132
struct fanotify_event_info_header {
@@ -160,6 +161,12 @@ struct fanotify_event_info_pidfd {
160161
__s32 pidfd;
161162
};
162163

164+
struct fanotify_event_info_error {
165+
struct fanotify_event_info_header hdr;
166+
__s32 error;
167+
__u32 error_count;
168+
};
169+
163170
struct fanotify_response {
164171
__s32 fd;
165172
__u32 response;

0 commit comments

Comments
 (0)