Skip to content

Commit 4d8a2fe

Browse files
dhowellsgregkh
authored andcommitted
afs: Fix lack of locking around modifications of net->cells_dyn_ino
[ Upstream commit 55e8418 ] Fix the lack of locking around modifications of net->cells_dyn_ino by taking net->cells_lock exclusively. This also requires to cell to be removed from net->cells_dyn_ino in afs_destroy_cell_work() rather than in afs_cell_destroy() as the latter runs in RCU cleanup context and sleeping locks cannot be taken there. Fixes: 1d0b929 ("afs: Change dynroot to create contents on demand") Closes: https://sashiko.dev/#/patchset/20260618074903.2374756-1-dhowells%40redhat.com Signed-off-by: David Howells <dhowells@redhat.com> Link: https://patch.msgid.link/20260622090856.2746629-19-dhowells@redhat.com cc: Marc Dionne <marc.dionne@auristor.com> cc: linux-afs@lists.infradead.org Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org> Stable-dep-of: 26f17ce ("afs: Fix premature cell exposure through /afs") Signed-off-by: Sasha Levin <sashal@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent fa4ccdc commit 4d8a2fe

2 files changed

Lines changed: 8 additions & 2 deletions

File tree

fs/afs/cell.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,10 @@ static struct afs_cell *afs_alloc_cell(struct afs_net *net,
198198
cell->dns_source = vllist->source;
199199
cell->dns_status = vllist->status;
200200
smp_store_release(&cell->dns_lookup_count, 1); /* vs source/status */
201+
down_write(&net->cells_lock);
201202
ret = idr_alloc_cyclic(&net->cells_dyn_ino, cell,
202203
2, INT_MAX / 2, GFP_KERNEL);
204+
up_write(&net->cells_lock);
203205
if (ret < 0)
204206
goto error;
205207
atomic_inc(&net->cells_outstanding);
@@ -572,7 +574,6 @@ static void afs_cell_destroy(struct rcu_head *rcu)
572574
afs_put_vlserverlist(net, rcu_access_pointer(cell->vl_servers));
573575
afs_unuse_cell(cell->alias_of, afs_cell_trace_unuse_alias);
574576
key_put(cell->anonymous_key);
575-
idr_remove(&net->cells_dyn_ino, cell->dynroot_ino);
576577
kfree(cell->name - 1);
577578
kfree(cell);
578579

@@ -587,6 +588,11 @@ static void afs_destroy_cell_work(struct work_struct *work)
587588
afs_see_cell(cell, afs_cell_trace_destroy);
588589
timer_delete_sync(&cell->management_timer);
589590
cancel_work_sync(&cell->manager);
591+
592+
down_write(&cell->net->cells_lock);
593+
idr_remove(&cell->net->cells_dyn_ino, cell->dynroot_ino);
594+
up_write(&cell->net->cells_lock);
595+
590596
call_rcu(&cell->rcu, afs_cell_destroy);
591597
}
592598

fs/afs/dynroot.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ static struct dentry *afs_lookup_atcell(struct inode *dir, struct dentry *dentry
278278
}
279279

280280
/*
281-
* Transcribe the cell database into readdir content under the RCU read lock.
281+
* Transcribe the cell database into readdir content under net->cells_lock.
282282
* Each cell produces two entries, one prefixed with a dot and one not.
283283
*/
284284
static int afs_dynroot_readdir_cells(struct afs_net *net, struct dir_context *ctx)

0 commit comments

Comments
 (0)