From patchwork Tue May 21 21:38:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Rapoport X-Patchwork-Id: 13669779 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 34629C41513 for ; Tue, 21 May 2024 21:38:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C5F476B007B; Tue, 21 May 2024 17:38:31 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C0FDA6B008C; Tue, 21 May 2024 17:38:31 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AD8FB6B0093; Tue, 21 May 2024 17:38:31 -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 8BAB16B007B for ; Tue, 21 May 2024 17:38:31 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 2941DA26D5 for ; Tue, 21 May 2024 21:38:31 +0000 (UTC) X-FDA: 82143717222.01.AF7DAC9 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf03.hostedemail.com (Postfix) with ESMTP id E8E4620010 for ; Tue, 21 May 2024 21:38:28 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=aRRWV2mz; spf=pass (imf03.hostedemail.com: domain of rppt@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=rppt@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1716327509; 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:references:dkim-signature; bh=MCgn78kTkoBYLwLAMiolO+tqPnpkyeXtwHO5X3OvrwM=; b=gI7EAKPQ7VPyE4sVhG2pM7b0JcH6NPJxN4pJjXpnh4c36c905ERhAj+bnkmjuoOZYGZm2X iraOfQZ4S2P6VgMp+dtf6VSAuCtu7tZYq1lu8oQ0lnEirWw1GAuvRYrETQM4c/GHys0+sG XGke6pybvZk8oo/LyQhgIPqIfwnFLTw= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=aRRWV2mz; spf=pass (imf03.hostedemail.com: domain of rppt@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=rppt@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1716327509; a=rsa-sha256; cv=none; b=nDe9mkyTtbf2BwUMdG6/4yxQ3YwbxAduKNj83V07LDDW0lhffVtdzkXBMg3ORcVhBPMggM 8HXrYeznSsr1W844GhlCuKqUqdNTlq4el91Xoo84x4jGJeZ3BGxZ913kvXeSGCFeqDQ8Bk tpsaFX1XZx/o1iqhGNuDKJwH7vvmQGE= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id 9DDAACE0F74; Tue, 21 May 2024 21:38:25 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B2885C2BD11; Tue, 21 May 2024 21:38:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1716327504; bh=oR5loQ/i/Rsx1Ierj/b9bxTyVCpBalS4Ej8gyPm7Brc=; h=From:To:Cc:Subject:Date:From; b=aRRWV2mzamYq+493uTYGefAmM60IvfIRY1mQoBMKUKToegUyImYWhjdjer739pp6V rnLAeZBEOgI5p2RLFhbROQW0e5xW/WU5AaADkrJrktemwNy1Gd42o38uGS7RNGotFk 9LojW1/7Wm12ZCDj3gcxlh2CtkxtA8D3RDiG85ZKh5qI9GKvnIOh+vRTlygAg9AaAQ sFJMKb+79MAZIrCjgplDdCda8GA7IwNPi0177W8UabsDqgB5++qC2ME5GlmlKZBWCt 4ZmPJFej36azxQctCBZuHO3OGBxdTKnJehAx7dBwX3Wu+wFoLvVm56zmrtXIe7iObm 88JpRliRgktbg== From: Mike Rapoport To: Andrew Morton Cc: Catalin Marinas , Klara Modin , Mike Rapoport , Will Deacon , linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH] arm64: patching: fix handling of execmem addresses Date: Wed, 22 May 2024 00:38:13 +0300 Message-ID: <20240521213813.703309-1-rppt@kernel.org> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: E8E4620010 X-Stat-Signature: nipgkrkd4rrs98e7axifdwm1kghqd1gg X-Rspam-User: X-HE-Tag: 1716327508-812213 X-HE-Meta: U2FsdGVkX19YevZ21+VOH3sFTMabU2M9PLTG0w5DDmluhZsuonM7a7y/fFtVYndm714E/OYULjNXgjxFo2wdBJFtgbsUZH97DIXHopYmo+t3ZszH0pK7n4DZH6/KGk0e8+77AVfbQsGF6wJ0X5C66HG3FqRYBgaKlWmJGXzVI/J89kEygcCT/SOWOlwPEN7AV/g8+YxdiTDnpszHwSDs1aVscoLuaQaZ62L0E6GNonRMHVv0JWVIXhoGAeVK0TzwlXdN5NJcEMLNZK0qgMUP7Za3B1jaf9ebt2+aj/8QARwRNCHub6hqOutokmG3c5+1gX2xVEhyj8roc0wOeiKAkP+545cG36tvf95OlobbpIB4YPH4X2ybeUpuZWPk3OF+qZhVEUmh2IT/EBHsNQxWRQa/VuD8H+khVIi6bKfQewkQLv+GcA9+4HW9ps+uACo8UmuK+qu7OT7MEjuw3NOEKQ+Ia5egBJqUcyXWaEEqX1/tbQeehT3vpnK26ZYVzGacWpZGDIkRfkFUypP2ox2JU+1aeBNyrsHPuMCRxpdgOIOvyqhBoOSYqDUvjon72Cg+rcnJiZDMywQpTqEqXBxWq25V+hbpF7CSclzHfkEl+H6C6tLg8inwcJoLxxAGNF9i5Fc6IXvJx9HORJz9SrXRyS8XkhonPXdet1o+apikJqW4dCTGC0LE8srDjejaBRPNCQtDvuIsUv71pOTUO4TYYNqMx6V1C1tznHJI/PJP9Nrg++1ceSZxsf4dLCXsRqRMgkclxlTibqJH4QuPCZidaRDR0ECbJp02MmADGf2FrhsRP7552hU8uO1FMORr3klaqE4F3hmdQFzQjmq9gVxCaEZzVx48FdePi4y/YPm+savnhJy9K5CD3Q7DnfxvVj7DzCYwMTHO6cnwGA7m5d5rhgfYETXhSHCfvIdOC+ZWEU2rNTDPkB72gf/GDTlFDK+e/Ei5iH3f+W8GcoWa9Gn o9zYSC8x sa4fK6hKHa+SIg5PkTjp3iVZmJO+zrSwE2AO6N4JgbkQb6x4VoIX0D/I17PSfCqW/+ZFZzou+1jUtWx7T74cVClMH3ykz56p3RH+8wVGtx+TsEx12SuNu9NJGdG2EgRroj91TcK2BXoVxKLEX31X+XL/VeC29X6hiIzjjZKeKwHDfMG8mzNn20MTxRj+NcAfGys85FFLdLjPzc4/BpxtnGZnE3WHRSWXA6n3JLnt65tipNDJny0DOdqR22FcrWMF3+QWy 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: From: Will Deacon Klara Modin reported warnings for a kernel configured with BPF_JIT but without MODULES: [ 44.131296] Trying to vfree() bad address (000000004a17c299) [ 44.138024] WARNING: CPU: 1 PID: 193 at mm/vmalloc.c:3189 remove_vm_area (mm/vmalloc.c:3189 (discriminator 1)) [ 44.146675] CPU: 1 PID: 193 Comm: kworker/1:2 Tainted: G D W 6.9.0-01786-g2c9e5d4a0082 #25 [ 44.158229] Hardware name: Raspberry Pi 3 Model B (DT) [ 44.164433] Workqueue: events bpf_prog_free_deferred [ 44.170492] pstate: 60000005 (nZCv daif -PAN -UAO -TCO -DIT -SSBS BTYPE=--) [ 44.178601] pc : remove_vm_area (mm/vmalloc.c:3189 (discriminator 1)) [ 44.183705] lr : remove_vm_area (mm/vmalloc.c:3189 (discriminator 1)) [ 44.188772] sp : ffff800082a13c70 [ 44.193112] x29: ffff800082a13c70 x28: 0000000000000000 x27: 0000000000000000 [ 44.201384] x26: 0000000000000000 x25: ffff00003a44efa0 x24: 00000000d4202000 [ 44.209658] x23: ffff800081223dd0 x22: ffff00003a198a40 x21: ffff8000814dd880 [ 44.217924] x20: 00000000d4202000 x19: ffff8000814dd880 x18: 0000000000000006 [ 44.226206] x17: 0000000000000000 x16: 0000000000000020 x15: 0000000000000002 [ 44.234460] x14: ffff8000811a6370 x13: 0000000020000000 x12: 0000000000000000 [ 44.242710] x11: ffff8000811a6370 x10: 0000000000000144 x9 : ffff8000811fe370 [ 44.250959] x8 : 0000000000017fe8 x7 : 00000000fffff000 x6 : ffff8000811fe370 [ 44.259206] x5 : 0000000000000000 x4 : 0000000000000000 x3 : 0000000000000000 [ 44.267457] x2 : 0000000000000000 x1 : 0000000000000000 x0 : ffff000002203240 [ 44.275703] Call trace: [ 44.279158] remove_vm_area (mm/vmalloc.c:3189 (discriminator 1)) [ 44.283858] vfree (mm/vmalloc.c:3322) [ 44.287835] execmem_free (mm/execmem.c:70) [ 44.292347] bpf_jit_free_exec+0x10/0x1c [ 44.297283] bpf_prog_pack_free (kernel/bpf/core.c:1006) [ 44.302457] bpf_jit_binary_pack_free (kernel/bpf/core.c:1195) [ 44.307951] bpf_jit_free (include/linux/filter.h:1083 arch/arm64/net/bpf_jit_comp.c:2474) [ 44.312342] bpf_prog_free_deferred (kernel/bpf/core.c:2785) [ 44.317785] process_one_work (kernel/workqueue.c:3273) [ 44.322684] worker_thread (kernel/workqueue.c:3342 (discriminator 2) kernel/workqueue.c:3429 (discriminator 2)) [ 44.327292] kthread (kernel/kthread.c:388) [ 44.331342] ret_from_fork (arch/arm64/kernel/entry.S:861) The problem is because bpf_arch_text_copy() silently fails to write to the read-only area as a result of patch_map() faulting and the resulting -EFAULT being chucked away. Update patch_map() to use CONFIG_EXECMEM instead of CONFIG_STRICT_MODULE_RWX to check for vmalloc addresses. Fixes: 2c9e5d4a0082 ("bpf: remove CONFIG_BPF_JIT dependency on CONFIG_MODULES of") Reported-by: Klara Modin Closes: https://lore.kernel.org/all/7983fbbf-0127-457c-9394-8d6e4299c685@gmail.com Signed-off-by: Will Deacon Tested-by: Klara Modin Signed-off-by: Mike Rapoport (IBM) --- Andrew, if you can pick this up before -rc1 it won't need to wait for arm64 tree rebase arch/arm64/kernel/patching.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) base-commit: 8f6a15f095a63a83b096d9b29aaff4f0fbe6f6e6 diff --git a/arch/arm64/kernel/patching.c b/arch/arm64/kernel/patching.c index 255534930368..945df74005c7 100644 --- a/arch/arm64/kernel/patching.c +++ b/arch/arm64/kernel/patching.c @@ -36,7 +36,7 @@ static void __kprobes *patch_map(void *addr, int fixmap) if (image) page = phys_to_page(__pa_symbol(addr)); - else if (IS_ENABLED(CONFIG_STRICT_MODULE_RWX)) + else if (IS_ENABLED(CONFIG_EXECMEM)) page = vmalloc_to_page(addr); else return addr;