History

bpf: Zero queue and stack outputs on lock failure

Queue and stack pop/peek helpers accept an uninitialized output buffer because the verifier expects the helper to initialize it. The empty-map error path clears the buffer, but a failed lock acquisition returns -EBUSY without writing it. Clear the output before returning -EBUSY so BPF programs cannot observe uninitialized stack contents after a failed helper call.

Kumar Kartikeya Dwivedi committed 3 months ago

Commit 7ac6e1a1 parent 5f30ac91 file · +6 −2Browse files

Unified · Split

kernel/bpf/queue_stack_maps.c+6−2
@@ -99,8 +99,10 @@ static long __queue_map_get(struct bpf_map *map, void *value, bool delete) · 98 unmodified lines
9999 int err = 0;
100100 void *ptr;
101101
102− if (raw_res_spin_lock_irqsave(&qs->lock, flags))
102+ if (raw_res_spin_lock_irqsave(&qs->lock, flags)) {
103+ memset(value, 0, qs->map.value_size);
103104 return -EBUSY;
105+ }
104106
105107 if (queue_stack_map_is_empty(qs)) {
106108 memset(value, 0, qs->map.value_size);
@@ -130,8 +132,10 @@ static long __stack_map_get(struct bpf_map *map, void *value, bool delete) · 23 unmodified lines
130132 void *ptr;
131133 u32 index;
132134
133− if (raw_res_spin_lock_irqsave(&qs->lock, flags))
135+ if (raw_res_spin_lock_irqsave(&qs->lock, flags)) {
136+ memset(value, 0, qs->map.value_size);
134137 return -EBUSY;
138+ }
135139
136140 if (queue_stack_map_is_empty(qs)) {
137141 memset(value, 0, qs->map.value_size);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t