From nobody Fri Dec 19 11:48:18 2025 Received: from mail-ot1-f69.google.com (mail-ot1-f69.google.com [209.85.210.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 13115275AF0 for ; Sun, 7 Dec 2025 15:38:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.69 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765121899; cv=none; b=YzzlPiWJtiGGjga2VngRuY1/HPpq8qTyNA/rB0+qZVWQHTPCajeXzmJ/acbRX7Ki3eb2VrD1ODMwZ7ybC8ImWrOHZV5zzx/zblLWn3FQ/aCMNyUPexfMGKmGcTY5u8MlzrgHNNR4djWo/NqncmYxfOQRymofhLFReZoJF+TDQhs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765121899; c=relaxed/simple; bh=PVC4EeXsX625kw9ZZdgQsFDwQ2xnm2y7kGQNIbw42Fg=; h=MIME-Version:Date:In-Reply-To:Message-ID:Subject:From:To: Content-Type; b=DqTbFqKI8vI2D6765148loUhLckHhDooy6x4+oBE9g+sU30h1QozTL+dtU/WVRlTQg+gcp12VYOT+m1a0EHbeSfI/tGjYIqSDCzM7BW6zMGUqGZnNHkrzR7ERCQWsxEXQWyz6lX3Avwf/lE2zhDOMHOT30uXdXf64/+4Ukl7BQ4= 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.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-ot1-f69.google.com with SMTP id 46e09a7af769-7c982b11ccbso224517a34.0 for ; Sun, 07 Dec 2025 07:38:16 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765121895; x=1765726695; 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=05Er7y+eLMtuw5N3mDalHFwCNA5DdZawV5PWDhC0Xy0=; b=Nev47Gilsx7RRR06qI1WGciXTwbbyGyMJahQW61ZsuvKDHeDmw6mDwo4D8zk9nuqk8 A6sokBAfUCZr5zbIf1gsYZRKlMc7Ut8WS9Ofc0s8VLRKwGMr6z34S/KXQGMkqw6Jlxjh tROTrvXsGJd29EiUomzU0AePjKQypFnch3lFuCf+yUdib+UzbtXQ3M9QomDDPZjtlfcM ZU2Z11UrJSjsNGGsU6TUKKi/8kr8g3ONFj9udxBeAKqjuwshMHw28pItl94464obSWx1 i8fcaXafmwfWvN103TKgBNrluEkiT9OBXZeYaUemb1Vi1JnCEw1TW+l+yUgcVlxc2XvI jMag== X-Gm-Message-State: AOJu0YwWBNxvK4nQnA85zj5ZLqoNsWIvuJKmIRsvxi4aBBH6e8fStBRy LrBKyfVqLbCpolw2FrTkArLcvh+BBx/VyqahZBctysg0nG0jXTDPQySq5MITYRCy7olWavFGj66 Ppbu/hhurBpjHYq7aL6uUm/56THzSt7eXcX20TI3nqytnue7Mw3rO9IZ+zEI= X-Google-Smtp-Source: AGHT+IEHBp9+qgx9g3xoJCIhTT7AKuFYOYYFgHOPeAUBZdkXPH6BDKJqs3nFsBg5ZFxuje0mTlIMQVaWvt29p31MAagck0++f174 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:308b:b0:659:9a49:8f62 with SMTP id 006d021491bc7-6599a9612dcmr2123970eaf.39.1765121895440; Sun, 07 Dec 2025 07:38:15 -0800 (PST) Date: Sun, 07 Dec 2025 07:38:15 -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: <69359f67.a70a0220.38f243.005f.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 | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/mm/workingset.c b/mm/workingset.c index e9f05634747a..4fa33b57f0ca 100644 --- a/mm/workingset.c +++ b/mm/workingset.c @@ -272,7 +272,11 @@ 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); - *lruvec =3D mem_cgroup_lruvec(memcg, pgdat); + if(unlikely(!memcg)) { + *lruvec =3D &pgdat->__lruvec; + } else { + *lruvec =3D mem_cgroup_lruvec(memcg, pgdat); + } =20 max_seq =3D READ_ONCE((*lruvec)->lrugen.max_seq); max_seq &=3D EVICTION_MASK >> LRU_REFS_WIDTH; --=20 2.43.0