2024-01-22 13:09:39

by David Howells

[permalink] [raw]
Subject: [PATCH 00/10] netfs, afs, cifs, cachefiles, erofs: Miscellaneous fixes

Hi Christian,

Here are some miscellaneous fixes for netfslib and a number of filesystems:

(1) Replace folio_index() with folio->index in netfs, afs and cifs.

(2) Fix an oops in fscache_put_cache().

(3) Fix error handling in netfs_perform_write().

(4) Fix an oops in cachefiles when not using erofs ondemand mode.

(5) In afs, hide silly-rename files from getdents() to avoid problems with
tar and suchlike.

(6) In afs, fix error handling in lookup with a bulk status fetch.

(7) In afs, afs_dynroot_d_revalidate() is redundant, so remove it.

(8) In afs, fix the RCU unlocking in afs_proc_addr_prefs_show().

The patches can also be found here:

https://git.kernel.org/pub/scm/linux/kernel/git/dhowells/linux-fs.git/log/?h=netfs-fixes

Thanks,
David

Dan Carpenter (2):
netfs, fscache: Prevent Oops in fscache_put_cache()
netfs: Fix a NULL vs IS_ERR() check in netfs_perform_write()

David Howells (8):
netfs: Don't use certain internal folio_*() functions
afs: Don't use certain internal folio_*() functions
cifs: Don't use certain internal folio_*() functions
cachefiles, erofs: Fix NULL deref in when cachefiles is not doing
ondemand-mode
afs: Hide silly-rename files from userspace
afs: Fix error handling with lookup via FS.InlineBulkStatus
afs: Remove afs_dynroot_d_revalidate() as it is redundant
afs: Fix missing/incorrect unlocking of RCU read lock

fs/afs/dir.c | 30 ++++++++++++++++++++++--------
fs/afs/dynroot.c | 9 ---------
fs/afs/proc.c | 5 +++--
fs/cachefiles/namei.c | 16 ++++++++++------
fs/netfs/buffered_read.c | 12 ++++++------
fs/netfs/buffered_write.c | 15 ++++++++-------
fs/netfs/fscache_cache.c | 3 ++-
fs/netfs/io.c | 2 +-
fs/netfs/misc.c | 2 +-
fs/smb/client/file.c | 10 +++++-----
include/trace/events/afs.h | 25 +++++++++++++++++++++++++
11 files changed, 83 insertions(+), 46 deletions(-)



2024-01-22 13:19:22

by David Howells

[permalink] [raw]
Subject: [PATCH 06/10] cachefiles, erofs: Fix NULL deref in when cachefiles is not doing ondemand-mode

cachefiles_ondemand_init_object() as called from cachefiles_open_file() and
cachefiles_create_tmpfile() does not check if object->ondemand is set
before dereferencing it, leading to an oops something like:

RIP: 0010:cachefiles_ondemand_init_object+0x9/0x41
...
Call Trace:
<TASK>
cachefiles_open_file+0xc9/0x187
cachefiles_lookup_cookie+0x122/0x2be
fscache_cookie_state_machine+0xbe/0x32b
fscache_cookie_worker+0x1f/0x2d
process_one_work+0x136/0x208
process_scheduled_works+0x3a/0x41
worker_thread+0x1a2/0x1f6
kthread+0xca/0xd2
ret_from_fork+0x21/0x33

Fix this by making the calls to cachefiles_ondemand_init_object()
conditional.

Fixes: 3c5ecfe16e76 ("cachefiles: extract ondemand info field from cachefiles_object")
Reported-by: Marc Dionne <[email protected]>
Signed-off-by: David Howells <[email protected]>
cc: Gao Xiang <[email protected]>
cc: Chao Yu <[email protected]>
cc: Yue Hu <[email protected]>
cc: Jeffle Xu <[email protected]>
cc: [email protected]
cc: [email protected]
cc: [email protected]
---
fs/cachefiles/namei.c | 16 ++++++++++------
1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
index 7ade836beb58..180594d24c44 100644
--- a/fs/cachefiles/namei.c
+++ b/fs/cachefiles/namei.c
@@ -473,9 +473,11 @@ struct file *cachefiles_create_tmpfile(struct cachefiles_object *object)
if (!cachefiles_mark_inode_in_use(object, file_inode(file)))
WARN_ON(1);

- ret = cachefiles_ondemand_init_object(object);
- if (ret < 0)
- goto err_unuse;
+ if (object->ondemand) {
+ ret = cachefiles_ondemand_init_object(object);
+ if (ret < 0)
+ goto err_unuse;
+ }

ni_size = object->cookie->object_size;
ni_size = round_up(ni_size, CACHEFILES_DIO_BLOCK_SIZE);
@@ -579,9 +581,11 @@ static bool cachefiles_open_file(struct cachefiles_object *object,
}
_debug("file -> %pd positive", dentry);

- ret = cachefiles_ondemand_init_object(object);
- if (ret < 0)
- goto error_fput;
+ if (object->ondemand) {
+ ret = cachefiles_ondemand_init_object(object);
+ if (ret < 0)
+ goto error_fput;
+ }

ret = cachefiles_check_auxdata(object, file);
if (ret < 0)


2024-01-22 22:02:05

by David Howells

[permalink] [raw]
Subject: Re: [PATCH 06/10] cachefiles, erofs: Fix NULL deref in when cachefiles is not doing ondemand-mode

Jingbo Xu <[email protected]> wrote:

> > - ret = cachefiles_ondemand_init_object(object);
> > - if (ret < 0)
> > - goto err_unuse;
> > + if (object->ondemand) {
> > + ret = cachefiles_ondemand_init_object(object);
> > + if (ret < 0)
> > + goto err_unuse;
> > + }
>
> I'm not sure if object->ondemand shall be checked by the caller or
> inside cachefiles_ondemand_init_object(), as
> cachefiles_ondemand_clean_object() is also called without checking
> object->ondemand. cachefiles_ondemand_clean_object() won't trigger the
> NULL oops as the called cachefiles_ondemand_send_req() will actually
> checks that.

Meh. The above doesn't actually build if CONFIG_CACHEFILES_ONDEMAND=N. I
think I have to push the check down into cachefiles_ondemand_init_object()
instead.

David


2024-01-23 15:04:54

by Christian Brauner

[permalink] [raw]
Subject: Re: [PATCH 00/10] netfs, afs, cifs, cachefiles, erofs: Miscellaneous fixes

On Mon, Jan 22, 2024 at 04:18:08PM +0100, Christian Brauner wrote:
> On Mon, Jan 22, 2024 at 12:38:33PM +0000, David Howells wrote:
> > Hi Christian,
> >
> > Here are some miscellaneous fixes for netfslib and a number of filesystems:
> >
> > (1) Replace folio_index() with folio->index in netfs, afs and cifs.
> >
> > (2) Fix an oops in fscache_put_cache().
> >
> > (3) Fix error handling in netfs_perform_write().
> >
> > (4) Fix an oops in cachefiles when not using erofs ondemand mode.
> >
> > (5) In afs, hide silly-rename files from getdents() to avoid problems with
> > tar and suchlike.
> >
> > (6) In afs, fix error handling in lookup with a bulk status fetch.
> >
> > (7) In afs, afs_dynroot_d_revalidate() is redundant, so remove it.
> >
> > (8) In afs, fix the RCU unlocking in afs_proc_addr_prefs_show().
> >
> > The patches can also be found here:
> >
> > https://git.kernel.org/pub/scm/linux/kernel/git/dhowells/linux-fs.git/log/?h=netfs-fixes
>
> Thank you! I can pull this in right and will send a pr together with the
> other changes around Wednesday/Thursday for -rc2. So reviews before that
> would be nice.

Pulled and pushed:

tree: https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git
branch: vfs.netfs

Timeline still the same.