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 DC6293AFCF0; Sat, 17 Oct 2026 17:07:30 +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=1792256851; cv=none; b=N0aGwffuTVU335iz8iG4xxriz2+dpCCjjNDQmRKJ5m85obLC3GIdVIzLd7p6TcTkzzz0JPfVJ9dq/Acu7xueWH+ce5hQvgRCKIZVujiW2PQaVfnSSyfarnBCTmJV7w9H2CF4Z+17mcv9W6G2LFPDrvdKoUpodzjQwW7u8J7j0nQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1792256851; c=relaxed/simple; bh=WXzqHjKdI6MrFD9Ea8cSY5Uq+o2z4gxn2YuUrtzF0EE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UY5rlLZCKmIv+OGNJXfiLrGeFb9/CbZhDpMlJs+sJ5LHbFE20hUQYwZfYV9q+Dx2VDYNgF7+PIuP/htMeqJzcElzh6TyMdgCmoaLogrDKnT6cwLpObXJJs7uuwOUQgPonzXYKfGNiX6DDjmTOuF7Id2i4uELskfMlsuludC5AwU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=lVEKSFx2; 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="lVEKSFx2" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 687B11F000C4; Sat, 17 Oct 2026 17:07:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1792256850; bh=vuGJPj7eIJ1Fy1WoAIQ35iuRt0cng1XScu6F3MnfiPo=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=lVEKSFx2EAKcUNpaiOnkUCTxp/Qs0JTSHmWoHx5mldkVaYbhQtOlE1u3znkgttP5m IaMNDX7YcHEGrgvGmv7AEqxRXFwtpOiP2elVN9s9gQXqxCENxHKYFJmi9Rdu+DJubT QAieASKJEPCkXrIqxOm8KX+ih26TuiG4s7CCAF3M= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Xingyu Jin , Neill Kapron , Sasha Levin Subject: [PATCH 6.6 0371/1674] usb: gadget: f_fs: Fix Use-After-Free in AIO error path Date: Sat, 17 Oct 2026 17:44:03 +0200 Message-ID: <20261017160440.640680224@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261017160431.119607952@linuxfoundation.org> References: <20261017160431.119607952@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 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Neill Kapron [ Upstream commit e78dcb1f7ec271449c54984dc90c62a5ba272de7 ] In ffs_epfile_write_iter() and ffs_epfile_read_iter(), when ffs_epfile_io() fails with an error other than -EIOCBQUEUED, the io_data structure (`p`) is freed. However, for AIO operations, the kiocb cancel function was already armed and kiocb->private was set to `p`. If a concurrent cancel operation (such as sys_io_cancel()) executes after ffs_epfile_io() fails but before the function frees `p`, a Use-After-Free can occur when the cancellation handler accesses the freed pointer. To securely fix this race condition, we must properly un-arm the cancellation. Invoking `kiocb->ki_complete()` does exactly this by acquiring `ctx->ctx_lock` and safely removing the kiocb from the active sequence. In doing so, it ensures that a parallel io_cancel can no longer discover the kiocb, effectively closing the race window. We then return -EIOCBQUEUED to notify the VFS layer that the kiocb has been consumed and it should avoid attempting to complete the request again or triggering subsequent completion handlers. Fixes: de2080d41b5d ("gadget/function/f_fs.c: close leaks") Cc: stable@vger.kernel.org Reported-by: Xingyu Jin Assisted-by: Antigravity:gemini-3.1-pro Signed-off-by: Neill Kapron Link: https://patch.msgid.link/20260724235100.106011-1-nkapron@google.com Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- drivers/usb/gadget/function/f_fs.c | 4 ++++ 1 file changed, 4 insertions(+) --- a/drivers/usb/gadget/function/f_fs.c +++ b/drivers/usb/gadget/function/f_fs.c @@ -1225,8 +1225,10 @@ static ssize_t ffs_epfile_write_iter(str if (res == -EIOCBQUEUED) return res; if (p->aio) { + kiocb->ki_complete(kiocb, res); mmdrop(p->mm); kfree(p); + return -EIOCBQUEUED; } else { *from = p->data; } @@ -1274,9 +1276,11 @@ static ssize_t ffs_epfile_read_iter(stru return res; if (p->aio) { + kiocb->ki_complete(kiocb, res); mmdrop(p->mm); kfree(p->to_free); kfree(p); + return -EIOCBQUEUED; } else { *to = p->data; }