Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp123740pxm; Tue, 22 Feb 2022 18:30:34 -0800 (PST) X-Google-Smtp-Source: ABdhPJwrT0XkmKC8sU92QpkujLaDUQhft68QR9S4OTVUXV3N6hxfukrkLidq83+U/LNDJmGpJISd X-Received: by 2002:a50:ee14:0:b0:410:7a88:4b0c with SMTP id g20-20020a50ee14000000b004107a884b0cmr29326544eds.37.1645583434227; Tue, 22 Feb 2022 18:30:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645583434; cv=none; d=google.com; s=arc-20160816; b=Q27n6t2u2dBxym+8wL2JuVoIB8xgF0jP7JSSA1op/6bDNxMY9ZX+4R9U70wo+dz5hv tupk/8MvcTYFJedwcT8wcQVsTLS6s9hcxe/H8cA6X/jEEGR/g2e6z4U6TPaa6Uymx+nP X5EIYAJqbvXcVdZ3LQCIsXYNZoq/a4Iyd5eiUGq/G4NHUQRXSvJSUsow4IZJDi+9fMDP tKb5iTkC0bDw0dfy+ADA4wpYxPEZXqTkHsJX+VsHlBM8vsyFJTXrqqL1EmDby83kaTTB i2XTilPcrSSjzx9pql4xDDF1WRFaQjINswgsAozanmUQ89CwhR93mg2padk9R7xDhkNA NHYw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:from:subject :mime-version:message-id:date:dkim-signature; bh=XJt7E+/TbSWO+R4K5yrVaKdlcnMjFDGRebGSqWZKoOM=; b=JAYFw1PWbm4PuIUAznKVMZXIcmLfFSkZySxpEI0eg0N2O4OpKREdK4FfLRZIM5nR7C KJhLFplr4dK4uZG2UclC5WOhq2frrjuO/MeuySz+GawZgCDjjwnDjjltHl0ZwK7siPqx y/BLsUOB2dKl7MOEcte5VUHhVtnxoiqz6VQkvE/D59421DyezBYg3fCofqhDA0nwFQwr ryW6P56KaEQ9BEXgYlCnA9AwJjyR0Axy22Y3x8D6CYTrPi6ljF7jlTxJqXo4kX6vwsFn dFTW80fV0/6emhCgA2dZY7eBk4eMt4dGTpktewW/acBFgWkcfjF5y0f+6VFGKnSvPGHj BZ5g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=VUYknfLX; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g17si12958212edr.427.2022.02.22.18.30.11; Tue, 22 Feb 2022 18:30:34 -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=VUYknfLX; 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 S236567AbiBWB34 (ORCPT + 99 others); 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-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 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,T_SCC_BODY_TEXT_LINE,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 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