Received: by 2002:ab2:6816:0:b0:1f9:5764:f03e with SMTP id t22csp3352420lqo; Tue, 21 May 2024 14:38:32 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWrb5yivCoA2PgbWpPoWf6ZJpey+gb42Asc79BO7mGj/MrLnptOdh0NHZ6BX1JTfQgTJKK6kNC35MaWCPdhpa1+QE9/mhGkmfMPHwylMQ== X-Google-Smtp-Source: AGHT+IHhXEV7rqOa8KJtNz8kUHuw9YtDtav15+F2A9IATxo81WLrPKir0dOEq4ghVwVWkgnKx7oW X-Received: by 2002:a05:6808:5ce:b0:3c9:92f3:d528 with SMTP id 5614622812f47-3cdb3f5a7c4mr318799b6e.12.1716327512275; Tue, 21 May 2024 14:38:32 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716327512; cv=pass; d=google.com; s=arc-20160816; b=yqslzQ8pg3WD4T9zxxVs5KNP+3bFmJLhLfoOzdEA4oLrQ6GR1brMOa+w8utr85USck ISpGztz4gAwFSKRcUsFuFqH9rrXTzfvAZFGn77iG9ywnEZqPygIWG9KRTtCgVOjo+jLd AKv2+6y3GbbPuiEUuZseYb3Tf5TF/1KamPpbd91wD4TmEGMo5d/E9GY0KktP8KiF+oZi S6P2WWaUUYF2JK7MncHbkLUZhCcHbrz9nuLWBaX9qQG5egW97IN+WmU1cWoa0m8DOHs9 ZcghcoCPVsF+px+FtnQA13sbPeS1eFQyHuwZV3o10XmbBs+Gpt+MlBkGvjbxdU9NGSr+ Tdig== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=MCgn78kTkoBYLwLAMiolO+tqPnpkyeXtwHO5X3OvrwM=; fh=SW0aiYLeRNm9bqLHPXqstQqZPXWHv/jiPbQjLmKYC8w=; b=yKus2sMs3sqEQSjzZ9+h87AGg75LQpFcCUvxCTPNag1Q53MjHsb+vjjTAh7rWEueIx liwQJmj5HrLrAfHA5BIrD+9PstohO8YyEibo/XuFQN+ITv5Nob16sqrR28odtAjWCTE7 Fp47tN4CreXa53LyWVWBscEM7Sv3Iv0TfNxpOGtJuKyFpCTJ0eMo0cCA+tSjb44PsOD3 YnUE/bM6ZPTtVYMyVh3LXrM5nmUKaY+HZsHtIygJlclOwYNd24Natr5d840H5V5k8pPN IpRTuMdi4r8bghAsmlKRrYnHQTNQZJxI/+gHWDlca3/RBM0Gi0hXHe6nfxIAySuTNu/f EdMQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=aRRWV2mz; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-185487-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-185487-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id d75a77b69052e-43df7176563si64492081cf.372.2024.05.21.14.38.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 May 2024 14:38:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-185487-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=aRRWV2mz; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-185487-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-185487-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 021841C20DEF for ; Tue, 21 May 2024 21:38:32 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4AABC149E09; Tue, 21 May 2024 21:38:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="aRRWV2mz" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 64AF81494D6 for ; Tue, 21 May 2024 21:38:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716327505; cv=none; b=iMZq27DO0J4lzx+oxmwRjVK9h0w5gK401FI+c35Cqbg83wgVSmMUbfvlxK0cLZ8EbIxXuGWgXKd1T8JXmFgmthvlAgLaYFbxUzqWajjG9OabHc64T1CEOekMbgYEgSKD+1Kz2CI7n0Vt/z3UWstPiEGZ0N2+dPJU1BZ/hxq/gmI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716327505; c=relaxed/simple; bh=oR5loQ/i/Rsx1Ierj/b9bxTyVCpBalS4Ej8gyPm7Brc=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=Jli7Vn1nC+xTnHEKJ7YJMuY61gMp81NR4xwcFzrC9373S+Tnsq9PMNIc2L4DJggqdnh1YLY04MAzUyz4ZWXjpDGAa7iO3qovE3l7HIGj6O0aJ6MQnAlEDR5ajTwti8EFxSHvotF726XUs3QursPfBnyzR1voQcp9tNPaeQMeSvU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=aRRWV2mz; arc=none smtp.client-ip=10.30.226.201 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 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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(-) 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; base-commit: 8f6a15f095a63a83b096d9b29aaff4f0fbe6f6e6 -- 2.43.0