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 0511332E151; Sat, 17 Oct 2026 17:07:28 +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=1792256849; cv=none; b=DJMECUr5ZFNWRITJi7pJLv0YxbV7FAjje8xJ96sR4IPgz6PVsXEKa+gksxPFvJGZBtnh/xwBcvNLzHsVAXtNiIYx+G4IOZ6SjX8Om+BlirvEYgQ7QhKdPKmnycbfv3PTE9rCtpbYICGE3Clxg/e1T+B9am1cAYK4W5kCoR1/VMU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1792256849; c=relaxed/simple; bh=GQ9R2bEtvna1RCvLQTDJongCcKsoFmKK3e5adtR9pwY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hEW+GC7+p4T89Fk07O6LN27ITHeGzjk5kBNtPfhZLXQLhlTVEY03peB0WG44Q/G7HOYy9ZtHoCBrvFDIybKhlkVqa+Y6LuJrA6cvw/JzmYRw58PSDSbjJbIRxLODYKpGYyRDRgMTEhQdBRdy5Jcz/gtNketB2glG2wTwRJBe/Ok= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=2LqBcd5u; 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="2LqBcd5u" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 499AE1F000C4; Sat, 17 Oct 2026 17:07:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1792256847; bh=d2MhqoV8LTzTA03kh5m4RaFPZAz/oa6j4Bb2wRzCZ3c=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=2LqBcd5uD4hY/ayLKy1+vHHm6xZmWt+13ANs6wvGFrpwXuthWm9Y3UTWNokLO1SBp PDLnNjJYDRION8mCkgYwRZVXn/3afVfO6Tnp0TXTZQyuUnVdhgy6cLIP0RJAhB3+r+ sOz3mNUf68GIyeNiTLb3OEoudpkE4uzTfh6M35Xg= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Gabriel Prostitis , Sasha Levin Subject: [PATCH 6.6 0370/1674] USB: gadget: ffs: fix mm lifetime handling Date: Sat, 17 Oct 2026 17:44:02 +0200 Message-ID: <20261017160440.616786736@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: Gabriel Prostitis [ Upstream commit 5eb5c72c72fef76cb765ef1669b62b6a3ba1bfc8 ] io_data stores a pointer to the submitting task's mm_struct, but does not currently hold a reference to it while async requests are pending. This can result in a use-after-free if the task exits before completion handling finishes. Take a reference with mmgrab() when queuing the read request and release it with mmdrop() on request completion. Reported-by: Gabriel Prostitis Signed-off-by: Gabriel Prostitis Link: https://patch.msgid.link/20260601-mm-uaf-fix-v2-1-3c942a707bce@gmail.com Signed-off-by: Greg Kroah-Hartman Stable-dep-of: e78dcb1f7ec2 ("usb: gadget: f_fs: Fix Use-After-Free in AIO error path") Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- drivers/usb/gadget/function/f_fs.c | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) --- a/drivers/usb/gadget/function/f_fs.c +++ b/drivers/usb/gadget/function/f_fs.c @@ -831,9 +831,15 @@ static void ffs_user_copy_worker(struct unsigned long flags; if (io_data->read && ret > 0) { - kthread_use_mm(io_data->mm); - ret = ffs_copy_to_iter(io_data->buf, ret, &io_data->data); - kthread_unuse_mm(io_data->mm); + if (mmget_not_zero(io_data->mm)) { + kthread_use_mm(io_data->mm); + ret = ffs_copy_to_iter(io_data->buf, ret, &io_data->data); + kthread_unuse_mm(io_data->mm); + mmput(io_data->mm); + } else { + ret = -EFAULT; + } + mmdrop(io_data->mm); } io_data->kiocb->ki_complete(io_data->kiocb, ret); @@ -1210,16 +1216,20 @@ static ssize_t ffs_epfile_write_iter(str kiocb->private = p; - if (p->aio) + if (p->aio) { + mmgrab(p->mm); kiocb_set_cancel_fn(kiocb, ffs_aio_cancel); + } res = ffs_epfile_io(kiocb->ki_filp, p); if (res == -EIOCBQUEUED) return res; - if (p->aio) + if (p->aio) { + mmdrop(p->mm); kfree(p); - else + } else { *from = p->data; + } return res; } @@ -1254,14 +1264,17 @@ static ssize_t ffs_epfile_read_iter(stru kiocb->private = p; - if (p->aio) + if (p->aio) { + mmgrab(p->mm); kiocb_set_cancel_fn(kiocb, ffs_aio_cancel); + } res = ffs_epfile_io(kiocb->ki_filp, p); if (res == -EIOCBQUEUED) return res; if (p->aio) { + mmdrop(p->mm); kfree(p->to_free); kfree(p); } else {