From nobody Fri Dec 19 11:47:15 2025 Received: from mail-oa1-f70.google.com (mail-oa1-f70.google.com [209.85.160.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 631D024290D for ; Sun, 7 Dec 2025 15:05:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.70 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765119925; cv=none; b=U5wpW5WICWoli0AA2MsTJJhu6oLr5j5A7IaPQq4VXBwIUNYmlR/obFjLXxbANXF8bEj8px/SYjlwKpLhN1/adC9SIJfc95WJlNhxoKEOeCdi1hvH2l8m7VDxWU0wrG6uzPSNj4StgPry/aNW6aWfM59t39dcUnlsYWUWgvfqG3A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765119925; c=relaxed/simple; bh=eRbT3u1BXyDpIsXHfoxp0HdYBkDaw6bV8Yt7d9Vv1Qg=; h=MIME-Version:Date:In-Reply-To:Message-ID:Subject:From:To: Content-Type; b=ah1UC2qi1OgYpQLDMh6ltfkMqa0T7dLanfBELYvQRpzUktC/7EsoYYZEH19KWbSZhCqNqGGKnP7/X5n5K9epf0SoXgnZ8n+wvAnlCq8jP0gvdv+PSk0YBcTptH47WpFptV8uJa/Gq1W4vCxDb88CgbsIyj9dPJkhB0afYvboatI= 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.160.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-oa1-f70.google.com with SMTP id 586e51a60fabf-3ec31d72794so8875082fac.0 for ; Sun, 07 Dec 2025 07:05:21 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765119920; x=1765724720; 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=UBafrJ8MCSOv0s6nS14fIn1tqY+YyqRQ3L7J67SvVQY=; b=Pi1fM1+qjd1RifM4VrQvt0LodPfkrbDnFDQZL9qiWr2twxMYz/U1RzURmN1aDjRZXU tNGqnKjKiFWJrFmo9bDK/oBAISXgs+HmPyllw+yspz6Qb0QRfuzBNu+dUbrD7SdJOPs3 Ln/39GjStveetzcwCqdJV7K3FULJfxlRpRoZJDCvM2iWRNINe62SHhhkhokt8W42zR6e 2OegXydtwhlkwSRLS5JOKH6CJ1OY/HCqjpKgXyE6/C5iukGROntsABHDJDPqd9xZZCIP kdLfYY/gKPA5P0HA6gilWwSOS3hCBZy9d+Zy4iHhklPKkf8CjNnGImFYhnVZrmdvCXGN NyZQ== X-Gm-Message-State: AOJu0YzoGGfiroE5EhYCtB7GjZdg+XzGSnzi1kR3OWBSDZmwOpVKKew6 RRZ31UKBhOwdXZ5s82mQoMm8aTC0nNK6DkrYRDw3u+4YPcRCvYE+o34QD3Fod3bvYkBsDtLQ29S RyFtMN2j8hL27/0uTMfT8SufxVEY5zYz8BM/UCkYKn7OgVct05XTLxl0fgKo= X-Google-Smtp-Source: AGHT+IHJusz+hmU8mRFBQLqvS/yDf7k9bbLn3OMLsF+Y0EdmZz9Po5+lBJV5t1brGFpTkI6kmmVrPrJ2FyWk4R3wsN37WYN7sMGK 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:851a:b0:659:9a49:8e29 with SMTP id 006d021491bc7-6599a499d46mr1671072eaf.27.1765119920502; Sun, 07 Dec 2025 07:05:20 -0800 (PST) Date: Sun, 07 Dec 2025 07:05:20 -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: <693597b0.a70a0220.38f243.005b.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 Signed-off-by: Deepanshu Kartikey --- mm/workingset.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/mm/workingset.c b/mm/workingset.c index e9f05634747a..847580173fb0 100644 --- a/mm/workingset.c +++ b/mm/workingset.c @@ -272,8 +272,15 @@ 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); + pr_warn("DEBUG: memcg_id=3D%d memcg=3D%p root_mem_cgroup=3D%p\n",memcg_id= , memcg, root_mem_cgroup); + if (!memcg) { + pr_warn("DEBUG: memcg is NULL, using root_mem_cgroup\n"); + memcg =3D root_mem_cgroup; + pr_warn("DEBUG: after assignment memcg=3D%p\n", memcg); + } + pr_warn("DEBUG: about to call mem_cgroup_lruvec with memcg=3D%p\n", memcg= ); *lruvec =3D mem_cgroup_lruvec(memcg, pgdat); - + pr_warn("DEBUG: mem_cgroup_lruvec returned successfully\n"); max_seq =3D READ_ONCE((*lruvec)->lrugen.max_seq); max_seq &=3D EVICTION_MASK >> LRU_REFS_WIDTH; =20 --=20 2.43.0