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 6D849C433F5 for ; Wed, 23 Feb 2022 01:29:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236581AbiBWB34 (ORCPT ); Tue, 22 Feb 2022 20:29:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57346 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236555AbiBWB3z (ORCPT ); Tue, 22 Feb 2022 20:29:55 -0500 Received: from mail-pj1-x104a.google.com (mail-pj1-x104a.google.com [IPv6:2607:f8b0:4864:20::104a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6716749CBE for ; Tue, 22 Feb 2022 17:29:26 -0800 (PST) Received: by mail-pj1-x104a.google.com with SMTP id x17-20020a17090ab01100b001bbffb2c5f3so434165pjq.9 for ; Tue, 22 Feb 2022 17:29:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:message-id:mime-version:subject:from:to:cc :content-transfer-encoding; bh=XJt7E+/TbSWO+R4K5yrVaKdlcnMjFDGRebGSqWZKoOM=; b=VUYknfLXL+unn/6VXtDwyrULYfWLDjOsZa0fJmThc66yI1NsTFLXS6HOfPxjE13UR0 wfmwCx/GaDmK8g9Seq1lutlHlvAv2/YRiwYFbBvOXJw2ZEj/WB9DTgIoDA84dsTiF24A /6zLKmpQbnTLC4tgp3e6zNGrOFs9syvzaoDMq5miys2dfVDHVuNhilHNQDsMksd6p5pP 9rSvP4TH5Ih9Nu9GwP0qxEdeCOVbDBSUbpgHqa7zjE/+PTlmyizMdoKp5f+kdjciUQXS h5sUUYrb2DvtR2As0ASss2/vfKVYUvuCWAOvppGcllXLKnyuYinNIAjYK1oVtKeRqYtc hTAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc :content-transfer-encoding; bh=XJt7E+/TbSWO+R4K5yrVaKdlcnMjFDGRebGSqWZKoOM=; b=knfOm+eULZDdgLsAo9Ruef6M/kGQuORspf/GcZPggNzK/KDAVO+yQlKYXciXfMGXex oOLSS6O7dipnJK6C+T4FpWsxr0F4/70cT1wn+SDwrv7g0x0vqevMn7yZKwHhKK2MEop4 Q8SDZFFMxIgJNd5BZiYFwrsEvmSpPnyETD3NyKVxGBwgh3/oQBL8GdsGuxWs+NtJsqqp DepjPQAltqMXLOGBU7/ZAVq6dFaqUJooXa2kLUoykIkZak97J4DhcqCwLNt1Fn43T/0o VngnjtvazPjbDe66bB+pyPzXmuGqjnuM9eQUQyF5cZAJw96Td/E7WbINAyjMey/GVC9r SxkQ== X-Gm-Message-State: AOAM530kXwrsoQDoOpeCud6VEyCjrp4HG695+CDZ22As67lS4554dSQF zFZUT0+P/VO2/CDstdR3wbg5YdWfV86x X-Google-Smtp-Source: ABdhPJwok/zYeBv9iYgH5TNm6XOpbgEypuRH1+BE3TzucfcQU2CHSzz99Lv+LdxirpLHnB05kLsrDfGCDg4o X-Received: from connoro.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:a99]) (user=connoro job=sendgmr) by 2002:a17:902:e34b:b0:14f:af20:4b3c with SMTP id p11-20020a170902e34b00b0014faf204b3cmr12782893plc.56.1645579765763; Tue, 22 Feb 2022 17:29:25 -0800 (PST) Date: Wed, 23 Feb 2022 01:28:14 +0000 Message-Id: <20220223012814.1898677-1-connoro@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.35.1.473.g83b2b277ed-goog Subject: [PATCH bpf-next] bpf: add config to allow loading modules with BTF mismatches From: "Connor O'Brien" To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko Cc: Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Shung-Hsi Yu , netdev@vger.kernel.org, bpf@vger.kernel.org, linux-kernel@vger.kernel.org, "Connor O'Brien" , "=?UTF-8?q?Michal=20Such=C3=A1nek?=" Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org BTF mismatch can occur for a separately-built module even when the ABI is otherwise compatible and nothing else would prevent successfully loading. Add a new config to control how mismatches are handled. By default, preserve the current behavior of refusing to load the module. If MODULE_ALLOW_BTF_MISMATCH is enabled, load the module but ignore its BTF information. Suggested-by: Yonghong Song Suggested-by: Michal Such=C3=A1nek Signed-off-by: Connor O'Brien --- Hello, In the discussion regarding BTF compatibility & modules, there seemed to be broad agreement that an option to ignore mismatches would be reasonable. Currently the only option for handling this problem seems to be to disable BTF entirely, so this would at least be an incremental improvement. Thanks, Connor kernel/bpf/btf.c | 3 ++- lib/Kconfig.debug | 10 ++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c index 11740b300de9..1a21f24105b3 100644 --- a/kernel/bpf/btf.c +++ b/kernel/bpf/btf.c @@ -6397,7 +6397,8 @@ static int btf_module_notify(struct notifier_block *n= b, unsigned long op, pr_warn("failed to validate module [%s] BTF: %ld\n", mod->name, PTR_ERR(btf)); kfree(btf_mod); - err =3D PTR_ERR(btf); + if (!IS_ENABLED(CONFIG_MODULE_ALLOW_BTF_MISMATCH)) + err =3D PTR_ERR(btf); goto out; } err =3D btf_alloc_id(btf); diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug index 1555da672275..ff857bb7d633 100644 --- a/lib/Kconfig.debug +++ b/lib/Kconfig.debug @@ -339,6 +339,16 @@ config DEBUG_INFO_BTF_MODULES help Generate compact split BTF type information for kernel modules. =20 +config MODULE_ALLOW_BTF_MISMATCH + bool "Allow loading modules with non-matching BTF type info" + depends on DEBUG_INFO_BTF_MODULES + help + For modules whose split BTF does not match vmlinux, load without + BTF rather than refusing to load. The default behavior with + module BTF enabled is to reject modules with such mismatches; + this option will still load module BTF where possible but ignore + it when a mismatch is found. + config GDB_SCRIPTS bool "Provide GDB scripts for kernel debugging" help --=20 2.35.1.473.g83b2b277ed-goog