Received: by 2002:ab2:69cc:0:b0:1f4:be93:e15a with SMTP id n12csp1277116lqp; Mon, 15 Apr 2024 00:59:46 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCW2vUwh7qmo/o7DKgfsM7DPFatl4E+UhHICCG8uPFLVNmY3yuCS+tjiHgj4jJ4g4RcaSS2QHs0Fjh9ioVszAEc16EUVv9uN7xa3SzlooQ== X-Google-Smtp-Source: AGHT+IFIBXUCAPkKDvtXuB0Qy1irUx6ANFI624Mi+kahxh0tpYH7d1ap6i28qX9qaxmhU+x589cQ X-Received: by 2002:a50:d78e:0:b0:56e:2452:f867 with SMTP id w14-20020a50d78e000000b0056e2452f867mr7453973edi.37.1713167986711; Mon, 15 Apr 2024 00:59:46 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713167986; cv=pass; d=google.com; s=arc-20160816; b=SGnFSO35nw5V1fLdJn1e0aE1yDmssjGS5GjkDKNw6RSBWvXQJCqw/FCfH0rf2/hRYc kYVRNxKZH8pLn9OXwvn+LoEKv2P+R3kk1x8F6eR15eXE+ZuKbNq8MEDDbYzQph1AC/KR nJBsXFGkgwLDtEswx1HdoMxervLVpKClNf32KLHuIy9wIGFITMr3a3BY62UloPIWlGnm WsObIGkCMBRmrt/AVQM/8fATvjv0AwrMMSoFkjMXAKjw5drDNCNkmQyQhColi3EaONgi XklkZPJotBtieew4acuITYUP6sEKi0A2KBKITWlWlhmzmw/LWZ1ncLTwZrY3yVpIEPiB jlNg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:message-id:references:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:in-reply-to:date :dkim-signature; bh=xg18GyqyaeWty+ItqB3Iy6JPUVdZJOOF1IDiLwlHKNc=; fh=37SgqZs8NHw5UWa65nNC35xbN7HF32A7CKr0tgrvZK0=; b=l3tIynk/xCpXvle+HzbEr/UQ15jTWxJh43l3PSqKgTiPWDedSHfYVJ57A/0qo6Mz3H T0jeeR8OwT7vDrhBeGiH5OANs1WzhbXcdBNZ2TftIYg8nVU1nFGwzVLthhB7/4JQxa7W R7fhfYxYQfiyTko9XRXbnwhr4mRayZCzXDrZOlh02At/0P5c7CmuHbjux11b9lERbJlc 1aBmOUxnUumV3VD/ESkdGeURVZcqQH3OqWrfuj5AJgHL7QInvJUGlXcoKXS9hsfFmolK 5rjePykyaAT5p0ZleecZlPpuWSIJEb59P0ghdMdg3a2DfGo0j8hZIlABXjbUOAo2R7Rg G/Fg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="1HAvSx/M"; arc=pass (i=1 spf=pass spfdomain=flex--ardb.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-144714-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-144714-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id t26-20020a50ab5a000000b0057009a26a26si2607695edc.126.2024.04.15.00.59.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Apr 2024 00:59:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-144714-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="1HAvSx/M"; arc=pass (i=1 spf=pass spfdomain=flex--ardb.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-144714-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-144714-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.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 am.mirrors.kernel.org (Postfix) with ESMTPS id 445F01F23F52 for ; Mon, 15 Apr 2024 07:59:46 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 01CE339FF4; Mon, 15 Apr 2024 07:58:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="1HAvSx/M" Received: from mail-wr1-f74.google.com (mail-wr1-f74.google.com [209.85.221.74]) (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 36C5E376E7 for ; Mon, 15 Apr 2024 07:58:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.74 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713167935; cv=none; b=WaJBUfq5AB3jeAuQBu4918C5sx9b0TezSQsurFyyWwLHfDpR7+mzkz3D2fNTxUEqLxB0/l0MNcaUMgTSgc+l087Y9ng7ZvGGEPzPc9BrJjo2jOQEkm+VaTaCYBbe9x8Dto7L2sxHrQKKu7h9SU8lmC5DIcxkKEa9gtj5GEL8qV8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713167935; c=relaxed/simple; bh=pSFwalqd3s5K1XjaH3Dk31u90WGesAg2Ef0b/1JvrU8=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=Q3QfDXPzS0GZK91qQq83iGNalYSIBOzO83LL+d1EQgnk8YAZHtTW8eJI2qnHrjuvM9xyGgpSB9PTv1QAnVLBsku26A5LiqFF+asCw5gcfLaxX6dV8QwPt+qBh3VsPjd5HGctVVRAGSX6MmfbaiXa0PLWAwdHVOahkXLe3KeRJWU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--ardb.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=1HAvSx/M; arc=none smtp.client-ip=209.85.221.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--ardb.bounces.google.com Received: by mail-wr1-f74.google.com with SMTP id ffacd0b85a97d-343ee356227so1871568f8f.2 for ; Mon, 15 Apr 2024 00:58:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1713167930; x=1713772730; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=xg18GyqyaeWty+ItqB3Iy6JPUVdZJOOF1IDiLwlHKNc=; b=1HAvSx/MirLi8qZCPzjzHBXa65Ssoi1NxSr1WbXE1tcQ/ICSMSEvcygfVcfd1Nrepn AG8rvW3Y2OuQ/bs/JreqLGS5lySPq6TSbz+k8k8tZlQnjS3ZdsinDqMBuvyIIOgjVDTg Jgq4+6BGPyW9roK9uwf/YHo9pJZUnWF16e7dK3AIvAmZIkJUeseFYMWNaOx5nidl+zOU A4QCbzitJSEGzEyDULWUkbwuY2Ayy9rZKiyNvoXHNQEqi8NjCoE6NVaTDXifoOtVZROd 1qa4UxvQfpgqw77SpQISVBsThS5PSArm4TrBY6K+q8As7oygPyoGY+yBRzHuTEjq4ZJZ 6PSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713167930; x=1713772730; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=xg18GyqyaeWty+ItqB3Iy6JPUVdZJOOF1IDiLwlHKNc=; b=AmIsVWDl7UO9VIdhavLGxtglZlIdVMMRlUVb0n9XU0rgmqM/ViHZ4v9D4aSJlZ5ViL B/qPGqkBJBiHkFT42Mo+QHbLI13JCFPaFdHc3IH9uGr+U0M30GDbNGd0VM4GNImEWsk6 o8gPSUK/PnogYF7Jl4e5MyGgFwXNI8zfcyyhl2z/TlNxDB7clOePcRjPSJHBJ7PuhPED FWBtp5iSG3ctPft0fp8/ueU/f6N4grpGW8X/nP6Rx7uwKIzn6J5y39/Ntxvfo28x2hWr 50kHi5lq4AYZ+aJD5j4vFdPri2q4/Ek6Sj8z9+JpQwpIgFxlNSmz0PWKSBWxPoYYJi/K E5tA== X-Gm-Message-State: AOJu0Yx8Ea4RUUkFRnkS1KdR6LGiqN+iH3qIjnI2+iPZ3uUN+G+lAd6y HjbxEeQWUDqSkj9oqmelkwoE0zFoSFnRSQFy79XdvrRW+yvIT48zsUZBHVr1YM+QHhNtRrQXZCq m9f2sBWXe9f+eLo1lKB2FaRc4bt6XvxmS4pmpMWi9aUkG3WkxInQOgrrfjql5neuaZqxFfT+rmn GQBbCp6oUI7OJquNSc9OigKxxhGbAISA== X-Received: from palermo.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:118a]) (user=ardb job=sendgmr) by 2002:adf:e351:0:b0:346:5932:a05d with SMTP id n17-20020adfe351000000b003465932a05dmr19116wrj.8.1713167930559; Mon, 15 Apr 2024 00:58:50 -0700 (PDT) Date: Mon, 15 Apr 2024 09:58:41 +0200 In-Reply-To: <20240415075837.2349766-5-ardb+git@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240415075837.2349766-5-ardb+git@google.com> X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Developer-Signature: v=1; a=openpgp-sha256; l=3445; i=ardb@kernel.org; h=from:subject; bh=Kj7lwSufbF5VMIDGpWufnrtYiMGkl56Qhtk1J6ZR1Ew=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JIU3mnsG81wt++v+NZFuZ8fnStSL1Se6xebsflCjflPkhX 3RywmGJjlIWBjEOBlkxRRaB2X/f7Tw9UarWeZYszBxWJpAhDFycAjCRBwWMDAslmD5NmVr72WvH h01cW2oeF76f5MB8fzHHv63X3Fnb9bQZ/sdxMK/3LyxKd/4XrHicbfaGY/l5q7bNjjr9OOdygW/ ZKh4A X-Mailer: git-send-email 2.44.0.683.g7961c838ac-goog Message-ID: <20240415075837.2349766-8-ardb+git@google.com> Subject: [PATCH v3 3/3] btf: Avoid weak external references From: Ard Biesheuvel To: linux-kernel@vger.kernel.org Cc: Ard Biesheuvel , Masahiro Yamada , Arnd Bergmann , Martin KaFai Lau , linux-arch@vger.kernel.org, linux-kbuild@vger.kernel.org, bpf@vger.kernel.org, Andrii Nakryiko , Jiri Olsa Content-Type: text/plain; charset="UTF-8" From: Ard Biesheuvel If the BTF code is enabled in the build configuration, the start/stop BTF markers are guaranteed to exist in the final link but not during the first linker pass. Avoid GOT based relocations to these markers in the final executable by providing preliminary definitions that will be used by the first linker pass, and superseded by the actual definitions in the subsequent ones. Make the preliminary definitions dependent on CONFIG_DEBUG_INFO_BTF so that inadvertent references to this section will trigger a link failure if they occur in code that does not honour CONFIG_DEBUG_INFO_BTF. Note that Clang will notice that taking the address of__start_BTF cannot yield NULL any longer, so testing for that condition is no longer needed. Acked-by: Andrii Nakryiko Acked-by: Arnd Bergmann Signed-off-by: Ard Biesheuvel --- include/asm-generic/vmlinux.lds.h | 9 +++++++++ kernel/bpf/btf.c | 7 +++++-- kernel/bpf/sysfs_btf.c | 6 +++--- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h index e8449be62058..4cb3d88449e5 100644 --- a/include/asm-generic/vmlinux.lds.h +++ b/include/asm-generic/vmlinux.lds.h @@ -456,6 +456,7 @@ * independent code. */ #define PRELIMINARY_SYMBOL_DEFINITIONS \ + PRELIMINARY_BTF_DEFINITIONS \ PROVIDE(kallsyms_addresses = .); \ PROVIDE(kallsyms_offsets = .); \ PROVIDE(kallsyms_names = .); \ @@ -466,6 +467,14 @@ PROVIDE(kallsyms_markers = .); \ PROVIDE(kallsyms_seqs_of_names = .); +#ifdef CONFIG_DEBUG_INFO_BTF +#define PRELIMINARY_BTF_DEFINITIONS \ + PROVIDE(__start_BTF = .); \ + PROVIDE(__stop_BTF = .); +#else +#define PRELIMINARY_BTF_DEFINITIONS +#endif + /* * Read only Data */ diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c index 90c4a32d89ff..6d46cee47ae3 100644 --- a/kernel/bpf/btf.c +++ b/kernel/bpf/btf.c @@ -5642,8 +5642,8 @@ static struct btf *btf_parse(const union bpf_attr *attr, bpfptr_t uattr, u32 uat return ERR_PTR(err); } -extern char __weak __start_BTF[]; -extern char __weak __stop_BTF[]; +extern char __start_BTF[]; +extern char __stop_BTF[]; extern struct btf *btf_vmlinux; #define BPF_MAP_TYPE(_id, _ops) @@ -5971,6 +5971,9 @@ struct btf *btf_parse_vmlinux(void) struct btf *btf = NULL; int err; + if (!IS_ENABLED(CONFIG_DEBUG_INFO_BTF)) + return ERR_PTR(-ENOENT); + env = kzalloc(sizeof(*env), GFP_KERNEL | __GFP_NOWARN); if (!env) return ERR_PTR(-ENOMEM); diff --git a/kernel/bpf/sysfs_btf.c b/kernel/bpf/sysfs_btf.c index ef6911aee3bb..fedb54c94cdb 100644 --- a/kernel/bpf/sysfs_btf.c +++ b/kernel/bpf/sysfs_btf.c @@ -9,8 +9,8 @@ #include /* See scripts/link-vmlinux.sh, gen_btf() func for details */ -extern char __weak __start_BTF[]; -extern char __weak __stop_BTF[]; +extern char __start_BTF[]; +extern char __stop_BTF[]; static ssize_t btf_vmlinux_read(struct file *file, struct kobject *kobj, @@ -32,7 +32,7 @@ static int __init btf_vmlinux_init(void) { bin_attr_btf_vmlinux.size = __stop_BTF - __start_BTF; - if (!__start_BTF || bin_attr_btf_vmlinux.size == 0) + if (bin_attr_btf_vmlinux.size == 0) return 0; btf_kobj = kobject_create_and_add("btf", kernel_kobj); -- 2.44.0.683.g7961c838ac-goog