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 B39C143E4BE; Thu, 17 Sep 2026 19:01:13 +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=1789671684; cv=none; b=eC4A1HzWDvyQEUmScooWoi9vK6lW0kaOkt/kDKAFuL45r8qgCry6x5zlpjF5EG+mBddYASP1Pyo+2eDucGLzQgMd1NAuP33DDkVASAqxDwYrvClAdGK1vPDEzvgrGKgrQR2nRqmlQYpRw8hl4d1El+/rg1ZPJD5fTEZnh/Zz3c8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789671684; c=relaxed/simple; bh=83zvQONYY/KIFTq4fGkHCYABwN28wOY/5O4PtBjFliY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=VLgaJEw+L0oYepSvXXjRC7v0wBMXpIuuNgUiCCeZlhpvmV5UJEc2jLRHzWv71nUgwp9K+8d2F3XdxLnICNfxpo7vQl2qC+1K2ZKp9lU3ban3pzqLTY/yAwC181TOydhzD0bT3itERxh8e2YCr3Zyqc4J0cH4S9rzujVstcjhiyg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=pXtAoV9v; 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="pXtAoV9v" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 082121F0089F; Thu, 17 Sep 2026 19:00:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1789671654; bh=Ka45sBtE3jecZSYpS/a9V2iWl4sNIlp3GaXzzRXCHzY=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=pXtAoV9viOkMxCN2lO4aXTQ+2uCWnpN6/HU3COCzlhGL+7RD13oTRDsupJvnAHpxL 0gdWZNybwWbzoLCvCNpACRO3cW6d7qVQPaYYMPejq+LkgyeCFsLBlbf90Uv3dUArDk 1/vWHvUkDBiHFdBKj+N0n7IahP3OKUrmY+rXC208= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Gabriel Prostitis , Sasha Levin Subject: [PATCH 6.12 1009/1102] USB: gadget: ffs: fix mm lifetime handling Date: Thu, 17 Sep 2026 16:15:52 +0100 Message-ID: <20260917151606.078013515@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260917151539.408551884@linuxfoundation.org> References: <20260917151539.408551884@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.12-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 @@ -866,9 +866,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); @@ -1258,16 +1264,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; } @@ -1302,14 +1312,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 {