From patchwork Tue Jul 27 13:25:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hengqi Chen X-Patchwork-Id: 12402721 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 84B95C4338F for ; Tue, 27 Jul 2021 13:26:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 61AD561A40 for ; Tue, 27 Jul 2021 13:26:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236888AbhG0N0p (ORCPT ); Tue, 27 Jul 2021 09:26:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33030 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236903AbhG0N0C (ORCPT ); Tue, 27 Jul 2021 09:26:02 -0400 Received: from mail-pl1-x636.google.com (mail-pl1-x636.google.com [IPv6:2607:f8b0:4864:20::636]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 06C2BC0617A0 for ; Tue, 27 Jul 2021 06:26:02 -0700 (PDT) Received: by mail-pl1-x636.google.com with SMTP id k1so15641761plt.12 for ; Tue, 27 Jul 2021 06:26:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=w0DZS25dqNWjln6apj95C/bElmocAC2rNL+DbbtPC48=; b=glwmcTCaUbofxvceGZtvinhEW4tIV8M/d5MO+4RtpMQ2x2M3mvl2fJ1S/8YE6OqrhB XTizafTB+xePqzWt5ZzArUV5rzrLEKGCNufwAvLugCCsBnq8qhFqyL0WknUtDIMivl8r Q2AaW/UHdbUhTMazqDZFv8yVA+fSd2D9B2hXO56OUtOltkZclB+zX0Cog9sZDNFx90VZ GMBhAZH7dj9MeTihzimZyrP+iNb9lbZMRj0YWshc1Wd0vKmVZUknfpysL3UkC8lcYzFR mb6cw0DRKL912bz4vybE4zqLDRFcfjSpuuo21xkCENs//uO8Mjft2Afw0reFFUumNIz4 1asA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=w0DZS25dqNWjln6apj95C/bElmocAC2rNL+DbbtPC48=; b=QmAB2sHf4ZSTm/oYvwbfZFyWhjcsghLRowXbW+lkdS43nwwG96ON5f9mtNJ17SZmBc 7gMLSTOcLeRsYMmGyjX7/HwC9Fx5i9FqVK/8c7kASnpMoNlNMy6Wg40rX4/eIzfX1rpQ pKzcywoytNxVa7o8FuVu0Xmde+T7VcDhYY8o4KWTdiGJe3N0AQ8piomkv49j16v6WoCV nWb+zUf22pH3b+sySnW6hqxZMkY8id4rgGFdhZN7aNubP1rcIzEPCa8mxz3bDAuX8XmZ NoGbqev3uETmCsUDqmp536x78COw8JKSsKFjx8WBZZjZ2pY4t7THVBZa73Z88eGQpdgi G2MQ== X-Gm-Message-State: AOAM532ogP7U971qsM4inqhWsQG/9XFRIcobApw5Z7yyKGjtsTSxSTHT soL15kqXmYffoKYhTSvwUj3EZnqKSiimqw== X-Google-Smtp-Source: ABdhPJyFZWy5z/AedWb84dZuaKh4v6nr0at0824H5TiuGlWmjUwWyZVeleWqrsgRGczH0tASR7oTHQ== X-Received: by 2002:a17:902:6b82:b029:120:3404:ce99 with SMTP id p2-20020a1709026b82b02901203404ce99mr18575538plk.49.1627392361455; Tue, 27 Jul 2021 06:26:01 -0700 (PDT) Received: from localhost.localdomain ([119.28.83.143]) by smtp.gmail.com with ESMTPSA id l11sm2002892pfd.187.2021.07.27.06.25.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Jul 2021 06:26:01 -0700 (PDT) From: Hengqi Chen To: bpf@vger.kernel.org Cc: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, yhs@fb.com, john.fastabend@gmail.com, jolsa@kernel.org, yanivagman@gmail.com, hengqi.chen@gmail.com Subject: [PATCH bpf-next v5 1/2] tools/resolve_btfids: emit warnings and patch zero id for missing symbols Date: Tue, 27 Jul 2021 21:25:31 +0800 Message-Id: <20210727132532.2473636-2-hengqi.chen@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210727132532.2473636-1-hengqi.chen@gmail.com> References: <20210727132532.2473636-1-hengqi.chen@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net Kernel functions referenced by .BTF_ids may be changed from global to static and get inlined or get renamed/removed, and thus disappears from BTF. This causes kernel build failure when resolve_btfids do id patch for symbols in .BTF_ids in vmlinux. Update resolve_btfids to emit warning messages and patch zero id for missing symbols instead of aborting kernel build process. Suggested-by: Andrii Nakryiko Acked-by: Yonghong Song Signed-off-by: Hengqi Chen --- tools/bpf/resolve_btfids/main.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/tools/bpf/resolve_btfids/main.c b/tools/bpf/resolve_btfids/main.c index 3ad9301b0f00..de6365b53c9c 100644 --- a/tools/bpf/resolve_btfids/main.c +++ b/tools/bpf/resolve_btfids/main.c @@ -291,7 +291,7 @@ static int compressed_section_fix(Elf *elf, Elf_Scn *scn, GElf_Shdr *sh) sh->sh_addralign = expected; if (gelf_update_shdr(scn, sh) == 0) { - printf("FAILED cannot update section header: %s\n", + pr_err("FAILED cannot update section header: %s\n", elf_errmsg(-1)); return -1; } @@ -317,6 +317,7 @@ static int elf_collect(struct object *obj) elf = elf_begin(fd, ELF_C_RDWR_MMAP, NULL); if (!elf) { + close(fd); pr_err("FAILED cannot create ELF descriptor: %s\n", elf_errmsg(-1)); return -1; @@ -484,7 +485,7 @@ static int symbols_resolve(struct object *obj) err = libbpf_get_error(btf); if (err) { pr_err("FAILED: load BTF from %s: %s\n", - obj->path, strerror(-err)); + obj->btf ?: obj->path, strerror(-err)); return -1; } @@ -555,8 +556,7 @@ static int id_patch(struct object *obj, struct btf_id *id) int i; if (!id->id) { - pr_err("FAILED unresolved symbol %s\n", id->name); - return -EINVAL; + pr_err("WARN: resolve_btfids: unresolved symbol %s\n", id->name); } for (i = 0; i < id->addr_cnt; i++) { @@ -734,8 +734,9 @@ int main(int argc, const char **argv) err = 0; out: - if (obj.efile.elf) + if (obj.efile.elf) { elf_end(obj.efile.elf); - close(obj.efile.fd); + close(obj.efile.fd); + } return err; } From patchwork Tue Jul 27 13:25:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hengqi Chen X-Patchwork-Id: 12402719 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-20.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 566B5C432BE for ; Tue, 27 Jul 2021 13:26:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3CC7F61AAB for ; Tue, 27 Jul 2021 13:26:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236976AbhG0N0n (ORCPT ); Tue, 27 Jul 2021 09:26:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32956 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237312AbhG0N0L (ORCPT ); Tue, 27 Jul 2021 09:26:11 -0400 Received: from mail-pl1-x62c.google.com (mail-pl1-x62c.google.com [IPv6:2607:f8b0:4864:20::62c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 884A2C061799 for ; Tue, 27 Jul 2021 06:26:11 -0700 (PDT) Received: by mail-pl1-x62c.google.com with SMTP id t21so15619069plr.13 for ; Tue, 27 Jul 2021 06:26:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=opjptYABd9lTAjTURUlye+PGqKAxcZ0rcai12mEW6Gw=; b=q7+kOBeo8gnXElVAaWQrnMCou/0GA5JCLDn+kUL8CsYabPADrf6EgdbVaZ8PH4PuB5 uAlSyYK1xtYnJgiPtZjXi1siZTfKU3ZaLvFz0pKooRx44/588cHoqDp3UiEFHF0Ip25o UwOBDbJDh/ZXCYnU9qLAs0131QKfLlwZgJaXYs+UCjTAH44VYlLViKWNJs515Rlkvg3N aHm1H9s6eS7aS0Mm3Kv2Y7l7Bb+4/1YTPQT7uIIXoBgpNNliAgIO66lmY4/5zNsjKHEX pOXFGk9jX8L/eyloAXNHsSQgzOk3ussPtC5lCL6b+7UTDtw4kbnlK2vUCAmvbtfc4to3 4ZKw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=opjptYABd9lTAjTURUlye+PGqKAxcZ0rcai12mEW6Gw=; b=mib2KSUk8ZIjYend0IdJU5YX4TGIK0ixx+cFTLrryO2/Sg202hbV2Hr0QxezGO87oQ 5MBz4TGNKAH7CSK0i+iAHR54QfsVTsLiHGZ8/i33TfwUMmNTtR09wtNeFa31Qpt/Wse1 00YCO/eU8fAfHNnm+HIxeyDnYduPULY3iQAjfAV0qNADlSh++gjPeN7tRDI3DsKc9DBr xychuYNumZKtbtpb8SR2JNAOqPwOKyf2yy7y88AV2zxmJrcyb8RgbQNLA91x74xcekhx 83JVpqaMshLWwXgLeUUipMq4HqbuqAl3yNMM6+R3DpC5RZbSxtBDaDm5Wu5BjCcyV9mO 7aug== X-Gm-Message-State: AOAM5322GweoUsU60ks7xd4WeF4Dp9EvYZ+lZZ7lQEsqyGe7I0TmdRFt NJUZZ34uzVwwQwW9VLvVhuyNgdOZPR8rSQ== X-Google-Smtp-Source: ABdhPJw1TUtv5rzFWg/NskEXRsk04VpVWrme6IjRn0HrlqzVjVQf2jfO2aSJGRreBu/W6KzjNYvQWg== X-Received: by 2002:a63:84:: with SMTP id 126mr6652730pga.221.1627392371028; Tue, 27 Jul 2021 06:26:11 -0700 (PDT) Received: from localhost.localdomain ([119.28.83.143]) by smtp.gmail.com with ESMTPSA id l11sm2002892pfd.187.2021.07.27.06.26.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Jul 2021 06:26:10 -0700 (PDT) From: Hengqi Chen To: bpf@vger.kernel.org Cc: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, yhs@fb.com, john.fastabend@gmail.com, jolsa@kernel.org, yanivagman@gmail.com, hengqi.chen@gmail.com Subject: [PATCH bpf-next v5 2/2] bpf: expose bpf_d_path helper to vfs_* and security_* functions Date: Tue, 27 Jul 2021 21:25:32 +0800 Message-Id: <20210727132532.2473636-3-hengqi.chen@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210727132532.2473636-1-hengqi.chen@gmail.com> References: <20210727132532.2473636-1-hengqi.chen@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net Add vfs_* and security_* to bpf_d_path allowlist, so that we can use bpf_d_path helper to extract full file path from these functions' arguments. This will help tools like BCC's filetop[1]/filelife to get full file path. [1] https://github.com/iovisor/bcc/issues/3527 Acked-by: Yonghong Song Signed-off-by: Hengqi Chen --- kernel/trace/bpf_trace.c | 60 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 56 insertions(+), 4 deletions(-) diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c index c5e0b6a64091..e7b24abcf3bf 100644 --- a/kernel/trace/bpf_trace.c +++ b/kernel/trace/bpf_trace.c @@ -849,18 +849,70 @@ BPF_CALL_3(bpf_d_path, struct path *, path, char *, buf, u32, sz) BTF_SET_START(btf_allowlist_d_path) #ifdef CONFIG_SECURITY +BTF_ID(func, security_bprm_check) +BTF_ID(func, security_bprm_committed_creds) +BTF_ID(func, security_bprm_committing_creds) +BTF_ID(func, security_bprm_creds_for_exec) +BTF_ID(func, security_bprm_creds_from_file) +BTF_ID(func, security_file_alloc) +BTF_ID(func, security_file_fcntl) +BTF_ID(func, security_file_free) +BTF_ID(func, security_file_ioctl) +BTF_ID(func, security_file_lock) +BTF_ID(func, security_file_open) BTF_ID(func, security_file_permission) +BTF_ID(func, security_file_receive) +BTF_ID(func, security_file_set_fowner) BTF_ID(func, security_inode_getattr) -BTF_ID(func, security_file_open) +BTF_ID(func, security_sb_mount) #endif #ifdef CONFIG_SECURITY_PATH +BTF_ID(func, security_path_chmod) +BTF_ID(func, security_path_chown) +BTF_ID(func, security_path_chroot) +BTF_ID(func, security_path_link) +BTF_ID(func, security_path_mkdir) +BTF_ID(func, security_path_mknod) +BTF_ID(func, security_path_notify) +BTF_ID(func, security_path_rename) +BTF_ID(func, security_path_rmdir) +BTF_ID(func, security_path_symlink) BTF_ID(func, security_path_truncate) +BTF_ID(func, security_path_unlink) #endif -BTF_ID(func, vfs_truncate) -BTF_ID(func, vfs_fallocate) BTF_ID(func, dentry_open) -BTF_ID(func, vfs_getattr) BTF_ID(func, filp_close) +BTF_ID(func, vfs_cancel_lock) +BTF_ID(func, vfs_clone_file_range) +BTF_ID(func, vfs_copy_file_range) +BTF_ID(func, vfs_dedupe_file_range) +BTF_ID(func, vfs_dedupe_file_range_one) +BTF_ID(func, vfs_fadvise) +BTF_ID(func, vfs_fallocate) +BTF_ID(func, vfs_fchmod) +BTF_ID(func, vfs_fchown) +BTF_ID(func, vfs_fsync) +BTF_ID(func, vfs_fsync_range) +BTF_ID(func, vfs_getattr) +BTF_ID(func, vfs_getattr_nosec) +BTF_ID(func, vfs_iocb_iter_read) +BTF_ID(func, vfs_iocb_iter_write) +BTF_ID(func, vfs_ioctl) +BTF_ID(func, vfs_iter_read) +BTF_ID(func, vfs_iter_write) +BTF_ID(func, vfs_llseek) +BTF_ID(func, vfs_lock_file) +BTF_ID(func, vfs_open) +BTF_ID(func, vfs_read) +BTF_ID(func, vfs_readv) +BTF_ID(func, vfs_setlease) +BTF_ID(func, vfs_setpos) +BTF_ID(func, vfs_statfs) +BTF_ID(func, vfs_test_lock) +BTF_ID(func, vfs_truncate) +BTF_ID(func, vfs_utimes) +BTF_ID(func, vfs_write) +BTF_ID(func, vfs_writev) BTF_SET_END(btf_allowlist_d_path) static bool bpf_d_path_allowed(const struct bpf_prog *prog)