From patchwork Sat Jan 7 02:53:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Connor O'Brien X-Patchwork-Id: 40303 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp1133681wrt; Fri, 6 Jan 2023 18:57:43 -0800 (PST) X-Google-Smtp-Source: AMrXdXt/eTUWqdw8VU/tZQb68eURaTzWBLYKaPgrgwYzeL+rXUjd0yn7AOMy3AJaaYbfvStIHizL X-Received: by 2002:a17:90a:ee86:b0:226:b627:6779 with SMTP id i6-20020a17090aee8600b00226b6276779mr12423774pjz.5.1673060262745; Fri, 06 Jan 2023 18:57:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673060262; cv=none; d=google.com; s=arc-20160816; b=R7ib7795WMh6oM31jDNtsQK4jIkKba961ngmXyIVlgG7WV8ZgiKPHnDB81R1AdIsA8 aEIK7VZARya94anTobbUd930uLZk3osNV7bD0Aj7ViQcVPfYLjDIhTS7ActNbtA/7Nwl FH6vZD+UW+u7IcGzQZRJQC/xQD4HkonoGQ9BnYmVsrPWZg38QD5nscp88dZVxL3FlMBR IaxatvVvTJhrOwDrxj+U+DljSbKDKWInfDYomciYWc5USZTI79kxGL4RInWR0AhZ9M+4 aeSUUCI9lhGpNO+uSEqPeG2mIKGQ21uHb2SQ6FloazwRuVglRqja08c6jdJmn4RGPVIn sUkg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:mime-version:date :dkim-signature; bh=/LXD7bWn6Jkwh9hHWJBLtYnysPLbu62uMIUKDSw+zHg=; b=L9e+wWQTGBno12AeF9uEO9yh/M8szDMAx+SVyAXb+CtsCD9HXCkhJQx0E8KBl9+xUI o5imfsu+bSpb6iI0YqwgkHzn7tGjlhS0FrAN8nKY/O7OzVX0njJ6awUFAwUS3knIijIj IKsimI40EmuIzrsL1+kFupVz3yaKa8hapudTp4JOo06kZeJNlq5RIKzKgFV1CIc8RmkH 3kVvUbt4fYYXpvGvH1r9uodPQN5BZstvRlA5cIhHk7QxvRIObfMfy3IDNp0pkESrTfsj He59FlO+wFe9DHR3xxenUigdD43mNA0AO39r5+dm8PsVUc+eqE6FI4xccrrShyrG8Ahn zVyA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b="D/axEx4F"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b30-20020a631b1e000000b004a5c9673b66si3046068pgb.323.2023.01.06.18.57.30; Fri, 06 Jan 2023 18:57:42 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b="D/axEx4F"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236290AbjAGCyp (ORCPT + 99 others); Fri, 6 Jan 2023 21:54:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60436 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229521AbjAGCyn (ORCPT ); Fri, 6 Jan 2023 21:54:43 -0500 Received: from mail-pl1-x649.google.com (mail-pl1-x649.google.com [IPv6:2607:f8b0:4864:20::649]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 484A28B538 for ; Fri, 6 Jan 2023 18:54:41 -0800 (PST) Received: by mail-pl1-x649.google.com with SMTP id y8-20020a170902b48800b00192a600df83so2353736plr.15 for ; Fri, 06 Jan 2023 18:54:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=/LXD7bWn6Jkwh9hHWJBLtYnysPLbu62uMIUKDSw+zHg=; b=D/axEx4FkjtSzhj6GtMgJ/eJNW2W8y+wGrdJ6WK+JKRibRRQcNB02GD5Ej+HMaYzOn I4r8jetP7aQCigvNTyA+nvW63VqQ2V6lagidpSk2Wc6g3eMvIVBCfLScXdMjhdGhYnS2 gZdq4p+zvacBigitPU1lyIDbtuDurtbuBWboWKzVSJylU00HTdVPoEFrfKombEw7cYgp fkl7HePlLnEugAAkQqbvJFIge9bxGIJIlNcDBXdTB4qpZZSDOGPLVcMmn64hFW/w8vgf 8UdkiTCNLip4UgwFTTGJyht9/eGWnzVCemsh9yUucwUUbZONP3ieq5KhQWJigpJdk5M1 VWag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=/LXD7bWn6Jkwh9hHWJBLtYnysPLbu62uMIUKDSw+zHg=; b=AhUw+VtgoFQTpvgWyScEDx6P1nxEAU+x/ozLM1JE1BISfYE2+r/4kns1D4nLwovLT3 hesacZ+1BL5z1/qWycZlvaOQcVNONudjWyVOwNtvOZvBumWXBVVciGqlSXJo/KzbG84q J7KgWTvtY4tmrHfY7OXou3G/V5IDR1VC+qI2i3mBrDt8cpRol5TCAVBZqViPOUJvDv1w CZbrBdclOMATwkbQk5OQr7hp17XfJDyhxtX06+gI03uGb9tU+5Ll0AkyNMDRDq7PQGoZ WZaeb3N1mxMxkaA6UNy9Rza/RY80c0clT4d81Jq9er/1TetcsdgVbMBCr5fcceHaGLIj q9mQ== X-Gm-Message-State: AFqh2kqcfSiU8m87x8otJYXF/2S6wYGGcKujkC1fMev86KulAmq1DniW +MBfXi5dbhqg9F6N5G5r7Mq6AX2nqgrm X-Received: from connoro.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:a99]) (user=connoro job=sendgmr) by 2002:a05:6a00:440b:b0:583:860:7a30 with SMTP id br11-20020a056a00440b00b0058308607a30mr906809pfb.1.1673060080726; Fri, 06 Jan 2023 18:54:40 -0800 (PST) Date: Sat, 7 Jan 2023 02:53:31 +0000 Mime-Version: 1.0 X-Mailer: git-send-email 2.39.0.314.g84b9a713c41-goog Message-ID: <20230107025331.3240536-1-connoro@google.com> Subject: [PATCH bpf-next v3] bpf: btf: limit logging of ignored BTF mismatches From: "Connor O'Brien" To: bpf@vger.kernel.org Cc: Martin KaFai Lau , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , linux-kernel@vger.kernel.org, "Connor O'Brien" X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754330837898508032?= X-GMAIL-MSGID: =?utf-8?q?1754330837898508032?= Enabling CONFIG_MODULE_ALLOW_BTF_MISMATCH is an indication that BTF mismatches are expected and module loading should proceed anyway. Logging with pr_warn() on every one of these "benign" mismatches creates unnecessary noise when many such modules are loaded. Instead, handle this case with a single log warning that BTF info may be unavailable. Mismatches also result in calls to __btf_verifier_log() via __btf_verifier_log_type() or btf_verifier_log_member(), adding several additional lines of logging per mismatched module. Add checks to these paths to skip logging for module BTF mismatches in the "allow mismatch" case. All existing logging behavior is preserved in the default CONFIG_MODULE_ALLOW_BTF_MISMATCH=n case. Signed-off-by: Connor O'Brien Acked-by: Yonghong Song --- v3: - fix commenting style - reuse existing "log->level == BPF_LOG_KERNEL" check for kernel BTF v2: - Use pr_warn_once instead of skipping logging entirely - Also skip btf verifier logs for ignored mismatches v1: https://lore.kernel.org/bpf/20221109024155.2810410-1-connoro@google.com/ --- kernel/bpf/btf.c | 38 +++++++++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c index f7dd8af06413..67eee2d83dc8 100644 --- a/kernel/bpf/btf.c +++ b/kernel/bpf/btf.c @@ -1397,12 +1397,18 @@ __printf(4, 5) static void __btf_verifier_log_type(struct btf_verifier_env *env, if (!bpf_verifier_log_needed(log)) return; - /* btf verifier prints all types it is processing via - * btf_verifier_log_type(..., fmt = NULL). - * Skip those prints for in-kernel BTF verification. - */ - if (log->level == BPF_LOG_KERNEL && !fmt) - return; + if (log->level == BPF_LOG_KERNEL) { + /* btf verifier prints all types it is processing via + * btf_verifier_log_type(..., fmt = NULL). + * Skip those prints for in-kernel BTF verification. + */ + if (!fmt) + return; + + /* Skip logging when loading module BTF with mismatches permitted */ + if (env->btf->base_btf && IS_ENABLED(CONFIG_MODULE_ALLOW_BTF_MISMATCH)) + return; + } __btf_verifier_log(log, "[%u] %s %s%s", env->log_type_id, @@ -1441,8 +1447,15 @@ static void btf_verifier_log_member(struct btf_verifier_env *env, if (!bpf_verifier_log_needed(log)) return; - if (log->level == BPF_LOG_KERNEL && !fmt) - return; + if (log->level == BPF_LOG_KERNEL) { + if (!fmt) + return; + + /* Skip logging when loading module BTF with mismatches permitted */ + if (env->btf->base_btf && IS_ENABLED(CONFIG_MODULE_ALLOW_BTF_MISMATCH)) + return; + } + /* The CHECK_META phase already did a btf dump. * * If member is logged again, it must hit an error in @@ -7260,11 +7273,14 @@ static int btf_module_notify(struct notifier_block *nb, unsigned long op, } btf = btf_parse_module(mod->name, mod->btf_data, mod->btf_data_size); if (IS_ERR(btf)) { - pr_warn("failed to validate module [%s] BTF: %ld\n", - mod->name, PTR_ERR(btf)); kfree(btf_mod); - if (!IS_ENABLED(CONFIG_MODULE_ALLOW_BTF_MISMATCH)) + if (!IS_ENABLED(CONFIG_MODULE_ALLOW_BTF_MISMATCH)) { + pr_warn("failed to validate module [%s] BTF: %ld\n", + mod->name, PTR_ERR(btf)); err = PTR_ERR(btf); + } else { + pr_warn_once("Kernel module BTF mismatch detected, BTF debug info may be unavailable for some modules\n"); + } goto out; } err = btf_alloc_id(btf);