Skip to content

Commit cf5bb09

Browse files
lostjefflebrauner
authored andcommitted
cachefiles: add missing lock protection when polling
Add missing lock protection in poll routine when iterating xarray, otherwise: Even with RCU read lock held, only the slot of the radix tree is ensured to be pinned there, while the data structure (e.g. struct cachefiles_req) stored in the slot has no such guarantee. The poll routine will iterate the radix tree and dereference cachefiles_req accordingly. Thus RCU read lock is not adequate in this case and spinlock is needed here. Fixes: b817e22 ("cachefiles: narrow the scope of triggering EPOLLIN events in ondemand mode") Signed-off-by: Jingbo Xu <[email protected]> Signed-off-by: Baokun Li <[email protected]> Link: https://lore.kernel.org/r/[email protected] Acked-by: Jeff Layton <[email protected]> Reviewed-by: Jia Zhu <[email protected]> Reviewed-by: Gao Xiang <[email protected]> Signed-off-by: Christian Brauner <[email protected]>
1 parent 19f4f39 commit cf5bb09

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

fs/cachefiles/daemon.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -365,14 +365,14 @@ static __poll_t cachefiles_daemon_poll(struct file *file,
365365

366366
if (cachefiles_in_ondemand_mode(cache)) {
367367
if (!xa_empty(&cache->reqs)) {
368-
rcu_read_lock();
368+
xas_lock(&xas);
369369
xas_for_each_marked(&xas, req, ULONG_MAX, CACHEFILES_REQ_NEW) {
370370
if (!cachefiles_ondemand_is_reopening_read(req)) {
371371
mask |= EPOLLIN;
372372
break;
373373
}
374374
}
375-
rcu_read_unlock();
375+
xas_unlock(&xas);
376376
}
377377
} else {
378378
if (test_bit(CACHEFILES_STATE_CHANGED, &cache->flags))

0 commit comments

Comments
 (0)