From patchwork Thu Jul 11 15:18:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Puranjay Mohan X-Patchwork-Id: 13730855 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 25FA7C3DA45 for ; Thu, 11 Jul 2024 16:30:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:Message-Id:Date:Subject:To:From:Reply-To:Cc:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=LNBIoekrw6qrv2J9zDu1HVXW3CaeSpVZkCSRkkfSFCE=; b=LswJyUuj7I8PtYcA7dfkeOw5sr r81+tRZQUhoMTVbMprj9KF5Pq73rJ5p37OK84r+Ajmn1lBjPyCG15H6bUDJ2aon53xfbxh9rv+3as ErdgbdyppPhtn9TUqgWblASeefxiMvMdogz5ACtTuVyZ9R7ZQibYgx4+7FnWQ3ci4FJeCf4vBOOTo I7EJ5AUp751V8MBryHYWVCPKwfUHsoONMUlVeA+oywXoTdOQocrwxwdRYoYuuF+3HK97yA2JriMZM x7vjRGEhrcF+krqg0busD6O4/oiE/ZKNeytt4gVd9SVO/SW4CKqS0FMn5EJZBRIJcqYMfBhBsZfY+ LEsLl10g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sRwgw-0000000EhMb-3R6c; Thu, 11 Jul 2024 16:30:46 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sRvZY-0000000EUDM-3qNi for linux-arm-kernel@bombadil.infradead.org; Thu, 11 Jul 2024 15:19:04 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Transfer-Encoding:MIME-Version :Message-Id:Date:Subject:To:From:Sender:Reply-To:Cc:Content-Type:Content-ID: Content-Description:In-Reply-To:References; bh=LNBIoekrw6qrv2J9zDu1HVXW3CaeSpVZkCSRkkfSFCE=; b=LLDUgTl2gp9KIkROvYsR3bqTMh daXszYm2ik+XrlEBmmwSwjjHnSAH4aFokF2c4qrxQpgAPjhKf6DEicJwxL1P98uhLF4mLDlu9Xu3e asrTsZ2PI5hNoZucGXPSO4Hg0DTu74zcaNUFW/EPP10nUw9wD9N14BsDlhiyvTz6O9RCX8/boC1u9 8QwxIwzC7nDqOfpipwUNsi4M9Y6Cj66bMfWoiD/hpQJZ7gTaC1m6lz2WPzZLRLLGW4ctVb+AAaAV3 AM/94C9yFmHC+lnhmzNcsajCT93OFttETIlkzGI2yIisbJ2atSmb6YQr5KIJ/D2mVw7dvJiKc9Zs2 o2j1i8hA==; Received: from sin.source.kernel.org ([2604:1380:40e1:4800::1]) by desiato.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sRvZV-000000017Z4-0q1E for linux-arm-kernel@lists.infradead.org; Thu, 11 Jul 2024 15:19:03 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id 10105CE13B7; Thu, 11 Jul 2024 15:18:55 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 11AF8C116B1; Thu, 11 Jul 2024 15:18:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1720711134; bh=lgCOm4ajbDC2WkfLf4CQCsarvwNbzKn4RzkwvqZn7DU=; h=From:To:Subject:Date:From; b=Vod8ZiegXAS+eCiFiA43QsxWkAF/BzmyEwLYmS7RVWpJcK0w9RQdWpdiqFL8KaoV9 NEEGpnz7pdk9LnQyW0rLLbt4AZeTEP9fr3ZQLyYc7GsPfybfudZ1y+NIwNmKhkpoLK IFXOGPBM+hySYlni/Cz56k8OQRr+yz9xU9FcfNF7cgXURK8AFxE5ZX0AhrSSmKFihf crVzC9tGc5U3+HIqOBKco07HiYdRimdnv567fBWdvLBrIMXv/Cl18XkexN1B+umB1d u16P4vzgQNPQqlMjLWNYGEn6VpH8wMuvQSdcExkwmgQj2Altc4g33pmIaSmqpYN9U0 Au8wWBr2wJAKg== From: Puranjay Mohan To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Eduard Zingerman , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Puranjay Mohan , Xu Kuohai , Catalin Marinas , Will Deacon , Jean-Philippe Brucker , bpf@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH bpf] bpf, arm64: fix trampoline for BPF_TRAMP_F_CALL_ORIG Date: Thu, 11 Jul 2024 15:18:38 +0000 Message-Id: <20240711151838.43469-1-puranjay@kernel.org> X-Mailer: git-send-email 2.40.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240711_161901_799641_01A48630 X-CRM114-Status: GOOD ( 13.24 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org When BPF_TRAMP_F_CALL_ORIG is set, the trampoline calls __bpf_tramp_enter() and __bpf_tramp_exit() functions, passing them the struct bpf_tramp_image *im pointer as an argument in R0. The trampoline generation code uses emit_addr_mov_i64() to emit instructions for moving the bpf_tramp_image address into R0, but emit_addr_mov_i64() assumes the address to be in the vmalloc() space and uses only 48 bits. Because bpf_tramp_image is allocated using kzalloc(), its address can use more than 48-bits, in this case the trampoline will pass an invalid address to __bpf_tramp_enter/exit() causing a kernel crash. Fix this by using emit_a64_mov_i64() in place of emit_addr_mov_i64() as it can work with addresses that are greater than 48-bits. Fixes: efc9909fdce0 ("bpf, arm64: Add bpf trampoline for arm64") Closes: https://lore.kernel.org/all/SJ0PR15MB461564D3F7E7A763498CA6A8CBDB2@SJ0PR15MB4615.namprd15.prod.outlook.com/ Signed-off-by: Puranjay Mohan --- arch/arm64/net/bpf_jit_comp.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/arm64/net/bpf_jit_comp.c b/arch/arm64/net/bpf_jit_comp.c index 720336d28856..1bf483ec971d 100644 --- a/arch/arm64/net/bpf_jit_comp.c +++ b/arch/arm64/net/bpf_jit_comp.c @@ -2141,7 +2141,7 @@ static int prepare_trampoline(struct jit_ctx *ctx, struct bpf_tramp_image *im, emit(A64_STR64I(A64_R(20), A64_SP, regs_off + 8), ctx); if (flags & BPF_TRAMP_F_CALL_ORIG) { - emit_addr_mov_i64(A64_R(0), (const u64)im, ctx); + emit_a64_mov_i64(A64_R(0), (const u64)im, ctx); emit_call((const u64)__bpf_tramp_enter, ctx); } @@ -2185,7 +2185,7 @@ static int prepare_trampoline(struct jit_ctx *ctx, struct bpf_tramp_image *im, if (flags & BPF_TRAMP_F_CALL_ORIG) { im->ip_epilogue = ctx->ro_image + ctx->idx; - emit_addr_mov_i64(A64_R(0), (const u64)im, ctx); + emit_a64_mov_i64(A64_R(0), (const u64)im, ctx); emit_call((const u64)__bpf_tramp_exit, ctx); }