From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=217.140.110.172 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796311520; b=Zia8K2R7Xk/NNuXtTg0Nuqvu/8WY587uSuwlYZUFouO7Q6lzOU9tj1qAT+8vL12XP+j5 FNf9iOGhz3eg0sa5umjWrAsFg3CsS47ewYdcEfMwigT6R5zvt1aNBhgrq9SzhHJrjJp2h LbK9yFb/mCbreugqdHEHCdgzaoMNuom66jMdibSUEwBGQOVgosVbbAgM6Do0ZM1G6MawE 0Px9nPaZ4a9zOibUXN6CLAGKdGSfFkAFYORxOVTBxz+UbHWuf6Yoyd26947glyV0fpWYC gS3tU+5xXHk/XrvXB1jtDXWFfkGaxJ4CSH1yzTrxBWkOMuHc0lbvOoqfYrqPFxmORbA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796311520; h=DMARC-Filter:Received:Received:DKIM-Signature:From:To:Cc:Subject: Date:Message-ID:X-Mailer:MIME-Version:Content-Transfer-Encoding; bh=fWuIfaizJNZr/QedEhuojpOVLh73J8wKCos5+2JtcJE=; b=u69G3WlpfztiecDVfoZQ4ynjk8VYj+6UFwoiWOYmpUkprQBEG6LnY3oxLCPQPtdQhxAQ uxeGaUXkVeTduNZPlzMcI+hL+QYg0uXq2dUciyCHTmALI0xwotQ3vNJ6etlbKmbOw08eN RFuQlb4/ogPyB5/Db0dtSPS66V48klJpSkKFNuc0Nw++5uKIJqfsbRwKRJQ4RrdlFKCUh WcODaKw8mMqN1ykS3eITGF6QZYLwjOjeoL1ugN6myPY22QFdo73ogM+eWKeuJ04kF+v7s tjuylFIDUf51jwxBrt7G9W98ktzuDZNzY3a36ia4MqL0qSkOH+oYCjyZ+eLyjKbRxiw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=arm.com; spf=pass smtp.mailfrom=arm.com; dkim=pass header.d=arm.com header.i=@arm.com header.a=rsa-sha256 header.s=foss header.b="C9yBK/Y8"; arc=none smtp.remote-ip=217.140.110.172 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BFC56606A322 for ; Thu, 3 Dec 2026 15:25:19 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org BFC56606A322 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.a=rsa-sha256 header.s=foss header.b=C9yBK/Y8 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 6518D497; Thu, 3 Dec 2026 07:25:16 -0800 (PST) Received: from gaia.lan (usa-sjc-mx-foss1.foss.arm.com [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 16CC63F7D8; Thu, 3 Dec 2026 07:25:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1796311519; bh=/SiLibIbZSYGObEi5bQFz/znXQyv0U3/eisw0Suiivg=; h=From:To:Cc:Subject:Date:From; b=C9yBK/Y8+El2q7If55JxKz1fYrM2jAK1SlsKijp03yB6DNKCAsFmzo7AKrlHD1PlV O91Q+RrQ//NTFGMuATUqaBb+MVQYlR5NpwYuu6h9jtsx4k93fmpQUqIFuR82Wmc5F2 4YMl1gpQaupZxXv60zKoyZKmmlJ5y54MhSX/FLIk= From: Catalin Marinas To: Andrew Morton Cc: Weilin Tong , Breno Leitao , David Hildenbrand , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 0/3] mm: kmemleak: fix the disable-time cleanup races Date: Thu, 3 Dec 2026 15:25:11 +0000 Message-ID: <20261203152515.2270778-1-catalin.marinas@arm.com> X-Mailer: git-send-email 2.47.3 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Hi Andrew, Patch 1 here supersedes Weilin's "mm: kmemleak: serialize disable-time cleanup" in mm-unstable, so I think we can drop that one. I reviewed it but Sashiko found more problems in the area, so here's a more comprehensive fix. If you'd rather keep it (it's harmless), I can rebase on top. This series is based on v7.4-rc1. When kmemleak is disabled at runtime, __kmemleak_do_cleanup() removes the objects without kmemleak_lock. A "clear" written to debugfs can run a second cleanup concurrently with cleanup_work's (reported by Weilin [1]) and callbacks such as kmemleak_free() that passed their enabled checks before the disable can still update the object tree and list (reported by Sashiko [2]). Both corrupt the tree and list. Patch 1 takes kmemleak_lock when removing each object in the cleanup, covering both cases. Patch 2 skips the hex dump in the report once frees are no longer tracked since the reported objects may have been freed. Patch 3 annotates the lockless accesses to the enable flags for completeness. I couldn't get KCSAN to trigger a warning. Tested on arm64 under Qemu with KASAN. On v7.4-rc1, writing "off" and then "clear" crashes reliably and patch 1 fixes it. The concurrent callback race needed some delays inserted to trigger a KASAN use-after-free in rb_erase() (also fixed by patch 1). LLM help (Claude): race analysis, testing, code and commit log checks/suggestions, identifying the hex dump problem fixed by patch 2. [1] https://lore.kernel.org/r/149d93f2cfe20d355f4d9882ce2bf99030217772.1793871596.git.tongweilin@linux.alibaba.com [2] https://sashiko.dev/#/bug/linux-d5496447-37ff-43f3-81ed-e1a5616df463 Catalin Marinas (3): mm: kmemleak: take kmemleak_lock in the disable-time object cleanup mm: kmemleak: do not hex dump objects once free tracking has stopped mm: kmemleak: annotate the lockless accesses to the enable flags mm/kmemleak.c | 73 +++++++++++++++++++++++++++++++-------------------- 1 file changed, 45 insertions(+), 28 deletions(-)