Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp2364642lqp; Sun, 24 Mar 2024 15:59:25 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUuoNudQ8GXg0F1yz5e9UHz59OGkfZrT8OkVddsyLXAkQ2SBHGsxL0LSi+EfGWkfoKT6sI8ry4z+a9s0iEPfErgw24X2YN1J14Oi45bBQ== X-Google-Smtp-Source: AGHT+IG2JAnOPrErGCOyzaJaL8BwD44YqlVtLz1REG0PU6r2UAPW5aOdXiZGxxzCo+/Srx4i1RXL X-Received: by 2002:a05:6808:6409:b0:3c3:c215:e69e with SMTP id fg9-20020a056808640900b003c3c215e69emr6932303oib.46.1711321164817; Sun, 24 Mar 2024 15:59:24 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711321164; cv=pass; d=google.com; s=arc-20160816; b=b81M6T5Ygehb946oGL18bJ6tWZXZySOFwHeCbEybpzKxUun7wIsM3aBEpPEF4IJfhS V7QkcSS+7rc11PzVrao+IcGsFB8+ItvrHjxRK/KzR0FucnKPSh/tKFjchWj5xM+dvIlu CActjvcg0hPdRbVVpCr2p+ODL+K/BZSCfYdyQbwW1QscNvJauZkZvdwIAxlJoWu3j7Sg kG0dsxw6AtrKQRwyxISXV/N8wr1XELSH9OpYDSeX0TxGcA4n0EA7aNDfHWlevXl3X4Zx d9/I39qvtYH9cWYYDLEGbc1EF8mkxEK+VwVnU6VOiXl9OvPX4qyzqzcKh2ZsLVH3G3PT vfFw== 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:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=tvhXDJUefkR959P0tIFYs2/bOEQZE7aRPEOGQQKBYCI=; fh=hBcrz64mJOHwMUislWQ7JYY7g5ob+mehd77hkKPTP78=; b=CVik9L77EPrG2vRGVAM82vpE81L+TnILiEZzDB3BkD1Eq2YRwFW7gUfpuCCrACPl5N fi577BmT6dgT1iURfTfj5TT2fo263roBQ8y6bsdfrVoz/ULmDqgKvJjxrrGne82bcrze R4CKHhPXCs/qPpM1QqYQVCJyX+3iE3x13nQ13Dt8LBthwNGXEMLhzrsLmOIzgy0LcfKs F88Uej0GUiPwA3exEcO4u8QcypO+A7MEiMn+zylvAImTywAPNJ2TIBm4nSjSXK+4TU9a v96KpzmUd3LPpVITDHPpt1+Y335zJafuyvNt0K80LaVM9gW0wieXPhkNyl3jyu9Kul0S 9WFg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=QtARC0bx; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-112990-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-112990-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id d1-20020a634f01000000b005cf94b8d9ddsi6611317pgb.869.2024.03.24.15.59.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Mar 2024 15:59:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-112990-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=QtARC0bx; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-112990-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-112990-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 77970281504 for ; Sun, 24 Mar 2024 22:59:24 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 741CD12DDBC; Sun, 24 Mar 2024 22:36:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="QtARC0bx" 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 8ABC412DD99; Sun, 24 Mar 2024 22:36:42 +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=1711319802; cv=none; b=kw2ro03KP8grL3cx+jaMkvd9SoOXwdhclEUshkJK03dFuty/1lTzb9dC6rXDSa6xOy6AJ9F42wqJxP1RWnmfB49bHGc5ln2RLcK16A808AbvH6saXGi0/KJIvmM0mh16fLW7T2mr+WGHLMDk6bPSutKw+MsOh4nFRC2MZkHICdA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711319802; c=relaxed/simple; bh=Pt8lfoqc4pHW8JA5jUyEQqyGcf753/ema3dIBVHANG0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mzsgWe5O6SbV2nQN6KqfC5RCSxb0oVFSf3UlBy1hVxNNmaf+kPuZOlRcyNzbF0YCw1IaPxQyRp7t13beI6VfgHVhpW4OuVw8gu6g0SWhGcaqcC6roH3+JI92Itm77BNaztCM9BXx5ZTDQ6PYrHL6Qk6oisXSExULi30Tjrqj5w0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=QtARC0bx; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id C88DFC433C7; Sun, 24 Mar 2024 22:36:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711319802; bh=Pt8lfoqc4pHW8JA5jUyEQqyGcf753/ema3dIBVHANG0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QtARC0bxHUGNRWASKUlk5lgv1zoETnWQgC6rQ16mHBpONnoSgN2bbJtqkPrcyT52r zvI7UFbO8p8qnmib9sHBvVNSO8cJ7E1WxFuirQTiBfSXpN8sshox/qTji5aJqRchm5 Hu5g9r7gnvrDJE0BbYucHeXwQMf1oSiWV6jR726nWgy+M4eNU433oOgPd74QbvRHaL mqWApKpd9pPSbpVnvth/yfvxzEbThqPdMmwr2LDEvrwh0ET8QZVmQHWuL7af7MM+G5 rWq3n4TVh6QD/luhzPGnsZKNG0zsgGaPPKVLgMiV/GjZ9nx6Uw/ulzE2YuVKUoRUfw zj3+HtNOWjKAA== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Andrii Nakryiko , Alexei Starovoitov , Sasha Levin Subject: [PATCH 6.8 103/715] libbpf: fix __arg_ctx type enforcement for perf_event programs Date: Sun, 24 Mar 2024 18:24:42 -0400 Message-ID: <20240324223455.1342824-104-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240324223455.1342824-1-sashal@kernel.org> References: <20240324223455.1342824-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit From: Andrii Nakryiko [ Upstream commit 9eea8fafe33eb70868f6ace2fc1e17c4ff5539c3 ] Adjust PERF_EVENT type enforcement around __arg_ctx to match exactly what kernel is doing. Fixes: 76ec90a996e3 ("libbpf: warn on unexpected __arg_ctx type when rewriting BTF") Signed-off-by: Andrii Nakryiko Link: https://lore.kernel.org/r/20240125205510.3642094-3-andrii@kernel.org Signed-off-by: Alexei Starovoitov Signed-off-by: Sasha Levin --- tools/lib/bpf/libbpf.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c index b8b00da629071..910f72c9e6a49 100644 --- a/tools/lib/bpf/libbpf.c +++ b/tools/lib/bpf/libbpf.c @@ -33,6 +33,7 @@ #include #include #include +#include #include #include #include @@ -6699,6 +6700,14 @@ static struct { /* all other program types don't have "named" context structs */ }; +/* forward declarations for arch-specific underlying types of bpf_user_pt_regs_t typedef, + * for below __builtin_types_compatible_p() checks; + * with this approach we don't need any extra arch-specific #ifdef guards + */ +struct pt_regs; +struct user_pt_regs; +struct user_regs_struct; + static bool need_func_arg_type_fixup(const struct btf *btf, const struct bpf_program *prog, const char *subprog_name, int arg_idx, int arg_type_id, const char *ctx_name) @@ -6739,11 +6748,21 @@ static bool need_func_arg_type_fixup(const struct btf *btf, const struct bpf_pro /* special cases */ switch (prog->type) { case BPF_PROG_TYPE_KPROBE: - case BPF_PROG_TYPE_PERF_EVENT: /* `struct pt_regs *` is expected, but we need to fix up */ if (btf_is_struct(t) && strcmp(tname, "pt_regs") == 0) return true; break; + case BPF_PROG_TYPE_PERF_EVENT: + if (__builtin_types_compatible_p(bpf_user_pt_regs_t, struct pt_regs) && + btf_is_struct(t) && strcmp(tname, "pt_regs") == 0) + return 0; + if (__builtin_types_compatible_p(bpf_user_pt_regs_t, struct user_pt_regs) && + btf_is_struct(t) && strcmp(tname, "user_pt_regs") == 0) + return 0; + if (__builtin_types_compatible_p(bpf_user_pt_regs_t, struct user_regs_struct) && + btf_is_struct(t) && strcmp(tname, "user_regs_struct") == 0) + return 0; + break; case BPF_PROG_TYPE_RAW_TRACEPOINT: case BPF_PROG_TYPE_RAW_TRACEPOINT_WRITABLE: /* allow u64* as ctx */ -- 2.43.0