From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796336243; b=WuUCzzltdnjkHalsNJW9EI9CKztQ+BDhGyFEiFPszaomOPXatTiG/vQ/yLnlgPhTokFT WxzWxE2O22ZmNiXXZe7qfZdDBbeOE1X0AFcUUKrMNZz40aGeBQFA/dZFAF5umiQ5SmCvV +NMSGkAVIay+OwrOc8r7YvbYga8BB79Saa5+Gun0suo0uOAPxW9gOAmWIsPlAYCemk7yE urBCANmu+jW8hsw5ZgJqx/Sz2OefoKg47o4Om7fGoHryTxnUkVlrdbLU3apN8IF9aqfC0 SowLsT0LkGz8Q7NNStCu9RlzDaI0S0M8SQ1afaD1zhZYWF2tsfTgGQF8wkvtHQSNvSg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796336243; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=OSUVq0+ZYumKb6uROepdOsNThaWI6vGYqoXwKKDWgPo=; b=vZhfFRQRS+qH9tnpNVig1tLfl1eAnX0XyaHjMHh0BF0Cci9P2yOxIJirB3OqwtwrVMFt qqeVHXWj7PrpKMkR3JyxVOC9GK6+ydIcQdeaGGuCFZfw+XjXXF/IwswVMrS47laHIIzp1 02KVQ2B3hnSBYDSThZk85jhXK4LQ8kzgs04duVg4bpA82+7h4YWDy3Z4+Y+w+SPudo0dy I+AtZNEbuhzKWNK7l6dssB8Co+NWPEQgD45MLs1l3H41HQP5mBadC7ooLLzUbNjDCbnq4 ls0Fwg20WdkTfy5cEVOE5AKJiVzvYXH9T5fQGL8WG8AibrwXXPrbnqZEI2/WjsT2ISQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=aH9cUPVE; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 42719606A322 for ; Thu, 3 Dec 2026 22:17:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=aH9cUPVE Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4E96A1F000C2; Thu, 3 Dec 2026 22:17:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796336242; bh=OSUVq0+ZYumKb6uROepdOsNThaWI6vGYqoXwKKDWgPo=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=aH9cUPVEztDo6J1Snoj7J8exAputdgKz8f0Cxq/4rBj9qZpygjvv9Han8r9FStIKu P0e1IE0jWncQzTXupPKHQsFPSfnAZGWuPU0gkOwFOl/JPBsgu2aHkRuCPfks4+Cw4T B/yT7wYIUuYxXn6tl3xsF0R3blOh+gyNILALq/Ob6C4sEx8LjznhtXAYmPWTQWcnK7 faXhb3GJucywK1VXhg83iEBz1oeHOm49fU8lKGG8ppclKKTqxlktvLUpDsE1u297Jn Ws41JOu7dteGR5hWx6rOfiKXLgliXQS6E8lCrUMjpNTzjaaPjMPugthGzku8CxKqVz +cHtBMhk4qKmA== From: Sasha Levin To: stable@vger.kernel.org Cc: Hengyu Liang , Miklos Szeredi , Sasha Levin Subject: [PATCH 7.3.y] fuse: preserve ENOTCONN after failed initialization and disconnect Date: Thu, 3 Dec 2026 17:17:21 -0500 Message-ID: <20261203221709.802707-1-sashal@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <2026120254-uplifting-daughter-6d2b@gregkh> References: <2026120254-uplifting-daughter-6d2b@gregkh> X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Hengyu Liang [ 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 Signed-off-by: Miklos Szeredi [ 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 --- 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