afs: Miscellaneous fixes
Subsystems (3)
David Howells
maintainerv4 cover afs: Miscellaneous fixes
Hi Christian,
Can you pick up these miscellaneous AFS fixes, please?
(1) Fix the CB.InitCallBackState3 service handler to handle an unknown server (server pointer is NULL).
(2) Fix the clobbering of the default error code in
afs_extract_vl_addrs().
(3) Fix a NULL pointer in a trace point in afs_get_tree().
(4) Fix double netfs_inode initialisation in afs_root_iget().
(5) Fix setting of AS_RELEASE_ALWAYS for symlinks (and mountpoints) as there's no release_folio function provided. The pagecache isn't used by afs for symlinks and directories.
(6) Fix the order of inode init to avoid clobbering NETFS_ICTX_SINGLE_NO_UPLOAD set on directories.
(7) Fix the release of op->more_files to Use kvfree().
(8) Fix erroneous seq |= 1 in volume lookup loop.
(9) Drop for duplicate server records when parsing DNS reply into the VL server list (this is not strictly a bug fix, so could be punted to the merge window).
(10) Fix malfunction in bulk lookup due to change in dir_emit() API added to mask off DT_* flags for overlayfs on fuse.
(11) Fix misplaced inc of net->cells_outstanding causing netns destruction hang.
(12) Fix reinitialisation of afs_vnode::lock_work. Not reinitialising it after allocation seems to upset DEBUG_OBJECTS despite there being an slab init-once handler provided.
(13) Fix callback service message parsers to pass through -EAGAIN when insufficient data yet received.
(14) Switch to using scoped_seqlock_read() in volume lookup loop as a follow up to (6).
(15) Fix leak of a volume we failed to get because its refcount had hit 0.
(16) Fix missing NULL pointer check in afs_break_some_callbacks().
(17) Fix leak of empty new vllist in afs_update_cell().
(18) Fix modifications of net->cells_dyn_ino to use locking; this requires the use of preallocation as the allocation has to be done under spinlock.
(19) Fix insertion into net->cells_dyn_ino to only add a new cell into the IDR only after we've checked it's not a duplicate.
(20) Fix afs_insert_volume_into_cell() to set AFS_VOLUME_RM_TREE on the old volume, not the new.
(21) Fix afs_extract_vlserver_list() to limit the string displayed in the debug statement.
The patches can be found here:
https://git.kernel.org/pub/scm/linux/kernel/git/dhowells/linux-fs.git/log/?h=afs-fixes
Thanks,
David
Changes
=======
ver #4)
- Addressed some Sashiko comments[3]:
- Fixed param name on afs_lookup_filldir() and afs_lookup_one_filldir().
- Fixed the cells_dyn_ino locking patch to use cells_lock rather than making a separate spinlock as dir_emit() must be callable thereunder.
- Added another cells_dyn_ino patch to insert a new cell into the IDR only after we've checked it isn't a duplicate.
ver #3)
- Relabelled the patch that switched to using scoped_seqlock_read().
- Moved a bit from scoped_seqlock_read() patch to the preceding patch that had got committed to the wrong patch.
- Merged the two AS_RELEASE_ALWAYS patches.
- Moved patch to remove double-init from afs_root_iget() before AS_RELEASE_ALWAYS patch.
- Moved the patch to check for a NULL pointer in afs_break_some_callbacks() before the patch to lookup the volume that might then return NULL.
- Addressed some Sashiko comments[2]:
- Made the ->lock_work reinit patch also flush the work when evicting an inode.
- Made the afs_break_some_callbacks() NULL check patch drop the RCU lock and clear the count if the server is unknown.
- Added some new fix patches.
ver #2)
- Added patches to fix issues raised by Sashiko[1]
[1] https://sashiko.dev/#/patchset/20260609081738.770127-1-dhowells%40re
[2] https://sashiko.dev/#/patchset/20260618074903.2374756-1-dhowells%40redhat.com
[3] https://sashiko.dev/#/patchset/20260618155141.2513212-1-dhowells%40redhat.com
Dan Carpenter (1):
afs: Fix error code in afs_extract_vl_addrs()
David Howells (15):
afs: Fix double netfs initialisation in afs_root_iget()
afs: Remove setting of AS_RELEASE_ALWAYS for symlinks and mountpoints
afs: Fix directory inode initialisation order
afs: Fix bulk lookup malfunction due to change in dir_emit() API
afs: Fix misplaced inc of net->cells_outstanding
afs: Fix reinitialisation of the inode, in particular ->lock_work
afs: Fix callback service message parsers to pass through -EAGAIN
afs: Use scoped_seqlock_read() rather than manually doing seqlock
stuff
afs: Fix missing NULL pointer check in afs_break_some_callbacks()
afs: Fix leak of ungot volume
afs: Fix vllist leak
afs: Fix lack of locking around modifications of net->cells_dyn_ino
afs: Fix premature cell exposure through /afs
afs: Fix the volume AFS_VOLUME_RM_TREE is set on
afs: Fix unchecked-length string display in debug statement
Li RongQing (1):
afs: Remove erroneous seq |= 1 in volume lookup loop
Matvey Kovalev (1):
afs: fix NULL pointer dereference in afs_get_tree()
Nan Li (1):
afs: handle CB.InitCallBackState3 requests without a server record
Yuto Ohnuki (1):
afs: check for duplicate servers in VL server list
Zilin Guan (1):
afs: use kvfree() to free memory allocated by kvcalloc()
fs/afs/callback.c | 17 +++++++---------- fs/afs/cell.c | 27 +++++++++++++++++++++------ fs/afs/cmservice.c | 7 +++++-- fs/afs/dir.c | 40 +++++++++++++++++++++++++--------------- fs/afs/dynroot.c | 2 +- fs/afs/fs_operation.c | 2 +- fs/afs/inode.c | 15 +++++++-------- fs/afs/internal.h | 3 +-- fs/afs/super.c | 5 +++-- fs/afs/vl_list.c | 24 +++++++++++++++++++++--- fs/afs/volume.c | 2 +- 11 files changed, 93 insertions(+), 51 deletions(-)
David Howells
maintainerPATCH v4 1/21 afs: handle CB.InitCallBackState3 requests without a server record
From: Nan Li <[email protected]>
The cache manager callback path now attaches the server record to an incoming call through the rxrpc peer's app data. That association is not guaranteed to exist for every callback request, and most callback handlers already tolerate that case.
Make CB.InitCallBackState3 follow the same pattern by checking whether a server record was attached before using it. If the peer is not mapped to a server record, trace the request and ignore it, matching the existing behaviour for other unmatched callback requests.
This keeps the callback handler consistent with the rest of the cache manager service and avoids depending on peer state that may not be available for a given request.
--- fs/afs/cmservice.c | 5 +++++ 1 file changed, 5 insertions(+)
fs/afs/cmservice.c +5 -0
@@ -364,6 +364,11 @@ static int afs_deliver_cb_init_call_back_state3(struct afs_call *call)if (!afs_check_call_state (call,AFS_CALL_SV_REPLYING ))return afs_io_error (call, afs_io_error_cm_reply); +if (!call->server) { +trace_afs_cm_no_server_u (call, call->request); +return 0 ; + } +if (memcmp (call->request, &call->server->_uuid,sizeof (call->server->_uuid)) !=0 ) {pr_notice ("Callback UUID does not match fileserver UUID\n" );trace_afs_cm_no_server_u (call, call->request);
David Howells
maintainerPATCH v4 2/21 afs: Fix error code in afs_extract_vl_addrs()
In reply to David HowellsFrom: Dan Carpenter <[email protected]>
The error codes on these paths are only set on the first iteration through the loop. Set the correct error code on every iteration.
--- fs/afs/vl_list.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
fs/afs/vl_list.c +3 -1
@@ -92,7 +92,7 @@ static struct afs_addr_list *afs_extract_vl_addrs(struct afs_net *net, {struct afs_addr_list *alist;const u8 *b = *_b; -int ret = -EINVAL ; +int ret; alist =afs_alloc_addrlist (nr_addrs);if (!alist)
@@ -110,6 +110,7 @@ static struct afs_addr_list *afs_extract_vl_addrs(struct afs_net *net,case DNS_ADDRESS_IS_IPV4 :if (end - b <4 ) {_leave (" = -EINVAL [short inet]" ); + ret = -EINVAL ; goto error; }memcpy (x, b,4 );
@@ -122,6 +123,7 @@ static struct afs_addr_list *afs_extract_vl_addrs(struct afs_net *net,case DNS_ADDRESS_IS_IPV6 :if (end - b <16 ) {_leave (" = -EINVAL [short inet6]" ); + ret = -EINVAL ; goto error; }memcpy (x, b,16 );
David Howells
maintainerPATCH v4 3/21 afs: fix NULL pointer dereference in afs_get_tree()
In reply to David HowellsFrom: Matvey Kovalev <[email protected]>
afs_alloc_sbi() uses kzalloc for memory allocation. And, if ctx->dyn_root is not null, as->cell and as->volume are null. In trace_afs_get_tree() they are dereferenced.
KASAN error message:
KASAN: null-ptr-deref in range [0x0000000000000000-0x0000000000000007] CPU: 2 PID: 18478 Comm: syz-executor.7 Not tainted 5.10.246-syzkaller #0 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.12.0-1 04/01/2014 RIP: 0010:perf_trace_afs_get_tree+0x1d9/0x550
include/trace/events/afs.h:1365
Call Trace: trace_afs_get_tree include/trace/events/afs.h:1365 [inline] afs_get_tree+0x922/0x1350 fs/afs/super.c:599 vfs_get_tree+0x8e/0x300 fs/super.c:1572 do_new_mount fs/namespace.c:3011 [inline] path_mount+0x14a5/0x2220 fs/namespace.c:3341 do_mount fs/namespace.c:3354 [inline] __do_sys_mount fs/namespace.c:3562 [inline] __se_sys_mount fs/namespace.c:3539 [inline] __x64_sys_mount+0x283/0x300 fs/namespace.c:3539 do_syscall_64+0x33/0x50 arch/x86/entry/common.c:46 entry_SYSCALL_64_after_hwframe+0x67/0xd1
Found by Linux Verification Center (linuxtesting.org) with Syzkaller.
--- fs/afs/super.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
fs/afs/super.c +2 -1
@@ -587,7 +587,8 @@ static int afs_get_tree(struct fs_context *fc) } fc->root =dget (sb->s_root); -trace_afs_get_tree (as->cell, as->volume); +if (!ctx->dyn_root) +trace_afs_get_tree (as->cell, as->volume);_leave (" = 0 [%p]" , sb);return 0 ;
David Howells
maintainerPATCH v4 4/21 afs: Fix double netfs initialisation in afs_root_iget()
In reply to David HowellsFix afs_root_iget() to leave initialisation of the netfs_inode part of the afs_vnode to afs_inode_init_from_status().
--- fs/afs/inode.c | 1 - 1 file changed, 1 deletion(-)
fs/afs/inode.c +0 -1
@@ -566,7 +566,6 @@ struct inode *afs_root_iget(struct super_block *sb, struct key *key) vnode =AFS_FS_I (inode); vnode->cb_v_check =atomic_read (&as->volume->cb_v_break); -afs_set_netfs_context (vnode); op =afs_alloc_operation (key, as->volume);if (IS_ERR (op)) {
David Howells
maintainerPATCH v4 5/21 afs: Remove setting of AS_RELEASE_ALWAYS for symlinks and mountpoints
In reply to David HowellsRegular AFS files correctly use afs_file_aops which have release_folio set as netfs_release_folio, so AS_RELEASE_ALWAYS is valid for them when fscache is enabled (set via afs_vnode_set_cache()). Symlinks and mountpoints in AFS use afs_dir_aops, which does not provide a release_folio callback. However, afs_apply_status() unconditionally calls mapping_set_release_always() for these.
In such case when memory management code attempts to release folios, filemap_release_folio() checks folio_needs_release() which returns true due to AS_RELEASE_ALWAYS being set. Since there is no release_folio callback, it falls through to try_to_free_buffers(), which at present expects buffer_heads to be not null. For symlinks and mountpoints without buffer_heads, this causes pointer dereference.
[dh: Added more bits that were missed]
--- fs/afs/inode.c | 7 +++---- fs/afs/internal.h | 2 -- 2 files changed, 3 insertions(+), 6 deletions(-)
fs/afs/inode.c +3 -4
@@ -52,9 +52,9 @@ static noinline void dump_vnode(struct afs_vnode *vnode, struct afs_vnode *paren/* * Set parameters for the netfs library */ -static void afs_set_netfs_context (struct afs_vnode *vnode) +static void afs_set_netfs_context (struct afs_vnode *vnode,bool is_file) { -netfs_inode_init (&vnode->netfs, &afs_req_ops, true); +netfs_inode_init (&vnode->netfs, &afs_req_ops, is_file); }/*
@@ -126,7 +126,6 @@ static int afs_inode_init_from_status(struct afs_operation *op, } inode->i_mapping->a_ops = &afs_symlink_aops;inode_nohighmem (inode); -mapping_set_release_always (inode->i_mapping);break ;default :dump_vnode (vnode, op->file[0 ].vnode != vnode ? op->file[0 ].vnode :NULL );
@@ -136,7 +135,7 @@ static int afs_inode_init_from_status(struct afs_operation *op,i_size_write (inode, status->size);inode_set_bytes (inode, status->size); -afs_set_netfs_context (vnode); +afs_set_netfs_context (vnode, status->type ==AFS_FTYPE_FILE ); vnode->invalid_before = status->data_version;trace_afs_set_dv (vnode, status->data_version);
fs/afs/internal.h +0 -2
@@ -750,8 +750,6 @@ static inline void afs_vnode_set_cache(struct afs_vnode *vnode, {#ifdef CONFIG_AFS_FSCACHE vnode->netfs.cache = cookie; -if (cookie) -mapping_set_release_always (vnode->netfs.inode.i_mapping);#endif }
David Howells
maintainerPATCH v4 6/21 afs: Fix directory inode initialisation order
In reply to David HowellsFix afs_inode_init_from_status() to call afs_set_netfs_context() before the switch to do file type-specific initialisation because local directory changes don't get uploaded to the server, only stored in the cache.
This requires that the file size be set before, so move that up too.
Without this, NETFS_ICTX_SINGLE_NO_UPLOAD as set on directories gets clobbered.
--- fs/afs/inode.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
fs/afs/inode.c +4 -4
@@ -93,6 +93,10 @@ static int afs_inode_init_from_status(struct afs_operation *op, inode->i_gid =make_kgid (&init_user_ns, status->group);set_nlink (&vnode->netfs.inode, status->nlink); +i_size_write (inode, status->size); +inode_set_bytes (inode, status->size); +afs_set_netfs_context (vnode, status->type ==AFS_FTYPE_FILE ); +switch (status->type) {case AFS_FTYPE_FILE : inode->i_mode =S_IFREG | (status->mode &S_IALLUGO );
@@ -133,10 +137,6 @@ static int afs_inode_init_from_status(struct afs_operation *op,return afs_protocol_error (NULL , afs_eproto_file_type); } -i_size_write (inode, status->size); -inode_set_bytes (inode, status->size); -afs_set_netfs_context (vnode, status->type ==AFS_FTYPE_FILE ); - vnode->invalid_before = status->data_version;trace_afs_set_dv (vnode, status->data_version);inode_set_iversion_raw (&vnode->netfs.inode, status->data_version);
David Howells
maintainerPATCH v4 7/21 afs: use kvfree() to free memory allocated by kvcalloc()
In reply to David HowellsFrom: Zilin Guan <[email protected]>
op->more_files is allocated with kvcalloc() but released via afs_put_operation(), which uses kfree() internally. This mismach prevents the resource from being released properly and may lead to undefined behavior.
Fix this by using kvfree() to free op->more_files to match its allocation method.
--- fs/afs/fs_operation.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/afs/fs_operation.c +1 -1
@@ -348,7 +348,7 @@ int afs_put_operation(struct afs_operation *op)for (i =0 ; i < op->nr_files -2 ; i++)if (op->more_files[i].put_vnode)iput (&op->more_files[i].vnode->netfs.inode); -kfree (op->more_files); +kvfree (op->more_files); }if (op->estate) {
David Howells
maintainerPATCH v4 8/21 afs: Remove erroneous seq |= 1 in volume lookup loop
In reply to David HowellsFrom: Li RongQing <[email protected]>
The seq |= 1 operation in the volume lookup loop is incorrect because:
seq is already incremented at start, making it odd in next iteration which triggers lock, but The |= 1 operation causes seq to be even and unintended lockless operation
Remove this erroneous operation to maintain proper lock sequencing.
--- fs/afs/callback.c | 1 - 1 file changed, 1 deletion(-)
fs/afs/callback.c +0 -1
@@ -140,7 +140,6 @@ static struct afs_volume *afs_lookup_volume_rcu(struct afs_cell *cell,break ;if (!need_seqretry (&cell->volume_lock, seq))break ; - seq |=1 ;/* Want a lock next time */ }done_seqretry (&cell->volume_lock, seq);
David Howells
maintainerPATCH v4 9/21 afs: check for duplicate servers in VL server list
In reply to David HowellsFrom: Yuto Ohnuki <[email protected]>
The DNS response may contain the same server more than once. Check for duplicates by name and port before inserting into the list to avoid duplicate entries.
Addresses the TODO comment in afs_extract_vlserver_list().
--- fs/afs/vl_list.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-)
fs/afs/vl_list.c +13 -1
@@ -289,8 +289,20 @@ struct afs_vlserver_list *afs_extract_vlserver_list(struct afs_cell *cell,afs_put_addrlist (old, afs_alist_trace_put_vlserver_old); } +/* Check for duplicates in the server list */ +for (j =0 ; j < vllist->nr_servers; j++) { +struct afs_vlserver *s = vllist->servers[j].server; -/* TODO: Might want to check for duplicates */ +if (s->name_len == server->name_len && + s->port == server->port && +strncasecmp (s->name, server->name, server->name_len) ==0 ) { +afs_put_vlserver (cell->net, server); + server =NULL ; +break ; + } + } +if (!server) +continue ;/* Insertion-sort by priority and weight */ for (j =0 ; j < vllist->nr_servers; j++) {
David Howells
maintainerPATCH v4 10/21 afs: Fix bulk lookup malfunction due to change in dir_emit() API
In reply to David Howellsafs_do_lookup() and afs_do_lookup_one() use the same directory parsing code as afs_readdir() and were supplying alternative dir_context actors to retrieve dirents, but because lookup needs the vnode's uniquifier as part of the reference, but not the DT flags, the uniquifier was being passed in the dt flags argument to the lookup actors.
Unfortunately, commit c644bce62b9c, added to fix overlayfs with fuse, broke this by masking off part of the uniquifier. This doesn't matter enough to be directly noticeable, instead causing bulk advance inode lookups to fail (which are retried later) and may cause dir revalidation to malfunction if the uniquifier is changed by masking.
Fix this by making the afs directory parsing code take special ->actor values of AFS_LOOKUP or AFS_LOOKUP_ONE instead that tell it to call afs_lookup_filldir() or afs_lookup_one_filldir() directly rather than going through dir_emit(). dir_emit() is still used for readdir.
--- fs/afs/dir.c | 40 +++++++++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 15 deletions(-)
fs/afs/dir.c +25 -15
@@ -28,9 +28,11 @@ static int afs_d_revalidate(struct inode *dir, const struct qstr *name,static int afs_d_delete (const struct dentry *dentry);static void afs_d_iput (struct dentry *dentry,struct inode *inode);static bool afs_lookup_one_filldir (struct dir_context *ctx,const char *name,int nlen, -loff_t fpos,u64 ino,unsigned dtype); +u64 ino,u32 uniquifier); +#define AFS_LOOKUP_ONE ((filldir_t)0x123UL)static bool afs_lookup_filldir (struct dir_context *ctx,const char *name,int nlen, -loff_t fpos,u64 ino,unsigned dtype); +u64 ino,u32 uniquifier); +#define AFS_LOOKUP ((filldir_t)0x137UL)static int afs_create (struct mnt_idmap *idmap,struct inode *dir,struct dentry *dentry,umode_t mode,bool excl); static struct dentry *afs_mkdir(struct mnt_idmap *idmap, struct inode *dir,
@@ -421,11 +423,18 @@ static int afs_dir_iterate_block(struct afs_vnode *dvnode, }/* found the next entry */ -if (!dir_emit (ctx, dire->u.name, nlen, -ntohl (dire->u.vnode), - (ctx->actor == afs_lookup_filldir || - ctx->actor == afs_lookup_one_filldir)? -ntohl (dire->u.unique) :DT_UNKNOWN )) { +if (ctx->actor ==AFS_LOOKUP ) { +if (!afs_lookup_filldir (ctx, dire->u.name, nlen, +ntohl (dire->u.vnode), +ntohl (dire->u.unique))) +return 0 ; + }else if (ctx->actor ==AFS_LOOKUP_ONE ) { +if (!afs_lookup_one_filldir (ctx, dire->u.name, nlen, +ntohl (dire->u.vnode), +ntohl (dire->u.unique))) +return 0 ; + }else if (!dir_emit (ctx, dire->u.name, nlen, +ntohl (dire->u.vnode),DT_UNKNOWN )) {_leave (" = 0 [full]" );return 0 ; }
@@ -545,6 +554,7 @@ static int afs_readdir(struct file *file, struct dir_context *ctx) {afs_dataversion_t dir_version; + ctx->dt_flags_mask =UINT_MAX ;return afs_dir_iterate (file_inode (file), ctx, file, &dir_version); }
@@ -554,14 +564,14 @@ static int afs_readdir(struct file *file, struct dir_context *ctx)* uniquifier through dtype */ static bool afs_lookup_one_filldir (struct dir_context *ctx,const char *name, -int nlen,loff_t fpos,u64 ino,unsigned dtype) +int nlen,u64 ino,u32 uniquifier) {struct afs_lookup_one_cookie *cookie = container_of(ctx, struct afs_lookup_one_cookie, ctx);_enter ("{%s,%u},%s,%u,,%llu,%u" , cookie->name.name, cookie->name.len, name, nlen, - (unsigned long long ) ino, dtype); + (unsigned long long ) ino, uniquifier);/* insanity checks first */ BUILD_BUG_ON (sizeof (union afs_xdr_dir_block ) !=2048 );
@@ -574,7 +584,7 @@ static bool afs_lookup_one_filldir(struct dir_context *ctx, const char *name, } cookie->fid.vnode = ino; - cookie->fid.unique = dtype; + cookie->fid.unique = uniquifier; cookie->found =1 ;_leave (" = false [found]" );
@@ -591,7 +601,7 @@ static int afs_do_lookup_one(struct inode *dir, const struct qstr *name, {struct afs_super_info *as = dir->i_sb->s_fs_info;struct afs_lookup_one_cookie cookie = { - .ctx.actor = afs_lookup_one_filldir, + .ctx.actor =AFS_LOOKUP_ONE , .name = *name, .fid.vid = as->volume->vid };
@@ -622,14 +632,14 @@ static int afs_do_lookup_one(struct inode *dir, const struct qstr *name,* uniquifier through dtype */ static bool afs_lookup_filldir (struct dir_context *ctx,const char *name, -int nlen,loff_t fpos,u64 ino,unsigned dtype) +int nlen,u64 ino,u32 uniquifier) {struct afs_lookup_cookie *cookie = container_of(ctx, struct afs_lookup_cookie, ctx);_enter ("{%s,%u},%s,%u,,%llu,%u" , cookie->name.name, cookie->name.len, name, nlen, - (unsigned long long ) ino, dtype); + (unsigned long long ) ino, uniquifier);/* insanity checks first */ BUILD_BUG_ON (sizeof (union afs_xdr_dir_block ) !=2048 );
@@ -637,7 +647,7 @@ static bool afs_lookup_filldir(struct dir_context *ctx, const char *name,if (cookie->nr_fids <50 ) { cookie->fids[cookie->nr_fids].vnode = ino; - cookie->fids[cookie->nr_fids].unique = dtype; + cookie->fids[cookie->nr_fids].unique = uniquifier; cookie->nr_fids++; }
@@ -778,7 +788,7 @@ static struct inode *afs_do_lookup(struct inode *dir, struct dentry *dentry)for (i =0 ; i <ARRAY_SIZE (cookie->fids); i++) cookie->fids[i].vid = dvnode->fid.vid; - cookie->ctx.actor = afs_lookup_filldir; + cookie->ctx.actor =AFS_LOOKUP ; cookie->name = dentry->d_name; cookie->nr_fids =2 ;/* slot 1 is saved for the fid we actually want * and slot 0 for the directory */
David Howells
maintainerPATCH v4 11/21 afs: Fix misplaced inc of net->cells_outstanding
In reply to David HowellsFix net->cells_outstanding being incremented before the check for failure of idr_alloc_cyclic(), leaving the count incremented on error.
--- fs/afs/cell.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/afs/cell.c +1 -1
@@ -205,11 +205,11 @@ static struct afs_cell *afs_alloc_cell(struct afs_net *net, cell->dns_source = vllist->source; cell->dns_status = vllist->status;smp_store_release (&cell->dns_lookup_count,1 );/* vs source/status */ -atomic_inc (&net->cells_outstanding); ret =idr_alloc_cyclic (&net->cells_dyn_ino, cell,2 ,INT_MAX /2 ,GFP_KERNEL );if (ret <0 ) goto error; +atomic_inc (&net->cells_outstanding); cell->dynroot_ino = ret; cell->debug_id =atomic_inc_return (&cell_debug_id);
David Howells
maintainerPATCH v4 12/21 afs: Fix reinitialisation of the inode, in particular ->lock_work
In reply to David HowellsIt seems that initalising afs_vnode::lock_work a single time in the slab's init function isn't sufficient for work_structs. This results in the DEBUG_OBJECTS debugging stuff producing a warning occasionally when running the generic/131 xfstest:
ODEBUG: activate not available (active state 0) object: 0000000016d8760f object type: work_struct hint: afs_lock_work+0x0/0x220
WARNING: lib/debugobjects.c:629 at debug_print_object+0x4b/0x90, CPU#3: locktest/7695 ... CPU: 3 UID: 0 PID: 7695 Comm: locktest Tainted: G S 7.1.0-build3+ #2771 PREEMPT ... RIP: 0010:debug_print_object+0x65/0x90 ... Call Trace: <TASK> ? __pfx_afs_lock_work+0x10/0x10 debug_object_activate+0x122/0x170 insert_work+0x25/0x60 __queue_work+0x2e0/0x340 queue_delayed_work_on+0x48/0x70 afs_fl_release_private+0x57/0x70 locks_release_private+0x5c/0xa0 locks_free_lock+0xe/0x20 posix_lock_inode+0x55f/0x5b0 locks_lock_inode_wait+0x81/0x140 ? file_write_and_wait_range+0x50/0x70 afs_lock+0xcd/0x110 fcntl_setlk+0x10d/0x260 do_fcntl+0x24e/0x5b0 __do_sys_fcntl+0x6a/0x90 do_syscall_64+0x11e/0x310 entry_SYSCALL_64_after_hwframe+0x71/0x79
Fix this by reinitialising ->lock_work after allocating an inode.
Also, flush ->lock_work when the inode is being evicted to make sure it's not still running.
--- fs/afs/inode.c | 1 + fs/afs/super.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-)
fs/afs/inode.c +1 -0
@@ -680,6 +680,7 @@ void afs_evict_inode(struct inode *inode) inode->i_mapping->a_ops->writepages (inode->i_mapping, &wbc); } +flush_delayed_work (&vnode->lock_work);netfs_wait_for_outstanding_io (inode);truncate_inode_pages_final (&inode->i_data);netfs_free_folioq_buffer (vnode->directory);
fs/afs/super.c +1 -1
@@ -660,7 +660,6 @@ static void afs_i_init_once(void *_vnode)INIT_LIST_HEAD (&vnode->wb_keys);INIT_LIST_HEAD (&vnode->pending_locks);INIT_LIST_HEAD (&vnode->granted_locks); -INIT_DELAYED_WORK (&vnode->lock_work, afs_lock_work);INIT_LIST_HEAD (&vnode->cb_mmap_link);seqlock_init (&vnode->cb_lock); }
@@ -694,6 +693,7 @@ static struct inode *afs_alloc_inode(struct super_block *sb)init_rwsem (&vnode->rmdir_lock);INIT_WORK (&vnode->cb_work, afs_invalidate_mmap_work); +INIT_DELAYED_WORK (&vnode->lock_work, afs_lock_work);_leave (" = %p" , &vnode->netfs.inode);return &vnode->netfs.inode;
David Howells
maintainerPATCH v4 13/21 afs: Fix callback service message parsers to pass through -EAGAIN
In reply to David HowellsThe AFS filesystem client uses an rxrpc server to listen for callback notifications. Each callback call type handler has a delivery function that parses the incoming request stream, and this should return -EAGAIN the last packet hasn't yet been seen, but all currently queued received data is consumed. afs_extract_data() does this, but the -EAGAIN return is switched to 0 inadvertantly
Fix callback service message parsers to pass through -EAGAIN
--- fs/afs/cmservice.c | 2 -- 1 file changed, 2 deletions(-)
fs/afs/cmservice.c +0 -2
@@ -334,7 +334,6 @@ static int afs_deliver_cb_init_call_back_state3(struct afs_call *call) ret =afs_extract_data (call, false);switch (ret) {case 0 :break ; -case -EAGAIN :return 0 ;default :return ret; }
@@ -456,7 +455,6 @@ static int afs_deliver_cb_probe_uuid(struct afs_call *call) ret =afs_extract_data (call, false);switch (ret) {case 0 :break ; -case -EAGAIN :return 0 ;default :return ret; }
David Howells
maintainerPATCH v4 14/21 afs: Use scoped_seqlock_read() rather than manually doing seqlock stuff
In reply to David HowellsThis is an addendum to the patch to remove the erroneous seq |= 1 in volume lookup loop.
Switch to using scoped_seqlock_read() as suggested by Oleg Nesterov[1].
--- fs/afs/callback.c | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-)
fs/afs/callback.c +1 -8
@@ -113,16 +113,12 @@ static struct afs_volume *afs_lookup_volume_rcu(struct afs_cell *cell, {struct afs_volume *volume =NULL ;struct rb_node *p; -int seq =1 ; -for (;;) { + scoped_seqlock_read(&cell->volume_lock, ss_lock) {/* Unfortunately, rbtree walking doesn't give reliable results * under just the RCU read lock, so we have to check for * changes. */ - seq++;/* 2 on the 1st/lockless path, otherwise odd */ -read_seqbegin_or_lock (&cell->volume_lock, &seq); - p =rcu_dereference_raw (cell->volumes.rb_node);while (p) { volume = rb_entry(p, struct afs_volume, cell_node);
@@ -138,11 +134,8 @@ static struct afs_volume *afs_lookup_volume_rcu(struct afs_cell *cell,if (volume &&afs_try_get_volume (volume, afs_volume_trace_get_callback))break ; -if (!need_seqretry (&cell->volume_lock, seq)) -break ; } -done_seqretry (&cell->volume_lock, seq);return volume; }
David Howells
maintainerPATCH v4 15/21 afs: Fix missing NULL pointer check in afs_break_some_callbacks()
In reply to David HowellsFix afs_break_some_callbacks() to check to see if afs_lookup_volume_rcu() returned NULL (e.g. the specified volume is unknown).
--- fs/afs/callback.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
fs/afs/callback.c +5 -1
@@ -213,7 +213,11 @@ static void afs_break_some_callbacks(struct afs_server *server,rcu_read_lock (); volume =afs_lookup_volume_rcu (server->cell, vid); -if (cbb->fid.vnode ==0 && cbb->fid.unique ==0 ) { +if (!volume) { +/* Ignore breaks on unknown volumes. */ +rcu_read_unlock (); + *_count =0 ; + }else if (cbb->fid.vnode ==0 && cbb->fid.unique ==0 ) {afs_break_volume_callback (server, volume); *_count -=1 ;if (*_count)
David Howells
maintainerPATCH v4 16/21 afs: Fix leak of ungot volume
In reply to David HowellsFix afs_lookup_volume_rcu() so that it doesn't leak a dying volume if afs_try_get_volume() fails.
--- fs/afs/callback.c | 1 + 1 file changed, 1 insertion(+)
fs/afs/callback.c +1 -0
@@ -134,6 +134,7 @@ static struct afs_volume *afs_lookup_volume_rcu(struct afs_cell *cell,if (volume &&afs_try_get_volume (volume, afs_volume_trace_get_callback))break ; + volume =NULL ; }return volume;
David Howells
maintainerPATCH v4 17/21 afs: Fix vllist leak
In reply to David HowellsFix a leak of the new vllist in afs_update_cell() in the event that it is an empty list (nr_servers == 0), in which case the old list isn't displaced unless the old list is also empty.
--- fs/afs/cell.c | 2 ++ 1 file changed, 2 insertions(+)
fs/afs/cell.c +2 -0
@@ -547,6 +547,8 @@ static int afs_update_cell(struct afs_cell *cell)rcu_assign_pointer (cell->vl_servers, vllist); cell->dns_source = vllist->source; old = p; + }else { + old = vllist; }write_unlock (&cell->vl_servers_lock);afs_put_vlserverlist (cell->net, old);
David Howells
maintainerPATCH v4 18/21 afs: Fix lack of locking around modifications of net->cells_dyn_ino
In reply to David HowellsFix 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.
--- fs/afs/cell.c | 8 +++++++- fs/afs/dynroot.c | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-)
fs/afs/cell.c +7 -1
@@ -205,8 +205,10 @@ static struct afs_cell *afs_alloc_cell(struct afs_net *net, cell->dns_source = vllist->source; cell->dns_status = vllist->status;smp_store_release (&cell->dns_lookup_count,1 );/* vs source/status */ +down_write (&net->cells_lock); ret =idr_alloc_cyclic (&net->cells_dyn_ino, cell,2 ,INT_MAX /2 ,GFP_KERNEL ); +up_write (&net->cells_lock);if (ret <0 ) goto error;atomic_inc (&net->cells_outstanding);
@@ -579,7 +581,6 @@ static void afs_cell_destroy(struct rcu_head *rcu)afs_put_vlserverlist (net,rcu_access_pointer (cell->vl_servers));afs_unuse_cell (cell->alias_of, afs_cell_trace_unuse_alias);key_put (cell->anonymous_key); -idr_remove (&net->cells_dyn_ino, cell->dynroot_ino);kfree (cell->name -1 );kfree (cell);
@@ -594,6 +595,11 @@ static void afs_destroy_cell_work(struct work_struct *work)afs_see_cell (cell, afs_cell_trace_destroy);timer_delete_sync (&cell->management_timer);cancel_work_sync (&cell->manager); + +down_write (&cell->net->cells_lock); +idr_remove (&cell->net->cells_dyn_ino, cell->dynroot_ino); +up_write (&cell->net->cells_lock); +call_rcu (&cell->rcu, afs_cell_destroy); }
fs/afs/dynroot.c +1 -1
@@ -278,7 +278,7 @@ static struct dentry *afs_lookup_atcell(struct inode *dir, struct dentry *dentry }/* -* Transcribe the cell database into readdir content under the RCU read lock. +* Transcribe the cell database into readdir content under net->cells_lock. * Each cell produces two entries, one prefixed with a dot and one not. */ static int afs_dynroot_readdir_cells (struct afs_net *net,struct dir_context *ctx)
David Howells
maintainerPATCH v4 19/21 afs: Fix premature cell exposure through /afs
In reply to David HowellsAFS cell records are prematurely exposured through the /afs dynamic root by virtue of adding them immediately to the net->cells_dyn_ino IDR when the cell is allocated rather than when it is added to the lookup tree. This allows a candidate record to be accessed, even if it's actually a duplicate or not published yet.
Fix this by not adding the cell to cells_dyn_ino until it's confirmed non-duplicate and is being published. A flag is then used to record whether it is added to the IDR to make removal from the IDR conditional.
--- fs/afs/cell.c | 27 +++++++++++++++++---------- fs/afs/internal.h | 1 + 2 files changed, 18 insertions(+), 10 deletions(-)
fs/afs/cell.c +17 -10
@@ -205,14 +205,7 @@ static struct afs_cell *afs_alloc_cell(struct afs_net *net, cell->dns_source = vllist->source; cell->dns_status = vllist->status;smp_store_release (&cell->dns_lookup_count,1 );/* vs source/status */ -down_write (&net->cells_lock); - ret =idr_alloc_cyclic (&net->cells_dyn_ino, cell, -2 ,INT_MAX /2 ,GFP_KERNEL ); -up_write (&net->cells_lock); -if (ret <0 ) - goto error;atomic_inc (&net->cells_outstanding); - cell->dynroot_ino = ret; cell->debug_id =atomic_inc_return (&cell_debug_id);trace_afs_cell (cell->debug_id,1 ,0 , afs_cell_trace_alloc);
@@ -306,6 +299,13 @@ struct afs_cell *afs_lookup_cell(struct afs_net *net, goto cell_already_exists; } + ret =idr_alloc_cyclic (&net->cells_dyn_ino, candidate, +2 ,INT_MAX /2 ,GFP_KERNEL ); +if (ret <0 ) + goto cant_alloc_ino; + candidate->dynroot_ino = ret; +set_bit (AFS_CELL_FL_HAVE_INO , &candidate->flags); + cell = candidate; candidate =NULL ;afs_use_cell (cell, trace);
@@ -380,6 +380,11 @@ struct afs_cell *afs_lookup_cell(struct afs_net *net,_leave (" = %p [cell]" , cell);return cell; +cant_alloc_ino: +up_write (&net->cells_lock); +afs_put_cell (candidate, afs_cell_trace_put_candidate); + goto error_noput; + cell_already_exists:_debug ("cell exists" ); cell = cursor;
@@ -596,9 +601,11 @@ static void afs_destroy_cell_work(struct work_struct *work)timer_delete_sync (&cell->management_timer);cancel_work_sync (&cell->manager); -down_write (&cell->net->cells_lock); -idr_remove (&cell->net->cells_dyn_ino, cell->dynroot_ino); -up_write (&cell->net->cells_lock); +if (test_bit (AFS_CELL_FL_HAVE_INO , &cell->flags)) { +down_write (&cell->net->cells_lock); +idr_remove (&cell->net->cells_dyn_ino, cell->dynroot_ino); +up_write (&cell->net->cells_lock); + }call_rcu (&cell->rcu, afs_cell_destroy); }
fs/afs/internal.h +1 -0
@@ -388,6 +388,7 @@ struct afs_cell {#define AFS_CELL_FL_NO_GC 0/* The cell was added manually, don't auto-gc */ #define AFS_CELL_FL_DO_LOOKUP 1/* DNS lookup requested */ #define AFS_CELL_FL_CHECK_ALIAS 2/* Need to check for aliases */ +#define AFS_CELL_FL_HAVE_INO 3/* Have dynroot_ino */ enum afs_cell_state state;short error; enum dns_record_source dns_source:8; /* Latest source of data from lookup */
David Howells
maintainerRe: [PATCH v4 19/21] afs: Fix premature cell exposure through /afs
David Howells
maintainerPATCH v4 20/21 afs: Fix the volume AFS_VOLUME_RM_TREE is set on
In reply to David HowellsFix afs_insert_volume_into_cell() to set AFS_VOLUME_RM_TREE on the volume replaced, not the new volume, as it's now removed from the cell's volume tree. This will cause the old volume to be removed from the tree twice and the new volume never to be removed.
--- fs/afs/volume.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/afs/volume.c +1 -1
@@ -40,7 +40,7 @@ static struct afs_volume *afs_insert_volume_into_cell(struct afs_cell *cell, goto found; } -set_bit (AFS_VOLUME_RM_TREE , &volume->flags); +set_bit (AFS_VOLUME_RM_TREE , &p->flags);rb_replace_node_rcu (&p->cell_node, &volume->cell_node, &cell->volumes); } }
David Howells
maintainerPATCH v4 21/21 afs: Fix unchecked-length string display in debug statement
In reply to David HowellsFix afs_extract_vlserver_list() to limit the length of the displayed string in a debug statement().
--- fs/afs/vl_list.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
fs/afs/vl_list.c +5 -1
@@ -200,6 +200,8 @@ struct afs_vlserver_list *afs_extract_vlserver_list(struct afs_cell *cell, b +=sizeof (*hdr);while (end - b >=sizeof (bs)) { +int nlen; + bs.name_len =afs_extract_le16 (&b); bs.priority =afs_extract_le16 (&b); bs.weight =afs_extract_le16 (&b);
@@ -209,10 +211,12 @@ struct afs_vlserver_list *afs_extract_vlserver_list(struct afs_cell *cell, bs.protocol = *b++; bs.nr_addrs = *b++; + nlen =min3 (bs.name_len, end - b,255 ); +_debug ("extract %u %u %u %u %u %u %*.*s" , bs.name_len, bs.priority, bs.weight, bs.port, bs.protocol, bs.nr_addrs, - bs.name_len, bs.name_len, b); + bs.name_len, nlen, b);if (end - b < bs.name_len)break ;
Quoted 10 lines · David Howells
afs: Miscellaneous fixes
Hi Christian,
Can you pick up these miscellaneous AFS fixes, please?
(1) Fix the CB.InitCallBackState3 service handler to handle an unknown server (server pointer is NULL).
[...]
Applied to the vfs.fixes branch of the vfs/vfs.git tree. Patches in the vfs.fixes branch should appear in linux-next soon.
Please report any outstanding bugs that were missed during review in a new review to the original patch series allowing us to drop it.
It's encouraged to provide Acked-bys and Reviewed-bys even though the patch has now been applied. If possible patch trailers will be updated.
Note that commit hashes shown below are subject to change due to rebase, trailer updates or similar. If in doubt, please check the listed branch.
tree: https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git branch: vfs.fixes
[01/21] afs: handle CB.InitCallBackState3 requests without a server record
https://git.kernel.org/vfs/vfs/c/f45dfe9144c7 [02/21] afs: Fix error code in afs_extract_vl_addrs() https://git.kernel.org/vfs/vfs/c/0acc5546d4a4 [03/21] afs: fix NULL pointer dereference in afs_get_tree() https://git.kernel.org/vfs/vfs/c/bae1d000c485 [04/21] afs: Fix double netfs initialisation in afs_root_iget() https://git.kernel.org/vfs/vfs/c/a3ee80a4b58c [05/21] afs: Remove setting of AS_RELEASE_ALWAYS for symlinks and mountpoints https://git.kernel.org/vfs/vfs/c/706849a44880 [06/21] afs: Fix directory inode initialisation order https://git.kernel.org/vfs/vfs/c/af8fcf434550 [07/21] afs: use kvfree() to free memory allocated by kvcalloc() https://git.kernel.org/vfs/vfs/c/de75d538b414 [08/21] afs: Remove erroneous seq |= 1 in volume lookup loop https://git.kernel.org/vfs/vfs/c/24062f2bb2a6 [09/21] afs: check for duplicate servers in VL server list https://git.kernel.org/vfs/vfs/c/677d037efa7f [10/21] afs: Fix bulk lookup malfunction due to change in dir_emit() API https://git.kernel.org/vfs/vfs/c/3986f11557ac [11/21] afs: Fix misplaced inc of net->cells_outstanding https://git.kernel.org/vfs/vfs/c/d45daf4b24cb [12/21] afs: Fix reinitialisation of the inode, in particular ->lock_work https://git.kernel.org/vfs/vfs/c/c0d3fb0b2da5 [13/21] afs: Fix callback service message parsers to pass through -EAGAIN https://git.kernel.org/vfs/vfs/c/705627309745 [14/21] afs: Use scoped_seqlock_read() rather than manually doing seqlock stuff https://git.kernel.org/vfs/vfs/c/288fff610357 [15/21] afs: Fix missing NULL pointer check in afs_break_some_callbacks() https://git.kernel.org/vfs/vfs/c/95b0a4b91aad [16/21] afs: Fix leak of ungot volume https://git.kernel.org/vfs/vfs/c/7d9517ebb956 [17/21] afs: Fix vllist leak https://git.kernel.org/vfs/vfs/c/11b51f828fb6 [18/21] afs: Fix lack of locking around modifications of net->cells_dyn_ino https://git.kernel.org/vfs/vfs/c/c3a9fe822d14 [19/21] afs: Fix premature cell exposure through /afs https://git.kernel.org/vfs/vfs/c/6baa330b35ed [20/21] afs: Fix the volume AFS_VOLUME_RM_TREE is set on https://git.kernel.org/vfs/vfs/c/2d02c376a453 [21/21] afs: Fix unchecked-length string display in debug statement https://git.kernel.org/vfs/vfs/c/6e05f5903290