linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH bpf-next] bpf: add config to allow loading modules with BTF mismatches
@ 2022-02-23  1:28 Connor O'Brien
  2022-02-23  4:34 ` Shung-Hsi Yu
  2022-02-28 13:30 ` patchwork-bot+netdevbpf
  0 siblings, 2 replies; 5+ messages in thread
From: Connor O'Brien @ 2022-02-23  1:28 UTC (permalink / raw)
  To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko
  Cc: Martin KaFai Lau, Song Liu, Yonghong Song, John Fastabend,
	KP Singh, Shung-Hsi Yu, netdev, bpf, linux-kernel,
	Connor O'Brien, Michal Suchánek

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 <yhs@fb.com>
Suggested-by: Michal Suchánek <msuchanek@suse.de>
Signed-off-by: Connor O'Brien <connoro@google.com>
---
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 *nb, unsigned long op,
 			pr_warn("failed to validate module [%s] BTF: %ld\n",
 				mod->name, PTR_ERR(btf));
 			kfree(btf_mod);
-			err = PTR_ERR(btf);
+			if (!IS_ENABLED(CONFIG_MODULE_ALLOW_BTF_MISMATCH))
+				err = PTR_ERR(btf);
 			goto out;
 		}
 		err = 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.
 
+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
-- 
2.35.1.473.g83b2b277ed-goog


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH bpf-next] bpf: add config to allow loading modules with BTF mismatches
  2022-02-23  1:28 [PATCH bpf-next] bpf: add config to allow loading modules with BTF mismatches Connor O'Brien
@ 2022-02-23  4:34 ` Shung-Hsi Yu
  2022-02-23  5:08   ` Song Liu
  2022-02-28 13:25   ` Daniel Borkmann
  2022-02-28 13:30 ` patchwork-bot+netdevbpf
  1 sibling, 2 replies; 5+ messages in thread
From: Shung-Hsi Yu @ 2022-02-23  4:34 UTC (permalink / raw)
  To: Connor O'Brien
  Cc: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
	Martin KaFai Lau, Song Liu, Yonghong Song, John Fastabend,
	KP Singh, netdev, bpf, linux-kernel, Michal Suchánek

On Wed, Feb 23, 2022 at 01:28:14AM +0000, Connor O'Brien wrote:
> 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 <yhs@fb.com>
> Suggested-by: Michal Suchánek <msuchanek@suse.de>
> Signed-off-by: Connor O'Brien <connoro@google.com>

Maybe reference the discussion thread as well?

Link: https://lore.kernel.org/bpf/CAADnVQJ+OVPnBz8z3vNu8gKXX42jCUqfuvhWAyCQDu8N_yqqwQ@mail.gmail.com/

Otherwise

Acked-by: Shung-Hsi Yu <shung-hsi.yu@suse.com>

> ---
> 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


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH bpf-next] bpf: add config to allow loading modules with BTF mismatches
  2022-02-23  4:34 ` Shung-Hsi Yu
@ 2022-02-23  5:08   ` Song Liu
  2022-02-28 13:25   ` Daniel Borkmann
  1 sibling, 0 replies; 5+ messages in thread
From: Song Liu @ 2022-02-23  5:08 UTC (permalink / raw)
  To: Shung-Hsi Yu
  Cc: Connor O'Brien, Alexei Starovoitov, Daniel Borkmann,
	Andrii Nakryiko, Martin Lau, Yonghong Song, John Fastabend,
	KP Singh, netdev, bpf, linux-kernel, Michal Suchánek



> On Feb 22, 2022, at 8:34 PM, Shung-Hsi Yu <shung-hsi.yu@suse.com> wrote:
> 
> On Wed, Feb 23, 2022 at 01:28:14AM +0000, Connor O'Brien wrote:
>> 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 <yhs@fb.com>
>> Suggested-by: Michal Suchánek <msuchanek@suse.de>
>> Signed-off-by: Connor O'Brien <connoro@google.com>
> 
> Maybe reference the discussion thread as well?
> 
> Link: https://lore.kernel.org/bpf/CAADnVQJ+OVPnBz8z3vNu8gKXX42jCUqfuvhWAyCQDu8N_yqqwQ@mail.gmail.com/
> 
> Otherwise
> 
> Acked-by: Shung-Hsi Yu <shung-hsi.yu@suse.com>

Acked-by: Song Liu <songliubraving@fb.com>


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH bpf-next] bpf: add config to allow loading modules with BTF mismatches
  2022-02-23  4:34 ` Shung-Hsi Yu
  2022-02-23  5:08   ` Song Liu
@ 2022-02-28 13:25   ` Daniel Borkmann
  1 sibling, 0 replies; 5+ messages in thread
From: Daniel Borkmann @ 2022-02-28 13:25 UTC (permalink / raw)
  To: Shung-Hsi Yu, Connor O'Brien
  Cc: Alexei Starovoitov, Andrii Nakryiko, Martin KaFai Lau, Song Liu,
	Yonghong Song, John Fastabend, KP Singh, netdev, bpf,
	linux-kernel, Michal Suchánek

On 2/23/22 5:34 AM, Shung-Hsi Yu wrote:
> On Wed, Feb 23, 2022 at 01:28:14AM +0000, Connor O'Brien wrote:
>> 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 <yhs@fb.com>
>> Suggested-by: Michal Suchánek <msuchanek@suse.de>
>> Signed-off-by: Connor O'Brien <connoro@google.com>
> 
> Maybe reference the discussion thread as well?
> 
> Link: https://lore.kernel.org/bpf/CAADnVQJ+OVPnBz8z3vNu8gKXX42jCUqfuvhWAyCQDu8N_yqqwQ@mail.gmail.com/

LGTM, and added above into the commit log while applying. Thanks everyone!

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH bpf-next] bpf: add config to allow loading modules with BTF mismatches
  2022-02-23  1:28 [PATCH bpf-next] bpf: add config to allow loading modules with BTF mismatches Connor O'Brien
  2022-02-23  4:34 ` Shung-Hsi Yu
@ 2022-02-28 13:30 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 5+ messages in thread
From: patchwork-bot+netdevbpf @ 2022-02-28 13:30 UTC (permalink / raw)
  To: Connor O'Brien
  Cc: ast, daniel, andrii, kafai, songliubraving, yhs, john.fastabend,
	kpsingh, shung-hsi.yu, netdev, bpf, linux-kernel, msuchanek

Hello:

This patch was applied to bpf/bpf-next.git (master)
by Daniel Borkmann <daniel@iogearbox.net>:

On Wed, 23 Feb 2022 01:28:14 +0000 you wrote:
> 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.
> 
> [...]

Here is the summary with links:
  - [bpf-next] bpf: add config to allow loading modules with BTF mismatches
    https://git.kernel.org/bpf/bpf-next/c/5e214f2e43e4

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-02-28 13:31 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-23  1:28 [PATCH bpf-next] bpf: add config to allow loading modules with BTF mismatches Connor O'Brien
2022-02-23  4:34 ` Shung-Hsi Yu
2022-02-23  5:08   ` Song Liu
2022-02-28 13:25   ` Daniel Borkmann
2022-02-28 13:30 ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).