Skip to contentSkip to conversation

libbpf: Support CO-RE relocation of tracing program arguments

PATCH kernel test robot 1 participant 1 message Nov 27

lore
Share & tools
lore

kernel test robot

author build bot
#0 lore raw

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: [email protected]
CC: [email protected]
In-Reply-To: <[email protected]>
References: <[email protected]>
TO: Alan Maguire <[email protected]>
TO: [email protected]
TO: [email protected]
TO: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: Alan Maguire <[email protected]>

Hi Alan,

kernel test robot noticed the following build warnings:

[auto build test WARNING on bpf-next/master]

url:    https://github.com/intel-lab-lkp/linux/commits/Alan-Maguire/libbpf-Support-CO-RE-relocation-of-tracing-program-arguments/20261123-223221
base:   https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git master
patch link:    https://lore.kernel.org/r/20261123223227.745345-2-almagui%40kernel.org
patch subject: [PATCH bpf-next 1/7] libbpf: Support CO-RE relocation of tracing program arguments

:::::: branch date: 4 days ago
:::::: commit date: 4 days ago
config: arm-randconfig-2200-20261126 (https://download.01.org/0day-ci/archive/20261127/[email protected]/config)
compiler: arm-linux-gnueabi-gcc (GCC) 8.5.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 <[email protected]>
| Reported-by: Dan Carpenter <[email protected]>
| Closes: https://lore.kernel.org/r/[email protected]/

smatch warnings:
kernel/bpf/../../tools/lib/bpf/relo_core.c:1337 bpf_core_calc_relo() error: we previously assumed 'targ_spec' could be null (see line 1322)

vim +/targ_spec +1337 kernel/bpf/../../tools/lib/bpf/relo_core.c

2a6fa26be8e26a Alan Maguire       2026-11-23  1292  
b0588390dbcedc Alexei Starovoitov 2021-07-20  1293  static int bpf_core_calc_relo(const char *prog_name,
b0588390dbcedc Alexei Starovoitov 2021-07-20  1294  			      const struct bpf_core_relo *relo,
b0588390dbcedc Alexei Starovoitov 2021-07-20  1295  			      int relo_idx,
b0588390dbcedc Alexei Starovoitov 2021-07-20  1296  			      const struct bpf_core_spec *local_spec,
b0588390dbcedc Alexei Starovoitov 2021-07-20  1297  			      const struct bpf_core_spec *targ_spec,
b0588390dbcedc Alexei Starovoitov 2021-07-20  1298  			      struct bpf_core_relo_res *res)
b0588390dbcedc Alexei Starovoitov 2021-07-20  1299  {
b0588390dbcedc Alexei Starovoitov 2021-07-20  1300  	int err = -EOPNOTSUPP;
b0588390dbcedc Alexei Starovoitov 2021-07-20  1301  
b0588390dbcedc Alexei Starovoitov 2021-07-20  1302  	res->orig_val = 0;
b0588390dbcedc Alexei Starovoitov 2021-07-20  1303  	res->new_val = 0;
b0588390dbcedc Alexei Starovoitov 2021-07-20  1304  	res->poison = false;
b0588390dbcedc Alexei Starovoitov 2021-07-20  1305  	res->validate = true;
b0588390dbcedc Alexei Starovoitov 2021-07-20  1306  	res->fail_memsz_adjust = false;
b0588390dbcedc Alexei Starovoitov 2021-07-20  1307  	res->orig_sz = res->new_sz = 0;
b0588390dbcedc Alexei Starovoitov 2021-07-20  1308  	res->orig_type_id = res->new_type_id = 0;
2a6fa26be8e26a Alan Maguire       2026-11-23  1309  	res->widen_func_arg = false;
2a6fa26be8e26a Alan Maguire       2026-11-23  1310  	res->func_arg_signed = false;
2a6fa26be8e26a Alan Maguire       2026-11-23  1311  	res->func_arg_slot_off = 0;
b0588390dbcedc Alexei Starovoitov 2021-07-20  1312  
b0588390dbcedc Alexei Starovoitov 2021-07-20  1313  	if (core_relo_is_field_based(relo->kind)) {
b0588390dbcedc Alexei Starovoitov 2021-07-20  1314  		err = bpf_core_calc_field_relo(prog_name, relo, local_spec,
b0588390dbcedc Alexei Starovoitov 2021-07-20  1315  					       &res->orig_val, &res->orig_sz,
b0588390dbcedc Alexei Starovoitov 2021-07-20  1316  					       &res->orig_type_id, &res->validate);
b0588390dbcedc Alexei Starovoitov 2021-07-20  1317  		err = err ?: bpf_core_calc_field_relo(prog_name, relo, targ_spec,
b0588390dbcedc Alexei Starovoitov 2021-07-20  1318  						      &res->new_val, &res->new_sz,
b0588390dbcedc Alexei Starovoitov 2021-07-20  1319  						      &res->new_type_id, NULL);
b0588390dbcedc Alexei Starovoitov 2021-07-20  1320  		if (err)
b0588390dbcedc Alexei Starovoitov 2021-07-20  1321  			goto done;
2a6fa26be8e26a Alan Maguire       2026-11-23 @1322  		if (relo->kind == BPF_CORE_FIELD_BYTE_OFFSET && targ_spec &&
2a6fa26be8e26a Alan Maguire       2026-11-23  1323  		    bpf_core_is_be_small_func_arg(targ_spec, &res->func_arg_signed)) {
2a6fa26be8e26a Alan Maguire       2026-11-23  1324  			/* context slots are 8-byte aligned */
2a6fa26be8e26a Alan Maguire       2026-11-23  1325  			res->widen_func_arg = true;
2a6fa26be8e26a Alan Maguire       2026-11-23  1326  			res->func_arg_slot_off = res->new_val & ~7ULL;
2a6fa26be8e26a Alan Maguire       2026-11-23  1327  		}
b0588390dbcedc Alexei Starovoitov 2021-07-20  1328  		/* Validate if it's safe to adjust load/store memory size.
b0588390dbcedc Alexei Starovoitov 2021-07-20  1329  		 * Adjustments are performed only if original and new memory
b0588390dbcedc Alexei Starovoitov 2021-07-20  1330  		 * sizes differ.
b0588390dbcedc Alexei Starovoitov 2021-07-20  1331  		 */
b0588390dbcedc Alexei Starovoitov 2021-07-20  1332  		res->fail_memsz_adjust = false;
b0588390dbcedc Alexei Starovoitov 2021-07-20  1333  		if (res->orig_sz != res->new_sz) {
b0588390dbcedc Alexei Starovoitov 2021-07-20  1334  			const struct btf_type *orig_t, *new_t;
b0588390dbcedc Alexei Starovoitov 2021-07-20  1335  
74753e1462e773 Alexei Starovoitov 2021-12-01  1336  			orig_t = btf_type_by_id(local_spec->btf, res->orig_type_id);
74753e1462e773 Alexei Starovoitov 2021-12-01 @1337  			new_t = btf_type_by_id(targ_spec->btf, res->new_type_id);
b0588390dbcedc Alexei Starovoitov 2021-07-20  1338  
b0588390dbcedc Alexei Starovoitov 2021-07-20  1339  			/* There are two use cases in which it's safe to
b0588390dbcedc Alexei Starovoitov 2021-07-20  1340  			 * adjust load/store's mem size:
b0588390dbcedc Alexei Starovoitov 2021-07-20  1341  			 *   - reading a 32-bit kernel pointer, while on BPF
b0588390dbcedc Alexei Starovoitov 2021-07-20  1342  			 *   size pointers are always 64-bit; in this case
b0588390dbcedc Alexei Starovoitov 2021-07-20  1343  			 *   it's safe to "downsize" instruction size due to
b0588390dbcedc Alexei Starovoitov 2021-07-20  1344  			 *   pointer being treated as unsigned integer with
b0588390dbcedc Alexei Starovoitov 2021-07-20  1345  			 *   zero-extended upper 32-bits;
b0588390dbcedc Alexei Starovoitov 2021-07-20  1346  			 *   - reading unsigned integers, again due to
b0588390dbcedc Alexei Starovoitov 2021-07-20  1347  			 *   zero-extension is preserving the value correctly.
b0588390dbcedc Alexei Starovoitov 2021-07-20  1348  			 *
b0588390dbcedc Alexei Starovoitov 2021-07-20  1349  			 * In all other cases it's incorrect to attempt to
b0588390dbcedc Alexei Starovoitov 2021-07-20  1350  			 * load/store field because read value will be
b0588390dbcedc Alexei Starovoitov 2021-07-20  1351  			 * incorrect, so we poison relocated instruction.
b0588390dbcedc Alexei Starovoitov 2021-07-20  1352  			 */
b0588390dbcedc Alexei Starovoitov 2021-07-20  1353  			if (btf_is_ptr(orig_t) && btf_is_ptr(new_t))
b0588390dbcedc Alexei Starovoitov 2021-07-20  1354  				goto done;
b0588390dbcedc Alexei Starovoitov 2021-07-20  1355  			if (btf_is_int(orig_t) && btf_is_int(new_t) &&
b0588390dbcedc Alexei Starovoitov 2021-07-20  1356  			    btf_int_encoding(orig_t) != BTF_INT_SIGNED &&
b0588390dbcedc Alexei Starovoitov 2021-07-20  1357  			    btf_int_encoding(new_t) != BTF_INT_SIGNED)
b0588390dbcedc Alexei Starovoitov 2021-07-20  1358  				goto done;
b0588390dbcedc Alexei Starovoitov 2021-07-20  1359  
b0588390dbcedc Alexei Starovoitov 2021-07-20  1360  			/* mark as invalid mem size adjustment, but this will
b0588390dbcedc Alexei Starovoitov 2021-07-20  1361  			 * only be checked for LDX/STX/ST insns
b0588390dbcedc Alexei Starovoitov 2021-07-20  1362  			 */
b0588390dbcedc Alexei Starovoitov 2021-07-20  1363  			res->fail_memsz_adjust = true;
b0588390dbcedc Alexei Starovoitov 2021-07-20  1364  		}
b0588390dbcedc Alexei Starovoitov 2021-07-20  1365  	} else if (core_relo_is_type_based(relo->kind)) {
4b443bc1785f28 Andrii Nakryiko    2021-12-12  1366  		err = bpf_core_calc_type_relo(relo, local_spec, &res->orig_val, &res->validate);
4b443bc1785f28 Andrii Nakryiko    2021-12-12  1367  		err = err ?: bpf_core_calc_type_relo(relo, targ_spec, &res->new_val, NULL);
b0588390dbcedc Alexei Starovoitov 2021-07-20  1368  	} else if (core_relo_is_enumval_based(relo->kind)) {
b0588390dbcedc Alexei Starovoitov 2021-07-20  1369  		err = bpf_core_calc_enumval_relo(relo, local_spec, &res->orig_val);
b0588390dbcedc Alexei Starovoitov 2021-07-20  1370  		err = err ?: bpf_core_calc_enumval_relo(relo, targ_spec, &res->new_val);
b0588390dbcedc Alexei Starovoitov 2021-07-20  1371  	}
b0588390dbcedc Alexei Starovoitov 2021-07-20  1372  
b0588390dbcedc Alexei Starovoitov 2021-07-20  1373  done:
b0588390dbcedc Alexei Starovoitov 2021-07-20  1374  	if (err == -EUCLEAN) {
b0588390dbcedc Alexei Starovoitov 2021-07-20  1375  		/* EUCLEAN is used to signal instruction poisoning request */
b0588390dbcedc Alexei Starovoitov 2021-07-20  1376  		res->poison = true;
b0588390dbcedc Alexei Starovoitov 2021-07-20  1377  		err = 0;
b0588390dbcedc Alexei Starovoitov 2021-07-20  1378  	} else if (err == -EOPNOTSUPP) {
b0588390dbcedc Alexei Starovoitov 2021-07-20  1379  		/* EOPNOTSUPP means unknown/unsupported relocation */
df3153758ddba5 Andrii Nakryiko    2026-06-24  1380  		pr_warn("prog '%s': relo #%d: unrecognized CO-RE relocation %s (%u) at insn #%u\n",
b0588390dbcedc Alexei Starovoitov 2021-07-20  1381  			prog_name, relo_idx, core_relo_kind_str(relo->kind),
b0588390dbcedc Alexei Starovoitov 2021-07-20  1382  			relo->kind, relo->insn_off / 8);
b0588390dbcedc Alexei Starovoitov 2021-07-20  1383  	}
b0588390dbcedc Alexei Starovoitov 2021-07-20  1384  
b0588390dbcedc Alexei Starovoitov 2021-07-20  1385  	return err;
b0588390dbcedc Alexei Starovoitov 2021-07-20  1386  }
b0588390dbcedc Alexei Starovoitov 2021-07-20  1387  
Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki