From nobody Fri Dec 19 11:50:38 2025 Received: from mail-oo1-f70.google.com (mail-oo1-f70.google.com [209.85.161.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 D95E0273805 for ; Sun, 7 Dec 2025 14:35:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.70 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765118149; cv=none; b=ce0nyvgnuxZorVo8pAkdh4FOGnjekInRFKvT6l5D0aY30tF94wqiWUI1ep220oaLh4Oy6H2AT9UowuvRkhhH6DbXNc31Kcq6z+ycq4uL/dVXUm7UgDr2K0J7ez0UtCEk0VLUtXqpUMCqECmSxA8S4yisXCsYrXqL52Kdi0vXVHo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765118149; c=relaxed/simple; bh=Oq1hpbTmBuF06FRZ3UKSPqhQBAj7MR1CDe1F0MWi2T8=; h=MIME-Version:Date:In-Reply-To:Message-ID:Subject:From:To: Content-Type; b=UCCK/chk0rlgdVTHYdYdd5qQw7m+7Iu+wbTsWTHlIdMJUyX0EkAnpS0oDpvAn6xnZlULcotXXTyX4TU0j245ScV2D25mR9Llpp1wDvQy9BkaTj6zt99duRsVPrulyQSr9NZeXD1OSX/y6fr9T86Bj5eF1CAJwDcAG1UK9vZMyOI= 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.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-oo1-f70.google.com with SMTP id 006d021491bc7-656b2edce07so4798354eaf.0 for ; Sun, 07 Dec 2025 06:35:44 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765118142; x=1765722942; 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=gSFUsyXhZ40Zo5nmZlMbdYemn1QY6WrQ1tAfWvex0bE=; b=Mn3PxfOcXv/tZiRnM44/KqBp3+muKOkdVvYy6D+T0mjrvwfNtKW4gRtOJ5Lp701br0 oqzsTndXLbB67RDZ85duzPwopIBsn8qXKxvlWbIBR8OAhn4AIkkpthjOXbPIblSOmFtl A1m2ZwCyoMjuUoBy6j2hyvIiXWYdPDVUG4y6nwmADaBzKcWPPHv5t+S4jHVu54dyTjuO bsXXgncbw/A8YRhscMKuvY/pvVT9cISdB3cL70ZWdDNVY13zI5NrbXm0efkN4VgLdoNV NmXeSKtPcrUi+me1quH2WeUXyd2gDzUjUp9Msyn9ycZF2Oa3ENK62EZl2tVBg8KgpUiD 12LA== X-Gm-Message-State: AOJu0Yz09POF5gB8uJqbkLDnFoZ9OgyWj0cnubdaitL6P1hXouz6oKB/ T6yAoL5QLCi3JU5H/v4JECAZGi/2VS4ogPjJKrfiwvs0PmWq8vAsu2cZmed7Kpfzx+QwGp5sw/b XsUMcbKRoKF7bNRqW5cAmX5wc/Rw4bZsckbgoeottVIZNaUBtkLI/SJD68Yg= X-Google-Smtp-Source: AGHT+IFcH4zAWe46AKIjNTd0emWnw6YMoHYYZVx25HMR/t8Bvq8qBDhziqDd4q2OhD/7LfjMIfxbu7eF8OZxXCxxScG2LtoKXgkp 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:f027:b0:659:9a49:8efa with SMTP id 006d021491bc7-6599a89fc5cmr2174202eaf.11.1765118142663; Sun, 07 Dec 2025 06:35:42 -0800 (PST) Date: Sun, 07 Dec 2025 06:35:42 -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: <693590be.a70a0220.38f243.0059.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 | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/mm/workingset.c b/mm/workingset.c index e9f05634747a..dad8b16af105 100644 --- a/mm/workingset.c +++ b/mm/workingset.c @@ -266,13 +266,14 @@ static bool lru_gen_test_recent(void *shadow, struct = lruvec **lruvec, { int memcg_id; unsigned long max_seq; - struct mem_cgroup *memcg; + struct mem_cgroup *memcg, *effective_memcg; struct pglist_data *pgdat; =20 unpack_shadow(shadow, &memcg_id, &pgdat, token, workingset); =20 memcg =3D mem_cgroup_from_id(memcg_id); - *lruvec =3D mem_cgroup_lruvec(memcg, pgdat); + effective_memcg =3D memcg ? : root_mem_cgroup; + *lruvec =3D mem_cgroup_lruvec(effective_memcg, pgdat); =20 max_seq =3D READ_ONCE((*lruvec)->lrugen.max_seq); max_seq &=3D EVICTION_MASK >> LRU_REFS_WIDTH; --=20 2.43.0