All of lore.kernel.org
 help / color / mirror / Atom feed
* [bpf-next:master 106/144] kernel/bpf/verifier.c:13748 check_helper_call() error: we previously assumed 'meta.map.ptr' could be null (see line 13691)
@ 2026-12-03  9:07 kernel test robot
  0 siblings, 0 replies; only message in thread
From: kernel test robot @ 2026-12-03  9:07 UTC (permalink / raw)
  To: oe-kbuild; +Cc: lkp, Dan Carpenter

Unfiltered warning: this smatch report is sent as-is and has not been
reviewed for false positives, so please treat it with due skepticism.

BCC: lkp@intel.com
CC: oe-kbuild-all@lists.linux.dev
TO: Kumar Kartikeya Dwivedi <memxor@gmail.com>
CC: Alexei Starovoitov <ast@kernel.org>

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git master
head:   289cd43f93ed974660044caaaa19bfea14b1781c
commit: 6e2b51cb4ccfd1f9caa253170bc81e7e14cb3687 [106/144] bpf: Check that a helper whose callback may unwind has an unwind label
:::::: branch date: 4 hours ago
:::::: commit date: 20 hours ago
config: x86_64-randconfig-2200-20261203 (https://download.01.org/0day-ci/archive/20261203/20261203100220.gRqmkJSz-lkp@intel.com/config)
compiler: gcc-14 (Debian 14.2.0-19) 14.2.0
smatch: v0.5.0-9187-g5189e3fb

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Reported-by: Dan Carpenter <error27@gmail.com>
| Closes: https://lore.kernel.org/r/20261203100220.gRqmkJSz-lkp@intel.com/

smatch warnings:
kernel/bpf/verifier.c:13748 check_helper_call() error: we previously assumed 'meta.map.ptr' could be null (see line 13691)

vim +13748 kernel/bpf/verifier.c

bcfcb15fde94ed39 Amery Hung              2026-05-28  13594  
69c087ba6225b574 Yonghong Song           2021-02-26  13595  static int check_helper_call(struct bpf_verifier_env *env, struct bpf_insn *insn,
69c087ba6225b574 Yonghong Song           2021-02-26  13596  			     int *insn_idx_p)
17a5267067f3c372 Alexei Starovoitov      2014-09-26  13597  {
aef9d4a34a51f0a5 Stanislav Fomichev      2022-07-20  13598  	enum bpf_prog_type prog_type = resolve_prog_type(env->prog);
01cc55af93884f1f Yonghong Song           2023-08-27  13599  	bool returns_cpu_specific_alloc_ptr = false;
17a5267067f3c372 Alexei Starovoitov      2014-09-26  13600  	const struct bpf_func_proto *fn = NULL;
3c4807322660d429 Hao Luo                 2021-12-16  13601  	enum bpf_return_type ret_type;
c25b2ae136039ffa Hao Luo                 2021-12-16  13602  	enum bpf_type_flag ret_flag;
cb445a6eedb66bca Kumar Kartikeya Dwivedi 2026-12-01  13603  	struct bpf_reg_state *regs, unwound_r0;
33ff9823c569f3ac Daniel Borkmann         2016-04-13  13604  	struct bpf_call_arg_meta meta;
99a6a288a82bf00b Kumar Kartikeya Dwivedi 2026-08-15  13605  	const char *operation;
69c087ba6225b574 Yonghong Song           2021-02-26  13606  	int insn_idx = *insn_idx_p;
969bf05eb3cedd5a Alexei Starovoitov      2016-05-05  13607  	bool changes_data;
69c087ba6225b574 Yonghong Song           2021-02-26  13608  	int i, err, func_id;
17a5267067f3c372 Alexei Starovoitov      2014-09-26  13609  
17a5267067f3c372 Alexei Starovoitov      2014-09-26  13610  	/* find function prototype */
69c087ba6225b574 Yonghong Song           2021-02-26  13611  	func_id = insn->imm;
f8a8faceab9953ed Alexei Starovoitov      2026-04-12  13612  	err = bpf_get_helper_proto(env, insn->imm, &fn);
45cbc7a5e004cf08 Eduard Zingerman        2024-07-22  13613  	if (err == -ERANGE) {
45cbc7a5e004cf08 Eduard Zingerman        2024-07-22  13614  		verbose(env, "invalid func %s#%d\n", func_id_name(func_id), func_id);
17a5267067f3c372 Alexei Starovoitov      2014-09-26  13615  		return -EINVAL;
17a5267067f3c372 Alexei Starovoitov      2014-09-26  13616  	}
17a5267067f3c372 Alexei Starovoitov      2014-09-26  13617  
45cbc7a5e004cf08 Eduard Zingerman        2024-07-22  13618  	if (err) {
786bf0e7e2ec90b3 Mykyta Yatsenko         2024-03-25  13619  		verbose(env, "program of this type cannot use helper %s#%d\n",
786bf0e7e2ec90b3 Mykyta Yatsenko         2024-03-25  13620  			func_id_name(func_id), func_id);
ac545b00ca56368b Kumar Kartikeya Dwivedi 2026-08-15  13621  		operation = bpf_diag_fmt(env, "helper %s#%d", func_id_name(func_id), func_id);
ac545b00ca56368b Kumar Kartikeya Dwivedi 2026-08-15  13622  		bpf_diag_policy(
ac545b00ca56368b Kumar Kartikeya Dwivedi 2026-08-15  13623  			env, insn_idx, operation, "this program type does not allow the helper",
ac545b00ca56368b Kumar Kartikeya Dwivedi 2026-08-15  13624  			"Use a helper allowed for this program type, or move the logic to a compatible program type.");
45cbc7a5e004cf08 Eduard Zingerman        2024-07-22  13625  		return err;
17a5267067f3c372 Alexei Starovoitov      2014-09-26  13626  	}
17a5267067f3c372 Alexei Starovoitov      2014-09-26  13627  
17a5267067f3c372 Alexei Starovoitov      2014-09-26  13628  	/* eBPF programs must be GPL compatible to use GPL-ed functions */
24701ecea76b0b93 Daniel Borkmann         2015-03-01  13629  	if (!env->prog->gpl_compatible && fn->gpl_only) {
3fe2867cdf088ffb Daniel Borkmann         2018-06-02  13630  		verbose(env, "cannot call GPL-restricted function from non-GPL compatible program\n");
ac545b00ca56368b Kumar Kartikeya Dwivedi 2026-08-15  13631  		operation = bpf_diag_fmt(env, "helper %s#%d", func_id_name(func_id), func_id);
ac545b00ca56368b Kumar Kartikeya Dwivedi 2026-08-15  13632  		bpf_diag_policy(
ac545b00ca56368b Kumar Kartikeya Dwivedi 2026-08-15  13633  			env, insn_idx, operation,
ac545b00ca56368b Kumar Kartikeya Dwivedi 2026-08-15  13634  			"this helper is restricted to GPL-compatible programs",
ac545b00ca56368b Kumar Kartikeya Dwivedi 2026-08-15  13635  			"Use a GPL-compatible license, or replace the helper with one that is available to non-GPL programs.");
17a5267067f3c372 Alexei Starovoitov      2014-09-26  13636  		return -EINVAL;
17a5267067f3c372 Alexei Starovoitov      2014-09-26  13637  	}
17a5267067f3c372 Alexei Starovoitov      2014-09-26  13638  
eae2e83e62633a26 Jiri Olsa               2020-08-25  13639  	if (fn->allowed && !fn->allowed(env->prog)) {
eae2e83e62633a26 Jiri Olsa               2020-08-25  13640  		verbose(env, "helper call is not allowed in probe\n");
ac545b00ca56368b Kumar Kartikeya Dwivedi 2026-08-15  13641  		operation = bpf_diag_fmt(env, "helper %s#%d", func_id_name(func_id), func_id);
ac545b00ca56368b Kumar Kartikeya Dwivedi 2026-08-15  13642  		bpf_diag_policy(
ac545b00ca56368b Kumar Kartikeya Dwivedi 2026-08-15  13643  			env, insn_idx, operation,
ac545b00ca56368b Kumar Kartikeya Dwivedi 2026-08-15  13644  			"the helper-specific policy callback rejected this program",
ac545b00ca56368b Kumar Kartikeya Dwivedi 2026-08-15  13645  			"Use the helper only from an allowed attach point or program configuration.");
eae2e83e62633a26 Jiri Olsa               2020-08-25  13646  		return -EINVAL;
eae2e83e62633a26 Jiri Olsa               2020-08-25  13647  	}
eae2e83e62633a26 Jiri Olsa               2020-08-25  13648  
04514d13222f2c4c Daniel Borkmann         2017-12-14  13649  	/* With LD_ABS/IND some JITs save/restore skb from r1. */
b238e187b4a2d3b5 Eduard Zingerman        2024-12-09  13650  	changes_data = bpf_helper_changes_pkt_data(func_id);
04514d13222f2c4c Daniel Borkmann         2017-12-14  13651  	if (changes_data && fn->arg1_type != ARG_PTR_TO_CTX) {
0df1a55afa832f46 Paul Chaignon           2025-07-01  13652  		verifier_bug(env, "func %s#%d: r1 != ctx", func_id_name(func_id), func_id);
fd508bde5d646fe8 Luis Gerhorst           2025-06-03  13653  		return -EFAULT;
04514d13222f2c4c Daniel Borkmann         2017-12-14  13654  	}
969bf05eb3cedd5a Alexei Starovoitov      2016-05-05  13655  
33ff9823c569f3ac Daniel Borkmann         2016-04-13  13656  	memset(&meta, 0, sizeof(meta));
33ff9823c569f3ac Daniel Borkmann         2016-04-13  13657  
0cc91f0e72415cbd Amery Hung              2026-09-11  13658  	err = check_func_proto(env, fn, &meta);
435faee1aae9c1ac Daniel Borkmann         2016-04-13  13659  	if (err) {
0df1a55afa832f46 Paul Chaignon           2025-07-01  13660  		verifier_bug(env, "incorrect func proto %s#%d", func_id_name(func_id), func_id);
435faee1aae9c1ac Daniel Borkmann         2016-04-13  13661  		return err;
435faee1aae9c1ac Daniel Borkmann         2016-04-13  13662  	}
435faee1aae9c1ac Daniel Borkmann         2016-04-13  13663  
a0d06cf102e4f088 Puranjay Mohan          2026-03-18  13664  	if (fn->might_sleep && !in_sleepable_context(env)) {
dac3b7a30d7e5384 Kumar Kartikeya Dwivedi 2026-09-24  13665  		const char *suggestion;
dac3b7a30d7e5384 Kumar Kartikeya Dwivedi 2026-09-24  13666  
a0d06cf102e4f088 Puranjay Mohan          2026-03-18  13667  		verbose(env, "sleepable helper %s#%d in %s\n", func_id_name(func_id), func_id,
a0d06cf102e4f088 Puranjay Mohan          2026-03-18  13668  			non_sleepable_context_description(env));
dac3b7a30d7e5384 Kumar Kartikeya Dwivedi 2026-09-24  13669  		if (in_sleepable(env))
dac3b7a30d7e5384 Kumar Kartikeya Dwivedi 2026-09-24  13670  			suggestion = "Move the helper call outside the critical section, or use a non-sleepable helper.";
dac3b7a30d7e5384 Kumar Kartikeya Dwivedi 2026-09-24  13671  		else
dac3b7a30d7e5384 Kumar Kartikeya Dwivedi 2026-09-24  13672  			suggestion = "Mark the program sleepable if the program type allows it, or use a non-sleepable helper.";
99a6a288a82bf00b Kumar Kartikeya Dwivedi 2026-08-15  13673  		operation = bpf_diag_fmt(env, "sleepable helper %s#%d",
99a6a288a82bf00b Kumar Kartikeya Dwivedi 2026-08-15  13674  					 func_id_name(func_id), func_id);
dac3b7a30d7e5384 Kumar Kartikeya Dwivedi 2026-09-24  13675  		bpf_diag_ctx_forbidden(env, insn_idx, operation, suggestion);
fc7566ad0a826cdc Kumar Kartikeya Dwivedi 2024-04-24  13676  		return -EINVAL;
fc7566ad0a826cdc Kumar Kartikeya Dwivedi 2024-04-24  13677  	}
c8e2ee1f3df05dc4 Kumar Kartikeya Dwivedi 2024-12-03  13678  
f233d4855918547f Kumar Kartikeya Dwivedi 2025-10-07  13679  	/* Track non-sleepable context for helpers. */
f233d4855918547f Kumar Kartikeya Dwivedi 2025-10-07  13680  	if (!in_sleepable_context(env))
f233d4855918547f Kumar Kartikeya Dwivedi 2025-10-07  13681  		env->insn_aux_data[insn_idx].non_sleepable = true;
469d638d1520a933 Kumar Kartikeya Dwivedi 2025-10-07  13682  
d83525ca62cf8ebe Alexei Starovoitov      2019-01-31  13683  	meta.func_id = func_id;
6523af719a2156e1 Amery Hung              2026-09-11  13684  	meta.func_name = func_id_name(func_id);
a49b70400b9de062 Amery Hung              2026-08-01  13685  	meta.fn = fn;
ab7fff217fd14ec1 Amery Hung              2026-09-11  13686  	err = check_func_args(env, &meta, insn_idx);
17a5267067f3c372 Alexei Starovoitov      2014-09-26  13687  	if (err)
17a5267067f3c372 Alexei Starovoitov      2014-09-26  13688  		return err;
17a5267067f3c372 Alexei Starovoitov      2014-09-26  13689  
9e38f12ae067cded Mike Bazov              2026-12-01  13690  	/* A per-CPU value stays the run's own only while no other run starts on the CPU */
9e38f12ae067cded Mike Bazov              2026-12-01 @13691  	if (meta.map.ptr && bpf_map_is_percpu_map(meta.map.ptr->map_type))
9e38f12ae067cded Mike Bazov              2026-12-01  13692  		env->prog->percpu_state = true;
9e38f12ae067cded Mike Bazov              2026-12-01  13693  
c93552c443ebc63b Daniel Borkmann         2018-05-24  13694  	err = record_func_map(env, &meta, func_id, insn_idx);
c93552c443ebc63b Daniel Borkmann         2018-05-24  13695  	if (err)
c93552c443ebc63b Daniel Borkmann         2018-05-24  13696  		return err;
c93552c443ebc63b Daniel Borkmann         2018-05-24  13697  
d2e4c1e6c2947269 Daniel Borkmann         2019-11-22  13698  	err = record_func_key(env, &meta, func_id, insn_idx);
d2e4c1e6c2947269 Daniel Borkmann         2019-11-22  13699  	if (err)
d2e4c1e6c2947269 Daniel Borkmann         2019-11-22  13700  		return err;
d2e4c1e6c2947269 Daniel Borkmann         2019-11-22  13701  
6a581b856c9e633c Yonghong Song           2026-04-22  13702  	regs = cur_regs(env);
6a581b856c9e633c Yonghong Song           2026-04-22  13703  
fc670d4b6c31d69f Kumar Kartikeya Dwivedi 2026-09-21  13704  	err = mark_raw_stack(env, &meta, insn_idx);
435faee1aae9c1ac Daniel Borkmann         2016-04-13  13705  	if (err)
435faee1aae9c1ac Daniel Borkmann         2016-04-13  13706  		return err;
435faee1aae9c1ac Daniel Borkmann         2016-04-13  13707  
6e2b51cb4ccfd1f9 Kumar Kartikeya Dwivedi 2026-12-01  13708  	if (insn_has_cb_pad(insn)) {
6e2b51cb4ccfd1f9 Kumar Kartikeya Dwivedi 2026-12-01  13709  		err = check_cb_pad(env, (unsigned long)fn->func, func_id_name(func_id));
6e2b51cb4ccfd1f9 Kumar Kartikeya Dwivedi 2026-12-01  13710  		if (err)
6e2b51cb4ccfd1f9 Kumar Kartikeya Dwivedi 2026-12-01  13711  			return err;
6e2b51cb4ccfd1f9 Kumar Kartikeya Dwivedi 2026-12-01  13712  	}
6e2b51cb4ccfd1f9 Kumar Kartikeya Dwivedi 2026-12-01  13713  
8f14852e89113d73 Kumar Kartikeya Dwivedi 2022-04-25  13714  	if (meta.release_regno) {
bcfcb15fde94ed39 Amery Hung              2026-05-28  13715  		struct bpf_reg_state *reg = &regs[meta.release_regno];
bcfcb15fde94ed39 Amery Hung              2026-05-28  13716  		bool convert_rcu = (func_id == BPF_FUNC_kptr_xchg) && in_rcu_cs(env) &&
bcfcb15fde94ed39 Amery Hung              2026-05-28  13717  				   (reg->type & MEM_ALLOC) && (reg->type & MEM_PERCPU);
5b221ecb3a9e4801 Yonghong Song           2023-08-27  13718  
bcfcb15fde94ed39 Amery Hung              2026-05-28  13719  		err = release_reg(env, reg, convert_rcu, !!meta.dynptr.id);
308c7a0ae8859b34 Amery Hung              2026-05-28  13720  		if (err)
fd978bf7fd312581 Joe Stringer            2018-10-02  13721  			return err;
fd978bf7fd312581 Joe Stringer            2018-10-02  13722  	}
fd978bf7fd312581 Joe Stringer            2018-10-02  13723  
e6f2dd0f80674e9d Joanne Koong            2021-11-29  13724  	switch (func_id) {
e6f2dd0f80674e9d Joanne Koong            2021-11-29  13725  	case BPF_FUNC_tail_call:
9e38f12ae067cded Mike Bazov              2026-12-01  13726  		/* The target runs without a recursion check of its own */
9e38f12ae067cded Mike Bazov              2026-12-01  13727  		env->prog->percpu_state = true;
af5311c370d8eb49 Alexei Starovoitov      2026-12-01  13728  		err = check_resource_leak(env, true, "tail_call");
d402755ced2ea8fc Kumar Kartikeya Dwivedi 2024-11-03  13729  		if (err)
e6f2dd0f80674e9d Joanne Koong            2021-11-29  13730  			return err;
e6f2dd0f80674e9d Joanne Koong            2021-11-29  13731  		break;
9e38f12ae067cded Mike Bazov              2026-12-01  13732  	case BPF_FUNC_get_smp_processor_id:
9e38f12ae067cded Mike Bazov              2026-12-01  13733  		/* The CPU id often indexes per-CPU slots that the program keeps itself */
9e38f12ae067cded Mike Bazov              2026-12-01  13734  		env->prog->percpu_state = true;
9e38f12ae067cded Mike Bazov              2026-12-01  13735  		break;
e6f2dd0f80674e9d Joanne Koong            2021-11-29  13736  	case BPF_FUNC_get_local_storage:
cd3394317653837e Roman Gushchin          2018-08-02  13737  		/* check that flags argument in get_local_storage(map, flags) is 0,
cd3394317653837e Roman Gushchin          2018-08-02  13738  		 * this is required because get_local_storage() can't return an error.
cd3394317653837e Roman Gushchin          2018-08-02  13739  		 */
c82834a5a11f743f Alexei Starovoitov      2026-04-12  13740  		if (!bpf_register_is_null(&regs[BPF_REG_2])) {
cd3394317653837e Roman Gushchin          2018-08-02  13741  			verbose(env, "get_local_storage() doesn't support non-zero flags\n");
cd3394317653837e Roman Gushchin          2018-08-02  13742  			return -EINVAL;
cd3394317653837e Roman Gushchin          2018-08-02  13743  		}
e6f2dd0f80674e9d Joanne Koong            2021-11-29  13744  		break;
e6f2dd0f80674e9d Joanne Koong            2021-11-29  13745  	case BPF_FUNC_for_each_map_elem:
6e2b51cb4ccfd1f9 Kumar Kartikeya Dwivedi 2026-12-01  13746  		/* The helper calls the op of the map, which calls the callback: check the op. */
6e2b51cb4ccfd1f9 Kumar Kartikeya Dwivedi 2026-12-01  13747  		err = BPF_HAS_CB_PADS ?
6e2b51cb4ccfd1f9 Kumar Kartikeya Dwivedi 2026-12-01 @13748  		      check_cb_pad(env, (unsigned long)meta.map.ptr->ops->map_for_each_callback,
6e2b51cb4ccfd1f9 Kumar Kartikeya Dwivedi 2026-12-01  13749  				   "map_for_each_callback()") : 0;
6e2b51cb4ccfd1f9 Kumar Kartikeya Dwivedi 2026-12-01  13750  		err = err ?: push_callback_call(env, insn, insn_idx, meta.subprogno,
69c087ba6225b574 Yonghong Song           2021-02-26  13751  						set_map_elem_callback_state);
e6f2dd0f80674e9d Joanne Koong            2021-11-29  13752  		break;
e6f2dd0f80674e9d Joanne Koong            2021-11-29  13753  	case BPF_FUNC_timer_set_callback:
ab5cfac139ab8576 Eduard Zingerman        2023-11-21  13754  		err = push_callback_call(env, insn, insn_idx, meta.subprogno,
b00628b1c7d595ae Alexei Starovoitov      2021-07-14  13755  					 set_timer_callback_state);
e6f2dd0f80674e9d Joanne Koong            2021-11-29  13756  		break;
e6f2dd0f80674e9d Joanne Koong            2021-11-29  13757  	case BPF_FUNC_find_vma:
ab5cfac139ab8576 Eduard Zingerman        2023-11-21  13758  		err = push_callback_call(env, insn, insn_idx, meta.subprogno,
7c7e3d31e7856a82 Song Liu                2021-11-05  13759  					 set_find_vma_callback_state);
e6f2dd0f80674e9d Joanne Koong            2021-11-29  13760  		break;
e6f2dd0f80674e9d Joanne Koong            2021-11-29  13761  	case BPF_FUNC_snprintf:
e6f2dd0f80674e9d Joanne Koong            2021-11-29  13762  		err = check_bpf_snprintf_call(env, regs);
e6f2dd0f80674e9d Joanne Koong            2021-11-29  13763  		break;
e6f2dd0f80674e9d Joanne Koong            2021-11-29  13764  	case BPF_FUNC_loop:
9f644d937dcf1bf5 Alexei Starovoitov      2026-11-07  13765  		update_loop_inline_state(env, meta.subprogno);
b93f7180f0bc3733 Eduard Zingerman        2026-04-24  13766  		if (cur_func(env)->callback_depth < reg_umax(&regs[BPF_REG_1])) {
ab5cfac139ab8576 Eduard Zingerman        2023-11-21  13767  			err = push_callback_call(env, insn, insn_idx, meta.subprogno,
e6f2dd0f80674e9d Joanne Koong            2021-11-29  13768  						 set_loop_callback_state);
bb124da69c47dd98 Eduard Zingerman        2023-11-21  13769  		} else {
623109e0f9313770 Alexei Starovoitov      2026-11-20  13770  			leave_callback(cur_func(env));
bb124da69c47dd98 Eduard Zingerman        2023-11-21  13771  			if (env->log.level & BPF_LOG_LEVEL2)
bb124da69c47dd98 Eduard Zingerman        2023-11-21  13772  				verbose(env, "frame%d bpf_loop iteration limit reached\n",
bb124da69c47dd98 Eduard Zingerman        2023-11-21  13773  					env->cur_state->curframe);
bb124da69c47dd98 Eduard Zingerman        2023-11-21  13774  		}
e6f2dd0f80674e9d Joanne Koong            2021-11-29  13775  		break;
263ae152e96253f4 Joanne Koong            2022-05-23  13776  	case BPF_FUNC_dynptr_from_mem:
263ae152e96253f4 Joanne Koong            2022-05-23  13777  		if (regs[BPF_REG_1].type != PTR_TO_MAP_VALUE) {
263ae152e96253f4 Joanne Koong            2022-05-23  13778  			verbose(env, "Unsupported reg type %s for bpf_dynptr_from_mem data\n",
263ae152e96253f4 Joanne Koong            2022-05-23  13779  				reg_type_str(env, regs[BPF_REG_1].type));
263ae152e96253f4 Joanne Koong            2022-05-23  13780  			return -EACCES;
263ae152e96253f4 Joanne Koong            2022-05-23  13781  		}
69fd337a975c7e69 Stanislav Fomichev      2022-06-28  13782  		break;
69fd337a975c7e69 Stanislav Fomichev      2022-06-28  13783  	case BPF_FUNC_set_retval:
b1f7f67b74c2e29e Xu Kuohai               2026-06-05  13784  	{
b1f7f67b74c2e29e Xu Kuohai               2026-06-05  13785  		struct bpf_retval_range range = {
b1f7f67b74c2e29e Xu Kuohai               2026-06-05  13786  			.minval = -MAX_ERRNO,
b1f7f67b74c2e29e Xu Kuohai               2026-06-05  13787  			.maxval = 0,
b1f7f67b74c2e29e Xu Kuohai               2026-06-05  13788  			.return_32bit = true
b1f7f67b74c2e29e Xu Kuohai               2026-06-05  13789  		};
b1f7f67b74c2e29e Xu Kuohai               2026-06-05  13790  		struct bpf_reg_state *r1 = &regs[BPF_REG_1];
b1f7f67b74c2e29e Xu Kuohai               2026-06-05  13791  
b1f7f67b74c2e29e Xu Kuohai               2026-06-05  13792  		if (r1->type != SCALAR_VALUE) {
b1f7f67b74c2e29e Xu Kuohai               2026-06-05  13793  			verbose(env, "R1 is not a scalar\n");
b1f7f67b74c2e29e Xu Kuohai               2026-06-05  13794  			return -EINVAL;
b1f7f67b74c2e29e Xu Kuohai               2026-06-05  13795  		}
b1f7f67b74c2e29e Xu Kuohai               2026-06-05  13796  
b1f7f67b74c2e29e Xu Kuohai               2026-06-05  13797  		/* CGROUP_GETSOCKOPT is allowed to return arbitrary value */
b1f7f67b74c2e29e Xu Kuohai               2026-06-05  13798  		if (prog_type == BPF_PROG_TYPE_CGROUP_SOCKOPT &&
b1f7f67b74c2e29e Xu Kuohai               2026-06-05  13799  		    env->prog->expected_attach_type == BPF_CGROUP_GETSOCKOPT)
b1f7f67b74c2e29e Xu Kuohai               2026-06-05  13800  			break;
b1f7f67b74c2e29e Xu Kuohai               2026-06-05  13801  
aef9d4a34a51f0a5 Stanislav Fomichev      2022-07-20  13802  		if (prog_type == BPF_PROG_TYPE_LSM &&
aef9d4a34a51f0a5 Stanislav Fomichev      2022-07-20  13803  		    env->prog->expected_attach_type == BPF_LSM_CGROUP) {
69fd337a975c7e69 Stanislav Fomichev      2022-06-28  13804  			if (!env->prog->aux->attach_func_proto->type) {
69fd337a975c7e69 Stanislav Fomichev      2022-06-28  13805  				/* Make sure programs that attach to void
69fd337a975c7e69 Stanislav Fomichev      2022-06-28  13806  				 * hooks don't try to modify return value.
69fd337a975c7e69 Stanislav Fomichev      2022-06-28  13807  				 */
69fd337a975c7e69 Stanislav Fomichev      2022-06-28  13808  				verbose(env, "BPF_LSM_CGROUP that attach to void LSM hooks can't modify return value!\n");
69fd337a975c7e69 Stanislav Fomichev      2022-06-28  13809  				return -EINVAL;
69fd337a975c7e69 Stanislav Fomichev      2022-06-28  13810  			}
b1f7f67b74c2e29e Xu Kuohai               2026-06-05  13811  			bpf_lsm_get_retval_range(env->prog, &range);
69fd337a975c7e69 Stanislav Fomichev      2022-06-28  13812  		}
b1f7f67b74c2e29e Xu Kuohai               2026-06-05  13813  
b1f7f67b74c2e29e Xu Kuohai               2026-06-05  13814  		if (!retval_range_within(range, r1)) {
b1f7f67b74c2e29e Xu Kuohai               2026-06-05  13815  			verbose_invalid_scalar(env, r1, range, "At bpf_set_retval", "R1");
b1f7f67b74c2e29e Xu Kuohai               2026-06-05  13816  			return -EINVAL;
b1f7f67b74c2e29e Xu Kuohai               2026-06-05  13817  		}
b1f7f67b74c2e29e Xu Kuohai               2026-06-05  13818  
69fd337a975c7e69 Stanislav Fomichev      2022-06-28  13819  		break;
b1f7f67b74c2e29e Xu Kuohai               2026-06-05  13820  	}
b5964b968ac64c2e Joanne Koong            2023-03-01  13821  	case BPF_FUNC_dynptr_write:
b5964b968ac64c2e Joanne Koong            2023-03-01  13822  	{
b5c0a07eb2c23bfd Amery Hung              2026-05-28  13823  		enum bpf_dynptr_type dynptr_type = meta.dynptr.type;
b5964b968ac64c2e Joanne Koong            2023-03-01  13824  
b5964b968ac64c2e Joanne Koong            2023-03-01  13825  		if (dynptr_type == BPF_DYNPTR_TYPE_INVALID)
b5964b968ac64c2e Joanne Koong            2023-03-01  13826  			return -EFAULT;
b5964b968ac64c2e Joanne Koong            2023-03-01  13827  
19e6ca6b4a22d62a Josef Bacik             2026-10-17  13828  		if (dynptr_write_changes_pkt_data(dynptr_type))
b5964b968ac64c2e Joanne Koong            2023-03-01  13829  			/* this will trigger clear_all_pkt_pointers(), which will
b5964b968ac64c2e Joanne Koong            2023-03-01  13830  			 * invalidate all dynptr slices associated with the skb
b5964b968ac64c2e Joanne Koong            2023-03-01  13831  			 */
b5964b968ac64c2e Joanne Koong            2023-03-01  13832  			changes_data = true;
b5964b968ac64c2e Joanne Koong            2023-03-01  13833  
b5964b968ac64c2e Joanne Koong            2023-03-01  13834  		break;
b5964b968ac64c2e Joanne Koong            2023-03-01  13835  	}
9f9fc3dc30b2f21c Alexei Starovoitov      2026-11-20  13836  	case BPF_FUNC_override_return:
9f9fc3dc30b2f21c Alexei Starovoitov      2026-11-20  13837  		/* see bpf_check_tail_call() */
9f9fc3dc30b2f21c Alexei Starovoitov      2026-11-20  13838  		for (i = 0; i < env->used_map_cnt; i++) {
9f9fc3dc30b2f21c Alexei Starovoitov      2026-11-20  13839  			if (!map_type_contains_progs(env->used_maps[i]))
9f9fc3dc30b2f21c Alexei Starovoitov      2026-11-20  13840  				continue;
9f9fc3dc30b2f21c Alexei Starovoitov      2026-11-20  13841  			verbose(env, "bpf_override_return() and a map of programs are used\n");
9f9fc3dc30b2f21c Alexei Starovoitov      2026-11-20  13842  			return -EINVAL;
9f9fc3dc30b2f21c Alexei Starovoitov      2026-11-20  13843  		}
9f9fc3dc30b2f21c Alexei Starovoitov      2026-11-20  13844  		break;
01cc55af93884f1f Yonghong Song           2023-08-27  13845  	case BPF_FUNC_per_cpu_ptr:
01cc55af93884f1f Yonghong Song           2023-08-27  13846  	case BPF_FUNC_this_cpu_ptr:
01cc55af93884f1f Yonghong Song           2023-08-27  13847  	{
01cc55af93884f1f Yonghong Song           2023-08-27  13848  		struct bpf_reg_state *reg = &regs[BPF_REG_1];
01cc55af93884f1f Yonghong Song           2023-08-27  13849  		const struct btf_type *type;
01cc55af93884f1f Yonghong Song           2023-08-27  13850  
9e38f12ae067cded Mike Bazov              2026-12-01  13851  		env->prog->percpu_state = true;
9e38f12ae067cded Mike Bazov              2026-12-01  13852  
01cc55af93884f1f Yonghong Song           2023-08-27  13853  		if (reg->type & MEM_RCU) {
01cc55af93884f1f Yonghong Song           2023-08-27  13854  			type = btf_type_by_id(reg->btf, reg->btf_id);
01cc55af93884f1f Yonghong Song           2023-08-27  13855  			if (!type || !btf_type_is_struct(type)) {
01cc55af93884f1f Yonghong Song           2023-08-27  13856  				verbose(env, "Helper has invalid btf/btf_id in R1\n");
01cc55af93884f1f Yonghong Song           2023-08-27  13857  				return -EFAULT;
01cc55af93884f1f Yonghong Song           2023-08-27  13858  			}
01cc55af93884f1f Yonghong Song           2023-08-27  13859  			returns_cpu_specific_alloc_ptr = true;
01cc55af93884f1f Yonghong Song           2023-08-27  13860  		}
fa83ca87f43151bf Alexei Starovoitov      2026-11-20  13861  		err = record_call_fixup(env, returns_cpu_specific_alloc_ptr, NULL);
01cc55af93884f1f Yonghong Song           2023-08-27  13862  		break;
01cc55af93884f1f Yonghong Song           2023-08-27  13863  	}
20571567384428df David Vernet            2022-09-19  13864  	case BPF_FUNC_user_ringbuf_drain:
ab5cfac139ab8576 Eduard Zingerman        2023-11-21  13865  		err = push_callback_call(env, insn, insn_idx, meta.subprogno,
20571567384428df David Vernet            2022-09-19  13866  					 set_user_ringbuf_callback_state);
20571567384428df David Vernet            2022-09-19  13867  		break;
7c7e3d31e7856a82 Song Liu                2021-11-05  13868  	}
7c7e3d31e7856a82 Song Liu                2021-11-05  13869  
e6f2dd0f80674e9d Joanne Koong            2021-11-29  13870  	if (err)
7b15523a989b6392 Florent Revest          2021-04-19  13871  		return err;
7b15523a989b6392 Florent Revest          2021-04-19  13872  
17a5267067f3c372 Alexei Starovoitov      2014-09-26  13873  	/* reset caller saved regs */
af4ea6e20fff383c Kumar Kartikeya Dwivedi 2026-08-15  13874  	bpf_diag_record_caller_saved(env, regs);
cb445a6eedb66bca Kumar Kartikeya Dwivedi 2026-12-01  13875  	/* The callback unwound: the helper leaves with the R0 of the callback, so keep R0. */
cb445a6eedb66bca Kumar Kartikeya Dwivedi 2026-12-01  13876  	if (env->cur_state->unwound)
cb445a6eedb66bca Kumar Kartikeya Dwivedi 2026-12-01  13877  		unwound_r0 = regs[BPF_REG_0];
cb445a6eedb66bca Kumar Kartikeya Dwivedi 2026-12-01  13878  	else
b26c0b2dd5195f33 Kumar Kartikeya Dwivedi 2026-08-16  13879  		bpf_diag_mod_begin(env, &regs[BPF_REG_0], NULL, BPF_DIAG_MOD_WRITE);
dc503a8ad98474ea Edward Cree             2017-08-15  13880  	for (i = 0; i < CALLER_SAVED_REGS; i++) {
c82834a5a11f743f Alexei Starovoitov      2026-04-12  13881  		bpf_mark_reg_not_init(env, &regs[caller_saved[i]]);
dc503a8ad98474ea Edward Cree             2017-08-15  13882  		check_reg_arg(env, caller_saved[i], DST_OP_NO_MARK);
dc503a8ad98474ea Edward Cree             2017-08-15  13883  	}
0f6bd5e7a804af27 Yonghong Song           2026-05-12  13884  	invalidate_outgoing_stack_args(env, cur_func(env));
cb445a6eedb66bca Kumar Kartikeya Dwivedi 2026-12-01  13885  	if (env->cur_state->unwound) {
cb445a6eedb66bca Kumar Kartikeya Dwivedi 2026-12-01  13886  		regs[BPF_REG_0] = unwound_r0;
cb445a6eedb66bca Kumar Kartikeya Dwivedi 2026-12-01  13887  		goto unwound;
cb445a6eedb66bca Kumar Kartikeya Dwivedi 2026-12-01  13888  	}
17a5267067f3c372 Alexei Starovoitov      2014-09-26  13889  
dc503a8ad98474ea Edward Cree             2017-08-15  13890  	/* update return register (already marked as written above) */
3c4807322660d429 Hao Luo                 2021-12-16  13891  	ret_type = fn->ret_type;
0c9a7a7e2049859d Joanne Koong            2022-08-02  13892  	ret_flag = type_flag(ret_type);
0c9a7a7e2049859d Joanne Koong            2022-08-02  13893  
0c9a7a7e2049859d Joanne Koong            2022-08-02  13894  	switch (base_type(ret_type)) {
0c9a7a7e2049859d Joanne Koong            2022-08-02  13895  	case RET_INTEGER:
f1174f77b50c94ee Edward Cree             2017-08-07  13896  		/* sets type to SCALAR_VALUE */
61bd5218eef349fc Jakub Kicinski          2017-10-09  13897  		mark_reg_unknown(env, regs, BPF_REG_0);
0c9a7a7e2049859d Joanne Koong            2022-08-02  13898  		break;
0c9a7a7e2049859d Joanne Koong            2022-08-02  13899  	case RET_VOID:
17a5267067f3c372 Alexei Starovoitov      2014-09-26  13900  		regs[BPF_REG_0].type = NOT_INIT;
0c9a7a7e2049859d Joanne Koong            2022-08-02  13901  		break;
0c9a7a7e2049859d Joanne Koong            2022-08-02  13902  	case RET_PTR_TO_MAP_VALUE:
f1174f77b50c94ee Edward Cree             2017-08-07  13903  		/* There is no offset yet applied, variable or fixed */
61bd5218eef349fc Jakub Kicinski          2017-10-09  13904  		mark_reg_known_zero(env, regs, BPF_REG_0);
17a5267067f3c372 Alexei Starovoitov      2014-09-26  13905  		/* remember map_ptr, so that check_map_access()
17a5267067f3c372 Alexei Starovoitov      2014-09-26  13906  		 * can check 'value_size' boundary of memory access
17a5267067f3c372 Alexei Starovoitov      2014-09-26  13907  		 * to map element returned from bpf_map_lookup_elem()
17a5267067f3c372 Alexei Starovoitov      2014-09-26  13908  		 */
98c4fd2963cb2bc5 Mykyta Yatsenko         2026-01-30  13909  		if (meta.map.ptr == NULL) {
0df1a55afa832f46 Paul Chaignon           2025-07-01  13910  			verifier_bug(env, "unexpected null map_ptr");
fd508bde5d646fe8 Luis Gerhorst           2025-06-03  13911  			return -EFAULT;
17a5267067f3c372 Alexei Starovoitov      2014-09-26  13912  		}
d2102f2f5d75a84d Daniel Xu               2025-01-14  13913  
d2102f2f5d75a84d Daniel Xu               2025-01-14  13914  		if (func_id == BPF_FUNC_map_lookup_elem &&
53040a81ae57cdca Nuoqi Gui               2026-06-07  13915  		    can_elide_value_nullness(meta.map.ptr) &&
c1e03c8479e3842c Alexei Starovoitov      2026-11-01  13916  		    meta.max_map_key < meta.map.ptr->max_entries)
d2102f2f5d75a84d Daniel Xu               2025-01-14  13917  			ret_flag &= ~PTR_MAYBE_NULL;
d2102f2f5d75a84d Daniel Xu               2025-01-14  13918  
98c4fd2963cb2bc5 Mykyta Yatsenko         2026-01-30  13919  		regs[BPF_REG_0].map_ptr = meta.map.ptr;
98c4fd2963cb2bc5 Mykyta Yatsenko         2026-01-30  13920  		regs[BPF_REG_0].map_uid = meta.map.uid;
c25b2ae136039ffa Hao Luo                 2021-12-16  13921  		regs[BPF_REG_0].type = PTR_TO_MAP_VALUE | ret_flag;
341d227fa5db567f Eduard Zingerman        2026-08-01  13922  		if (type_may_be_null(ret_flag) ||
98c4fd2963cb2bc5 Mykyta Yatsenko         2026-01-30  13923  		    btf_record_has_field(meta.map.ptr->record, BPF_SPIN_LOCK | BPF_RES_SPIN_LOCK)) {
cb137b692503d0cc Alexei Starovoitov      2026-11-20  13924  			regs[BPF_REG_0].id = bpf_new_id(env);
4d31f30148cea6e9 Daniel Borkmann         2018-11-01  13925  		}
341d227fa5db567f Eduard Zingerman        2026-08-01  13926  		/* requires regs[BPF_REG_0].id to be set because of the map-in-map case */
341d227fa5db567f Eduard Zingerman        2026-08-01  13927  		refine_map_lookup_value(&regs[BPF_REG_0]);
0c9a7a7e2049859d Joanne Koong            2022-08-02  13928  		break;
0c9a7a7e2049859d Joanne Koong            2022-08-02  13929  	case RET_PTR_TO_SOCKET:
46f8bc92758c6259 Martin KaFai Lau        2019-02-09  13930  		mark_reg_known_zero(env, regs, BPF_REG_0);
c25b2ae136039ffa Hao Luo                 2021-12-16  13931  		regs[BPF_REG_0].type = PTR_TO_SOCKET | ret_flag;
0c9a7a7e2049859d Joanne Koong            2022-08-02  13932  		break;
0c9a7a7e2049859d Joanne Koong            2022-08-02  13933  	case RET_PTR_TO_SOCK_COMMON:
85a51f8c28b98126 Lorenz Bauer            2019-03-22  13934  		mark_reg_known_zero(env, regs, BPF_REG_0);
c25b2ae136039ffa Hao Luo                 2021-12-16  13935  		regs[BPF_REG_0].type = PTR_TO_SOCK_COMMON | ret_flag;
0c9a7a7e2049859d Joanne Koong            2022-08-02  13936  		break;
0c9a7a7e2049859d Joanne Koong            2022-08-02  13937  	case RET_PTR_TO_TCP_SOCK:
655a51e536c09d15 Martin KaFai Lau        2019-02-09  13938  		mark_reg_known_zero(env, regs, BPF_REG_0);
c25b2ae136039ffa Hao Luo                 2021-12-16  13939  		regs[BPF_REG_0].type = PTR_TO_TCP_SOCK | ret_flag;
0c9a7a7e2049859d Joanne Koong            2022-08-02  13940  		break;
2de2669b4e52b2ae Kumar Kartikeya Dwivedi 2022-11-15  13941  	case RET_PTR_TO_MEM:
457f44363a889413 Andrii Nakryiko         2020-05-29  13942  		mark_reg_known_zero(env, regs, BPF_REG_0);
c25b2ae136039ffa Hao Luo                 2021-12-16  13943  		regs[BPF_REG_0].type = PTR_TO_MEM | ret_flag;
8faaa93b9f6a2794 Amery Hung              2026-07-14  13944  		regs[BPF_REG_0].mem_size = meta.ret_mem.size;
0c9a7a7e2049859d Joanne Koong            2022-08-02  13945  		break;
0c9a7a7e2049859d Joanne Koong            2022-08-02  13946  	case RET_PTR_TO_MEM_OR_BTF_ID:
0c9a7a7e2049859d Joanne Koong            2022-08-02  13947  	{
eaa6bcb71ef6ed3d Hao Luo                 2020-09-29  13948  		const struct btf_type *t;
eaa6bcb71ef6ed3d Hao Luo                 2020-09-29  13949  
eaa6bcb71ef6ed3d Hao Luo                 2020-09-29  13950  		mark_reg_known_zero(env, regs, BPF_REG_0);
22dc4a0f5ed11b6d Andrii Nakryiko         2020-12-03  13951  		t = btf_type_skip_modifiers(meta.ret_btf, meta.ret_btf_id, NULL);
eaa6bcb71ef6ed3d Hao Luo                 2020-09-29  13952  		if (!btf_type_is_struct(t)) {
eaa6bcb71ef6ed3d Hao Luo                 2020-09-29  13953  			u32 tsize;
eaa6bcb71ef6ed3d Hao Luo                 2020-09-29  13954  			const struct btf_type *ret;
eaa6bcb71ef6ed3d Hao Luo                 2020-09-29  13955  			const char *tname;
eaa6bcb71ef6ed3d Hao Luo                 2020-09-29  13956  
eaa6bcb71ef6ed3d Hao Luo                 2020-09-29  13957  			/* resolve the type size of ksym. */
22dc4a0f5ed11b6d Andrii Nakryiko         2020-12-03  13958  			ret = btf_resolve_size(meta.ret_btf, t, &tsize);
eaa6bcb71ef6ed3d Hao Luo                 2020-09-29  13959  			if (IS_ERR(ret)) {
22dc4a0f5ed11b6d Andrii Nakryiko         2020-12-03  13960  				tname = btf_name_by_offset(meta.ret_btf, t->name_off);
eaa6bcb71ef6ed3d Hao Luo                 2020-09-29  13961  				verbose(env, "unable to resolve the size of type '%s': %ld\n",
eaa6bcb71ef6ed3d Hao Luo                 2020-09-29  13962  					tname, PTR_ERR(ret));
eaa6bcb71ef6ed3d Hao Luo                 2020-09-29  13963  				return -EINVAL;
eaa6bcb71ef6ed3d Hao Luo                 2020-09-29  13964  			}
c25b2ae136039ffa Hao Luo                 2021-12-16  13965  			regs[BPF_REG_0].type = PTR_TO_MEM | ret_flag;
eaa6bcb71ef6ed3d Hao Luo                 2020-09-29  13966  			regs[BPF_REG_0].mem_size = tsize;
01cc55af93884f1f Yonghong Song           2023-08-27  13967  		} else {
01cc55af93884f1f Yonghong Song           2023-08-27  13968  			if (returns_cpu_specific_alloc_ptr) {
01cc55af93884f1f Yonghong Song           2023-08-27  13969  				regs[BPF_REG_0].type = PTR_TO_BTF_ID | MEM_ALLOC | MEM_RCU;
eaa6bcb71ef6ed3d Hao Luo                 2020-09-29  13970  			} else {
34d3a78c681e8e78 Hao Luo                 2021-12-16  13971  				/* MEM_RDONLY may be carried from ret_flag, but it
34d3a78c681e8e78 Hao Luo                 2021-12-16  13972  				 * doesn't apply on PTR_TO_BTF_ID. Fold it, otherwise
34d3a78c681e8e78 Hao Luo                 2021-12-16  13973  				 * it will confuse the check of PTR_TO_BTF_ID in
34d3a78c681e8e78 Hao Luo                 2021-12-16  13974  				 * check_mem_access().
34d3a78c681e8e78 Hao Luo                 2021-12-16  13975  				 */
34d3a78c681e8e78 Hao Luo                 2021-12-16  13976  				ret_flag &= ~MEM_RDONLY;
c25b2ae136039ffa Hao Luo                 2021-12-16  13977  				regs[BPF_REG_0].type = PTR_TO_BTF_ID | ret_flag;
01cc55af93884f1f Yonghong Song           2023-08-27  13978  			}
01cc55af93884f1f Yonghong Song           2023-08-27  13979  
22dc4a0f5ed11b6d Andrii Nakryiko         2020-12-03  13980  			regs[BPF_REG_0].btf = meta.ret_btf;
eaa6bcb71ef6ed3d Hao Luo                 2020-09-29  13981  			regs[BPF_REG_0].btf_id = meta.ret_btf_id;
eaa6bcb71ef6ed3d Hao Luo                 2020-09-29  13982  		}
0c9a7a7e2049859d Joanne Koong            2022-08-02  13983  		break;
0c9a7a7e2049859d Joanne Koong            2022-08-02  13984  	}
0c9a7a7e2049859d Joanne Koong            2022-08-02  13985  	case RET_PTR_TO_BTF_ID:
0c9a7a7e2049859d Joanne Koong            2022-08-02  13986  	{
c0a5a21c25f37c9f Kumar Kartikeya Dwivedi 2022-04-25  13987  		struct btf *ret_btf;
af7ec13833619e17 Yonghong Song           2020-06-23  13988  		int ret_btf_id;
af7ec13833619e17 Yonghong Song           2020-06-23  13989  
af7ec13833619e17 Yonghong Song           2020-06-23  13990  		mark_reg_known_zero(env, regs, BPF_REG_0);
c25b2ae136039ffa Hao Luo                 2021-12-16  13991  		regs[BPF_REG_0].type = PTR_TO_BTF_ID | ret_flag;
c0a5a21c25f37c9f Kumar Kartikeya Dwivedi 2022-04-25  13992  		if (func_id == BPF_FUNC_kptr_xchg) {
aa3496accc412b3d Kumar Kartikeya Dwivedi 2022-11-04  13993  			ret_btf = meta.kptr_field->kptr.btf;
aa3496accc412b3d Kumar Kartikeya Dwivedi 2022-11-04  13994  			ret_btf_id = meta.kptr_field->kptr.btf_id;
36d8bdf75a93190e Yonghong Song           2023-08-27  13995  			if (!btf_is_kernel(ret_btf)) {
738c96d5e2e3700b Dave Marchevsky         2023-03-10  13996  				regs[BPF_REG_0].type |= MEM_ALLOC;
36d8bdf75a93190e Yonghong Song           2023-08-27  13997  				if (meta.kptr_field->type == BPF_KPTR_PERCPU)
36d8bdf75a93190e Yonghong Song           2023-08-27  13998  					regs[BPF_REG_0].type |= MEM_PERCPU;
36d8bdf75a93190e Yonghong Song           2023-08-27  13999  			}
c0a5a21c25f37c9f Kumar Kartikeya Dwivedi 2022-04-25  14000  		} else {
47e34cb74d376ddf Dave Marchevsky         2022-09-12  14001  			if (fn->ret_btf_id == BPF_PTR_POISON) {
0df1a55afa832f46 Paul Chaignon           2025-07-01  14002  				verifier_bug(env, "func %s has non-overwritten BPF_PTR_POISON return type",
47e34cb74d376ddf Dave Marchevsky         2022-09-12  14003  					     func_id_name(func_id));
6b84d7895d78079c Luis Gerhorst           2025-06-03  14004  				return -EFAULT;
47e34cb74d376ddf Dave Marchevsky         2022-09-12  14005  			}
c0a5a21c25f37c9f Kumar Kartikeya Dwivedi 2022-04-25  14006  			ret_btf = btf_vmlinux;
af7ec13833619e17 Yonghong Song           2020-06-23  14007  			ret_btf_id = *fn->ret_btf_id;
c0a5a21c25f37c9f Kumar Kartikeya Dwivedi 2022-04-25  14008  		}
af7ec13833619e17 Yonghong Song           2020-06-23  14009  		if (ret_btf_id == 0) {
3c4807322660d429 Hao Luo                 2021-12-16  14010  			verbose(env, "invalid return type %u of func %s#%d\n",
3c4807322660d429 Hao Luo                 2021-12-16  14011  				base_type(ret_type), func_id_name(func_id),
3c4807322660d429 Hao Luo                 2021-12-16  14012  				func_id);
af7ec13833619e17 Yonghong Song           2020-06-23  14013  			return -EINVAL;
af7ec13833619e17 Yonghong Song           2020-06-23  14014  		}
c0a5a21c25f37c9f Kumar Kartikeya Dwivedi 2022-04-25  14015  		regs[BPF_REG_0].btf = ret_btf;
af7ec13833619e17 Yonghong Song           2020-06-23  14016  		regs[BPF_REG_0].btf_id = ret_btf_id;
0c9a7a7e2049859d Joanne Koong            2022-08-02  14017  		break;
0c9a7a7e2049859d Joanne Koong            2022-08-02  14018  	}
0c9a7a7e2049859d Joanne Koong            2022-08-02  14019  	default:
3c4807322660d429 Hao Luo                 2021-12-16  14020  		verbose(env, "unknown return type %u of func %s#%d\n",
3c4807322660d429 Hao Luo                 2021-12-16  14021  			base_type(ret_type), func_id_name(func_id), func_id);
17a5267067f3c372 Alexei Starovoitov      2014-09-26  14022  		return -EINVAL;
17a5267067f3c372 Alexei Starovoitov      2014-09-26  14023  	}
04fd61ab36ec065e Alexei Starovoitov      2015-05-19  14024  
341d227fa5db567f Eduard Zingerman        2026-08-01  14025  	if (type_may_be_null(regs[BPF_REG_0].type) && !regs[BPF_REG_0].id)
cb137b692503d0cc Alexei Starovoitov      2026-11-20  14026  		regs[BPF_REG_0].id = bpf_new_id(env);
93c230e3f5bd6e1d Martin KaFai Lau        2020-10-19  14027  
308c7a0ae8859b34 Amery Hung              2026-05-28  14028  	if (is_ptr_cast_function(func_id) &&
b7dd2b388657d996 Amery Hung              2026-05-28  14029  	    find_reference_state(env->cur_state, meta.ref_obj.id)) {
308c7a0ae8859b34 Amery Hung              2026-05-28  14030  		struct bpf_verifier_state *branch;
308c7a0ae8859b34 Amery Hung              2026-05-28  14031  		struct bpf_reg_state *r0;
308c7a0ae8859b34 Amery Hung              2026-05-28  14032  
b7dd2b388657d996 Amery Hung              2026-05-28  14033  		err = validate_ref_obj(env, &meta.ref_obj);
b7dd2b388657d996 Amery Hung              2026-05-28  14034  		if (err)
b7dd2b388657d996 Amery Hung              2026-05-28  14035  			return err;
b7dd2b388657d996 Amery Hung              2026-05-28  14036  
af4ea6e20fff383c Kumar Kartikeya Dwivedi 2026-08-15  14037  		bpf_diag_mod_end(env);
af4ea6e20fff383c Kumar Kartikeya Dwivedi 2026-08-15  14038  
308c7a0ae8859b34 Amery Hung              2026-05-28  14039  		/*
308c7a0ae8859b34 Amery Hung              2026-05-28  14040  		 * In order for a release of any of the original or cast pointers
308c7a0ae8859b34 Amery Hung              2026-05-28  14041  		 * to invalidate all other pointers, reuse the same reference id for
308c7a0ae8859b34 Amery Hung              2026-05-28  14042  		 * the cast result.
308c7a0ae8859b34 Amery Hung              2026-05-28  14043  		 * This reference id can't be used for nullness propagation,
308c7a0ae8859b34 Amery Hung              2026-05-28  14044  		 * as cast might return NULL for a non-NULL input.
308c7a0ae8859b34 Amery Hung              2026-05-28  14045  		 * Hence, explore the NULL case as a separate branch.
308c7a0ae8859b34 Amery Hung              2026-05-28  14046  		 */
308c7a0ae8859b34 Amery Hung              2026-05-28  14047  		branch = push_stack(env, env->insn_idx + 1, env->insn_idx, false);
308c7a0ae8859b34 Amery Hung              2026-05-28  14048  		if (IS_ERR(branch))
308c7a0ae8859b34 Amery Hung              2026-05-28  14049  			return PTR_ERR(branch);
308c7a0ae8859b34 Amery Hung              2026-05-28  14050  
308c7a0ae8859b34 Amery Hung              2026-05-28  14051  		r0 = &branch->frame[branch->curframe]->regs[BPF_REG_0];
308c7a0ae8859b34 Amery Hung              2026-05-28  14052  		__mark_reg_known_zero(r0);
308c7a0ae8859b34 Amery Hung              2026-05-28  14053  		r0->type = SCALAR_VALUE;
308c7a0ae8859b34 Amery Hung              2026-05-28  14054  
af4ea6e20fff383c Kumar Kartikeya Dwivedi 2026-08-15  14055  		bpf_diag_mod_begin(env, &regs[BPF_REG_0], NULL, BPF_DIAG_MOD_WRITE);
308c7a0ae8859b34 Amery Hung              2026-05-28  14056  		regs[BPF_REG_0].type &= ~PTR_MAYBE_NULL;
b7dd2b388657d996 Amery Hung              2026-05-28  14057  		regs[BPF_REG_0].id = meta.ref_obj.id;
98c4fd2963cb2bc5 Mykyta Yatsenko         2026-01-30  14058  	} else if (is_acquire_function(func_id, meta.map.ptr)) {
308c7a0ae8859b34 Amery Hung              2026-05-28  14059  		int id = acquire_reference(env, insn_idx, 0);
0f3adc288df8ba2a Lorenz Bauer            2019-03-22  14060  
0f3adc288df8ba2a Lorenz Bauer            2019-03-22  14061  		if (id < 0)
0f3adc288df8ba2a Lorenz Bauer            2019-03-22  14062  			return id;
308c7a0ae8859b34 Amery Hung              2026-05-28  14063  
0f3adc288df8ba2a Lorenz Bauer            2019-03-22  14064  		regs[BPF_REG_0].id = id;
8eeb5c69c7298e97 Kumar Kartikeya Dwivedi 2026-12-01  14065  		bpf_pad_note_acquire(env, &regs[BPF_REG_0]);
0f3adc288df8ba2a Lorenz Bauer            2019-03-22  14066  	}
1b986589680a2a5b Martin KaFai Lau        2019-03-12  14067  
308c7a0ae8859b34 Amery Hung              2026-05-28  14068  	if (func_id == BPF_FUNC_dynptr_data)
308c7a0ae8859b34 Amery Hung              2026-05-28  14069  		regs[BPF_REG_0].parent_id = meta.dynptr.id;
b5c0a07eb2c23bfd Amery Hung              2026-05-28  14070  
5f99f312bd3bedb3 Andrii Nakryiko         2023-11-11  14071  	err = do_refine_retval_range(env, regs, fn->ret_type, func_id, &meta);
5f99f312bd3bedb3 Andrii Nakryiko         2023-11-11  14072  	if (err)
5f99f312bd3bedb3 Andrii Nakryiko         2023-11-11  14073  		return err;
849fa50662fbc8b4 Yonghong Song           2018-04-28  14074  
af4ea6e20fff383c Kumar Kartikeya Dwivedi 2026-08-15  14075  	bpf_diag_mod_end(env);
cb445a6eedb66bca Kumar Kartikeya Dwivedi 2026-12-01  14076  unwound:
98c4fd2963cb2bc5 Mykyta Yatsenko         2026-01-30  14077  	err = check_map_func_compatibility(env, meta.map.ptr, func_id);
35578d7984003097 Kaixu Xia               2015-08-06  14078  	if (err)
35578d7984003097 Kaixu Xia               2015-08-06  14079  		return err;
04fd61ab36ec065e Alexei Starovoitov      2015-05-19  14080  
fa28dcb82a38f8e3 Song Liu                2020-06-29  14081  	if ((func_id == BPF_FUNC_get_stack ||
fa28dcb82a38f8e3 Song Liu                2020-06-29  14082  	     func_id == BPF_FUNC_get_task_stack) &&
fa28dcb82a38f8e3 Song Liu                2020-06-29  14083  	    !env->prog->has_callchain_buf) {
c195651e565ae7f4 Yonghong Song           2018-04-28  14084  		const char *err_str;
c195651e565ae7f4 Yonghong Song           2018-04-28  14085  

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-12-03  9:07 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-03  9:07 [bpf-next:master 106/144] kernel/bpf/verifier.c:13748 check_helper_call() error: we previously assumed 'meta.map.ptr' could be null (see line 13691) kernel test robot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.