Skip to content

Commit dac5e62

Browse files
hartkoppmarckleinebudde
authored andcommitted
can: bcm: add missing rcu read protection for procfs content
When the procfs content is generated for a bcm_op which is in the process to be removed the procfs output might show unreliable data (UAF). As the removal of bcm_op's is already implemented with rcu handling this patch adds the missing rcu_read_lock() and makes sure the list entries are properly removed under rcu protection. Fixes: f1b4e32 ("can: bcm: use call_rcu() instead of costly synchronize_rcu()") Reported-by: Anderson Nascimento <[email protected]> Suggested-by: Anderson Nascimento <[email protected]> Tested-by: Anderson Nascimento <[email protected]> Signed-off-by: Oliver Hartkopp <[email protected]> Link: https://patch.msgid.link/[email protected] Cc: [email protected] # >= 5.4 Signed-off-by: Marc Kleine-Budde <[email protected]>
1 parent c2aba69 commit dac5e62

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

net/can/bcm.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,9 @@ static int bcm_proc_show(struct seq_file *m, void *v)
219219
seq_printf(m, " / bound %s", bcm_proc_getifname(net, ifname, bo->ifindex));
220220
seq_printf(m, " <<<\n");
221221

222-
list_for_each_entry(op, &bo->rx_ops, list) {
222+
rcu_read_lock();
223+
224+
list_for_each_entry_rcu(op, &bo->rx_ops, list) {
223225

224226
unsigned long reduction;
225227

@@ -275,6 +277,9 @@ static int bcm_proc_show(struct seq_file *m, void *v)
275277
seq_printf(m, "# sent %ld\n", op->frames_abs);
276278
}
277279
seq_putc(m, '\n');
280+
281+
rcu_read_unlock();
282+
278283
return 0;
279284
}
280285
#endif /* CONFIG_PROC_FS */
@@ -858,7 +863,7 @@ static int bcm_delete_rx_op(struct list_head *ops, struct bcm_msg_head *mh,
858863
REGMASK(op->can_id),
859864
bcm_rx_handler, op);
860865

861-
list_del(&op->list);
866+
list_del_rcu(&op->list);
862867
bcm_remove_op(op);
863868
return 1; /* done */
864869
}
@@ -878,7 +883,7 @@ static int bcm_delete_tx_op(struct list_head *ops, struct bcm_msg_head *mh,
878883
list_for_each_entry_safe(op, n, ops, list) {
879884
if ((op->can_id == mh->can_id) && (op->ifindex == ifindex) &&
880885
(op->flags & CAN_FD_FRAME) == (mh->flags & CAN_FD_FRAME)) {
881-
list_del(&op->list);
886+
list_del_rcu(&op->list);
882887
bcm_remove_op(op);
883888
return 1; /* done */
884889
}
@@ -1296,7 +1301,7 @@ static int bcm_rx_setup(struct bcm_msg_head *msg_head, struct msghdr *msg,
12961301
bcm_rx_handler, op, "bcm", sk);
12971302
if (err) {
12981303
/* this bcm rx op is broken -> remove it */
1299-
list_del(&op->list);
1304+
list_del_rcu(&op->list);
13001305
bcm_remove_op(op);
13011306
return err;
13021307
}

0 commit comments

Comments
 (0)