From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-184.mta1.migadu.com (out-184.mta1.migadu.com [95.215.58.184]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1BB7028E2C for ; Mon, 6 Nov 2023 16:43:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="HAsdVZke" Message-ID: <038d3f11-b030-4d53-82ff-6434a543aefa@linux.dev> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1699289009; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=NXeDglBulIEK45i+YiMtoeo6awjpSaCGWm7GIgdoxPw=; b=HAsdVZkedrneHjsTkG8eJKLVPQYScp48Z3FvzdxM9Tb++okxSQUBD4x6vtpovMqXe+8jn9 7bOTVueTEmEMOP4DGcwjHEVO99trBjg1r69wgCXPL3cSUnHxqQB2P3DjacjVHNxfXeuq6v LU5RLY+Zbz1YdBu7XEO9u99FVV+Lbac= Date: Mon, 6 Nov 2023 16:43:27 +0000 Precedence: bulk X-Mailing-List: fsverity@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Subject: Re: [PATCH v12 bpf-next 3/9] bpf: Introduce KF_ARG_PTR_TO_CONST_STR Content-Language: en-US To: Song Liu , bpf@vger.kernel.org, fsverity@lists.linux.dev, Alexei Starovoitov , Andrii Nakryiko 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 References: <20231104001313.3538201-1-song@kernel.org> <20231104001313.3538201-4-song@kernel.org> X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Vadim Fedorenko In-Reply-To: <20231104001313.3538201-4-song@kernel.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_OUT 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 > Acked-by: Andrii Nakryiko > --- > 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 Alexei, Andrii, is it possible to apply patches 1-3? Looks like they are ready to go and can unblock other work.