From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 77A3A2BEC2E; Thu, 25 Jun 2026 13:12:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782393121; cv=none; b=AT1n6kpIO/ZSbia6ry3IGTJLpea1P0PGbvzdhizAXH1Qtt3ICyb/1ACVXbXwR34tas0zJE5gEMFhztyKLAUTwhtutiiSOpaBXc6xtnbJPEgTSPTcJs9KKTNQpTYFQ/lfFJipcgRsuP2eZjLI226pR570KUyvOedfT3bhIioxat4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782393121; c=relaxed/simple; bh=IVPXMfuRhQCZ/k9NwP08MOMKFWMoJ/LgPFFRlB46XZE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=oiGO3yvdfqHNgcDLtIdha61E6hxm6Ipyt7ak7qnFAv7YlkKJ0SwchYBOPMKtfeiM3TXhF8E1JZfECzUaZ+WgGJLj3HjFVq1xaA/JzjREL2Ki3Zu9BTA6DuhxCUGw/zHdAa317P8vMPSEyvBuj+GzbwC5FdvEpFpQz5CGdfItUf4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=NUtXRv9i; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="NUtXRv9i" Received: by smtp.kernel.org (Postfix) with ESMTPSA id BBE1C1F000E9; Thu, 25 Jun 2026 13:11:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1782393120; bh=u2/amJJtRutc6Dcb9rjEjwV9XE8tMHPcsGtGrW0zgt8=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=NUtXRv9iiaWgiSXUjsb7ijNXBULl/503sEavCl67Gd5P/FWZsWXwBk/Jx+LmTO2/6 dseQPSH9+j+Ej5jY91McyLR8eiDbAzcIqjkcW197RV62sDMs6H8n32uzw9ZvBvbJBX Mr7c+YVcOAW5rBl/ZqQnywuvLE7aH4dWVtv2SvaY= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Lei Lu , Joanne Koong , Miklos Szeredi Subject: [PATCH 7.1 02/21] fuse: re-lock request before replacing page cache folio Date: Thu, 25 Jun 2026 14:03:54 +0100 Message-ID: <20260625125613.554857280@linuxfoundation.org> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260625125613.243729608@linuxfoundation.org> References: <20260625125613.243729608@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 7.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Joanne Koong commit a078484921052d0badd827fcc2770b5cfc1d4120 upstream. fuse_try_move_folio() unlocks the request on entry but does not re-lock it on the success path. This means fuse_chan_abort() can end the request and free the fuse_io_args (eg fuse_readpages_end()) while the subsequent copy chain logic after fuse_try_move_folio() accesses the fuse_io_args, leading to use-after-free issues. Fix this by calling lock_request() before replace_page_cache_folio(). This ensures the request is locked on the success path which will prevent the fuse_io_args from being freed while the later copying logic runs, and also ensures that the ap->folios[i]->mapping is never null since ap->folios[i] will always point to the newfolio after replace_page_cache_folio(). Fixes: ce534fb05292 ("fuse: allow splice to move pages") Cc: stable@vger.kernel.org Reported-by: Lei Lu Signed-off-by: Joanne Koong Signed-off-by: Miklos Szeredi Signed-off-by: Greg Kroah-Hartman --- fs/fuse/dev.c | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) --- a/fs/fuse/dev.c +++ b/fs/fuse/dev.c @@ -1037,6 +1037,10 @@ static int fuse_try_move_folio(struct fu if (WARN_ON(folio_test_mlocked(oldfolio))) goto out_fallback_unlock; + err = lock_request(cs->req); + if (err) + goto out_fallback_unlock; + replace_page_cache_folio(oldfolio, newfolio); folio_get(newfolio); @@ -1050,20 +1054,7 @@ static int fuse_try_move_folio(struct fu */ pipe_buf_release(cs->pipe, buf); - err = 0; - spin_lock(&cs->req->waitq.lock); - if (test_bit(FR_ABORTED, &cs->req->flags)) - err = -ENOENT; - else - *foliop = newfolio; - spin_unlock(&cs->req->waitq.lock); - - if (err) { - folio_unlock(newfolio); - folio_put(newfolio); - goto out_put_old; - } - + *foliop = newfolio; folio_unlock(oldfolio); /* Drop ref for ap->pages[] array */ folio_put(oldfolio);