Received: by 2002:ab2:2994:0:b0:1ef:ca3e:3cd5 with SMTP id n20csp825073lqb; Fri, 15 Mar 2024 07:30:18 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWK+Ot/rW3+bUxy6iw56LX6vh+puEWSUHoYvRDcDWfS5PrmmBXHFAn1j8HW45HH1iKfQhuy97p+Q8GMwPxojZHJSFxeR205hxrTcQXFeg== X-Google-Smtp-Source: AGHT+IH/0oywH6lyUgVx+rBjzgj6EIHKDU0wQ/mp1GmOytwahGOeW6NppJSU/Vn/Sbxx7cEAt/8R X-Received: by 2002:a05:6a20:4f1b:b0:1a3:3690:5a84 with SMTP id gi27-20020a056a204f1b00b001a336905a84mr4063779pzb.30.1710513018075; Fri, 15 Mar 2024 07:30:18 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710513018; cv=pass; d=google.com; s=arc-20160816; b=nZ6xPxTX81GzHlCR5KNHaSWG7jsRK9MqGbxtPzYa5Ksr61jUwfL0beocEuUHu05fMc ldmmqrF/MuncS92YWXDWBJOd9908TNV3TI00cut1j7yvabH99WM7en0xHkzyjPelb3tE UiE1eMBxf7IcWZw4jlR9ucRoEIPLjEzDzdD4fM5DjvgCcbt+2YD25tTNmDOVkYgR5cYE 4zl0S6e0y/21KTnyGocwyJsZUcS5xpaBUxZlC//UpoJrqILoX/aizhot23pFxkWVQMt3 8AkEY6NfvMSMdG95GsiONSa+1ODkWEnnaHfmbfcMHllFjjZfnA+rsGFZYJD+VrGkFz37 Lp+Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :subject:date:from:dkim-signature; bh=jh4jmbKgnMidK79b0uVw4vM60fKEHIi7gGv6M/g7m30=; fh=L3UFV6no5Bg+ONjucac5Whrd1OR3maQPkF8kTmP37SU=; b=oYp8AhUiPceSxBVyn05X/fgtshpvJ/0gjrfL4r4b3LKoPcI8UY+478jEgmar3TNcoH 8ynBp7P3NCexG5AKIZkK5t5UIi13js6KAia32bvn1ez7KwJhmFp4eKefH/dWnbfWseAl dI2kKo/DzcBrxQluo3bh0v1Lu9CJzhpNXbgLi2AKZ8WmwCqXAIUIyDzfLooQ0Q+jZHt8 WKDY9cU/MY/kA1TCi46QMpnBF1O1a0tg6dxNuQN7M/RXCYq2HP/8hSLor0dW/8rsMvMN Oee4VqcQXOFDw5kYo4VTsGSlGizcZKlLggyua2Z3VVnrmeJD8QdseBSRComNdIeZTt+U F23A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="oeT/ujXO"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-104506-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-104506-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id i123-20020a62c181000000b006e69b40d4adsi3680700pfg.100.2024.03.15.07.30.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Mar 2024 07:30:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-104506-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="oeT/ujXO"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-104506-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-104506-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id B6C1E283E56 for ; Fri, 15 Mar 2024 14:30:17 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0DE1A3CF5D; Fri, 15 Mar 2024 14:29:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="oeT/ujXO" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 2E7423C68A; Fri, 15 Mar 2024 14:29:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710512986; cv=none; b=LlyPjjYoWAXjfxRfjk/f+R7RT19ReUPRzwMYuRJZzqPQxCJAAy7lha2LAK03sznshR7wEWYTquU6c1qV2nxIMuEXrbPbXqeeELqS2cx4K7CRJpq6H3RnmEl1rUeFCdvDD6ZDyxV/XbfYx+xeqi0Ud8hGgpvsYINcLz4dzyo9M3o= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710512986; c=relaxed/simple; bh=4PSR833wK54GZMHK7oT0FJLSGU3g6RHprWT+gjzjz4I=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=WXrt9Z52irwG1CZxD1VQ9P6bKFpSvP0quhFf4+3z0h66qtNPruigiuXPmbF5thhvWuGp4FTG8DCFZjx2etFafc+cffNH3xebW5dlmhZAO9r4DBDiKpII+JhAfYkZJIW0xzKV0p+S4ej2/Uc97kZ8yKCjeNbyxiNjJ8U6+LKVn3U= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=oeT/ujXO; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1DD7DC433C7; Fri, 15 Mar 2024 14:29:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1710512985; bh=4PSR833wK54GZMHK7oT0FJLSGU3g6RHprWT+gjzjz4I=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=oeT/ujXOzMWZS0hGAflCnWfXFC4EXS6R2Ft/UU7yNwScE1pgAFMs9L86FwB0FhRvg BN4hNZhPxiypHob04e5o03ZOo76Xqh4WUYODrdw76dXX7wPKV43liuIOoF+djtGqYz a0m6dsdUk0RNoT4UIcbQPAfaC/ftuOnFayjnQExxnW0aiJcdS0Td/W5bCw2TvMyMgQ q7pSMnfQ4pnhbK2OV7VgL9nBRg8fzbt05SG0SJo/MemK8o9vIPzhtP3WlPFu6SmJcC qC54PP5ioc5y8zKQ9egFLMq/pCPwVr0nOzUSs5cn6/vOdMILfpx379ddUB3ynOM7xl i+IYMwGJRMaFg== From: Benjamin Tissoires Date: Fri, 15 Mar 2024 15:29:26 +0100 Subject: [PATCH bpf-next v4 2/6] bpf/verifier: add bpf_timer as a kfunc capable type Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20240315-hid-bpf-sleepable-v4-2-5658f2540564@kernel.org> References: <20240315-hid-bpf-sleepable-v4-0-5658f2540564@kernel.org> In-Reply-To: <20240315-hid-bpf-sleepable-v4-0-5658f2540564@kernel.org> To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Eduard Zingerman , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Mykola Lysenko , Shuah Khan Cc: Benjamin Tissoires , bpf@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org X-Mailer: b4 0.12.4 X-Developer-Signature: v=1; a=ed25519-sha256; t=1710512973; l=2798; i=bentiss@kernel.org; s=20230215; h=from:subject:message-id; bh=4PSR833wK54GZMHK7oT0FJLSGU3g6RHprWT+gjzjz4I=; b=EUQIDqnCUQ4IzyqEY6pGPvT9gQP7IGI3pAKO+L6ei9K4rfJTvDWADgaqn0NuOvlLe445PUhwe GIKavhQXNO/BYatc0dBS/6XHpG/caDvqWDyqhZd2P28n0ZwVc1WbjEB X-Developer-Key: i=bentiss@kernel.org; a=ed25519; pk=7D1DyAVh6ajCkuUTudt/chMuXWIJHlv2qCsRkIizvFw= We need to extend the bpf_timer API, but the way forward relies on kfuncs. So make bpf_timer known for kfuncs from the verifier PoV Signed-off-by: Benjamin Tissoires --- changes in v4: - enforce KF_ARG_PTR_TO_TIMER to be of type PTR_TO_MAP_VALUE new in v3 (split from v2 02/10) --- kernel/bpf/verifier.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index 63749ad5ac6b..1483ebc0ee73 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -10826,6 +10826,7 @@ enum { KF_ARG_LIST_NODE_ID, KF_ARG_RB_ROOT_ID, KF_ARG_RB_NODE_ID, + KF_ARG_TIMER_ID, }; BTF_ID_LIST(kf_arg_btf_ids) @@ -10834,6 +10835,7 @@ BTF_ID(struct, bpf_list_head) BTF_ID(struct, bpf_list_node) BTF_ID(struct, bpf_rb_root) BTF_ID(struct, bpf_rb_node) +BTF_ID(struct, bpf_timer_kern) static bool __is_kfunc_ptr_arg_type(const struct btf *btf, const struct btf_param *arg, int type) @@ -10877,6 +10879,12 @@ static bool is_kfunc_arg_rbtree_node(const struct btf *btf, const struct btf_par return __is_kfunc_ptr_arg_type(btf, arg, KF_ARG_RB_NODE_ID); } +static bool is_kfunc_arg_timer(const struct btf *btf, const struct btf_param *arg) +{ + bool ret = __is_kfunc_ptr_arg_type(btf, arg, KF_ARG_TIMER_ID); + return ret; +} + static bool is_kfunc_arg_callback(struct bpf_verifier_env *env, const struct btf *btf, const struct btf_param *arg) { @@ -10946,6 +10954,7 @@ enum kfunc_ptr_arg_type { KF_ARG_PTR_TO_NULL, KF_ARG_PTR_TO_CONST_STR, KF_ARG_PTR_TO_MAP, + KF_ARG_PTR_TO_TIMER, }; enum special_kfunc_type { @@ -11102,6 +11111,9 @@ get_kfunc_ptr_arg_type(struct bpf_verifier_env *env, if (is_kfunc_arg_map(meta->btf, &args[argno])) return KF_ARG_PTR_TO_MAP; + if (is_kfunc_arg_timer(meta->btf, &args[argno])) + return KF_ARG_PTR_TO_TIMER; + 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", @@ -11735,6 +11747,7 @@ static int check_kfunc_args(struct bpf_verifier_env *env, struct bpf_kfunc_call_ case KF_ARG_PTR_TO_CALLBACK: case KF_ARG_PTR_TO_REFCOUNTED_KPTR: case KF_ARG_PTR_TO_CONST_STR: + case KF_ARG_PTR_TO_TIMER: /* Trusted by default */ break; default: @@ -12021,6 +12034,12 @@ static int check_kfunc_args(struct bpf_verifier_env *env, struct bpf_kfunc_call_ if (ret) return ret; break; + case KF_ARG_PTR_TO_TIMER: + if (reg->type != PTR_TO_MAP_VALUE) { + verbose(env, "arg#%d doesn't point to a map value\n", i); + return -EINVAL; + } + break; } } -- 2.44.0