From nobody Fri Dec 19 11:49:59 2025 Received: from mail-ot1-f72.google.com (mail-ot1-f72.google.com [209.85.210.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 A883426C3B0 for ; Mon, 8 Dec 2025 02:31:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.72 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765161104; cv=none; b=HINDfr0nuBsaBmgpOBwjALTEFy4Eq0Va5uX/POTg9lF7ZERXPeuprY+GxO9mjLNwU5d1WWpPihQ3lsMjrVRD9/SOlm+TZAUOZXPNoj2aZ89v65jSkw2GvIe8ERhlFQIZfXbqD1HK9G39t4cxlD+XfIyKRD27NMzz3SKIY7cuwFA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765161104; c=relaxed/simple; bh=w2QPJZxiVRKWJGyUR7bgAirk8FUgE6oaByEvGoductQ=; h=MIME-Version:Date:In-Reply-To:Message-ID:Subject:From:To: Content-Type; b=LYCMqjCYkSO1Ey3O7+3h3ENDveH3FtlZjiVgdy2HJ4kCDSRVjY9Db/znnyP1KBgIRt7DOrxYJcH78Qx+EU92GUiy/Q9JiIccq+Yd0Isj/UZyo+bjPUyBpW1CF7sMGJK4vjZyoeLGU10Gv9XY8p1jf32tl24qJPHCqqidIJK53b4= 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.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-ot1-f72.google.com with SMTP id 46e09a7af769-7c6db96dfcdso8656143a34.3 for ; Sun, 07 Dec 2025 18:31:42 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765161101; x=1765765901; 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=oK/LBkSsTBl1BRD4yBaDOmjkkCL5Bsw1gI5BtKUh20A=; b=oG0bSxlTDDb2HUuSJY6n9BJChvS2xQJlMUk9ou4J/8YRTvsV8NVQnGG8QN/gB93pEd CwSuGEG+OX1zO03MHJ6vVKlqAqnKSzdGgzGt+QN3MVe1gqExLXD8a3qyN4YlvtUcO40o R+hxkbtJo6kUAM/fVPa93ag6d+0rP6AHVx0FoOYaFVcVXYQvuPnkAVQhL3GHLwQ4EpDI mpgBhFdEWt7YRZgtIH42vMvJSzbvNqcS0kxiaW12FWBdqURTI9kBsbBjl+owV9bME4fv RhV7kpR5jT23PgSE4yiBv5snOsr2f4NUvcz/NhATD4nF094aaIUwl7xfG9Kblp9zIOA7 jc+A== X-Gm-Message-State: AOJu0YwPtptwVmRqWHygtjF7w3j1UDuoME+dr78BHyzUcW4vVlYZ8a9b 4oS8ldKmtAD6Bfp0/QaOp4V/rCzAr6qAeIpgO+AysGhdtZhhK4ZeqcxO3G3/VhiGDw49tCSbhz9 yvxhWAtdcxvVMLQQz3Rvct1Rf8zGNeRzMyaIpsLT7Y6NDJK4pqOidumMXyWU= X-Google-Smtp-Source: AGHT+IHE590ixjc3MaFFQQFwUZaXqNvQbX+Q3cE8wfHulunVksP1jwBKgE/njVrGd1t8Zz7sVD/gRdES0kWGsCCtRrkjJuRWjTNn 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:2911:b0:659:9a49:9055 with SMTP id 006d021491bc7-6599a8eb365mr2776699eaf.32.1765161101428; Sun, 07 Dec 2025 18:31:41 -0800 (PST) Date: Sun, 07 Dec 2025 18:31:41 -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: <6936388d.a70a0220.38f243.0075.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 Syzbot reported a general protection fault in lru_gen_test_recent() when accessing memcg->nodeinfo with a NULL memcg pointer: Oops: general protection fault in lru_gen_test_recent+0xfc/0x370 KASAN: probably user-memory-access in range [0x0000000000004e00-0x0000000= 000004e07] RIP: 0010:lru_gen_test_recent+0xfc/0x370 The crash occurs when unpack_shadow() extracts parameters from a shadow entry. There are two cases where NULL pointers can be returned: 1. pgdat can be NULL when NODE_DATA(nid) returns NULL for an invalid or offlined NUMA node ID stored in the shadow entry. 2. memcg can be NULL when mem_cgroup_from_id() fails to find the memory cgroup (e.g., if it was destroyed). The existing code directly passes these potentially NULL pointers to mem_cgroup_lruvec(), which dereferences memcg->nodeinfo without checking, leading to the crash. Fix this by: - Checking if pgdat is NULL and returning early if so, as we cannot determine page recency without a valid node. - Checking if memcg is NULL and falling back to pgdat->__lruvec (the root memcg's lruvec) instead of calling mem_cgroup_lruvec() which would dereference NULL. Reported-by: syzbot+e008db2ac01e282550ee@syzkaller.appspot.com Link: https://syzkaller.appspot.com/bug?extid=3De008db2ac01e282550ee Signed-off-by: Deepanshu Kartikey --- mm/workingset.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/mm/workingset.c b/mm/workingset.c index e9f05634747a..335c2d34ac94 100644 --- a/mm/workingset.c +++ b/mm/workingset.c @@ -270,10 +270,18 @@ static bool lru_gen_test_recent(void *shadow, struct = lruvec **lruvec, struct pglist_data *pgdat; =20 unpack_shadow(shadow, &memcg_id, &pgdat, token, workingset); - + if(unlikely(!pgdat)) + return false; memcg =3D mem_cgroup_from_id(memcg_id); - *lruvec =3D mem_cgroup_lruvec(memcg, pgdat); - + 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); + memcg =3D root_mem_cgroup; + *lruvec =3D &pgdat->__lruvec; + } else { + *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