From mboxrd@z Thu Jan 1 00:00:00 1970 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1E899C19F28 for ; Wed, 3 Aug 2022 16:32:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238303AbiHCQc5 (ORCPT ); Wed, 3 Aug 2022 12:32:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53130 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238442AbiHCQck (ORCPT ); Wed, 3 Aug 2022 12:32:40 -0400 Received: from mail-pg1-x54a.google.com (mail-pg1-x54a.google.com [IPv6:2607:f8b0:4864:20::54a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 74CBEBE0A for ; Wed, 3 Aug 2022 09:32:25 -0700 (PDT) Received: by mail-pg1-x54a.google.com with SMTP id q82-20020a632a55000000b0041bafd16728so4775975pgq.3 for ; Wed, 03 Aug 2022 09:32:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:mime-version:message-id:date:from:to:cc; bh=iyO7DTFE82DSnWeayUyzGKWvvGkvn6Eh0cYt/6e5Cs0=; b=pwVa5xrJllIxnM+BNXuMubZJtIyaJJQ8H7IV1FTtEEbjWxP0Rfi2wkog71lpFV9b4M EMULtkQy/1tSJK3xkGnUeFg/UPRCJfjYoFuX1nTewhN3rxETb8HmqbkvzMua9a0tuEvS FiCWhH6vbaKuJGe4Bg5yPLqlVcrAW5fpZLUirgWeGTQaJL/kkqRK3lgd/qYJZtVVNEA/ WYQGxn3oZ+lGw2wtKimF89x6xEFJLIAozanp/Y6fH9AxGs7TZsoUPnfb0tgSxXVhsdl1 rPgpMcPpXSpBl3ipzE2PbL4t4LlvwREECd2ga3l5JQuEHZprQo+B1gVQlaR1HRBio/6Y T6AA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:mime-version:message-id:date:x-gm-message-state :from:to:cc; bh=iyO7DTFE82DSnWeayUyzGKWvvGkvn6Eh0cYt/6e5Cs0=; b=VsDSbPAxgFH6haOlph9OYNhZKS2ah8OLU3eYdixKu6a84EskCiHEQ2FaetPyuUnmZW pZXEJvp4Wf1e6L9CJux6hy4oGpF1tX7+dXn0+Og8sjHO3oNf00zdYf2aW9+FZsrAxf/M YTx+2Rhy30Y7EErjAQ44IBvn59FS7dkejyRzALzyn8iN3II/epFJXahl1zgyhZlZ1Qg5 mtZYdAYFTVlgzv2LXN6kh/WITMnUdMXL6rtT35dpJbSdNPEDv610slLgVFDjGl/A1dM0 IvhEg7iOtLi758NAyfGwtZ8mlGmK4S5WQ6bqpYCDl5781tzoPyTuQ9ozoU3DCDWsDKFg wg6w== X-Gm-Message-State: ACgBeo27RBI4tEzwW/0bkqXMDltpJqYCe1E3I451OX9ieN88NdLaCqFC qcqSGIxWA6I+QaSG0S7HnLvwk44+eGW06vqYyja6WJy/mw+W7iAUpOpbsJfor4IteJjY6SLn1zG 3FDEMnVXwzLt2Pn2QV5oStFLerLRbeZD6nCXfLzncPAIlUZC05Q== X-Google-Smtp-Source: AA6agR5od8MRG15BgO0rZQKxsQUlWHWRCfsn97uuaWQ2+sMI4FUsEWPtfOww1Yrr2ZDY47Uh1T+It6k= X-Received: from sdf.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5935]) (user=sdf job=sendgmr) by 2002:a17:90b:2688:b0:1f3:3da3:22f4 with SMTP id pl8-20020a17090b268800b001f33da322f4mr5517722pjb.182.1659544344773; Wed, 03 Aug 2022 09:32:24 -0700 (PDT) Date: Wed, 3 Aug 2022 09:32:22 -0700 Message-Id: <20220803163223.3747004-1-sdf@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.37.1.455.g008518b4e5-goog Subject: [PATCH bpf-next v2 1/2] bpf: use proper target btf when exporting attach_btf_obj_id From: Stanislav Fomichev To: bpf@vger.kernel.org Cc: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, martin.lau@linux.dev, song@kernel.org, yhs@fb.com, john.fastabend@gmail.com, kpsingh@kernel.org, sdf@google.com, haoluo@google.com, jolsa@kernel.org, Martin KaFai Lau Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org When attaching to program, the program itself might not be attached to anything (and, hence, might not have attach_btf), so we can't unconditionally use 'prog->aux->dst_prog->aux->attach_btf'. Instead, use bpf_prog_get_target_btf to pick proper target btf: * when attached to dst_prog, use dst_prog->aux->btf * when attached to kernel btf, use prog->aux->attach_btf Fixes: b79c9fc9551b ("bpf: implement BPF_PROG_QUERY for BPF_LSM_CGROUP") Acked-by: Hao Luo Acked-by: Martin KaFai Lau Signed-off-by: Stanislav Fomichev --- kernel/bpf/syscall.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c index 83c7136c5788..7dc3f8003631 100644 --- a/kernel/bpf/syscall.c +++ b/kernel/bpf/syscall.c @@ -3886,6 +3886,7 @@ static int bpf_prog_get_info_by_fd(struct file *file, union bpf_attr __user *uattr) { struct bpf_prog_info __user *uinfo = u64_to_user_ptr(attr->info.info); + struct btf *attach_btf = bpf_prog_get_target_btf(prog); struct bpf_prog_info info; u32 info_len = attr->info.info_len; struct bpf_prog_kstats stats; @@ -4088,10 +4089,8 @@ static int bpf_prog_get_info_by_fd(struct file *file, if (prog->aux->btf) info.btf_id = btf_obj_id(prog->aux->btf); info.attach_btf_id = prog->aux->attach_btf_id; - if (prog->aux->attach_btf) - info.attach_btf_obj_id = btf_obj_id(prog->aux->attach_btf); - else if (prog->aux->dst_prog) - info.attach_btf_obj_id = btf_obj_id(prog->aux->dst_prog->aux->attach_btf); + if (attach_btf) + info.attach_btf_obj_id = btf_obj_id(attach_btf); ulen = info.nr_func_info; info.nr_func_info = prog->aux->func_info_cnt; -- 2.37.1.455.g008518b4e5-goog