From nobody Sat Feb 7 05:01:09 2026 Received: from mail-pl1-f180.google.com (mail-pl1-f180.google.com [209.85.214.180]) (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 155CE313523 for ; Sun, 18 Jan 2026 10:58:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768733908; cv=none; b=YUSbdO55vpc9aQON5yQq2oiQH0GIWNnxFj+qNBWJA75NSgTQTTVoFNbjMM/dQe1gLBN6IctMB4VJpzclhrw5Mnko53JD/XCKjiq4LlZN0A21jORrcr/HaAr05NZatRu1WjraT8M7ZLKpwcSCYD9XdEzRg4L9lKpN1zSHGwwhUXY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768733908; c=relaxed/simple; bh=8y9zVKOLqfh0+p4JgGYrIvs7Wnj3ApFmMpfqOFPecs4=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=ZwsKrMhuWdLJR4hBlWbQKQ2ESoPDQEct8A8GZY/y/UYxtPgDrZLkfTzmcu4p6Eg8EVTdfjtGsY0Lz+Dl35wG35A0fiSkw/+LVaFghD53Hb2+aZHQZGGwpwMLrn3kqNDwvSrKzgf0jp7F+zCjza5iDg0pJnjqs14hqM31c4KSH+8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Pd4F5+KT; arc=none smtp.client-ip=209.85.214.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Pd4F5+KT" Received: by mail-pl1-f180.google.com with SMTP id d9443c01a7336-2a09d981507so24962985ad.1 for ; Sun, 18 Jan 2026 02:58:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1768733906; x=1769338706; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=efB5jJg9txWaP3Srv2/3fTGgn87O8iEs9FizbGyzl88=; b=Pd4F5+KToEDaw0b+lKU7UC3pQqOb1qykjGW+4owB19oGWiZTkUXYBLAh78FuVEWiq7 IhoBd79rqCMXvyE6wh357e+rmGTDnjwDsTCTd+QyHdm5BKzR6P9X1A3y1kJXie+Ds+Oq GN38+Ml4RlpLCIenGOHAXKzOnduLHMXom+l7mkZCmhAp4NFz7jIBqd5ngyJ4+eqESc+i /Raii/1tfS7j2b6dG7Uu/c6YlCP5w1NsLvSge6eDlH6S7Uj5kcvzXxQLwJwigr1i2NGP 0HXLDLF13kzUaFGnfoBeXoxYJQ3T30UC6DLOlE4yFxFmSofK4h+GBikhvHtlGff6YYiD KLGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768733906; x=1769338706; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=efB5jJg9txWaP3Srv2/3fTGgn87O8iEs9FizbGyzl88=; b=oDGlrF/0NBpZmk2mFw4z1bcq726pv7JASR0+pBF2DJkBdn3P8Cy0ToFOZ07TVJB4ha J+WO+froFAfVGTKGp5GxzXNPOe2Mio1Cw73iH244xqGuo30sBtQ+rOcwEHsB2eF13vAa 9YIBfWs/VKyw3y3Ir+5uouInswgcLlWJncKvP026BOy7C04wrsTFloV/XKqGnUd5Wvoz ca2NaN65vkk4cdEbSEPDNn5RgWxs9H3XtPTfrkSnkIOTddKoB1r1fkXXb0zQbVQIqe1L 1826Fezm1ziBKu5PzBU2Ri1ARsFOlT1J6b9HiX+1+wYzjcwia9i46HpUluvwYCvfa6Nk qvcg== X-Forwarded-Encrypted: i=1; AJvYcCUVzJngZIDI9FBlJ2ULVaHpOx4NcASaR1+X3Gn8SCIwUs3cgmSbTzerE7Aiay9Zn2Y43LTOtN1feP6eZU4=@vger.kernel.org X-Gm-Message-State: AOJu0YxGmnKOVEBx0Z2qsmAOJIyrPQWs7XlNJxN+fLp9PR4nNRpUoxmS 64y7Fs+TEV1Nk8djupW8TQqn7SwVXTgY1mKRvUOBrf01lCleC+3+uPtFytDOIQ== X-Gm-Gg: AY/fxX7s+SvNmU1/1s+XfOXShazKBK63JgwHGw13c9r6cz1Xdk6COG0qln4gthOXJjF RGydVyxHCo/uyn8jFR38+SpreHy5b4pIrapsKk4oQ/uYZarMbUKqYzls4bNCGdM6pA3gVLa9XcC fvu5sJ+Fu5vWtIx7iSbYvVfdQbnLpkgOgO7R/SwCAfqYSKoJ3a7X9JGioEK3Fy+GDToO8uWdPI0 /nlGDKlmzdcx/uJQhqMhilXWG+nuzX3dgbrwWqOCG6f2aGWT3Io3YKdwMfqY8S3GHsgL/TDbNMw AsbGYElX8xghnTi7+jPoT5d/Fl8e2N7Iyz9FFQGVCQ2efyJu70MccBjIMamDxVvSOFqM+dmCyQd 5B8liiKj1/UaZ83tF7MuIcH3tVF3ByGaKmCjVkiWhFt2V7+zeVTLUP7A2QTa6Y5v9jooq+KLEzo wBxnP5lt63MDSx3iRfu+1F2vQIJPPGWTNejaubzG6rM3Ry5Dl2dgoUOXPg7N+v1yfu+kU= X-Received: by 2002:a17:902:f686:b0:2a0:e5c3:d149 with SMTP id d9443c01a7336-2a71780a3e3mr69817635ad.23.1768733906219; Sun, 18 Jan 2026 02:58:26 -0800 (PST) Received: from deepanshu-kernel-hacker.. ([2405:201:682f:389d:68d0:4222:6b49:f651]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2a7193fb239sm65708265ad.70.2026.01.18.02.58.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Jan 2026 02:58:25 -0800 (PST) From: Deepanshu Kartikey To: akpm@linux-foundation.org, david@kernel.org, lorenzo.stoakes@oracle.com, riel@surriel.com, Liam.Howlett@oracle.com, vbabka@suse.cz, harry.yoo@oracle.com, jannh@google.com Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Deepanshu Kartikey , syzbot+c27fa543e10a45d4e149@syzkaller.appspotmail.com Subject: [PATCH] mm/rmap: fix unlink_anon_vmas() handling of error case from anon_vma_fork Date: Sun, 18 Jan 2026 16:28:17 +0530 Message-ID: <20260118105817.1270617-1-kartikey406@gmail.com> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" When anon_vma_fork() encounters a memory allocation failure after anon_vma_clone() has succeeded, unlink_anon_vmas() is called with vma->anon_vma being NULL but the anon_vma_chain populated with entries that are present in the anon_vma interval trees. This happens in the following sequence: 1. anon_vma_clone() succeeds, populating vma->anon_vma_chain and inserting entries into interval trees 2. maybe_reuse_anon_vma() does not set vma->anon_vma because reuse conditions are not met (common case for active processes) 3. anon_vma_alloc() or anon_vma_chain_alloc() fails due to memory pressure 4. Error path invokes unlink_anon_vmas() with vma->anon_vma =3D=3D NULL The existing code triggered VM_WARN_ON_ONCE and returned without performing cleanup, leaving entries in interval trees and causing memory leaks. Fix this by detecting the condition and properly cleaning up: - Iterate through the populated chain - Lock each anon_vma - Remove entries from interval trees - Unlock and free chain entries This prevents both the warning and the resource leaks. Reported-by: syzbot+c27fa543e10a45d4e149@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=3Dc27fa543e10a45d4e149 Tested-by: syzbot+c27fa543e10a45d4e149@syzkaller.appspotmail.com Signed-off-by: Deepanshu Kartikey --- mm/rmap.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/mm/rmap.c b/mm/rmap.c index f13480cb9f2e..acc8df6ad4a7 100644 --- a/mm/rmap.c +++ b/mm/rmap.c @@ -477,7 +477,31 @@ void unlink_anon_vmas(struct vm_area_struct *vma) =20 /* Unfaulted is a no-op. */ if (!active_anon_vma) { - VM_WARN_ON_ONCE(!list_empty(&vma->anon_vma_chain)); + /* + * Handle anon_vma_fork() error path where anon_vma_clone() + * succeeded and populated the chain (with entries in interval + * trees), but maybe_reuse_anon_vma() didn't set vma->anon_vma + * because reuse conditions weren't met, and a later allocation + * failed before we could allocate and assign a new anon_vma. + * + * We must properly remove entries from interval trees before + * freeing to avoid leaving dangling pointers. + */ + if (!list_empty(&vma->anon_vma_chain)) { + struct anon_vma_chain *avc, *next; + + list_for_each_entry_safe(avc, next, &vma->anon_vma_chain, + same_vma) { + struct anon_vma *anon_vma =3D avc->anon_vma; + + anon_vma_lock_write(anon_vma); + anon_vma_interval_tree_remove(avc, &anon_vma->rb_root); + anon_vma_unlock_write(anon_vma); + list_del(&avc->same_vma); + anon_vma_chain_free(avc); + } + } + return; } =20 --=20 2.43.0