Received: by 2002:ab2:6a05:0:b0:1f8:1780:a4ed with SMTP id w5csp2169438lqo; Mon, 13 May 2024 09:39:44 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUX1TZJOjCeTc4aPifXZDnnIzhIIXb5b6qQ+0Mbkxoww9AZtA2+E3iLnwfX8c+e12DktL9wD8oIHp49b/LRVGlX4RkvfgSvLlH3lEGwpA== X-Google-Smtp-Source: AGHT+IFIbFfhymosi/X1Tvkg0e4FLOoqZznnniCk0CmMf2pMnAVtGdWefLs0ECAr0n1bVzOaq/Ov X-Received: by 2002:a05:620a:46a3:b0:792:e5ba:5b04 with SMTP id af79cd13be357-792e5ba5c7cmr255242585a.75.1715618383875; Mon, 13 May 2024 09:39:43 -0700 (PDT) Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id af79cd13be357-792bf277b91si972448585a.32.2024.05.13.09.39.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 May 2024 09:39:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-177842-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20230601 header.b=LtNnHQ5c; arc=fail (body hash mismatch); spf=pass (google.com: domain of linux-kernel+bounces-177842-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-177842-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com 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 8B1601C22CFE for ; Mon, 13 May 2024 16:39:43 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3D2FD18E2A; Mon, 13 May 2024 16:39:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="LtNnHQ5c" Received: from mail-wm1-f54.google.com (mail-wm1-f54.google.com [209.85.128.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C00F81864C; Mon, 13 May 2024 16:39:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.54 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715618374; cv=none; b=JrlNvrhBx8lU6RmIJKryrzgz1CfWJ1V+hdNznhBai3aLrvsH9rScf1LmDzv98E56BI7VroZ3jBWN+dVEXYwOKh0IH3dTBwgMmsA3vNsaeTiBZ8PGtYBUyfCZiPoDt6/zD6cLaaIHzFmBXn4BE/xUJpevWfwM7H0ObVrtsMbQwIE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715618374; c=relaxed/simple; bh=FXjTIu7Javcp57PGJ37+TMBH2Efe81br2mmREIXkSTU=; h=From:To:Cc:Subject:In-Reply-To:References:Date:Message-ID: MIME-Version:Content-Type; b=ZPqgGxZmUDIOw532MS63rL4FIGRJEPY0Sjbsa3oNFmlbcrp9PCKtwrJvBynBeZGCfvuww2MSiXQs94DjAHGP4u7Pc3XKU8Tbhn/L462VaCCASk+judofbtXN1bdOgWl2eBtLR0RB7A0xSysyCglKnXUWOdMj3F64GN0CTg2bGkQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=LtNnHQ5c; arc=none smtp.client-ip=209.85.128.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-wm1-f54.google.com with SMTP id 5b1f17b1804b1-420180b5838so6811545e9.2; Mon, 13 May 2024 09:39:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1715618371; x=1716223171; darn=vger.kernel.org; h=mime-version:message-id:date:references:in-reply-to:subject:cc:to :from:from:to:cc:subject:date:message-id:reply-to; bh=JlL47WvthT5p4/6Hq0zcLfQwW5agcsSiG76b2RdCPO8=; b=LtNnHQ5cWHgNVzUA18Y58DxfeI1IUuVEr/7P5nHgG6WbIGPomfTfR7eoh1FQuMrgRy 4Jz9JGl817Qs+HTxs84xCKFikmhrHniBkSyMH1IYfEUpj5NDpB6RymYjEhnaYjt5kJFt JsizPvQ1TfUvqCigtz5nJHI+WJsCFzYzLCcXXZu4sq9rqg4vbdliZOFYIwEeOA+JjN8q J+yQeW1c4Sf64sVKPdr43U0bSJDyUx0aRqoRtXvJ7Cw9CowIBtR+VHhEyxN+HURvONkt ZeAfgeli+OwTRhz4233tehFEOyPcQTMcRgtz6E2TcjEJWhZS7tiG2YMd9NZJAA5ipz8F 3V+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715618371; x=1716223171; h=mime-version:message-id:date:references:in-reply-to:subject:cc:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=JlL47WvthT5p4/6Hq0zcLfQwW5agcsSiG76b2RdCPO8=; b=wuk6q6tf3LWbS8q1hPfuIhJSWeaONcemD49e1tpih1Ek5OLbI0YUrfhkGRldCPD0pQ OfukWLwOoCgxhIFU1Qi9BeKe9NQ/qWCoXkTxyxHqQ7IG6229QrlgFQ8ONjE56IjEUUDx 7YIXwNpNFB09BkPzig/bd/bFtuBIFxQBxpPs4WVCPIvM/rr+BFA65aMg2zcR5NQ6GuRI Up1XgsvmUB1x/i3Bo1AKDR8ZHxgez46seIf1fnSgkSIfbEm5LdsRBSLegzWyXStocdV1 HyZA8WFysuTyaKDo4CJtqNUlQS+NNKtzaEvp4qhl5FW17DmneVEMzwCBaCC6e/DoXTs9 csoQ== X-Forwarded-Encrypted: i=1; AJvYcCXB3wL7jpheRl4qU200ftHQwEPSWuXKhUkwBIb9vOfDaLntRBUnGE0bnNQ1PKCdUKxUGVX1cKmNM3uDeklONUm1cqB0Yq0BeP0fw/xTxg3SWCCYOTOVjTTAwJ+E+Nh/4QQI X-Gm-Message-State: AOJu0YwHqfrZx+dJTHLnxGSplibyHekp1043ZYF3OC7jZ2+gl13Y7PtC qx4bMv/4ZhkanYfpSB6vJzUUtua+kXxIjRBOmEzCEzjLPMsmHSWq X-Received: by 2002:a05:600c:4714:b0:41b:13d5:7da9 with SMTP id 5b1f17b1804b1-41fead643famr128548145e9.38.1715618370680; Mon, 13 May 2024 09:39:30 -0700 (PDT) Received: from localhost (54-240-197-231.amazon.com. [54.240.197.231]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-41fccee94dasm163110125e9.32.2024.05.13.09.39.30 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 13 May 2024 09:39:30 -0700 (PDT) From: Puranjay Mohan To: Maxwell Bland , "open list:BPF [GENERAL] (Safe Dynamic Programs and Tools)" Cc: Catalin Marinas , Will Deacon , 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 , Zi Shen Lim , Mark Rutland , Suzuki K Poulose , Mark Brown , linux-arm-kernel@lists.infradead.org, open list , Josh Poimboeuf Subject: Re: [PATCH bpf-next v4 2/3] arm64/cfi,bpf: Support kCFI + BPF on arm64 In-Reply-To: References: Date: Mon, 13 May 2024 16:39:28 +0000 Message-ID: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain Maxwell Bland writes: This patch has a subtle difference from the patch that I sent in v2[1] Unfortunately, you didn't test this. :( It will break BPF on an ARM64 kernel compiled with CONFIG_CFI_CLANG=y See below: > diff --git a/arch/arm64/net/bpf_jit_comp.c b/arch/arm64/net/bpf_jit_comp.c > index 76b91f36c729..703247457409 100644 > --- a/arch/arm64/net/bpf_jit_comp.c > +++ b/arch/arm64/net/bpf_jit_comp.c > @@ -17,6 +17,7 @@ > #include > #include > #include > +#include > #include > #include > #include > @@ -162,6 +163,12 @@ static inline void emit_bti(u32 insn, struct jit_ctx *ctx) > emit(insn, ctx); > } > > +static inline void emit_kcfi(u32 hash, struct jit_ctx *ctx) > +{ > + if (IS_ENABLED(CONFIG_CFI_CLANG)) > + emit(hash, ctx); > +} > + > /* > * Kernel addresses in the vmalloc space use at most 48 bits, and the > * remaining bits are guaranteed to be 0x1. So we can compose the address > @@ -337,6 +344,7 @@ static int build_prologue(struct jit_ctx *ctx, bool ebpf_from_cbpf, > * > */ In my original patch the hunk here looked something like: --- >8 --- - const int idx0 = ctx->idx; int cur_offset; /* @@ -332,6 +338,8 @@ static int build_prologue(struct jit_ctx *ctx, bool ebpf_from_cbpf, * */ + emit_kcfi(is_subprog ? cfi_bpf_subprog_hash : cfi_bpf_hash, ctx); + const int idx0 = ctx->idx; --- 8< --- moving idx0 = ctx->idx; after emit_kcfi() is important because later this 'idx0' is used like: cur_offset = ctx->idx - idx0; if (cur_offset != PROLOGUE_OFFSET) { pr_err_once("PROLOGUE_OFFSET = %d, expected %d!\n", cur_offset, PROLOGUE_OFFSET); return -1; } With the current version, when I boot the kernel I get: [ 0.499207] bpf_jit: PROLOGUE_OFFSET = 13, expected 12! and now no BPF program can be JITed! Please fix this in the next version and test it by running: /tools/testing/selftests/bpf/test_progs Pay attention to the `rbtree_success` and the `dummy_st_ops` tests, they are the important ones for this change. [1] https://lore.kernel.org/all/20240324211518.93892-2-puranjay12@gmail.com/ Thanks, Puranjay