From nobody Fri Dec 19 11:52:30 2025 Received: from mail-oo1-f72.google.com (mail-oo1-f72.google.com [209.85.161.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 26C232566DD for ; Sun, 7 Dec 2025 15:31:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.72 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765121474; cv=none; b=kyv0Q2pegB9+eH13m/sW8oeeANwnvcGViLPEBMXISBagO15Ga9KfmKqNsnPKsxxEU1k8pf8Uma2TAMVgSguiXtmUpgJIWtkBgBUZHNqvrrd1ha/T+x2SfXzCq5ELWq+PMNSEGNtu2095jtXtlEzAYbWymfZfa06Rc5p0PKaa2fM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765121474; c=relaxed/simple; bh=tsejdY2MLZnP73soHa0i2BvsE8o26LWE7qfyBXTqhIQ=; h=MIME-Version:Date:In-Reply-To:Message-ID:Subject:From:To: Content-Type; b=DoYhytlAHQxVNo7Hpj0XSc9iwaKt66JUhR20hK/abmBosiP2LwRrhUGUaLZtATfqmqYZzx+VGM8KWMORSD14Lqf1tqshYscwE+fBl/X9sqlEUKF0wvOtr2n8rI/WnvyrkS3vMnEL3QTmyQQNC5rN8hnqszk5FNMwWlWFKuthEo0= 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.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-oo1-f72.google.com with SMTP id 006d021491bc7-657a467228eso5611905eaf.0 for ; Sun, 07 Dec 2025 07:31:08 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765121467; x=1765726267; 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=lK3ilEZ6dpTkUqintnnrgGkC0G5eG31SnrMhhyakTKw=; b=ROFTzJ/RjRzEoveHJutLHT4v/U86Z/1h8hL/WKKid3srKh4GIFFHl36diDhVoejTEJ 3An67N1A1EIr/6/DkCUGNC7LlpAis0FvMdGRisj0XqfP+iMWwmH76XpHEaUWoKKndw5n SaDygzh63UF1RGvZutQZ9bw+JxPs3RW1/o45JVRrAuorAKlvl0E2peI1DfD66EDCsRWp NE7yEndiAM9vBW4s3i8uIGkKa2jsfb2G0PVB9Rnk1N0i7FuwtmFzK8CTEOIQJXV+f6WK bL6wP7WRO9Ww+b411/0wAKK7nuOw7J1e7cylgs25+oxWgDG3LI06sGxGFuaMQlsqGdKP jkwQ== X-Gm-Message-State: AOJu0YzT0PV3whRRuIulzRovnLrxsAIC11dBUl+sfWFFAfbxKnY+Bhzu V5bxBbGLJkWNmurfmL3UddMJzdZ4PBAuL9AhQFTKQ5h0vBMIEw0rl2KKkuLA6yvY7PqXBMhfT0e h5ZgLMPED2ppmwYVYNMcFR5BG8rNd036S5WyG2PEpjZMfn8YHRMnMbdLqqFw= X-Google-Smtp-Source: AGHT+IF90CV9DZlorni978mzzxoW7OCtipROZItLQEX0vzbQDCQfSarXaYpraYeYhArzYOPoER+fZEO2b6kKtPD30xELBp84sy7O 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:1c9f:b0:659:9a49:8fa8 with SMTP id 006d021491bc7-6599a8e6838mr2095353eaf.33.1765121466882; Sun, 07 Dec 2025 07:31:06 -0800 (PST) Date: Sun, 07 Dec 2025 07:31:06 -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: <69359dba.a70a0220.38f243.005e.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 | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mm/workingset.c b/mm/workingset.c index e9f05634747a..8166793b38dc 100644 --- a/mm/workingset.c +++ b/mm/workingset.c @@ -272,6 +272,8 @@ static bool lru_gen_test_recent(void *shadow, struct lr= uvec **lruvec, unpack_shadow(shadow, &memcg_id, &pgdat, token, workingset); =20 memcg =3D mem_cgroup_from_id(memcg_id); + if (unlikely(!memcg)) + WRITE_ONCE(memcg, root_mem_cgroup); *lruvec =3D mem_cgroup_lruvec(memcg, pgdat); =20 max_seq =3D READ_ONCE((*lruvec)->lrugen.max_seq); --=20 2.43.0