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 61DA346C4CF; Tue, 21 Jul 2026 21:08:04 +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=1784668085; cv=none; b=kng9OvukYSUz3p66xlkV8p90/GoUAw3QKQ/Nmk/oA5HaxvYGlvVdvB/7H9sHdXPnoXCAbJ3VEeET/6qoZ+7gOeBmHjn0ZQ8g5l3YKEU5mNfeOSKfQs4B6i6z5j6rSRvY7rSM8m7X/+vfosFEWEFs4dtD/P6AMv184PDaqPYC/bc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784668085; c=relaxed/simple; bh=sappWnQT/ZaS//DD51yDXhs53kE/rZ/Dnm3X34h08eA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ryginqf/H7fuFcywegqvRsVm0l+vwsczIByNLIzOfm5vVwVQ8M5HIrJnjbxXJFOstYkAxdzRB62sJ5GJamncS7lx+H7UeU0NjFt3Wu+YRkmRd7g2SWjlLM+rsgZHO4TE1q0umImsOy4ZE/+tC4fr+lpwG18KyjlZ2tV8+HUZMpc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=fJ2uJMco; 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="fJ2uJMco" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C5FCA1F000E9; Tue, 21 Jul 2026 21:08:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1784668084; bh=UQLxw+RoxDgOC8sBYolyCwZws4F2u+b+jKt7lbbHe10=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=fJ2uJMcoKWknLFQ83yCdPEFbKiuZfA89BkX6BcIL4rG/USrlaZg8f4k0AHG2SW1Ux 0g4VmtTvKWTCpcF0UrXNBUy7jk+hwIc/UKm3kgBQ+H8SebZls7OIsutnk6TwlZV5Ij Yee1tWb5j8UUbDh2rlDXe98gXpz1YwlKHP7zs0ic= From: Greg Kroah-Hartman To: stable@vger.kernel.org, carnil@debian.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Linus Torvalds , "Christian Brauner (Amutable)" , Quentin Schulz , Wentao Guan Subject: [PATCH 6.1 0041/1067] eventpoll: split __ep_remove() Date: Tue, 21 Jul 2026 17:10:42 +0200 Message-ID: <20260721152425.475634763@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-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Christian Brauner [ Upstream commit 0f7bdfd413000985de09fc39eb9efa1e091a3ce0 ] Split __ep_remove() to delineate file removal from epoll item removal. Suggested-by: Linus Torvalds Link: https://patch.msgid.link/20260423-work-epoll-uaf-v1-2-2470f9eec0f5@kernel.org Signed-off-by: Christian Brauner (Amutable) Stable-dep-of: a6dc643c6931 ("eventpoll: fix ep_remove struct eventpoll / struct file UAF") Signed-off-by: Quentin Schulz Signed-off-by: Wentao Guan Signed-off-by: Greg Kroah-Hartman --- fs/eventpoll.c | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) --- a/fs/eventpoll.c +++ b/fs/eventpoll.c @@ -715,6 +715,9 @@ static void ep_free(struct eventpoll *ep kfree_rcu(ep, rcu); } +static void __ep_remove_file(struct eventpoll *ep, struct epitem *epi, struct file *file); +static bool __ep_remove_epi(struct eventpoll *ep, struct epitem *epi); + /* * Removes a "struct epitem" from the eventpoll RB tree and deallocates * all the associated resources. Must be called with "mtx" held. @@ -726,8 +729,6 @@ static void ep_free(struct eventpoll *ep static bool __ep_remove(struct eventpoll *ep, struct epitem *epi, bool force) { struct file *file = epi->ffd.file; - struct epitems_head *to_free; - struct hlist_head *head; lockdep_assert_irqs_enabled(); @@ -743,8 +744,21 @@ static bool __ep_remove(struct eventpoll return false; } - to_free = NULL; - head = file->f_ep; + __ep_remove_file(ep, epi, file); + return __ep_remove_epi(ep, epi); +} + +/* + * Called with &file->f_lock held, + * returns with it released + */ +static void __ep_remove_file(struct eventpoll *ep, struct epitem *epi, struct file *file) +{ + struct epitems_head *to_free = NULL; + struct hlist_head *head = file->f_ep; + + lockdep_assert_held(&ep->mtx); + if (hlist_is_singular_node(&epi->fllink, head)) { /* See eventpoll_release() for details. */ WRITE_ONCE(file->f_ep, NULL); @@ -758,6 +772,11 @@ static bool __ep_remove(struct eventpoll hlist_del_rcu(&epi->fllink); spin_unlock(&file->f_lock); free_ephead(to_free); +} + +static bool __ep_remove_epi(struct eventpoll *ep, struct epitem *epi) +{ + lockdep_assert_held(&ep->mtx); rb_erase_cached(&epi->rbn, &ep->rbr);