History

rseq: Fix using an uninitialized stack variable in rseq_exit_user_update()

There is an bug in which an uninitialized stack variable is used in rseq_exit_user_update() as reported by syzbot: BUG: KMSAN: kernel-infoleak in rseq_set_ids_get_csaddr include/linux/rseq_entry.h:502 [inline] The local variable: struct rseq_ids ids = { .cpu_id = task_cpu(t), .mm_cid = task_mm_cid(t), .node_id = cpu_to_node(ids.cpu_id), }; According to the C standard, the evaluation order of expressions in an initializer list is indeterminately sequenced. The compiler (Clang, in this KMSAN build) evaluates `cpu_to_node(ids.cpu_id)` *before* `ids.cpu_id` is initialized with `task_cpu(t)`. This is fixed by moving the assignment of ids.node_id outside the structure initialization.

Qing Wang committed 5 months ago

Commit 6d994791 parent e43ffb61 file · +3 −2Browse files

Showing the changes to include (1 of 1 file). Show all

Unified · Split

include/linux/rseq_entry.h+3−2
@@ -635,10 +635,11 @@ static __always_inline bool rseq_exit_user_update(struct pt_regs *regs, struct t · 634 unmodified lines
635 return true;635 return true;
636 }636 }
637 637
638 int cpu = task_cpu(t);
638 struct rseq_ids ids = {639 struct rseq_ids ids = {
639 .cpu_id = task_cpu(t),640 .cpu_id = cpu,
640 .mm_cid = task_mm_cid(t),641 .mm_cid = task_mm_cid(t),
641 .node_id = cpu_to_node(ids.cpu_id),642 .node_id = cpu_to_node(cpu),
642 };643 };
643 644
644 return rseq_update_usr(t, regs, &ids);645 return rseq_update_usr(t, regs, &ids);

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