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=1796311523; b=sthAI03p6o0tSrp3E0OUlOOiN7fclWHKGQVg7hYQgymAKEA4peVzCJq/ZqR9GRoyYagU S4TbFmjq20Tss8c4L5YCOmtoYdFzxExF20uS67G6wFX30duGcrHJXV2J+VUvmQpgNqTyy eVRyg93PYUAeolIclfy6gTy4/CFO4pSgyLcx7wWJt/D9dDtqb09gkltx/ezg8Fq9Cy2cW HTwbZWf3Wj046u5FzuzvLWBkCblV0qoN7JBzXZJYWYlHfQxeCo8jxULZtkBgXAFrBfDX7 tf1nm58Ewgb/HhD5xoH9VF5CU39moEmPuKoJLeZZe0nkbAnlrLtTj5SmBEXIkFsG5iw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796311523; h=DMARC-Filter:Received:Received:DKIM-Signature:From:To:Cc:Subject: Date:Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding; bh=holSBhHB0ZZHwz744WUHtm82GpQsOo1agYEJi9qfASo=; b=RlK2W8c4uAU6LLzP2An35LBt2kl28t5Lw2l571G1KoGorGcPBMh8tMRK/O47lk7gIVH1 +FDllszV50Y/1MdjTrKkaTwY3q6kWfNf/nJc4NXEpP8J56KssK1oflex10BebIN0gidod 4GzlzAwKRh6+ROsYXJplCx6nhQjMxfh00vDkACfkT3Y0L8r+7XAZLzyFLqhS5Z2ANz9R7 MU9iyJvYKGSQb2Q4GsbFE9fdgU17tvTMgOtZf8EgW+PMqf3knA58z/tfuW+AWk5eHxuZp O90dvcBqhavcwrjartU/2RMBuhizHpBL9xZHuGhuf0WjmHDvLTbOKbMVi5SXQM5jpsQ== 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=Zd9Szs71; 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 A25D4606A33C for ; Thu, 3 Dec 2026 15:25:22 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org A25D4606A33C 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=Zd9Szs71 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 5B026152B; Thu, 3 Dec 2026 07:25:19 -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 0F9F93F7D8; Thu, 3 Dec 2026 07:25:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1796311522; bh=12zcIbpyzq2m4081eNeTaEDX2J/QGSEzsOvc1ptUHwY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Zd9Szs71tHUw0Z9Um3GGZ4EvXGuTxcoV1Sb24wQ09X/78sYZwmDx5YgrVz9FRPrVY RMj9quGPloFCiaFnBzEn28drEXryV5h6y/c1KVZAgWZ07nu9ci5cdl5F94CnkuWZVG D6F6ac14bLNSXApbBZTfcoxpqP4WUIPvuxyQp2+c= From: Catalin Marinas To: Andrew Morton Cc: Weilin Tong , Breno Leitao , David Hildenbrand , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/3] mm: kmemleak: do not hex dump objects once free tracking has stopped Date: Thu, 3 Dec 2026 15:25:13 +0000 Message-ID: <20261203152515.2270778-3-catalin.marinas@arm.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261203152515.2270778-1-catalin.marinas@arm.com> References: <20261203152515.2270778-1-catalin.marinas@arm.com> 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 If kmemleak is disabled after reporting leaks, the metadata is kept so that the report can still be read, but kmemleak_free_enabled is cleared. kmemleak_free() then no longer clears OBJECT_ALLOCATED, which the report checks under object->lock before hex dumping an object. Reading the report can therefore hex dump memory that has been freed, or unmapped in the case of vmalloc and percpu areas. Skip the hex dump once kmemleak_free_enabled is cleared. The callers hold scan_mutex, under which kmemleak_do_cleanup() clears the flag. Fixes: 74341703edca ("kmemleak: Report previously found leaks even after an error") Cc: Signed-off-by: Catalin Marinas --- mm/kmemleak.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/mm/kmemleak.c b/mm/kmemleak.c index 9c2d01fd4113..0fd3ea174367 100644 --- a/mm/kmemleak.c +++ b/mm/kmemleak.c @@ -311,6 +311,13 @@ static void hex_dump_object(struct seq_file *seq, if (WARN_ON_ONCE(object->flags & OBJECT_PHYS)) return; + /* + * Frees are no longer tracked, so the object may have been freed or + * unmapped. The callers hold scan_mutex, under which the flag is cleared. + */ + if (!kmemleak_free_enabled) + return; + if (object->flags & OBJECT_PERCPU) ptr = (const u8 *)this_cpu_ptr((void __percpu *)object->pointer);