Skip to contentSkip to conversation

bpf: normalize arg_track state construction

PATCH Superseded Tao Yu 4 participants 7 messages Jul 23 – Jul 27 BPF

lore
Share & tools
lore

Tao Yu

author
#0 lore raw

PATCH 1/1 bpf: normalize arg_track state construction

KMSAN reports an uninit-value bug in __arg_track_join() when liveness analysis propagates arg_track states:

  BUG: KMSAN: uninit-value in __arg_track_join

arg_track carries its state in a union:
- precise pointers use .off[] with off_cnt > 0;
- offset-imprecise pointers use frame >= 0 with off_cnt == 0;
- fully-imprecise pointers use frame == ARG_IMPRECISE with .mask.

The bug is caused by ad-hoc state downgrades and partial state construction. Some paths only updated selected fields, such as switching to offset-imprecise by writing off_cnt = 0, or building temporary arg_track values by filling fields manually. Later joins then copied and merged these values and KMSAN could observe uninitialized union content when the state was interpreted through a different union member.

Fix this by normalizing arg_track state construction:
- introduce helpers for ARG_NONE, ARG_UNVISITED, offset-imprecise, and fully-imprecise states;
- use these helpers when producing downgraded states;
- replace in-place off_cnt-only downgrades with full object assignment;
- initialize temporary resolved states through the same constructors before filling precise offsets.

This keeps arg_track state transitions explicit and ensures every state seen by join/merge code is fully initialized.

Fixes bf0c571f7feb ("bpf: introduce forward arg-tracking dataflow analysis")
Reported-by [email protected]
---
 kernel/bpf/liveness.c | 65 ++++++++++++++++++++++++++++---------------
 1 file changed, 43 insertions(+), 22 deletions(-)
kernel/bpf/liveness.c +43 -22
index 0aadfbae0acc5..58b979c17c3e4 100644
@@ -607,6 +607,31 @@ enum arg_track_state {
 	ARG_IMPRECISE	= -3,	/* lost identity; .mask is arg bitmask */
 };
 
+static struct arg_track arg_track_state(s8 frame)
+{
+	return (struct arg_track){ .frame = frame };
+}
+
+static struct arg_track arg_track_none(void)
+{
+	return arg_track_state(ARG_NONE);
+}
+
+static struct arg_track arg_track_unvisited(void)
+{
+	return arg_track_state(ARG_UNVISITED);
+}
+
+static struct arg_track arg_track_off_imprecise(s8 frame)
+{
+	return arg_track_state(frame);
+}
+
+static struct arg_track arg_track_imprecise(u16 mask)
+{
+	return (struct arg_track){ .mask = mask, .frame = ARG_IMPRECISE };
+}
+
 /* Track callee stack slots fp-8 through fp-512 (64 slots of 8 bytes each) */
 #define MAX_ARG_SPILL_SLOTS 64
 
@@ -693,8 +718,8 @@ static struct arg_track arg_single(s8 arg, s16 off)
  */
 static struct arg_track arg_merge_offsets(struct arg_track a, struct arg_track b)
 {
-	struct arg_track result = { .frame = a.frame };
-	struct arg_track imp = { .frame = a.frame };
+	struct arg_track result = arg_track_state(a.frame);
+	struct arg_track imp = arg_track_off_imprecise(a.frame);
 	int i = 0, j = 0, k = 0;
 
 	while (i < a.off_cnt && j < b.off_cnt) {
@@ -747,7 +772,7 @@ static struct arg_track arg_join_imprecise(struct arg_track a, struct arg_track
 	else if (b.frame == ARG_IMPRECISE)
 		m |= b.mask;
 
-	return (struct arg_track){ .mask = m, .frame = ARG_IMPRECISE };
+	return arg_track_imprecise(m);
 }
 
 /* Join two arg_track values at merge points */
@@ -760,7 +785,7 @@ static struct arg_track __arg_track_join(struct arg_track a, struct arg_track b)
 	if (a.frame == b.frame && a.frame >= 0) {
 		/* Both offset-imprecise: stay imprecise */
 		if (a.off_cnt == 0 || b.off_cnt == 0)
-			return (struct arg_track){ .frame = a.frame };
+			return arg_track_off_imprecise(a.frame);
 		/* Merge offset sets; falls back to off_cnt=0 if >4 */
 		return arg_merge_offsets(a, b);
 	}
@@ -837,7 +862,7 @@ static void arg_track_alu64(struct arg_track *dst, const struct arg_track *src)
 		 * rX += rY where rY is not arg derived
 		 * rX += rX
 		 */
-		dst->off_cnt = 0;
+		*dst = arg_track_off_imprecise(dst->frame);
 		return;
 	}
 	if (src->frame >= 0 && dst->frame == ARG_NONE) {
@@ -845,8 +870,7 @@ static void arg_track_alu64(struct arg_track *dst, const struct arg_track *src)
 		 * rX += rY where rX is not arg derived
 		 * rY identity leaks into rX
 		 */
-		dst->off_cnt = 0;
-		dst->frame = src->frame;
+		*dst = arg_track_off_imprecise(src->frame);
 		return;
 	}
 
@@ -875,7 +899,7 @@ static void arg_padd(struct arg_track *at, s64 delta)
 		s16 new_off;
 
 		if (arg_add(at->off[i], delta, &new_off)) {
-			at->off_cnt = 0;
+			*at = arg_track_off_imprecise(at->frame);
 			return;
 		}
 		at->off[i] = new_off;
@@ -901,11 +925,8 @@ static struct arg_track fill_from_stack(struct bpf_insn *insn,
 					struct arg_track *at_stack_out,
 					int depth)
 {
-	struct arg_track imp = {
-		.mask = (1u << (depth + 1)) - 1,
-		.frame = ARG_IMPRECISE
-	};
-	struct arg_track result = { .frame = ARG_NONE };
+	struct arg_track imp = arg_track_imprecise((1u << (depth + 1)) - 1);
+	struct arg_track result = arg_track_state(ARG_NONE);
 	int cnt, i;
 
 	if (reg == BPF_REG_FP) {
@@ -940,7 +961,7 @@ static void spill_to_stack(struct bpf_insn *insn, struct arg_track *at_out,
 			   int reg, struct arg_track *at_stack_out,
 			   struct arg_track *val, u32 sz)
 {
-	struct arg_track none = { .frame = ARG_NONE };
+	struct arg_track none = arg_track_none();
 	struct arg_track new_val = sz == 8 ? *val : none;
 	int cnt, i;
 
@@ -979,7 +1000,7 @@ static void spill_to_stack(struct bpf_insn *insn, struct arg_track *at_out,
  */
 static void clear_overlapping_stack_slots(struct arg_track *at_stack, s16 off, u32 sz, int cnt)
 {
-	struct arg_track none = { .frame = ARG_NONE };
+	struct arg_track none = arg_track_none();
 
 	if (cnt == 0) {
 		for (int i = 0; i < MAX_ARG_SPILL_SLOTS; i++)
@@ -1103,7 +1124,7 @@ static void arg_track_xfer(struct bpf_verifier_env *env, struct bpf_insn *insn,
 	u8 code = BPF_OP(insn->code);
 	struct arg_track *dst = &at_out[insn->dst_reg];
 	struct arg_track *src = &at_out[insn->src_reg];
-	struct arg_track none = { .frame = ARG_NONE };
+	struct arg_track none = arg_track_none();
 	int r, slot;
 
 	/* Handle stack arg stores and loads. */
@@ -1128,7 +1149,7 @@ static void arg_track_xfer(struct bpf_verifier_env *env, struct bpf_insn *insn,
 				arg_padd(dst, -(s64)insn->imm);
 			else
 				/* Any other 64-bit alu on the pointer makes it imprecise */
-				dst->off_cnt = 0;
+				*dst = arg_track_off_imprecise(dst->frame);
 		} /* else if dst->frame is imprecise it stays so */
 	} else if (class == BPF_ALU64 && BPF_SRC(insn->code) == BPF_X) {
 		if (code == BPF_MOV) {
@@ -1379,11 +1400,11 @@ static int record_load_store_access(struct bpf_verifier_env *env,
 
 	/* Resolve offsets: fold insn->off into arg_track */
 	if (ptr->off_cnt > 0) {
+		resolved = arg_track_state(ptr->frame);
 		resolved.off_cnt = ptr->off_cnt;
-		resolved.frame = ptr->frame;
 		for (oi = 0; oi < ptr->off_cnt; oi++) {
 			if (arg_add(ptr->off[oi], insn->off, &resolved.off[oi])) {
-				resolved.off_cnt = 0;
+				resolved = arg_track_off_imprecise(ptr->frame);
 				break;
 			}
 		}
@@ -1630,8 +1651,8 @@ static int compute_subprog_args(struct bpf_verifier_env *env,
 	struct arg_track (*at_stack_in)[MAX_ARG_SPILL_SLOTS] = NULL;
 	struct arg_track *at_stack_out = NULL;
 	struct arg_track at_stack_arg_entry[MAX_STACK_ARG_SLOTS];
-	struct arg_track unvisited = { .frame = ARG_UNVISITED };
-	struct arg_track none = { .frame = ARG_NONE };
+	struct arg_track unvisited = arg_track_unvisited();
+	struct arg_track none = arg_track_none();
 	bool changed;
 	int i, p, r, err = -ENOMEM;
 
@@ -1895,7 +1916,7 @@ static int analyze_subprog(struct bpf_verifier_env *env,
 	for (int p = po_start; p < po_end; p++) {
 		int idx = env->cfg.insn_postorder[p];
 		struct arg_track callee_args[MAX_AT_TRACK_REGS] = {};
-		struct arg_track none = { .frame = ARG_NONE };
+		struct arg_track none = arg_track_none();
 		struct bpf_insn *insn = &insns[idx];
 		struct func_instance *callee_instance;
 		int callee, target;
Signature · 1 line
2.34.1
#1 lore raw
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] The helper `arg_track_imprecise()` leaves union bytes uninitialized, failing to fully resolve…

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] The helper arg_track_imprecise() leaves union bytes uninitialized, failing to fully resolve the KMSAN uninit-value bug. --

--- Patch [1]: [PATCH] bpf: normalize arg_track state construction --- commit 66a3cf2cd9455714944be22e6ff4f7ab5a037e76
Author: Tao Yu <[email protected]>

bpf: normalize arg_track state construction

This commit introduces explicit helper functions to normalize arg_track state construction and address a KMSAN uninitialized-value bug during liveness analysis.

Quoted 4 lines
kernel/bpf/liveness.c +0 -0
index 0aadfbae0acc5..58b979c17c3e4 100644

[ ... ]

kernel/bpf/liveness.c enum arg_track_state { · line 633

Quoted 4 lines
kernel/bpf/liveness.c +4 -0
+static struct arg_track arg_track_imprecise(u16 mask)
+{
+	return (struct arg_track){ .mask = mask, .frame = ARG_IMPRECISE };
+}

[Severity: Medium]
Does this compound literal leave the remaining 6 bytes of the anonymous union uninitialized?

Since the union contains both an 8-byte offset array and a 2-byte mask, explicitly initializing only the mask member leaves the remaining bytes of the union unspecified.

When this state is returned, such as from fill_from_stack(), and propagated via arg_track_join() during liveness analysis, won't KMSAN continue to trigger warnings when the structure is copied by value?

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#2 lore raw
In reply to Tao Yu
The commit message states:

kernel/bpf/liveness.c

Quoted 4 lines
kernel/bpf/liveness.c +0 -0
index 0aadfbae0acc..58b979c17c3e 100644

[ ... ]

The commit message states:

Quoted 6 lines

The bug is caused by ad-hoc state downgrades and partial state construction. Some paths only updated selected fields, such as switching to offset-imprecise by writing off_cnt = 0, or building temporary arg_track values by filling fields manually. Later joins then copied and merged these values and KMSAN could observe uninitialized union content when the state was interpreted through a different union member.

Can you clarify the root cause mechanism? While in-place off_cnt=0 downgrades exist in the parent code at arg_track_alu64, arg_padd, arg_track_xfer, and record_load_store_access, each operates on arg_track values whose union already holds defined data:

- at_in[] and at_stack_in[] are fully initialized to 'unvisited' via compound literal { .frame = ARG_UNVISITED } which zero-initializes the union

- at_out[] is memcpy'd from at_in[i]

- Every explicit constructor ({ .frame = X }, arg_single with '= {}', arg_merge_offsets, arg_join_imprecise) zero-initializes or fully writes the union

A concrete code path where an in-place off_cnt=0 downgrade leaves the union with undefined bytes that subsequently reach the crash site 'm |= a.mask' in __arg_track_join could not be verified. The .mask is only read when frame==ARG_IMPRECISE, and every producer of ARG_IMPRECISE explicitly sets .mask.

So while the described in-place edit code paths exist, their causal link to the reported crash remains unproven.

The commit message also states:

Quoted 4 lines

...or building temporary arg_track values by filling fields manually. Later joins then copied and merged these values and KMSAN could observe uninitialized union content when the state was interpreted through a different union member.

The clearest manually-filled temporary is 'resolved' in record_load_store_access. The parent code sets resolved.off_cnt, resolved.frame, and resolved.off[0..off_cnt-1], leaving resolved.off[off_cnt..3] genuinely uninitialized. This is a real latent uninit. However:

- 'resolved' is a function-local that is only passed to record_stack_access() and record_imprecise(), never to __arg_track_join()

- record_stack_access() reads only off[0..off_cnt-1]

- resolved.frame is always >= 0 in that block (guarded by ptr->off_cnt > 0), so the ARG_IMPRECISE/.mask branch is never taken for it

Therefore 'resolved' cannot be the value that reaches the reported crash 'm |= a.mask'. The causal story ('later joins then copied and merged these values') is not demonstrated for any manually-built temporary reaching __arg_track_join with an undefined .mask.

Could the commit message be more precise about the proven initialization issue the patch addresses, rather than an unverified copy-of-uninitialized- union narrative?

The exact mechanism producing the reported uninit read may be a clang-21 by-value struct-copy or union-shadow codegen detail rather than the described field-update logic. The fix likely eliminates the KMSAN warning by zeroing unions in the whole-object assignments (a defensive normalization that quiets the tool), which is a valid improvement for code robustness.

---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md

CI run summary: https://github.com/kernel-patches/bpf/actions/runs/29984640227

maintainer
#3 lore raw
In reply to Tao Yu
Quoted 25 lines · Tao Yu

KMSAN reports an uninit-value bug in __arg_track_join() when liveness analysis propagates arg_track states:

  BUG: KMSAN: uninit-value in __arg_track_join

arg_track carries its state in a union:
- precise pointers use .off[] with off_cnt > 0;
- offset-imprecise pointers use frame >= 0 with off_cnt == 0;
- fully-imprecise pointers use frame == ARG_IMPRECISE with .mask.

The bug is caused by ad-hoc state downgrades and partial state construction. Some paths only updated selected fields, such as switching to offset-imprecise by writing off_cnt = 0, or building temporary arg_track values by filling fields manually. Later joins then copied and merged these values and KMSAN could observe uninitialized union content when the state was interpreted through a different union member.

Fix this by normalizing arg_track state construction:
- introduce helpers for ARG_NONE, ARG_UNVISITED, offset-imprecise, and fully-imprecise states;
- use these helpers when producing downgraded states;
- replace in-place off_cnt-only downgrades with full object assignment;
- initialize temporary resolved states through the same constructors before filling precise offsets.

Quoted 7 lines

This keeps arg_track state transitions explicit and ensures every state seen by join/merge code is fully initialized.

Fixes bf0c571f7feb ("bpf: introduce forward arg-tracking dataflow analysis")
Reported-by [email protected]

---

Hi Yu,

I think the changes themselves are fine, but I second the findings by the bot. Could you please elaborate which assignments trigger KMSAN report? I tried running with KMSAN enabled, but the boot appears to take forever.

Thanks,
Eduard

...

author
#4 lore raw

Hi Eduard,

Thanks for pointing this out.

After re-checking the old code, I don't think I can honestly attribute the KMSAN report to one specific assignment.

The old code did have a few patterns that are undesirable for a tagged-union state machine:
- in-place downgrades such as off_cnt = 0;
- manually assembled temporaries such as resolved in record_load_store_access().

However, I could not prove a concrete source-to-sink path from one of those assignments to the m |= a.mask read in __arg_track_join().

In particular:
- the off_cnt = 0 downgrades operate on states that are still interpreted as frame-based states in source-level logic, so their causal link to the later .mask read is not proven;
- the local resolved temporary is indeed only partially materialized, but it does not flow into __arg_track_join().

So I think the code change is still reasonable as a state-construction normalization for arg_track, but the original changelog overstated the proven root-cause mechanism.

I've respun the patch as v2, reworded the commit message to describe this as normalizing construction of the tagged-union state, and added the Reported-by tag requested by syzbot.

Thanks,
Tao

maintainer
#5 lore raw
Quoted 23 lines · Tao Yu

Hi Eduard,

Thanks for pointing this out.

After re-checking the old code, I don't think I can honestly attribute the KMSAN report to one specific assignment.

The old code did have a few patterns that are undesirable for a tagged-union state machine:
- in-place downgrades such as off_cnt = 0;
- manually assembled temporaries such as resolved in record_load_store_access().

However, I could not prove a concrete source-to-sink path from one of those assignments to the m |= a.mask read in __arg_track_join().

In particular:
- the off_cnt = 0 downgrades operate on states that are still interpreted as frame-based states in source-level logic, so their causal link to the later .mask read is not proven;
- the local resolved temporary is indeed only partially materialized, but it does not flow into __arg_track_join().

Quoted 7 lines

So I think the code change is still reasonable as a state-construction normalization for arg_track, but the original changelog overstated the proven root-cause mechanism.

I've respun the patch as v2, reworded the commit message to describe this as normalizing construction of the tagged-union state, and added the Reported-by tag requested by syzbot.

Hi Tao,

Sounds good to me, thank you!

author
#6 lore raw

PATCH v2 1/1 bpf: normalize arg_track state construction

In reply to Tao Yu

KMSAN reported an uninitialized read from a.mask in __arg_track_join() during liveness analysis.

=====================================================

BUG: KMSAN: uninit-value in __arg_track_join+0x15a/0x810 kernel/bpf/liveness.c:743
 __arg_track_join+0x15a/0x810 kernel/bpf/liveness.c:743
 arg_track_join+0x186/0x870 kernel/bpf/liveness.c:784
 compute_subprog_args kernel/bpf/liveness.c:1623 [inline]
 analyze_subprog+0x3eb0/0xff30 kernel/bpf/liveness.c:1799
 bpf_compute_subprog_arg_access+0x3ee/0x2370 kernel/bpf/liveness.c:1937
 bpf_compute_live_registers+0xfdb/0x3090 kernel/bpf/liveness.c:2149
 bpf_check+0x5bcb/0x9360 kernel/bpf/verifier.c:20065
 bpf_prog_load+0x28d2/0x2d00 kernel/bpf/syscall.c:3082
 __sys_bpf+0x8e0/0xee0 kernel/bpf/syscall.c:6274
 __do_sys_bpf kernel/bpf/syscall.c:6387 [inline]
 __se_sys_bpf kernel/bpf/syscall.c:6385 [inline]
 __ia32_sys_bpf+0xa4/0xf0 kernel/bpf/syscall.c:6385
 ia32_sys_call+0x33e7/0x4360 arch/x86/include/generated/asm/syscalls_32.h:358
 do_syscall_32_irqs_on arch/x86/entry/syscall_32.c:83 [inline]
 __do_fast_syscall_32+0x195/0x470 arch/x86/entry/syscall_32.c:307
 do_fast_syscall_32+0x37/0x80 arch/x86/entry/syscall_32.c:332
 do_SYSENTER_32+0x1f/0x30 arch/x86/entry/syscall_32.c:370
 entry_SYSENTER_compat_after_hwframe+0x84/0x8e

Local variable old created at:

 arg_track_join+0x86/0x870 kernel/bpf/liveness.c:783
 compute_subprog_args kernel/bpf/liveness.c:1623 [inline]
 analyze_subprog+0x3eb0/0xff30 kernel/bpf/liveness.c:1799

CPU: 0 UID: 0 PID: 18676 Comm: syz.0.5880 Tainted: G        W           syzkaller #0 PREEMPT(lazy)
Tainted: [W]=WARN
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 04/18/2026
=====================================================

arg_track is a tagged-union state machine, but a number of transitions were previously expressed by mutating selected fields or by manually assembling temporary values. This makes the state encoding less explicit and weakens the invariant that each logical arg_track state is materialized as a complete object.

Normalize arg_track state construction through explicit helpers for the special states used by the analysis: ARG_NONE, ARG_UNVISITED, offset-imprecise, and ARG_IMPRECISE. Use these helpers consistently instead of open-coded partial updates and ad-hoc temporaries.

Besides making the state transitions easier to reason about, this makes the state representation explicit at each transition and avoids carrying partially materialized union-backed state through by-value copies and joins, matching the class of issue reported by KMSAN.

Fixes bf0c571f7feb ("bpf: introduce forward arg-tracking dataflow analysis")
Reported-by [email protected]
---
 kernel/bpf/liveness.c | 65 ++++++++++++++++++++++++++++---------------
 1 file changed, 43 insertions(+), 22 deletions(-)
kernel/bpf/liveness.c +43 -22
index 0aadfbae0acc5..58b979c17c3e4 100644
@@ -607,6 +607,31 @@ enum arg_track_state {
 	ARG_IMPRECISE	= -3,	/* lost identity; .mask is arg bitmask */
 };
 
+static struct arg_track arg_track_state(s8 frame)
+{
+	return (struct arg_track){ .frame = frame };
+}
+
+static struct arg_track arg_track_none(void)
+{
+	return arg_track_state(ARG_NONE);
+}
+
+static struct arg_track arg_track_unvisited(void)
+{
+	return arg_track_state(ARG_UNVISITED);
+}
+
+static struct arg_track arg_track_off_imprecise(s8 frame)
+{
+	return arg_track_state(frame);
+}
+
+static struct arg_track arg_track_imprecise(u16 mask)
+{
+	return (struct arg_track){ .mask = mask, .frame = ARG_IMPRECISE };
+}
+
 /* Track callee stack slots fp-8 through fp-512 (64 slots of 8 bytes each) */
 #define MAX_ARG_SPILL_SLOTS 64
 
@@ -693,8 +718,8 @@ static struct arg_track arg_single(s8 arg, s16 off)
  */
 static struct arg_track arg_merge_offsets(struct arg_track a, struct arg_track b)
 {
-	struct arg_track result = { .frame = a.frame };
-	struct arg_track imp = { .frame = a.frame };
+	struct arg_track result = arg_track_state(a.frame);
+	struct arg_track imp = arg_track_off_imprecise(a.frame);
 	int i = 0, j = 0, k = 0;
 
 	while (i < a.off_cnt && j < b.off_cnt) {
@@ -747,7 +772,7 @@ static struct arg_track arg_join_imprecise(struct arg_track a, struct arg_track
 	else if (b.frame == ARG_IMPRECISE)
 		m |= b.mask;
 
-	return (struct arg_track){ .mask = m, .frame = ARG_IMPRECISE };
+	return arg_track_imprecise(m);
 }
 
 /* Join two arg_track values at merge points */
@@ -760,7 +785,7 @@ static struct arg_track __arg_track_join(struct arg_track a, struct arg_track b)
 	if (a.frame == b.frame && a.frame >= 0) {
 		/* Both offset-imprecise: stay imprecise */
 		if (a.off_cnt == 0 || b.off_cnt == 0)
-			return (struct arg_track){ .frame = a.frame };
+			return arg_track_off_imprecise(a.frame);
 		/* Merge offset sets; falls back to off_cnt=0 if >4 */
 		return arg_merge_offsets(a, b);
 	}
@@ -837,7 +862,7 @@ static void arg_track_alu64(struct arg_track *dst, const struct arg_track *src)
 		 * rX += rY where rY is not arg derived
 		 * rX += rX
 		 */
-		dst->off_cnt = 0;
+		*dst = arg_track_off_imprecise(dst->frame);
 		return;
 	}
 	if (src->frame >= 0 && dst->frame == ARG_NONE) {
@@ -845,8 +870,7 @@ static void arg_track_alu64(struct arg_track *dst, const struct arg_track *src)
 		 * rX += rY where rX is not arg derived
 		 * rY identity leaks into rX
 		 */
-		dst->off_cnt = 0;
-		dst->frame = src->frame;
+		*dst = arg_track_off_imprecise(src->frame);
 		return;
 	}
 
@@ -875,7 +899,7 @@ static void arg_padd(struct arg_track *at, s64 delta)
 		s16 new_off;
 
 		if (arg_add(at->off[i], delta, &new_off)) {
-			at->off_cnt = 0;
+			*at = arg_track_off_imprecise(at->frame);
 			return;
 		}
 		at->off[i] = new_off;
@@ -901,11 +925,8 @@ static struct arg_track fill_from_stack(struct bpf_insn *insn,
 					struct arg_track *at_stack_out,
 					int depth)
 {
-	struct arg_track imp = {
-		.mask = (1u << (depth + 1)) - 1,
-		.frame = ARG_IMPRECISE
-	};
-	struct arg_track result = { .frame = ARG_NONE };
+	struct arg_track imp = arg_track_imprecise((1u << (depth + 1)) - 1);
+	struct arg_track result = arg_track_state(ARG_NONE);
 	int cnt, i;
 
 	if (reg == BPF_REG_FP) {
@@ -940,7 +961,7 @@ static void spill_to_stack(struct bpf_insn *insn, struct arg_track *at_out,
 			   int reg, struct arg_track *at_stack_out,
 			   struct arg_track *val, u32 sz)
 {
-	struct arg_track none = { .frame = ARG_NONE };
+	struct arg_track none = arg_track_none();
 	struct arg_track new_val = sz == 8 ? *val : none;
 	int cnt, i;
 
@@ -979,7 +1000,7 @@ static void spill_to_stack(struct bpf_insn *insn, struct arg_track *at_out,
  */
 static void clear_overlapping_stack_slots(struct arg_track *at_stack, s16 off, u32 sz, int cnt)
 {
-	struct arg_track none = { .frame = ARG_NONE };
+	struct arg_track none = arg_track_none();
 
 	if (cnt == 0) {
 		for (int i = 0; i < MAX_ARG_SPILL_SLOTS; i++)
@@ -1103,7 +1124,7 @@ static void arg_track_xfer(struct bpf_verifier_env *env, struct bpf_insn *insn,
 	u8 code = BPF_OP(insn->code);
 	struct arg_track *dst = &at_out[insn->dst_reg];
 	struct arg_track *src = &at_out[insn->src_reg];
-	struct arg_track none = { .frame = ARG_NONE };
+	struct arg_track none = arg_track_none();
 	int r, slot;
 
 	/* Handle stack arg stores and loads. */
@@ -1128,7 +1149,7 @@ static void arg_track_xfer(struct bpf_verifier_env *env, struct bpf_insn *insn,
 				arg_padd(dst, -(s64)insn->imm);
 			else
 				/* Any other 64-bit alu on the pointer makes it imprecise */
-				dst->off_cnt = 0;
+				*dst = arg_track_off_imprecise(dst->frame);
 		} /* else if dst->frame is imprecise it stays so */
 	} else if (class == BPF_ALU64 && BPF_SRC(insn->code) == BPF_X) {
 		if (code == BPF_MOV) {
@@ -1379,11 +1400,11 @@ static int record_load_store_access(struct bpf_verifier_env *env,
 
 	/* Resolve offsets: fold insn->off into arg_track */
 	if (ptr->off_cnt > 0) {
+		resolved = arg_track_state(ptr->frame);
 		resolved.off_cnt = ptr->off_cnt;
-		resolved.frame = ptr->frame;
 		for (oi = 0; oi < ptr->off_cnt; oi++) {
 			if (arg_add(ptr->off[oi], insn->off, &resolved.off[oi])) {
-				resolved.off_cnt = 0;
+				resolved = arg_track_off_imprecise(ptr->frame);
 				break;
 			}
 		}
@@ -1630,8 +1651,8 @@ static int compute_subprog_args(struct bpf_verifier_env *env,
 	struct arg_track (*at_stack_in)[MAX_ARG_SPILL_SLOTS] = NULL;
 	struct arg_track *at_stack_out = NULL;
 	struct arg_track at_stack_arg_entry[MAX_STACK_ARG_SLOTS];
-	struct arg_track unvisited = { .frame = ARG_UNVISITED };
-	struct arg_track none = { .frame = ARG_NONE };
+	struct arg_track unvisited = arg_track_unvisited();
+	struct arg_track none = arg_track_none();
 	bool changed;
 	int i, p, r, err = -ENOMEM;
 
@@ -1895,7 +1916,7 @@ static int analyze_subprog(struct bpf_verifier_env *env,
 	for (int p = po_start; p < po_end; p++) {
 		int idx = env->cfg.insn_postorder[p];
 		struct arg_track callee_args[MAX_AT_TRACK_REGS] = {};
-		struct arg_track none = { .frame = ARG_NONE };
+		struct arg_track none = arg_track_none();
 		struct bpf_insn *insn = &insns[idx];
 		struct func_instance *callee_instance;
 		int callee, target;
Signature · 1 line
2.34.1