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 8044544AB62; Tue, 21 Jul 2026 21:51:44 +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=1784670705; cv=none; b=Nh7vcWIMpFxUAVTcDwEeVNmB0vTPF44CgsWUMr1Fryl5lGmbMbq8Y4gRCcXG+nYj9Cvv1x+wjTllfduzTNoHaB7GksH6EgPGv4QSm3q4F8/psu5+rzU7bILYv90Iq4zwycwqrc8PJ2v5QgsMv6S2oFSZSR8Xs12+VLr9wiZLUvc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784670705; c=relaxed/simple; bh=DU0WMe6xwajuxTWKDs8mP/WPlLdiiWKoGCF8rcr+xsc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Htjt3Rfd4jz2e9DzDWMCP4IOKd/pmU0PDoxK2MXEYOVZfh0TPWYYrVDPc05OQdE5fyN76xAU4KJIP8JuJU28OXl7zzVk/YRh019vYlM4hIvbIvXsgMGsMu8nDT4XM162yIq0tjSnNcSG6MeepJnYFhlSRdIJC4F1uRhtt4d0TLM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=zFoVRbOP; 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="zFoVRbOP" Received: by smtp.kernel.org (Postfix) with ESMTPSA id ACAF21F000E9; Tue, 21 Jul 2026 21:51:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1784670704; bh=7WiZBsnOTXoYGkRu9txXBOXWUuOxvaomUpDqjc3Fvms=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=zFoVRbOPtf8/0IpnKtcLHFWRf0dfR5i2WfexCPp0jAHqfNoS0EBDrGymV0xlL8vOP NF5M3pjbZjLc8eRVw1CTOBXSjIEYM+WOV+omDhFj88v1/Bnk039h9kZZvvY0KrsU2s HPOUbxa+JVu64b+DN0mJUFbDp7M4KRvq7987yPe4= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, stable , Neill Kapron , Sasha Levin Subject: [PATCH 6.1 1034/1067] usb: gadget: f_fs: Tie read_buffer lifetime to ffs_epfile Date: Tue, 21 Jul 2026 17:27:15 +0200 Message-ID: <20260721152447.714478581@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260721152424.521567757@linuxfoundation.org> References: <20260721152424.521567757@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-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Neill Kapron [ Upstream commit 8bdcf96eb135aebacac319667f87db034fb38406 ] Currently, ffs_epfile_release unconditionally frees the endpoint's read_buffer when a file descriptor is closed. If userspace explicitly opens the endpoint multiple times and closes one, the read_buffer is destroyed. This can lead to silent data loss if other file descriptors are still actively reading from the endpoint. By tying the lifetime of the read_buffer to the ffs_epfile structure itself (which is destroyed when the functionfs instance is torn down in ffs_epfiles_destroy), we eliminate the brittle dependency on open/release calls while correctly matching the conceptual lifetime of unread data on the hardware endpoint. Fixes: 9353afbbfa7b ("usb: gadget: f_fs: buffer data from ‘oversized’ OUT requests") Cc: stable Assisted-by: Antigravity:gemini-3.1-pro Signed-off-by: Neill Kapron Link: https://patch.msgid.link/20260619040609.4010746-3-nkapron@google.com Signed-off-by: Greg Kroah-Hartman [ adjusted context in ffs_epfiles_destroy() since 6.12 lacks the simple_remove_by_name() rework and still uses dentry-based cleanup ] Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- drivers/usb/gadget/function/f_fs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/drivers/usb/gadget/function/f_fs.c +++ b/drivers/usb/gadget/function/f_fs.c @@ -1292,7 +1292,6 @@ ffs_epfile_release(struct inode *inode, ENTER(); - __ffs_epfile_read_buffer_free(epfile); ffs_data_closed(epfile->ffs); return 0; @@ -1957,6 +1956,7 @@ static void ffs_epfiles_destroy(struct f for (; count; --count, ++epfile) { BUG_ON(mutex_is_locked(&epfile->mutex)); + __ffs_epfile_read_buffer_free(epfile); if (epfile->dentry) { d_delete(epfile->dentry); dput(epfile->dentry);