BPF List
 help / color / mirror / Atom feed
From: Martin KaFai Lau <martin.lau@linux.dev>
To: Geliang Tang <geliang@kernel.org>
Cc: Geliang Tang <tanggeliang@kylinos.cn>,
	bpf@vger.kernel.org, mptcp@lists.linux.dev,
	Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Andrii Nakryiko <andrii@kernel.org>, Song Liu <song@kernel.org>,
	Yonghong Song <yonghong.song@linux.dev>,
	Matthieu Baerts <matttbe@kernel.org>,
	Eduard Zingerman <eddyz87@gmail.com>,
	John Fastabend <john.fastabend@gmail.com>,
	KP Singh <kpsingh@kernel.org>,
	Stanislav Fomichev <sdf@google.com>, Hao Luo <haoluo@google.com>,
	Jiri Olsa <jolsa@kernel.org>
Subject: Re: [PATCH bpf-next v4 1/3] bpf, btf: Fix error checks for btf_get_module_btf
Date: Wed, 7 Feb 2024 16:56:34 -0800	[thread overview]
Message-ID: <0dbeee01-6a41-41b9-a485-943ba371a476@linux.dev> (raw)
In-Reply-To: <d79e5dd6b4a189252af696a10df8ce585e9cb46d.1707314646.git.tanggeliang@kylinos.cn>

On 2/7/24 6:07 AM, Geliang Tang wrote:
> From: Geliang Tang <tanggeliang@kylinos.cn>
> 
> To let the modules loaded, commit 3de4d22cc9ac ("bpf, btf: Warn but
> return no error for NULL btf from __register_btf_kfunc_id_set()")
> changes the return value of __register_btf_kfunc_id_set() from -ENOENT
> to 0 when btf is NULL.
> 
> A better way to do this is to enable CONFIG_MODULE_ALLOW_BTF_MISMATCH.
> 
> An error code -ENOENT should indeed be returned when kernel module BTF
> mismatch detected except CONFIG_MODULE_ALLOW_BTF_MISMATCH is enabled in
> __register_btf_kfunc_id_set().
> 
> The same in register_btf_id_dtor_kfuncs(), give the modules a chance
> to be loaded when CONFIG_MODULE_ALLOW_BTF_MISMATCH is enabled.
> 
> Fixes: 3de4d22cc9ac ("bpf, btf: Warn but return no error for NULL btf from __register_btf_kfunc_id_set()")
> Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
> ---
>   kernel/bpf/btf.c | 8 ++++++--
>   1 file changed, 6 insertions(+), 2 deletions(-)
> 
> diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c
> index f7725cb6e564..203391e61d93 100644
> --- a/kernel/bpf/btf.c
> +++ b/kernel/bpf/btf.c
> @@ -8103,8 +8103,11 @@ static int __register_btf_kfunc_id_set(enum btf_kfunc_hook hook,
>   			pr_err("missing vmlinux BTF, cannot register kfuncs\n");
>   			return -ENOENT;
>   		}
> -		if (kset->owner && IS_ENABLED(CONFIG_DEBUG_INFO_BTF_MODULES))
> +		if (kset->owner && IS_ENABLED(CONFIG_DEBUG_INFO_BTF_MODULES) &&
> +		    !IS_ENABLED(CONFIG_MODULE_ALLOW_BTF_MISMATCH)) {

I am not sure this new test can be added here now. Otherwise, the existing 
kconfig that does not have CONFIG_MODULE_ALLOW_BTF_MISMATCH set will fail to 
load a module with btf section stripped out as described in commit 3de4d22cc9ac.

A module with stripped btf section does not mean BTF_MISMATCH also.

>   			pr_warn("missing module BTF, cannot register kfuncs\n");
> +			return -ENOENT;
> +		}
>   		return 0;
>   	}
>   	if (IS_ERR(btf))
> @@ -8219,7 +8222,8 @@ int register_btf_id_dtor_kfuncs(const struct btf_id_dtor_kfunc *dtors, u32 add_c
>   			pr_err("missing vmlinux BTF, cannot register dtor kfuncs\n");
>   			return -ENOENT;
>   		}
> -		if (owner && IS_ENABLED(CONFIG_DEBUG_INFO_BTF_MODULES)) {
> +		if (owner && IS_ENABLED(CONFIG_DEBUG_INFO_BTF_MODULES) &&
> +		    !IS_ENABLED(CONFIG_MODULE_ALLOW_BTF_MISMATCH)) {
>   			pr_err("missing module BTF, cannot register dtor kfuncs\n");
>   			return -ENOENT;
>   		}


  reply	other threads:[~2024-02-08  0:56 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-07 14:07 [PATCH bpf-next v4 0/3] bpf, btf: Add DEBUG_INFO_BTF checks for __register_bpf_struct_ops Geliang Tang
2024-02-07 14:07 ` [PATCH bpf-next v4 1/3] bpf, btf: Fix error checks for btf_get_module_btf Geliang Tang
2024-02-08  0:56   ` Martin KaFai Lau [this message]
2024-02-07 14:07 ` [PATCH bpf-next v4 2/3] bpf, btf: Add check_btf_kconfigs helper Geliang Tang
2024-02-07 14:07 ` [PATCH bpf-next v4 3/3] bpf, btf: Check btf for register_bpf_struct_ops Geliang Tang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=0dbeee01-6a41-41b9-a485-943ba371a476@linux.dev \
    --to=martin.lau@linux.dev \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=eddyz87@gmail.com \
    --cc=geliang@kernel.org \
    --cc=haoluo@google.com \
    --cc=john.fastabend@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=kpsingh@kernel.org \
    --cc=matttbe@kernel.org \
    --cc=mptcp@lists.linux.dev \
    --cc=sdf@google.com \
    --cc=song@kernel.org \
    --cc=tanggeliang@kylinos.cn \
    --cc=yonghong.song@linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox