From: Sasha Levin <sashal@kernel.org>
To: stable@vger.kernel.org
Cc: Hengyu Liang <hengyul@cs.unc.edu>,
Miklos Szeredi <mszeredi@redhat.com>,
Sasha Levin <sashal@kernel.org>
Subject: [PATCH 7.3.y] fuse: preserve ENOTCONN after failed initialization and disconnect
Date: Thu, 3 Dec 2026 17:17:21 -0500 [thread overview]
Message-ID: <20261203221709.802707-1-sashal@kernel.org> (raw)
In-Reply-To: <2026120254-uplifting-daughter-6d2b@gregkh>
From: Hengyu Liang <hengyul@cs.unc.edu>
[ Upstream commit 2eb2329f9ce7f29f227656cc2686fe6f1879d11c ]
Commit 794e811d1443 ("fuse: split out filesystem part of request
sending") moved the INIT failure check into fuse_req_prep(), before
the channel checks whether it is still connected.
If a daemon closes /dev/fuse before replying to INIT, aborting the
channel completes INIT with an error. stat() and open() on the mount
then return ECONNREFUSED instead of the previous ENOTCONN. The same
change occurs when INIT is rejected before the daemon closes the fd.
Record INIT failure in the channel before publishing initialized, and
check it in fuse_get_req() after waiting for initialization and checking
for disconnection. This preserves ECONNREFUSED for failed INIT while
the device remains open, and restores ENOTCONN after disconnection.
Set the failure flag only while the channel is connected, since abort
also marks it initialized to wake waiters after a successful INIT.
Fixes: 794e811d1443 ("fuse: split out filesystem part of request sending")
Cc: stable@vger.kernel.org
Signed-off-by: Hengyu Liang <hengyul@cs.unc.edu>
Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
[ sashal: adapted the context for the non-const struct mnt_idmap *idmap parameter type in fs/fuse/req.c when removing fuse_req_prep(); the rest matches upstream. ]
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
fs/fuse/dev.c | 8 ++++++++
fs/fuse/fuse_dev_i.h | 3 +++
fs/fuse/req.c | 14 +++-----------
3 files changed, 14 insertions(+), 11 deletions(-)
diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
index 60d6e93ed1640..115841edb11f1 100644
--- a/fs/fuse/dev.c
+++ b/fs/fuse/dev.c
@@ -80,6 +80,10 @@ void fuse_chan_set_initialized(struct fuse_chan *fch, struct fuse_chan_param *pa
fuse_uring_conn_init(fch);
}
+ /* An aborted channel is also marked initialized to wake waiters. */
+ if (!param && fch->connected)
+ fch->conn_refused = true;
+
/* Pairs with smp_load_acquire() readers of fch->initialized */
smp_store_release(&fch->initialized, 1);
wake_up_all(&fch->blocked_waitq);
@@ -130,6 +134,10 @@ static struct fuse_req *fuse_get_req(struct fuse_chan *fch, bool for_background)
if (!fch->connected)
goto out;
+ err = -ECONNREFUSED;
+ if (fch->conn_refused)
+ goto out;
+
req = fuse_request_alloc(fch, GFP_KERNEL);
err = -ENOMEM;
if (!req) {
diff --git a/fs/fuse/fuse_dev_i.h b/fs/fuse/fuse_dev_i.h
index 4b412a76225f8..0c078bdc270c5 100644
--- a/fs/fuse/fuse_dev_i.h
+++ b/fs/fuse/fuse_dev_i.h
@@ -245,6 +245,9 @@ struct fuse_chan {
/** Is interrupt not implemented by fs? */
bool no_interrupt;
+ /** @conn_refused: INIT failed while the channel was still connected. */
+ bool conn_refused;
+
/* Use io_uring for communication */
unsigned int io_uring;
diff --git a/fs/fuse/req.c b/fs/fuse/req.c
index 51cfd64ea1bad..baaffa78af8aa 100644
--- a/fs/fuse/req.c
+++ b/fs/fuse/req.c
@@ -48,19 +48,11 @@ static int fuse_fill_creds(struct fuse_mount *fm, struct fuse_args *args, struct
return 0;
}
-static int fuse_req_prep(struct fuse_mount *fm, struct fuse_args *args, struct mnt_idmap *idmap)
-{
- if (!args->force && fm->fc->conn_error)
- return -ECONNREFUSED;
-
- return fuse_fill_creds(fm, args, idmap);
-}
-
ssize_t __fuse_simple_request(struct mnt_idmap *idmap, struct fuse_mount *fm,
struct fuse_args *args)
{
struct fuse_conn *fc = fm->fc;
- int err = fuse_req_prep(fm, args, idmap);
+ int err = fuse_fill_creds(fm, args, idmap);
if (err)
return err;
@@ -75,7 +67,7 @@ int fuse_simple_background(struct fuse_mount *fm, struct fuse_args *args, gfp_t
WARN_ON(args->force && !args->nocreds);
- err = fuse_req_prep(fm, args, &invalid_mnt_idmap);
+ err = fuse_fill_creds(fm, args, &invalid_mnt_idmap);
if (err)
return err;
@@ -90,7 +82,7 @@ int fuse_simple_notify_reply(struct fuse_mount *fm, struct fuse_args *args, u64
WARN_ON(args->force && !args->nocreds);
- err = fuse_req_prep(fm, args, &invalid_mnt_idmap);
+ err = fuse_fill_creds(fm, args, &invalid_mnt_idmap);
if (err)
return err;
--
2.53.0
prev parent reply other threads:[~2026-12-03 22:17 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-02 13:03 FAILED: patch "[PATCH] fuse: preserve ENOTCONN after failed initialization and" failed to apply to 7.3-stable tree gregkh
2026-12-03 22:17 ` Sasha Levin [this message]
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=20261203221709.802707-1-sashal@kernel.org \
--to=sashal@kernel.org \
--cc=hengyul@cs.unc.edu \
--cc=mszeredi@redhat.com \
--cc=stable@vger.kernel.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox