From nobody Mon Jun 8 15:36:52 2026 Received: from mail-oo1-f70.google.com (mail-oo1-f70.google.com [209.85.161.70]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3E1543F5BDB for ; Thu, 28 May 2026 13:34:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.70 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779975292; cv=none; b=DVN1/08mper2eumDOp5c7FQw3rFrqRVPQN0Yu7Of/lq8r3N0/VJVjgX4GawIjUFq8K1NX/w08gMHE1I7jgiJ3MRKW1Ao5yY2Arq3mVLvf/zEdS+WSTOPSMPZhh3mZVQVadkO8odwa7i8Ymbm3JizFyoUdCZbP/YEv+nMA2h8q64= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779975292; c=relaxed/simple; bh=ftZqCNosXdBNgIVfsu5hDwerzuvglOzdoNdsA7q+Gn4=; h=MIME-Version:Date:In-Reply-To:Message-ID:Subject:From:To: Content-Type; b=f05P0rWNnj2iqoe8WkHha7wt9MIJ3l2IEiL2syC0Tgkf9dCz7vNjNQyh0sgyxiY+kjQ+CAqTY0zWRFFvRIXH12FTbjK21ctYHialXy84NBV/JgrzjUWOdyOXbRL8cBf7PpJH/apltUtjPulXK27Sl9jYP0qCsD9kKgWEDBH6t1c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=syzkaller.appspotmail.com; spf=pass smtp.mailfrom=M3KW2WVRGUFZ5GODRSRYTGD7.apphosting.bounces.google.com; arc=none smtp.client-ip=209.85.161.70 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=syzkaller.appspotmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=M3KW2WVRGUFZ5GODRSRYTGD7.apphosting.bounces.google.com Received: by mail-oo1-f70.google.com with SMTP id 006d021491bc7-69d0183aeedso11011507eaf.2 for ; Thu, 28 May 2026 06:34:50 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779975290; x=1780580090; h=to:from:subject:message-id:in-reply-to:date:mime-version :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=WbPW7i2sUakGdGKq5CGSMzArsnR4oRtdNtinbhSt0G4=; b=bUcA3nlQ5mcrCl1mJcsjxBnhUhBCwnuG2URmvckqxUtSEkD4KS1EFKwy2ekMzOmM+j gF4sFeKjNHgqKZ2840Y05wEY0QpQDet9JgLJKJ/ofejWJeh+5zCA5aSe8rvw9cygUjPt amJoWdrAqUFR6HX/Du8/MC42p8YN3RTSWS+7drW6YTeAp2AZS9DztkKPmLxkIphL3Ckd vob4rFeUR1oDxWx/suenYEwNKuLqBWL+x7CClabX+e90HqwufjwKo04jf0ttjqk2mvAO sf9DFKxe5kjrl0Sxwx61yiTwfnJBwT9zn8OTOVgWtyXJojZ2kkYlH3AB72N1ev2dbcpW aJTg== X-Gm-Message-State: AOJu0YyXsZAk/lG5HmG54rfl5zqxzAVaR7rHCjQBeOkBpc6WHcr4p7Cj a0xvqS7ojSwAu35RgXuaNKfJdP2J/xYqS+lbcTYR9dhHgvWk0y/tRx3cppYBUFrfqHqlwDHXN7+ Wo4+EiKPfwBrGGuYVFm61nxn6aFjHlVFe9sxIcRuPPuQUOPJxui/za6eteB8= Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Received: by 2002:a05:6820:1348:b0:69d:e28e:2fff with SMTP id 006d021491bc7-69de28e34c6mr3825291eaf.40.1779975290213; Thu, 28 May 2026 06:34:50 -0700 (PDT) Date: Thu, 28 May 2026 06:34:50 -0700 In-Reply-To: <6a181a34.a5d0663d.c282a.0000.GAE@google.com> X-Google-Appengine-App-Id: s~syzkaller X-Google-Appengine-App-Id-Alias: syzkaller Message-ID: <6a18447a.9efe2910.1869e6.0001.GAE@google.com> Subject: Forwarded: [PATCH] eventpoll: fix use-after-free in clear_tfile_check_list() From: syzbot To: linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" For archival purposes, forwarding an incoming command email to linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com. *** Subject: [PATCH] eventpoll: fix use-after-free in clear_tfile_check_list() Author: kartikey406@gmail.com #syz test: git://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.gi= t master syzbot reports a slab-use-after-free read in clear_tfile_check_list() during EPOLL_CTL_ADD when ep_insert() takes an error path that calls ep_remove() before do_epoll_ctl_file() drains ctx->tfile_check_list. ep_remove_file() decides whether to kmem_cache_free() a struct epitems_head by testing v->next =3D=3D NULL, on the convention that NULL means "this head is not linked on any check list". list_file() pushes a head onto ctx->tfile_check_list by storing the previous list head into head->next; when the list is empty that store is NULL, so the head that ends up at the tail of the check list also has next =3D=3D NULL. ep_remove_file() then misreads the tail as "not linked" and frees it. clear_tfile_check_list() later walks the list and dereferences head->next on the freed object: BUG: KASAN: slab-use-after-free in clear_tfile_check_list+0x114/0x380 fs/eventpoll.c:2443 Allocated by task 5985: ep_attach_file fs/eventpoll.c:1751 [inline] ep_register_epitem fs/eventpoll.c:1833 [inline] ep_insert+0x512/0x1820 fs/eventpoll.c:1876 Freed by task 5985: ep_remove+0x155/0x2a0 fs/eventpoll.c:1135 ep_insert+0x1372/0x1820 Terminate ctx->tfile_check_list with a non-NULL sentinel (EP_TFILE_LIST_END) so that next =3D=3D NULL unambiguously means "not on any check list". list_file() stores the sentinel when the list is empty, reverse_path_check() and clear_tfile_check_list() stop the walk on the sentinel, and do_epoll_ctl_file() seeds ctx->tfile_check_list with it. The guard in ep_remove_file() then correctly refuses to free a head while it remains on the check list. Reported-by: syzbot+f83fa2cf571bd7650422@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=3Df83fa2cf571bd7650422 Signed-off-by: Deepanshu Kartikey --- fs/eventpoll.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/fs/eventpoll.c b/fs/eventpoll.c index a569e98d4a99..349d79e8ddc8 100644 --- a/fs/eventpoll.c +++ b/fs/eventpoll.c @@ -222,6 +222,15 @@ =20 #define EP_UNACTIVE_PTR ((void *) -1L) =20 +/* Non-NULL sentinel terminating ctx->tfile_check_list, so that + * "head->next =3D=3D NULL" unambiguously means "this head is not on any + * check list" -- the invariant ep_remove_file() and list_file() rely + * on. Without this, the tail of the check list aliases the + * "not linked" state and ep_remove_file() may free a head that + * clear_tfile_check_list() still references. + */ +#define EP_TFILE_LIST_END ((struct epitems_head *)EP_UNACTIVE_PTR) + #define EP_ITEM_COST (sizeof(struct epitem) + sizeof(struct eppoll_entry)) =20 /* Wait structure used by the poll hooks */ @@ -472,7 +481,7 @@ static void list_file(struct file *file, struct ep_ctl_= ctx *ctx) =20 head =3D container_of(file->f_ep, struct epitems_head, epitems); if (!head->next) { - head->next =3D ctx->tfile_check_list; + head->next =3D ctx->tfile_check_list ? : EP_TFILE_LIST_END; ctx->tfile_check_list =3D head; } } @@ -1685,7 +1694,7 @@ static int reverse_path_check(struct ep_ctl_ctx *ctx) { struct epitems_head *p; =20 - for (p =3D ctx->tfile_check_list; p; p =3D p->next) { + for (p =3D ctx->tfile_check_list; p !=3D EP_TFILE_LIST_END; p =3D p->next= ) { int error; path_count_init(ctx); rcu_read_lock(); @@ -2438,11 +2447,12 @@ static int ep_loop_check(struct ep_ctl_ctx *ctx, st= ruct eventpoll *ep, static void clear_tfile_check_list(struct ep_ctl_ctx *ctx) { rcu_read_lock(); - while (ctx->tfile_check_list) { + while (ctx->tfile_check_list !=3D EP_TFILE_LIST_END) { struct epitems_head *head =3D ctx->tfile_check_list; ctx->tfile_check_list =3D head->next; unlist_file(head); } + ctx->tfile_check_list =3D NULL; rcu_read_unlock(); } =20 @@ -2601,7 +2611,7 @@ int do_epoll_ctl_file(struct file *f, int op, struct = epoll_key *tf, int full_check; struct eventpoll *ep; struct epitem *epi; - struct ep_ctl_ctx ctx =3D { }; + struct ep_ctl_ctx ctx =3D {.tfile_check_list =3D EP_TFILE_LIST_END }; =20 /* The target file descriptor must support poll */ if (!file_can_poll(tf->file)) --=20 2.43.0