From mboxrd@z Thu Jan 1 00:00:00 1970 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 D028E24728A; Tue, 20 May 2025 14:05:46 +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=1747749946; cv=none; b=Io+gMCUNmoAzyfDYW1PWvJaE7637P+0G46AiaLqscj9Cv47nZSt4bnrahlqfJOx4hYNb9KDDlLkpVow+B6GbFzw/1/eRdR2mQeoHi2oVJZ4FbQR36V4rjs1U/j/7rNXp2lFBbWWPnHUZswKfo2i8TKpLSOmfjMQ8ldOEl4yDSuY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747749946; c=relaxed/simple; bh=H0wFkCMYbLMqN9GvMbIkA6+m3B81G+FAQ6rMfNXgp4k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uz67Rcl8nxKJ+Uq04gtZUaNaX/QZFEJee7AfCQ6HD0UnYF7dQQYCya+Sr/Qe4Jp7Aug48w3qqYrYVBSXxORx1q2kEheaGNoobRdN2b/cW5262i1gEbBpkESrPk/95qNUVKC8lY8QCeqp/JGbNZOLG8G6tUcGunX9GsVdxIiJqL4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=ExJWBbuU; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="ExJWBbuU" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 359FAC4CEEB; Tue, 20 May 2025 14:05:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1747749946; bh=H0wFkCMYbLMqN9GvMbIkA6+m3B81G+FAQ6rMfNXgp4k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ExJWBbuUd1w/4YM6QjEiEIUXDR/OmvMV3KiAFvp3ZwkJSuya6/XmNJKppMbko6tng a7a/QncH6ZDeGZPfMJWuzMTsctot2Je7sWU8hTNhVuY7MgoYTSZgcmQ+4S6IeJvNfP YCaLks8k1wKqFJdjSxgCxkWPy1RtnelVFAfK27tA= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Peter Collingbourne , Daniel Borkmann , Xu Kuohai , Bin Lan , He Zhe Subject: [PATCH 6.6 110/117] bpf, arm64: Fix address emission with tag-based KASAN enabled Date: Tue, 20 May 2025 15:51:15 +0200 Message-ID: <20250520125808.367935395@linuxfoundation.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250520125803.981048184@linuxfoundation.org> References: <20250520125803.981048184@linuxfoundation.org> User-Agent: quilt/0.68 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Peter Collingbourne commit a552e2ef5fd1a6c78267cd4ec5a9b49aa11bbb1c upstream. When BPF_TRAMP_F_CALL_ORIG is enabled, the address of a bpf_tramp_image struct on the stack is passed during the size calculation pass and an address on the heap is passed during code generation. This may cause a heap buffer overflow if the heap address is tagged because emit_a64_mov_i64() will emit longer code than it did during the size calculation pass. The same problem could occur without tag-based KASAN if one of the 16-bit words of the stack address happened to be all-ones during the size calculation pass. Fix the problem by assuming the worst case (4 instructions) when calculating the size of the bpf_tramp_image address emission. Fixes: 19d3c179a377 ("bpf, arm64: Fix trampoline for BPF_TRAMP_F_CALL_ORIG") Signed-off-by: Peter Collingbourne Signed-off-by: Daniel Borkmann Acked-by: Xu Kuohai Link: https://linux-review.googlesource.com/id/I1496f2bc24fba7a1d492e16e2b94cf43714f2d3c Link: https://lore.kernel.org/bpf/20241018221644.3240898-1-pcc@google.com [Minor context change fixed.] Signed-off-by: Bin Lan Signed-off-by: He Zhe Signed-off-by: Greg Kroah-Hartman --- arch/arm64/net/bpf_jit_comp.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) --- a/arch/arm64/net/bpf_jit_comp.c +++ b/arch/arm64/net/bpf_jit_comp.c @@ -2001,7 +2001,11 @@ static int prepare_trampoline(struct jit emit(A64_STR64I(A64_R(20), A64_SP, regs_off + 8), ctx); if (flags & BPF_TRAMP_F_CALL_ORIG) { - emit_a64_mov_i64(A64_R(0), (const u64)im, ctx); + /* for the first pass, assume the worst case */ + if (!ctx->image) + ctx->idx += 4; + else + emit_a64_mov_i64(A64_R(0), (const u64)im, ctx); emit_call((const u64)__bpf_tramp_enter, ctx); } @@ -2045,7 +2049,11 @@ static int prepare_trampoline(struct jit if (flags & BPF_TRAMP_F_CALL_ORIG) { im->ip_epilogue = ctx->image + ctx->idx; - emit_a64_mov_i64(A64_R(0), (const u64)im, ctx); + /* for the first pass, assume the worst case */ + if (!ctx->image) + ctx->idx += 4; + else + emit_a64_mov_i64(A64_R(0), (const u64)im, ctx); emit_call((const u64)__bpf_tramp_exit, ctx); }