Skip to content

Commit c285a2f

Browse files
amir73iljankara
authored andcommitted
fanotify: update connector fsid cache on add mark
When implementing connector fsid cache, we only initialized the cache when the first mark added to object was added by FAN_REPORT_FID group. We forgot to update conn->fsid when the second mark is added by FAN_REPORT_FID group to an already attached connector without fsid cache. Reported-and-tested-by: syzbot+c277e8e2f46414645508@syzkaller.appspotmail.com Fixes: 7711522 ("fanotify: cache fsid in fsnotify_mark_connector") Signed-off-by: Amir Goldstein <amir73il@gmail.com> Signed-off-by: Jan Kara <jack@suse.cz>
1 parent c6d9c35 commit c285a2f

3 files changed

Lines changed: 18 additions & 4 deletions

File tree

‎fs/notify/fanotify/fanotify.c‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,10 @@ static __kernel_fsid_t fanotify_get_fsid(struct fsnotify_iter_info *iter_info)
355355
/* Mark is just getting destroyed or created? */
356356
if (!conn)
357357
continue;
358+
if (!(conn->flags & FSNOTIFY_CONN_FLAG_HAS_FSID))
359+
continue;
360+
/* Pairs with smp_wmb() in fsnotify_add_mark_list() */
361+
smp_rmb();
358362
fsid = conn->fsid;
359363
if (WARN_ON_ONCE(!fsid.val[0] && !fsid.val[1]))
360364
continue;

‎fs/notify/mark.c‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -482,10 +482,13 @@ static int fsnotify_attach_connector_to_object(fsnotify_connp_t *connp,
482482
conn->type = type;
483483
conn->obj = connp;
484484
/* Cache fsid of filesystem containing the object */
485-
if (fsid)
485+
if (fsid) {
486486
conn->fsid = *fsid;
487-
else
487+
conn->flags = FSNOTIFY_CONN_FLAG_HAS_FSID;
488+
} else {
488489
conn->fsid.val[0] = conn->fsid.val[1] = 0;
490+
conn->flags = 0;
491+
}
489492
if (conn->type == FSNOTIFY_OBJ_TYPE_INODE)
490493
inode = igrab(fsnotify_conn_inode(conn));
491494
/*
@@ -560,7 +563,12 @@ static int fsnotify_add_mark_list(struct fsnotify_mark *mark,
560563
if (err)
561564
return err;
562565
goto restart;
563-
} else if (fsid && (conn->fsid.val[0] || conn->fsid.val[1]) &&
566+
} else if (fsid && !(conn->flags & FSNOTIFY_CONN_FLAG_HAS_FSID)) {
567+
conn->fsid = *fsid;
568+
/* Pairs with smp_rmb() in fanotify_get_fsid() */
569+
smp_wmb();
570+
conn->flags |= FSNOTIFY_CONN_FLAG_HAS_FSID;
571+
} else if (fsid && (conn->flags & FSNOTIFY_CONN_FLAG_HAS_FSID) &&
564572
(fsid->val[0] != conn->fsid.val[0] ||
565573
fsid->val[1] != conn->fsid.val[1])) {
566574
/*

‎include/linux/fsnotify_backend.h‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,9 @@ typedef struct fsnotify_mark_connector __rcu *fsnotify_connp_t;
292292
*/
293293
struct fsnotify_mark_connector {
294294
spinlock_t lock;
295-
unsigned int type; /* Type of object [lock] */
295+
unsigned short type; /* Type of object [lock] */
296+
#define FSNOTIFY_CONN_FLAG_HAS_FSID 0x01
297+
unsigned short flags; /* flags [lock] */
296298
__kernel_fsid_t fsid; /* fsid of filesystem containing object */
297299
union {
298300
/* Object pointer [lock] */

0 commit comments

Comments
 (0)