From patchwork Wed Dec 31 22:29:38 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1143 Return-Path: X-Original-To: u-boot-concept@u-boot.org Delivered-To: u-boot-concept@u-boot.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767220252; bh=RMPORJiZdlKWAPBMnOdm/Ew9dL3z36SNrb3hqwHLu+Q=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=urCQbEU04FRGuf4dW+ndo2SRa3Ppv1f4SXTnlEmdf/BNQR1AlY5iFD2CgfI3sAtGR UZX3qRPvTzDDU7PFryCC0ho3ge5VtifbMQvW8lk4M3eR9J5GIqXm0j+bHGQICRZebf NXdjHKLejhh4ZsAzt0ji2Ly8NYOj5nI++8n26k61SbgTZCkSfdMF9hrnoVkO7U8QDq mEiWgSgTDk5WyS5HiK5R5vv1JezpmORYsV02MBgAPb67xrJRKfdlqNShcIjCTSbm1l J0wyCPwCXOYqZtk8gJ4R5lk951CYlF1HBWKqYkvKrbymXA4B4Uj68MHM+azrLv+fqv 7+2bsNgNOMPxA== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id BA4EB68C5D for ; Wed, 31 Dec 2025 15:30:52 -0700 (MST) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10024) with ESMTP id XuojbRUqvdo4 for ; Wed, 31 Dec 2025 15:30:52 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767220252; bh=RMPORJiZdlKWAPBMnOdm/Ew9dL3z36SNrb3hqwHLu+Q=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=urCQbEU04FRGuf4dW+ndo2SRa3Ppv1f4SXTnlEmdf/BNQR1AlY5iFD2CgfI3sAtGR UZX3qRPvTzDDU7PFryCC0ho3ge5VtifbMQvW8lk4M3eR9J5GIqXm0j+bHGQICRZebf NXdjHKLejhh4ZsAzt0ji2Ly8NYOj5nI++8n26k61SbgTZCkSfdMF9hrnoVkO7U8QDq mEiWgSgTDk5WyS5HiK5R5vv1JezpmORYsV02MBgAPb67xrJRKfdlqNShcIjCTSbm1l J0wyCPwCXOYqZtk8gJ4R5lk951CYlF1HBWKqYkvKrbymXA4B4Uj68MHM+azrLv+fqv 7+2bsNgNOMPxA== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id A737E68FCB for ; Wed, 31 Dec 2025 15:30:52 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767220251; bh=QqRLzzD3qY93rfsOjAuKSNB/rFDySMQn8xMoIzAe3FE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Pv+8Fa89WtKNavoLTouYqvfqgf9+6mwYHCe2vimFLQBrJlYZshzCmzn/jbV7nn876 0vtjL+UqWNo0DkdSSuO3MSdG636a6tLR2RHgF5UCEcEOlAf8MR/nLlXiKwQna5EVsj E+J5tNrOZdCNAmatiuOoNWcRUgPYWTahV3umqJ3fWje6grsBHUJCVTNB8xbSdeJv+T LSF8kjK/daIdPhd1X90BgeMTLC/u4ifx/J0X3lwlFxYeLE149GvNRo9qR6O5wB47uB B9JzpLZTSMzk/9XxCz7VGydyPodaxh5rwKBgtSwx7NqqHF/My9YotokXk66GwZLbal 3fkw8GoyPYvDg== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id B173768FC2; Wed, 31 Dec 2025 15:30:51 -0700 (MST) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10026) with ESMTP id D68AOGIYjBnd; Wed, 31 Dec 2025 15:30:51 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767220246; bh=zKwRkI4jC3zhLsledkLrLb/qxwnbtNRX5jTjpU1d5YA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Rn67Gy3Cxztdj2nuCdEhtERgq2mxAD5lE/u/HoojnKacgEFiKWmBvKt7vggrxOJuW MpruCL3rJGtGeKoXPVKc+eQJ1LxNTJw23H8uXz2qQsghxd43uQzQtAK4+ajUWF6j9v Q1Trj0m6IEGurLSNOVqr64oT6gQ9QvtWKOXR9b2vRS2UCFfXfq5W+IvDUn0nLgw+Ul mVcaz6uD1Sii92ZsZatUiK2yFIOeZXvX6NaaSjGy3AoeRtZNOqc5660+D2ywbO5yNg ugCnh0EetVgCChljOEiH6Asb0IkFJKMdotpQ5KOmHBETp23hDOkT7KSalq72BuBQFT 57LH+4/q2Y4VQ== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 574A468C5D; Wed, 31 Dec 2025 15:30:46 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Wed, 31 Dec 2025 15:29:38 -0700 Message-ID: <20251231223008.3251711-6-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251231223008.3251711-1-sjg@u-boot.org> References: <20251231223008.3251711-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: KMPX3VZLOQFFSSKSA2OUDIEF75EMFKQL X-Message-ID-Hash: KMPX3VZLOQFFSSKSA2OUDIEF75EMFKQL X-MailFrom: sjg@u-boot.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Heinrich Schuchardt , Simon Glass , "Claude Opus 4 . 5" X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 05/26] mcheck: Add Kconfig option for caller string length List-Id: Discussion and patches related to U-Boot Concept Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Simon Glass The mcheck heap protection stores a caller string in each allocation header for debugging purposes. The length is hard-coded to 48 bytes in mcheck_core.inc.h Add a CONFIG_MCHECK_CALLER_LEN Kconfig option to make this configurable, allowing users to adjust the trade-off between the amount of debugging context and the memory overhead per allocation. Co-developed-by: Claude Opus 4.5 Signed-off-by: Simon Glass --- Kconfig | 11 +++++++++++ common/mcheck_core.inc.h | 5 ++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/Kconfig b/Kconfig index c28fddf5016..3b89f2c48dd 100644 --- a/Kconfig +++ b/Kconfig @@ -355,6 +355,17 @@ config MCHECK_HEAP_PROTECTION significantly increases memory overhead and should only be used for debugging. +config MCHECK_CALLER_LEN + int "Length of caller string in mcheck header" + depends on MCHECK_HEAP_PROTECTION + default 48 + help + Sets the maximum length of the caller string stored in each + allocation header. This string records the function/file/line + that allocated the memory, useful for debugging memory leaks. + Larger values provide more context but increase memory overhead + per allocation. + config SPL_SYS_MALLOC_F bool "Enable malloc() pool in SPL" depends on SPL_FRAMEWORK && SYS_MALLOC_F && SPL diff --git a/common/mcheck_core.inc.h b/common/mcheck_core.inc.h index 598a5d018ab..fa152790d45 100644 --- a/common/mcheck_core.inc.h +++ b/common/mcheck_core.inc.h @@ -73,7 +73,6 @@ // Full test suite can exceed 10000 concurrent allocations #define REGISTRY_SZ 12000 #define CANARY_DEPTH 2 -#define MCHECK_CALLER_LEN 48 // avoid problems with BSS at early stage: static char mcheck_pedantic_flag __section(".data") = 0; @@ -89,7 +88,7 @@ struct mcheck_hdr { size_t size; /* Exact size requested by user. */ size_t aln_skip; /* Ignored bytes, before the mcheck_hdr, to fulfill alignment */ mcheck_canary canary; /* Magic number to check header integrity. */ - char caller[MCHECK_CALLER_LEN]; /* caller info for debugging */ + char caller[CONFIG_MCHECK_CALLER_LEN]; /* caller info for debugging */ }; static void mcheck_default_abort(enum mcheck_status status, const void *p) @@ -212,7 +211,7 @@ static void *mcheck_allocated_helper(void *altoghether_ptr, size_t customer_sz, for (i = 0; i < CANARY_DEPTH; ++i) hdr->canary.elems[i] = MAGICWORD; if (caller) - strlcpy(hdr->caller, caller, MCHECK_CALLER_LEN); + strlcpy(hdr->caller, caller, CONFIG_MCHECK_CALLER_LEN); else hdr->caller[0] = '\0';