From nobody Fri Dec 19 11:49:32 2025 Received: from mail-oo1-f69.google.com (mail-oo1-f69.google.com [209.85.161.69]) (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 9E4EB3B8D7E for ; Sun, 7 Dec 2025 16:08:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.69 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765123682; cv=none; b=QoPp4NrCf0kKIxiHxCT4Y/YKe84kLbQ6FCVQEqTOeZzwWONf3WP4d5YcWo0V+jUsx7kjCOzGnepZnU0SWy+kbU0YwgmymfP9KFNf0I8XJeM5g4H0RjJ0qCQnZAstIpOX6gq0RX+zY926blAN1Qg95x7ts3iGJLl39Kz41HNyLAQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765123682; c=relaxed/simple; bh=wQ+lkBx/n1OHnH/CoxY6VTVr+d9crPyu0upZsLheBfM=; h=MIME-Version:Date:In-Reply-To:Message-ID:Subject:From:To: Content-Type; b=UN2tfRh4JclFYJWbeOoYQH4r3jF5k5bex5Ppp6zbeZOau66MDMG0Gw8Ezz/JVc/lz08O9mFPab7lh1YBQHWS5ID0Jwn0a1QrEEX67tKJi7PrwMYDtGKgWR1kOUiQOLJ6NLhyhx9gHQABgI7hF/rS1PKr+9o4dAkHiTLYA02JAYw= 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.69 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-f69.google.com with SMTP id 006d021491bc7-65742f8c565so5814186eaf.1 for ; Sun, 07 Dec 2025 08:08:00 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765123680; x=1765728480; 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=yeroxCE/PZ6IWpI975ulyfq/qWdXdQUnlw62HxZHAd0=; b=gz5/slAr6cxHk4DQRlQgXMBOHpWsoWFk9g75+VPm2gydGgYfYfCQxHa5xz4rq0YPvY 0zgYqZ6BJRL8xwUUyxDWRy6YaCNtNLdLheG71wpkiQt0ZFaR6eVr52SQnha4P/mQidJU X0qGL3tNvbAtI7m7LhPwvGZjvDXAEgANy6bny0MmsnCM9KGd3r8W8TGllUHCzpX87uYO 3YrxM5k5uEdUBD7xo1E9OF8GXamrGjje1h3OKYO9qzYSTNCfIHuNOXxUkq7Ia59Wsog7 8L0Yzh52ozYoeWYiT2erSvXOJlK5F+0y8A1XgzAVjftbxf0n5pRyyo+h6tJSxXkvXAzW nUGA== X-Gm-Message-State: AOJu0YxL7Z1PCXw7aWPdjhDmGvLzy/C2zh3D6x0qW8hK/B1Y2uj4eIiT X1kSZIf640GNZfTa3yWGlmotIdcPJMDn+UTYyEEL6q0O1vFWsvgACTrUqxszW35Lmo+ygCK22ln DEbPcY1aSdSyaln/m0PsqAAwto9bacISAC+4gd92JxPHv73XqTWf4mBjlSV8= X-Google-Smtp-Source: AGHT+IECziznPcuecWlw/Tvhm9MUpP8xNnwMIzNiVZYo7NI81zsnk+s8L+t1fatfoIdNgOfi5xfvyBeaJEksQ55qEV+ixEsN04Yk Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Received: by 2002:a4a:ee98:0:b0:659:9a49:8fdb with SMTP id 006d021491bc7-6599a99941fmr1851101eaf.84.1765123679727; Sun, 07 Dec 2025 08:07:59 -0800 (PST) Date: Sun, 07 Dec 2025 08:07:59 -0800 In-Reply-To: <693540fe.a70a0220.38f243.004c.GAE@google.com> X-Google-Appengine-App-Id: s~syzkaller X-Google-Appengine-App-Id-Alias: syzkaller Message-ID: <6935a65f.a70a0220.38f243.0063.GAE@google.com> Subject: Forwarded: [PATCH] mm/workingset: fix NULL pointer dereference in lru_gen_test_recent 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] mm/workingset: fix NULL pointer dereference in lru_gen_tes= t_recent Author: kartikey406@gmail.com #syz test: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git= master Add NULL check for memcg in lru_gen_test_recent() to prevent crash when mem_cgroup_from_id() returns NULL. The crash occurs when a folio's shadow entry contains a memcg_id that no longer maps to a valid memory cgroup. This can happen when: 1. The memory cgroup has been deleted/freed 2. A folio was created without proper memcg association (e.g., during procmap_query build ID parsing via freader_get_folio) 3. The memcg_id in the shadow entry is invalid or zero When lru_gen_test_recent() calls mem_cgroup_from_id(), it may return NULL. The subsequent call to mem_cgroup_lruvec() with NULL memcg triggers a crash. Although mem_cgroup_lruvec() has an internal NULL check, the crash occurs before reaching it due to compiler optimization. Since mem_cgroup_lruvec() is an inline function, the compiler calculates the offset memcg->nodeinfo (0x4e00) before the function's NULL check can execute, causing a NULL pointer dereference. Fix this by introducing an effective_memcg variable that is explicitly set to root_mem_cgroup when memcg is NULL. This approach forces the compiler to use a separate register/memory location, preventing the premature offset calculation that caused the crash with a simple in-place NULL check. Reported-by: syzbot+e008db2ac01e282550ee@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=3De008db2ac01e282550ee Fixes: ac35a4902374 ("mm: multi-gen LRU: minimal implementation") Signed-off-by: Deepanshu Kartikey --- mm/workingset.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/mm/workingset.c b/mm/workingset.c index e9f05634747a..6a45e98317e9 100644 --- a/mm/workingset.c +++ b/mm/workingset.c @@ -272,8 +272,13 @@ static bool lru_gen_test_recent(void *shadow, struct l= ruvec **lruvec, unpack_shadow(shadow, &memcg_id, &pgdat, token, workingset); =20 memcg =3D mem_cgroup_from_id(memcg_id); + if (unlikely(!memcg)) { + pr_warn("DEBUG: memcg is NULL (memcg_id=3D%d), pgdat=3D%p, returning fal= se\n",memcg_id, pgdat); + pr_warn("DEBUG: shadow=3D%p token=3D%lx workingset=3D%d\n",shadow, *toke= n, *workingset); + return false; + } *lruvec =3D mem_cgroup_lruvec(memcg, pgdat); - + pr_warn("DEBUG: memcg=3D%p, lruvec=3D%p, continuing normally\n", memcg, *= lruvec); max_seq =3D READ_ONCE((*lruvec)->lrugen.max_seq); max_seq &=3D EVICTION_MASK >> LRU_REFS_WIDTH; =20 --=20 2.43.0