From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ed1-f44.google.com (mail-ed1-f44.google.com [209.85.208.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B0F6B3E168E for ; Mon, 18 May 2026 09:06:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.44 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779095214; cv=none; b=PeIhAUixjl8qQ/Q7uC+OJjRmgWqgLdxUqibG2kNJhFxzhQ7DoURPYOzsNOEjbLlqaElac3sG7rMX1KwZJNp20U3HmhNYnx6VWSITsaqFhGGMvAUSYVwkJtmyG6Yeb+JmCMqujonmWhjUBSPVjb0iMT36iYH/xHChTNli+BSt574= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779095214; c=relaxed/simple; bh=+sv4jnUTyOdjjZciCJyC+lf1CirV23BI+BT8te+prnE=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=YqrQ2Hcen/TOSV51r9FgdTKXZTv+js7ijxEXekjfn1JfMDQ/CTRPKuJd8+ow4khKINHvE9LDE0xtmv7Jc7wOp29Mj0aFLLVIWbsFcsKhU3Bm61xNYyZ88+FstMgUjTKZ1fPZEKkFzE8tncQDkUBaKKDOo1P9IgPoYwu2lVBfY6c= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Yi+h26dv; arc=none smtp.client-ip=209.85.208.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Yi+h26dv" Received: by mail-ed1-f44.google.com with SMTP id 4fb4d7f45d1cf-67e24b8ef55so3575458a12.1 for ; Mon, 18 May 2026 02:06:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1779095211; x=1779700011; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=zSl2K2WdTrcT8MX7//EVVA3HDXITKieSgfsnYmfI0m8=; b=Yi+h26dvDZQ2jdYVDig1OE4cz3PzmeF5K6Dlb9K30eV8DlMW50Vw4XbH3n1TZXa2KR lrM+MH4a4cgHcPhnNh3BVv3eozzr+u3MFV2oXZUXk8xbw51nHgVF/Tnvj+T2bBG+MwHx BTjVwNO3Pb19C48esnsh1cWM0DZ5awSo77UTuLh0X9b+OugX+6BfWiWaq08gma/+e5ax 2CNrCb9tXVI75Wtb6FM4lCOMblDw3iJwtgrhZ+jkdX7k4ENpm0d5GHaxRVznpjDTQmbn 0DKj7WJiV8v0Tk2OjfUWJzmn6Flxxcas7MzadIxCL/gjdJNAzTHM/dbTivscOUBP0A7C OcAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779095211; x=1779700011; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=zSl2K2WdTrcT8MX7//EVVA3HDXITKieSgfsnYmfI0m8=; b=sQKujSE2+s9XJdLDxzf1utUIbgJopOP4SqvwQFe/oFActNAoJO5l5cROeVzUgODLWo Gm8BPe0O2ehO57TmuBV5ZPJmhg2/j0b1M7LYCw4VznD/21OTh3vFuRKOiuNp8/M8Y7qJ Y2WXItsYwAS6w3++sj0XHEeJHubzV0K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id a640c23a62f3a-bd51780c8acmr759171166b.10.1779095211030; Mon, 18 May 2026 02:06:51 -0700 (PDT) Received: from ?IPV6:2620:10d:c096:325:77fd:1068:74c8:af87? ([2620:10d:c092:600::1:6e9b]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-bd4f4e57cb8sm535358566b.50.2026.05.18.02.06.50 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 18 May 2026 02:06:50 -0700 (PDT) Message-ID: <9f3f3dc7-1c52-49b6-91d5-046f1fc7b2a8@gmail.com> Date: Mon, 18 May 2026 10:06:48 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 2/2] fuse: wait for aborted connection before releasing last fuse_dev To: Bernd Schubert , Berkant Koc , Greg KH , Miklos Szeredi Cc: "security@kernel.org" , Joanne Koong , "linux-fuse@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "io-uring@vger.kernel.org" , Jens Axboe , fuse-devel References: <20260517095846.fuse-iouring-uaf.dc5f5dbb71dc@berkoc.com> <2026051703-equinox-multitude-91e2@gregkh> <20260517-fuse-uaf-cover@berkoc.com> <20260517-fuse-uaf-patch2@berkoc.com> <08d3f6e0-7745-4084-995a-95ddb77f7f11@ddn.com> Content-Language: en-US From: Pavel Begunkov In-Reply-To: <08d3f6e0-7745-4084-995a-95ddb77f7f11@ddn.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 5/17/26 16:00, Bernd Schubert wrote: > On 5/17/26 14:59, Berkant Koc wrote: >> [You don't often get email from me@berkoc.com. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ] >> >> From: Berkant Koc >> >> fuse_dev_release() on the last fuse_dev of a connection calls >> fuse_abort_conn(fc) and then immediately fuse_conn_put(fc). For io-uring >> backed connections fuse_abort_conn() reaches fuse_uring_abort(), which >> runs fuse_uring_teardown_all_queues() synchronously once and then >> schedules ring->async_teardown_work to run after >> FUSE_URING_TEARDOWN_INTERVAL (HZ/20). If the synchronous pass left >> queue_refs > 0 the work owns further accesses to ring->queues[*]-> >> ent_avail_queue and ent_in_userspace entries. >> >> Meanwhile fuse_conn_put() can drop the last reference and arm >> delayed_release() via call_rcu(). After the RCU grace period >> delayed_release() calls fuse_uring_destruct(), which kfree()s the ring >> entries on each queue->ent_released list. The previously scheduled >> async_teardown_work then runs and walks per-queue lists that contain >> freed entries, producing a slab-use-after-free reported by KASAN at >> fuse_uring_teardown_all_queues+0xee reading ent->list.next from a >> freed kmalloc-192 region. >> >> fuse_wait_aborted() already exists for this purpose: it waits on >> fc->blocked_waitq for num_waiting to drain and then calls >> fuse_uring_wait_stopped_queues(), which waits for ring->queue_refs to >> reach zero. Call it between fuse_abort_conn() and fuse_conn_put() on >> the last-device path so the io-uring teardown work has fully drained >> before the connection can be torn down. >> >> Fixes: c090c8abae4b ("fuse: Add io-uring sqe commit and fetch support") >> Cc: stable@vger.kernel.org # 6.14+ >> Tested-by: Berkant Koc >> Signed-off-by: Berkant Koc >> --- >> fs/fuse/dev.c | 1 + >> 1 file changed, 1 insertion(+) >> >> diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c >> index 5dda7080f4a9..7d9c06654a98 100644 >> --- a/fs/fuse/dev.c >> +++ b/fs/fuse/dev.c >> @@ -2566,6 +2566,7 @@ int fuse_dev_release(struct inode *inode, struct file *file) >> if (last) { >> WARN_ON(fc->iq.fasync != NULL); >> fuse_abort_conn(fc); >> + fuse_wait_aborted(fc); >> } >> fuse_conn_put(fc); >> } > > I might be wrong, but I don't think it is possible, Maybe Pavel or Jens > could help (added to CC). Basically as long as > fuse_uring_async_stop_queues() runs we do not have completed all > io-uring commands via io_uring_cmd_done() and as long as we do not have > completed these io-uring commands. If I understand the question right, yes, fuse io_uring cmd requests hold a reference to the fuse file, so until you complete them the file will not get released. -- Pavel Begunkov