From patchwork Fri Mar 21 20:40:58 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 14026034 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 473E9C36007 for ; Fri, 21 Mar 2025 20:41:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2F3B1280004; Fri, 21 Mar 2025 16:41:11 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 20740280008; Fri, 21 Mar 2025 16:41:11 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E2F3A280004; Fri, 21 Mar 2025 16:41:10 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id A1C4D280004 for ; Fri, 21 Mar 2025 16:41:10 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 0F9041A06CA for ; Fri, 21 Mar 2025 20:41:12 +0000 (UTC) X-FDA: 83246727984.01.9801DE7 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf30.hostedemail.com (Postfix) with ESMTP id 45BB08000B for ; Fri, 21 Mar 2025 20:41:10 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b="qgCd6kW/"; spf=pass (imf30.hostedemail.com: domain of kees@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=kees@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1742589670; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=pY5u90SRoVP23l/VY5i93H4+BEubuNaiYggAdY+P1dc=; b=hF4gcIckClr6aNw8KKX3PJzqPD52Wdcn+aeiK63tFBCzgZaKG+hGMINdHMN/uUVZPPZ9/q pRJLztod7W74v1Q2UVIi7k2Rq4UHAF3T78l2LYYmtDT96GgFVVFmpd94YRQxoYD1Vt69i0 ngjbPKJMg0CXip1RTUjMOmhvH/oHWSc= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1742589670; a=rsa-sha256; cv=none; b=GXaqwNuBgJOHG6yxR2vDvaos47ZHDP4s/Fe2tC3CmeOsKz3IIq0o3AYgDCrsj6p5I2z6tP 80rj8SJdj8CxbyhgglKxdShfu4Qq9JQrgnAY2uF38R6KJQq0rODqn01utZkw1HFhtAcOpv iJKZHD2uS3bb+On8vmW+emEmY+x+9JA= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b="qgCd6kW/"; spf=pass (imf30.hostedemail.com: domain of kees@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=kees@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 4F0685C66B4; Fri, 21 Mar 2025 20:38:52 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E6729C4CEE3; Fri, 21 Mar 2025 20:41:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1742589669; bh=LFQAzM70Y8/4bSi3hs970uFuPutGXlC4X01Ugec4ydw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qgCd6kW/4cf5U9VoXqzgie8/lOZnRnTBbNsmqaM8c9IgwSMdkh10zu+Gf4/x+4QMz F77o/Q6Xpu/bj0wUyHlY2hb8b6ENvPRFa2xUYnNmS3xYrXxVAsvnxUxvx+QqQ/Cy+H F9IVLpAqbwbjLZB0zrRPOYHj6MDmvqHfZEoc7f+s8w3u6sU7FfcgFOzXHfqc3JOL4e /3vykj1nDJIwjNY8EUKJzXbCSyUeq4FOTEerXoDOQHcK5jrzoRnfXfs0dUb4jq1HUF eg5XsILMLFaClPNQxQ/dWoZdN7XUndWFU+Ejv0mg4IdZ/UoVVixTOnlp2XbDCapAKS /TPIkUpZymQSg== From: Kees Cook To: Vlastimil Babka Cc: Kees Cook , Christoph Lameter , Miguel Ojeda , Nathan Chancellor , Marco Elver , Nick Desaulniers , Przemek Kitszel , Pekka Enberg , David Rientjes , Joonsoo Kim , Andrew Morton , Roman Gushchin , Hyeonggon Yoo <42.hyeyoo@gmail.com>, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-hardening@vger.kernel.org Subject: [PATCH 2/5] treewide: Prepare for kfree() to __kfree() rename Date: Fri, 21 Mar 2025 13:40:58 -0700 Message-Id: <20250321204105.1898507-2-kees@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250321202620.work.175-kees@kernel.org> References: <20250321202620.work.175-kees@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=4240; i=kees@kernel.org; h=from:subject; bh=LFQAzM70Y8/4bSi3hs970uFuPutGXlC4X01Ugec4ydw=; b=owGbwMvMwCVmps19z/KJym7G02pJDOl3z93unF6W+Z710Pvrd5tj3dhqnk3pnaPV9KjkmGxzj XnZ811qHaUsDGJcDLJiiixBdu5xLh5v28Pd5yrCzGFlAhnCwMUpABN5s5zhf6q2cNeSL3tOJdg3 tE7/WPyDx4DPcfLRlaFGdhP9S+8dMmNkeBv3dM7qAGEe+c/zVpsduXh00xmxq/ll6cnHcx2dfIw 1uAE= X-Developer-Key: i=kees@kernel.org; a=openpgp; fpr=A5C3F68F229DD60F723E6E138972F4DFDC6DC026 X-Stat-Signature: yb3rmascq9kgm3rwh7tubep7enmawfdc X-Rspam-User: X-Rspamd-Queue-Id: 45BB08000B X-Rspamd-Server: rspam08 X-HE-Tag: 1742589670-779693 X-HE-Meta: U2FsdGVkX18+Xuw2xM18yGDvVWsE1pHzMNpyy36trHdefnykhtADLTDW/rPbi8YhNjQeTmgrok73UBY6P7D+A7aGkhP8sUmDBru6HfdbK5gXHtMzBajkKpH+V0cmyRRMphzGsubwljigxftcs8BrVkyEHgTTCLJzk7CXKo5qXwhTcTeUE68r+ka7OlJpO3M21JpliS7CVGMedNElXkG2UZ5zQVuX00VVSmfidZNOQWzA/bVGGL0EOWGGNT+t6Bj090YK/hHQ4IVkob9C5a+hFazrdf0QIzXZFTzobxXPVXu03YuQZ+F7/loGwyRgg9FDtYyJ/4Oc7QVXSMHkZRfzUaVDzoIVBBb39ymjqocPZyxlH3jEY05mnnp0e7JAvmyadQxPL8HqEfSIIOXyu5ZE7S1xWpFI2B3CZ5biKoJJytPz2b0rIW8xu3pQLI62T4PIBUP8Ym0VswwHgQv1a2UhbhYo9ehPv0qQTE+OGEP43riipNiA7fy3Tl/3sk44pt+9UHCOj1u1aDd/84M9RqQOt8I+HQ1aSfs7NkNMv07nSU3XemvuIStHEndBqRuSIHTsYfZmIauxRG/GmRItAg4PSDsazOmAmp0dHtu6z5i5O7ja6Nyvv7KiocNqDRSnVazo6pMh5JoY/5cBO7sj+vHdAClwFRPQOZeV1TAOwfziUFbYugykPBR26ijlQKvjzKLHipgL9fe1TTMu2JIpjAUiHDXBWM9GbkGHIwk2K1Xa0RbB+ihTHJ+GRcLFsCsnpbKZqsm7akn0yztAc4kzyb4bFqF1TfYsxZ3QqXIKEfcfbAg2PZB5gm65x9od+A91nPZEJwKXt3314DqmMzLAcfdgZ6doEl6PH2pIhOwjp/z0yNbfG4pDAUYWZMAt1BeqBj3Ulz7UvBpZyeFcla9091yMaAxbbONHcUOp0BLQpwhhobJan7VOXMCzsB1M2qGo+addZaqsG6Y1VnsVveMSXYh UzLIywYt irpOehZuz3DjNn7TYYkoVrxJpVWquqTlLbs6Q1xzCWkE5hTbhYfoeJQbCSk5ZRokJ74X7pHES10sTK49MsxvucglOF22qPmxukGonFA6VwqQjIJFs65E0GVLfkFOeLm2oWF8tBtwHvn55/JMLjI9+sFR2ulNh1PZqfHK8vKZsoYgTz94di8gzwlf2iSjwcoG+kY2tpcskGhfyQi5iTzgqrNudM0HcaIpBo01Z5+k59ajGXbJLTj7V6CLY483OqAlEJ4cEXTnZjxTR0M8Mo6EqAKQzjVtvRrucMXcXa7kR1MsUmzw1M3uDAWiKRQkvMBf9/dzEXsVDCUlhhaKr13lnDJ0AnPgVBHSLNvkn X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: In preparation for making kfree() a wrapper macro, replace address-taken instances of kfree with __kfree so the future renaming of kfree to __kfree will work correctly. (Or to avoid needing to create a union for a cast.) This is an example subset needed to build my bootable image. I'm sure there are more, but they immediately throw build errors when encountered so they cannot be silently missed. Signed-off-by: Kees Cook --- arch/mips/alchemy/common/dbdma.c | 2 +- include/linux/slab.h | 2 ++ io_uring/futex.c | 2 +- io_uring/io_uring.c | 12 ++++++------ kernel/bpf/core.c | 3 ++- 5 files changed, 12 insertions(+), 9 deletions(-) diff --git a/arch/mips/alchemy/common/dbdma.c b/arch/mips/alchemy/common/dbdma.c index 6a3c890f7bbf..08548e5daead 100644 --- a/arch/mips/alchemy/common/dbdma.c +++ b/arch/mips/alchemy/common/dbdma.c @@ -422,7 +422,7 @@ u32 au1xxx_dbdma_ring_alloc(u32 chanid, int entries) * Lost....do it again, allocate extra, and round * the address base. */ - kfree((const void *)desc_base); + __kfree((const void *)desc_base); i = entries * sizeof(au1x_ddma_desc_t); i += (sizeof(au1x_ddma_desc_t) - 1); desc_base = (u32)kmalloc(i, GFP_KERNEL|GFP_DMA); diff --git a/include/linux/slab.h b/include/linux/slab.h index 09eedaecf120..3e807ccc8583 100644 --- a/include/linux/slab.h +++ b/include/linux/slab.h @@ -469,6 +469,8 @@ void kfree(const void *objp); void kfree_sensitive(const void *objp); size_t __ksize(const void *objp); +#define __kfree(x) kfree(x) + DEFINE_FREE(kfree, void *, if (!IS_ERR_OR_NULL(_T)) kfree(_T)) DEFINE_FREE(kfree_sensitive, void *, if (_T) kfree_sensitive(_T)) diff --git a/io_uring/futex.c b/io_uring/futex.c index 43e2143255f5..e46a019fbd08 100644 --- a/io_uring/futex.c +++ b/io_uring/futex.c @@ -41,7 +41,7 @@ bool io_futex_cache_init(struct io_ring_ctx *ctx) void io_futex_cache_free(struct io_ring_ctx *ctx) { - io_alloc_cache_free(&ctx->futex_cache, kfree); + io_alloc_cache_free(&ctx->futex_cache, __kfree); } static void __io_futex_complete(struct io_kiocb *req, struct io_tw_state *ts) diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c index ceacf6230e34..0a41a3a981b1 100644 --- a/io_uring/io_uring.c +++ b/io_uring/io_uring.c @@ -360,11 +360,11 @@ static __cold struct io_ring_ctx *io_ring_ctx_alloc(struct io_uring_params *p) free_ref: percpu_ref_exit(&ctx->refs); err: - io_alloc_cache_free(&ctx->apoll_cache, kfree); + io_alloc_cache_free(&ctx->apoll_cache, __kfree); io_alloc_cache_free(&ctx->netmsg_cache, io_netmsg_cache_free); io_alloc_cache_free(&ctx->rw_cache, io_rw_cache_free); - io_alloc_cache_free(&ctx->uring_cache, kfree); - io_alloc_cache_free(&ctx->msg_cache, kfree); + io_alloc_cache_free(&ctx->uring_cache, __kfree); + io_alloc_cache_free(&ctx->msg_cache, __kfree); io_futex_cache_free(ctx); kvfree(ctx->cancel_table.hbs); xa_destroy(&ctx->io_bl_xa); @@ -2702,11 +2702,11 @@ static __cold void io_ring_ctx_free(struct io_ring_ctx *ctx) io_sqe_files_unregister(ctx); io_cqring_overflow_kill(ctx); io_eventfd_unregister(ctx); - io_alloc_cache_free(&ctx->apoll_cache, kfree); + io_alloc_cache_free(&ctx->apoll_cache, __kfree); io_alloc_cache_free(&ctx->netmsg_cache, io_netmsg_cache_free); io_alloc_cache_free(&ctx->rw_cache, io_rw_cache_free); - io_alloc_cache_free(&ctx->uring_cache, kfree); - io_alloc_cache_free(&ctx->msg_cache, kfree); + io_alloc_cache_free(&ctx->uring_cache, __kfree); + io_alloc_cache_free(&ctx->msg_cache, __kfree); io_futex_cache_free(ctx); io_destroy_buffers(ctx); io_free_region(ctx, &ctx->param_region); diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c index da729cbbaeb9..9d2721d24c40 100644 --- a/kernel/bpf/core.c +++ b/kernel/bpf/core.c @@ -280,7 +280,8 @@ void __bpf_prog_free(struct bpf_prog *fp) mutex_destroy(&fp->aux->used_maps_mutex); mutex_destroy(&fp->aux->dst_mutex); kfree(fp->aux->poke_tab); - kfree(fp->aux); + /* "fp" may be in read-only memory */ + __kfree(fp->aux); } free_percpu(fp->stats); free_percpu(fp->active);