All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Miklos Szeredi" <mszeredi@redhat.com>
Cc: linux-cxl@vger.kernel.org, nvdimm@lists.linux.dev
Subject: Re: [PATCH v3 4/9] fuse: support 64 bit, server allocated backing ID
Date: Tue, 06 Oct 2026 18:20:17 +0000	[thread overview]
Message-ID: <sashiko-outbox-162331@kernel.org> (raw)
In-Reply-To: <20261006180115.1425232-5-mszeredi@redhat.com>

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] fuse: Uninitialized rhashtable destruction on failed init
- [High] fuse: TOCTOU race between fuse_backing_close and process_init_reply
- [Medium] fuse: rhashtable_insert_fast allows duplicate backing_id
--

commit 90eba0277f715071875b550790d8bf829971f8b3
Author: Miklos Szeredi <mszeredi@redhat.com>

fuse: support 64 bit, server allocated backing ID

This commit adds support for server-allocated 64-bit backing IDs alongside
the existing kernel-allocated 32-bit IDs. It introduces a new ioctl to
create these backing IDs and handles their removal.

> diff --git a/fs/fuse/backing.c b/fs/fuse/backing.c
> index 433fa3098d71f..bc40818778dff 100644
> --- a/fs/fuse/backing.c
> +++ b/fs/fuse/backing.c
[ ... ]
> +static const struct rhashtable_params fuse_backing_prm = {
> +	.head_offset = offsetof(struct fuse_backing, hash_node),
> +	.key_offset = offsetof(struct fuse_backing, backing_id),
> +	.key_len = sizeof_field(struct fuse_backing, backing_id),
> +};
>  
> +static int fuse_backing_add_64(struct fuse_conn *fc, struct fuse_backing *fb)
> +{
> +	return rhashtable_insert_fast(&fc->backing_64_ht, &fb->hash_node, fuse_backing_prm);
>  }

[Severity: Medium]
Does this code allow duplicate backing_id values?

If a FUSE daemon provides an already-existing backing_id,
rhashtable_insert_fast() will insert the new object instead of rejecting
it with -EEXIST.

Should this use rhashtable_lookup_insert_fast() instead to safely enforce
uniqueness?

[ ... ]
>  int fuse_backing_close(struct fuse_conn *fc, int backing_id)
>  {
>  	struct fuse_backing *fb = NULL;
>  	int err;
>  
>  	pr_debug("%s: backing_id=%d\n", __func__, backing_id);
>  
> +	if (fc->backing_id_64)
> +		return -EINVAL;
> +

[Severity: High]
Can this TOCTOU race lead to memory corruption? Since fc->backing_id_64 is
read here outside of fc->lock, it can be observed as false concurrently with
process_init_reply() setting it to true:

CPU1 (fuse_dev_ioctl_backing_close):
    if (fc->backing_id_64) // reads false
        ...
    fuse_backing_id_remove()
        spin_lock(&fc->lock);
        idr_remove(&fc->backing_files_map, id);

CPU2 (process_init_reply):
    scoped_guard(spinlock, &fc->lock) {
        fc->backing_id_64 = true;
    }
    if (ok)
        fuse_backing_files_init_64(fc); // calls rhashtable_init()

Because fuse_backing_close() proceeds, it calls idr_remove() on the union
concurrently with rhashtable_init() in CPU2, corrupting the shared memory.

>  	/* TODO: relax CAP_SYS_ADMIN once backing files are visible to lsof */
>  	err = -EPERM;
>  	if (!fc->passthrough || !capable(CAP_SYS_ADMIN))
[ ... ]
> diff --git a/fs/fuse/inode.c b/fs/fuse/inode.c
> index cbb10e19e7e86..b5b51865d59f8 100644
> --- a/fs/fuse/inode.c
> +++ b/fs/fuse/inode.c
[ ... ]
>  			if (IS_ENABLED(CONFIG_FUSE_PASSTHROUGH) &&
> -			    (flags & FUSE_PASSTHROUGH) &&
> +			    (flags & (FUSE_PASSTHROUGH | FUSE_PASSTHROUGH_V2)) &&
>  			    arg->max_stack_depth > 0 &&
>  			    arg->max_stack_depth <= FILESYSTEM_MAX_STACK_DEPTH &&
>  			    !(flags & FUSE_WRITEBACK_CACHE))  {
>  				fc->passthrough = 1;
>  				fc->max_stack_depth = arg->max_stack_depth;
>  				fm->sb->s_stack_depth = arg->max_stack_depth;
> +				if (flags & FUSE_PASSTHROUGH_V2) {
> +					/* Prevent race with fuse_backing_open() */
> +					scoped_guard(spinlock, &fc->lock) {
> +						if (fc->backing_id_32)
> +							ok = false;
> +						else
> +							fc->backing_id_64 = true;
> +					}
> +					if (ok)
> +						fuse_backing_files_init_64(fc);
> +				}

[Severity: High]
Does this unconditionally set fc->backing_id_64 = true but skip initialization
if ok is false?

If an earlier validation check sets ok = false, this code still sets
fc->backing_id_64 = true but skips calling fuse_backing_files_init_64(fc).

When the FUSE connection is later torn down, fuse_backing_files_free() will
see fc->backing_id_64 == true and attempt to call rhashtable_free_and_destroy()
on an uninitialized rhashtable, causing a kernel crash.

>  			}
>  			if (flags & FUSE_NO_EXPORT_SUPPORT)
>  				fm->sb->s_export_op = &fuse_export_fid_operations;

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261006180115.1425232-1-mszeredi@redhat.com?part=4

  reply	other threads:[~2026-10-06 18:20 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-06 18:01 [PATCH v3 0/9] fuse: DAX device based extent maps (famfs) Miklos Szeredi
2026-10-06 18:01 ` [PATCH v3 1/9] dax: replace exported dax_dev_get() with non-allocating dax_dev_find() Miklos Szeredi
2026-10-06 18:10   ` sashiko-bot
2026-10-06 18:01 ` [PATCH v3 2/9] dax: use READ_ONCE() in dax_holder() Miklos Szeredi
2026-10-06 18:13   ` sashiko-bot
2026-10-08  1:02   ` Alison Schofield
2026-10-08  6:58     ` Miklos Szeredi
2026-10-06 18:01 ` [PATCH v3 3/9] fuse: add helpers for EIO return value with kernel message Miklos Szeredi
2026-10-06 21:03   ` Amir Goldstein
2026-10-06 18:01 ` [PATCH v3 4/9] fuse: support 64 bit, server allocated backing ID Miklos Szeredi
2026-10-06 18:20   ` sashiko-bot [this message]
2026-10-06 20:10   ` John Groves
2026-10-07 12:49     ` Miklos Szeredi
2026-10-06 22:08   ` Amir Goldstein
2026-10-07 12:54     ` Miklos Szeredi
2026-10-06 18:01 ` [PATCH v3 5/9] fuse: support opening 64 bit " Miklos Szeredi
2026-10-06 18:01 ` [PATCH v3 6/9] fuse: add support for opening dax device as backing Miklos Szeredi
2026-10-06 18:18   ` sashiko-bot
2026-10-06 18:01 ` [PATCH v3 7/9] fuse: add extent map data structure Miklos Szeredi
2026-10-06 18:17   ` sashiko-bot
2026-10-06 18:01 ` [PATCH v3 8/9] fuse: add extent map I/O support Miklos Szeredi
2026-10-06 18:22   ` sashiko-bot
2026-10-06 18:01 ` [PATCH v3 9/9] fuse: add support for striped backing Miklos Szeredi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=sashiko-outbox-162331@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-cxl@vger.kernel.org \
    --cc=mszeredi@redhat.com \
    --cc=nvdimm@lists.linux.dev \
    --cc=sashiko-reviews@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.