From nobody Mon Jun 8 10:56:41 2026 Received: from mail-ot1-f72.google.com (mail-ot1-f72.google.com [209.85.210.72]) (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 025A32D063E for ; Fri, 29 May 2026 13:24:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.72 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780061082; cv=none; b=fpstAF0Btbjzqkwl8OWQNxWdk9rdTNHxp5a44TY/cfDuGlMAy8Dt1BNVPPrXVZ/cpJtvNy8RunUmXW3124bCCx/sOdAkh4dfQAgUUKgbHZf8FQ2l8RDrs5AmwqDljlCSy1VxOa5XkT9vCjghxRVwJ45HM6AtpVyX1BXvqihs/XA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780061082; c=relaxed/simple; bh=5Ih8kZAhZLbOn+BWycxEC+3p7jHDL4MrscLjcX8egEE=; h=MIME-Version:Date:In-Reply-To:Message-ID:Subject:From:To: Content-Type; b=HMYqcozx+tTIyJDPFFZ6m/8X57+RVS04e3avpHDK+zgwBZbkImerIAweSaacq6d8c12AFqfDPhCYeVU02Ywrtl1qjibvP0+LhE/vGz71NGfAuowdQqclbALAgamrzN3P6ubPR3vKY7smj0Yimp4pk4bCuPwRvV7zm/PFpG9Ea/8= 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.210.72 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-ot1-f72.google.com with SMTP id 46e09a7af769-7e63575a87cso7731563a34.2 for ; Fri, 29 May 2026 06:24:40 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780061080; x=1780665880; 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=rjDf0SNzXxR86/vaFMGsWuods9da0i8gN+ybnHjmX8Y=; b=ewcRYnu9dL4wQ3Sy/ssj1pvjbi8OldGTR+k2zpu9RDuhaVzxatnYqm2ofUzTRd+Q8p LJJKaHdsOhD/tSuwA1t5IydeZWKIxGE9DfRsR7yuygRasmuQAJyzW6NoGvWNPhMlodpI aREcv5iQDu2ovwMgdbcd/KUB2YMIzKYBGh1resevX8kN1hII9VM4RnJD2SU+en5X+iiR mhdCpd+ygQ+1QBQOgPbO62fcRyyQxhCoVJl1LShk/sVLtLnz4/WxNbp/0pi25mPT72sP XREtD0zMpWny/k+RR/y/m8l311593/F2iqiPuXtScdGF/1zRp2TZg2AJcmNJtqazZ0P/ mO/A== X-Gm-Message-State: AOJu0Ywq1pzDU7+GszsgApIaMgO8ds7I5ZPKV20nHm2OLewTourAU+KD H6ZovEzP1tWnh1PxCUhlGibsA45WsxPKYmQMACLLZhSpPIfFv6aDVfqudsN9JuxnZz93tSUGqRx 1c+CIXnWRQR76wNrs9kzX4XTVyZaysrerEDv0gdj4ANMVbBFO+Yhx3h8wAVA= 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:610:b0:69d:c5ad:40aa with SMTP id 006d021491bc7-69e04044fedmr1347406eaf.40.1780061079967; Fri, 29 May 2026 06:24:39 -0700 (PDT) Date: Fri, 29 May 2026 06:24:39 -0700 In-Reply-To: <6a10b30b.050a0220.19f61f.0003.GAE@google.com> X-Google-Appengine-App-Id: s~syzkaller X-Google-Appengine-App-Id-Alias: syzkaller Message-ID: <6a199397.0a9e871e.332604.0004.GAE@google.com> Subject: Forwarded: [PATCH] eventpoll: restore EP_UNACTIVE_PTR sentinel for ctx->tfile_check_list From: syzbot To: linux-kernel@vger.kernel.org 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. *** Subject: [PATCH] eventpoll: restore EP_UNACTIVE_PTR sentinel for ctx->tfile= _check_list Author: zhanwei919@gmail.com #syz test: git://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.gi= t master commit e09c77d94003 ("eventpoll: hoist CTL_ADD scratch state into struct ep_ctl_ctx") moved tfile_check_list from file-scope global to stack-allocated struct ep_ctl_ctx, replacing the EP_UNACTIVE_PTR sentinel with NULL because "NULL is the obvious 'empty' value and the zero-init handle it for free", and describe the change "No functional change". but its not. epitems_head->next is overload: 1: as a linked-list next pointer for heads on ctx->tfile_check_list, 2: as a membership flag: ep_remove_file() uses !smp_load_acquire(&v->next) to mean "this head is not on any pending ctx->tfile_check_list and is safe to free". Before e09c77d94003, the EP_UNACTIVE_PTR sentinel made the two role disjoint: a head on tfile_check_list always has a non-NULL next (another head, or the sentinel), so v->next =3D=3D NULL was equivalent to never list. With the sentinel gone the list is NULL-terminated and the tail head's ->next is NULL also. ep_remove_file()'s gate no longer tell never list from list at the tail, and misfires on the tail. The reader hold epnested_mutex + rcu_read_lock; the freer hold ep->mtx + file->f_lock. There is no sharing mutex between them; the sentinel was the invariant the gate relied on to skip the read side. The syzbot reproducer hit this within seconds on a multi-CPU VM. Restore the sentinel: initialize ctx.tfile_check_list to EP_UNACTIVE_PTR in do_epoll_ctl_file(), and walk it with "!=3D EP_UNACTIVE_PTR" termination in reverse_path_check() and clear_tfile_check_list(). The gate in ep_remove_file() regains its never list exclusivity and stop misfiring on the tail. ep_remove_file() itself does not change. This restores the invariant the file-scope tfile_check_list relied on before e09c77d94003, preserving the ctx packaging that commit introduced. Reported-by: syzbot+e70e1b6cba8714543f7c@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=3De70e1b6cba8714543f7c Fixes: e09c77d94003 ("eventpoll: hoist CTL_ADD scratch state into struct ep= _ctl_ctx") Suggested-by: Christian Brauner Link: https://lore.kernel.org/all/20260528-rotwild-summt-kuhhandel-7276ef4c= 33b7@brauner.io/ Signed-off-by: Zhan Wei --- fs/eventpoll.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/fs/eventpoll.c b/fs/eventpoll.c index a569e98d4a99..4973a5a5a3e1 100644 --- a/fs/eventpoll.c +++ b/fs/eventpoll.c @@ -1685,7 +1685,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_UNACTIVE_PTR; p =3D p->next) { int error; path_count_init(ctx); rcu_read_lock(); @@ -2438,7 +2438,7 @@ static int ep_loop_check(struct ep_ctl_ctx *ctx, stru= ct 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_UNACTIVE_PTR) { struct epitems_head *head =3D ctx->tfile_check_list; ctx->tfile_check_list =3D head->next; unlist_file(head); @@ -2601,7 +2601,9 @@ 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_UNACTIVE_PTR, + }; =20 /* The target file descriptor must support poll */ if (!file_can_poll(tf->file)) --=20 2.43.0