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 02F35492E33; Wed, 9 Sep 2026 13:48:14 +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=1788961695; cv=none; b=QO0H8kr8ksng54x19WR7ltmChYbjW6cpYGYAhC6QAFHFI77ZJibnKdL0Ylp3TQfkUHWhJJHQxRBL0LmJB96CUDpeMlOOYr1NbvNqozRi5LEedCzNs4f1GqLybuxMSgDIMJ/5ISRaQ14M01kJwpYHfO/q22ln30VEVLTFfyqbYqY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788961695; c=relaxed/simple; bh=aOgiB6HHQ4U7J7Nhwl9zFR125o3BvP9jeNmfQfCEhKo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bbCIKjdjds9Hb/mO46NvSKuyDumwbXZuWda3qXn2xiCyksviKtn+9TIcA51soUA7AITPInrfo8wOXP6sFGDOhlCALzBln2APn00c8wkfhh83c4LtBSqCsJGaUCt8p9O3lbE0vKvWZ2MkChS2RD/HQFxehAacRpvYLDoYjgHpScw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=X0/1Q0tu; 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="X0/1Q0tu" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2AD3A1F00A3A; Wed, 9 Sep 2026 13:48:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1788961693; bh=ZstqRs/WW1FxAc1fMhc36dhASYRGt1og7kJHttBdTh8=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=X0/1Q0tucmZzogNbsR5g4vZuif7auRNyDUWHrq9ghY9uJEVAOKV8manqP6b1fdtJj XSnPI6Dg+Z8ejHW/YqGbN1g2tSWYMfqHupJGg7WTdDGwwp8J2/dPImiGeatxvZI7/E Hg38mVd84nOlvebluSZYvXknwZL8mtn5xIC8l6Ls= 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 7.2 006/556] usb: gadget: f_fs: Fix Use-After-Free in AIO error path Date: Wed, 9 Sep 2026 15:34:46 +0200 Message-ID: <20260909134230.681862146@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260909134230.441546314@linuxfoundation.org> References: <20260909134230.441546314@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.2-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 @@ -1285,8 +1285,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; } @@ -1334,9 +1336,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; }