public inbox for fsverity@lists.linux.dev
 help / color / mirror / Atom feed
From: Vadim Fedorenko <vadim.fedorenko@linux.dev>
To: Song Liu <song@kernel.org>,
	bpf@vger.kernel.org, fsverity@lists.linux.dev,
	Alexei Starovoitov <ast@kernel.org>,
	Andrii Nakryiko <andrii@kernel.org>
Cc: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org,
	martin.lau@kernel.org, kernel-team@meta.com, ebiggers@kernel.org,
	tytso@mit.edu, roberto.sassu@huaweicloud.com, kpsingh@kernel.org,
	vadfed@meta.com
Subject: Re: [PATCH v12 bpf-next 3/9] bpf: Introduce KF_ARG_PTR_TO_CONST_STR
Date: Mon, 6 Nov 2023 16:43:27 +0000	[thread overview]
Message-ID: <038d3f11-b030-4d53-82ff-6434a543aefa@linux.dev> (raw)
In-Reply-To: <20231104001313.3538201-4-song@kernel.org>

On 04/11/2023 00:13, Song Liu wrote:
> Similar to ARG_PTR_TO_CONST_STR for BPF helpers, KF_ARG_PTR_TO_CONST_STR
> specifies kfunc args that point to const strings. Annotation "__str" is
> used to specify kfunc arg of type KF_ARG_PTR_TO_CONST_STR. Also, add
> documentation for the "__str" annotation.
> 
> bpf_get_file_xattr() will be the first kfunc that uses this type.
> 
> Signed-off-by: Song Liu <song@kernel.org>
> Acked-by: Andrii Nakryiko <andrii@kernel.org>
> ---
>   Documentation/bpf/kfuncs.rst | 24 ++++++++++++++++++++++++
>   kernel/bpf/verifier.c        | 19 +++++++++++++++++++
>   2 files changed, 43 insertions(+)
> 
> diff --git a/Documentation/bpf/kfuncs.rst b/Documentation/bpf/kfuncs.rst
> index 0d2647fb358d..bfe065f7e23c 100644
> --- a/Documentation/bpf/kfuncs.rst
> +++ b/Documentation/bpf/kfuncs.rst
> @@ -137,6 +137,30 @@ Either way, the returned buffer is either NULL, or of size buffer_szk. Without t
>   annotation, the verifier will reject the program if a null pointer is passed in with
>   a nonzero size.
>   
> +2.2.5 __str Annotation
> +----------------------------
> +This annotation is used to indicate that the argument is a constant string.
> +
> +An example is given below::
> +
> +        __bpf_kfunc bpf_get_file_xattr(..., const char *name__str, ...)
> +        {
> +        ...
> +        }
> +
> +In this case, ``bpf_get_file_xattr()`` can be called as::
> +
> +        bpf_get_file_xattr(..., "xattr_name", ...);
> +
> +Or::
> +
> +        const char name[] = "xattr_name";  /* This need to be global */
> +        int BPF_PROG(...)
> +        {
> +                ...
> +                bpf_get_file_xattr(..., name, ...);
> +                ...
> +        }
>   
>   .. _BPF_kfunc_nodef:
>   
> diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
> index 618446006d5a..bf94ba50c6ee 100644
> --- a/kernel/bpf/verifier.c
> +++ b/kernel/bpf/verifier.c
> @@ -10803,6 +10803,11 @@ static bool is_kfunc_arg_nullable(const struct btf *btf, const struct btf_param
>   	return __kfunc_param_match_suffix(btf, arg, "__nullable");
>   }
>   
> +static bool is_kfunc_arg_const_str(const struct btf *btf, const struct btf_param *arg)
> +{
> +	return __kfunc_param_match_suffix(btf, arg, "__str");
> +}
> +
>   static bool is_kfunc_arg_scalar_with_name(const struct btf *btf,
>   					  const struct btf_param *arg,
>   					  const char *name)
> @@ -10946,6 +10951,7 @@ enum kfunc_ptr_arg_type {
>   	KF_ARG_PTR_TO_RB_ROOT,
>   	KF_ARG_PTR_TO_RB_NODE,
>   	KF_ARG_PTR_TO_NULL,
> +	KF_ARG_PTR_TO_CONST_STR,
>   };
>   
>   enum special_kfunc_type {
> @@ -11090,6 +11096,9 @@ get_kfunc_ptr_arg_type(struct bpf_verifier_env *env,
>   	if (is_kfunc_arg_rbtree_node(meta->btf, &args[argno]))
>   		return KF_ARG_PTR_TO_RB_NODE;
>   
> +	if (is_kfunc_arg_const_str(meta->btf, &args[argno]))
> +		return KF_ARG_PTR_TO_CONST_STR;
> +
>   	if ((base_type(reg->type) == PTR_TO_BTF_ID || reg2btf_ids[base_type(reg->type)])) {
>   		if (!btf_type_is_struct(ref_t)) {
>   			verbose(env, "kernel function %s args#%d pointer type %s %s is not supported\n",
> @@ -11713,6 +11722,7 @@ static int check_kfunc_args(struct bpf_verifier_env *env, struct bpf_kfunc_call_
>   		case KF_ARG_PTR_TO_MEM_SIZE:
>   		case KF_ARG_PTR_TO_CALLBACK:
>   		case KF_ARG_PTR_TO_REFCOUNTED_KPTR:
> +		case KF_ARG_PTR_TO_CONST_STR:
>   			/* Trusted by default */
>   			break;
>   		default:
> @@ -11984,6 +11994,15 @@ static int check_kfunc_args(struct bpf_verifier_env *env, struct bpf_kfunc_call_
>   			meta->arg_btf = reg->btf;
>   			meta->arg_btf_id = reg->btf_id;
>   			break;
> +		case KF_ARG_PTR_TO_CONST_STR:
> +			if (reg->type != PTR_TO_MAP_VALUE) {
> +				verbose(env, "arg#%d doesn't point to a const string\n", i);
> +				return -EINVAL;
> +			}
> +			ret = check_reg_const_str(env, reg, regno);
> +			if (ret)
> +				return ret;
> +			break;
>   		}
>   	}
>   

Acked-by: Vadim Fedorenko <vadim.fedorenko@linux.dev>

Alexei, Andrii, is it possible to apply patches 1-3? Looks like they
are ready to go and can unblock other work.

  reply	other threads:[~2023-11-06 16:43 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-04  0:13 [PATCH v12 bpf-next 0/9] bpf: File verification with LSM and fsverity Song Liu
2023-11-04  0:13 ` [PATCH v12 bpf-next 1/9] bpf: Add __bpf_dynptr_data* for in kernel use Song Liu
2023-11-06 16:39   ` Vadim Fedorenko
2023-11-06 21:07   ` Andrii Nakryiko
2023-11-06 22:00     ` Song Liu
2023-11-06 22:40       ` Andrii Nakryiko
2023-11-04  0:13 ` [PATCH v12 bpf-next 2/9] bpf: Factor out helper check_reg_const_str() Song Liu
2023-11-06 16:40   ` Vadim Fedorenko
2023-11-04  0:13 ` [PATCH v12 bpf-next 3/9] bpf: Introduce KF_ARG_PTR_TO_CONST_STR Song Liu
2023-11-06 16:43   ` Vadim Fedorenko [this message]
2023-11-04  0:13 ` [PATCH v12 bpf-next 4/9] bpf: Add kfunc bpf_get_file_xattr Song Liu
2023-11-04  9:11   ` Alexei Starovoitov
2023-11-04 14:20     ` Song Liu
2023-11-04  0:13 ` [PATCH v12 bpf-next 5/9] bpf, fsverity: Add kfunc bpf_get_fsverity_digest Song Liu
2023-11-04  0:13 ` [PATCH v12 bpf-next 6/9] Documentation/bpf: Add documentation for filesystem kfuncs Song Liu
2023-11-04  0:13 ` [PATCH v12 bpf-next 7/9] selftests/bpf: Sort config in alphabetic order Song Liu
2023-11-04  0:13 ` [PATCH v12 bpf-next 8/9] selftests/bpf: Add tests for filesystem kfuncs Song Liu
2023-11-04  0:13 ` [PATCH v12 bpf-next 9/9] selftests/bpf: Add test that uses fsverity and xattr to sign a file Song Liu
     [not found] ` <CAADnVQLZ7RkH2ykEohFdDLJkjhmizHUuBakoevjEwvxOFMFjBw@mail.gmail.com>
2023-11-04 14:05   ` [PATCH v12 bpf-next 0/9] bpf: File verification with LSM and fsverity Song Liu

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=038d3f11-b030-4d53-82ff-6434a543aefa@linux.dev \
    --to=vadim.fedorenko@linux.dev \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=ebiggers@kernel.org \
    --cc=fsverity@lists.linux.dev \
    --cc=kernel-team@meta.com \
    --cc=kpsingh@kernel.org \
    --cc=martin.lau@kernel.org \
    --cc=roberto.sassu@huaweicloud.com \
    --cc=song@kernel.org \
    --cc=tytso@mit.edu \
    --cc=vadfed@meta.com \
    /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