Skip to content

Commit fb579e6

Browse files
tobluxNeeraj Upadhyay
authored andcommitted
rcu: Annotate struct kvfree_rcu_bulk_data with __counted_by()
Add the __counted_by compiler attribute to the flexible array member records to improve access bounds-checking via CONFIG_UBSAN_BOUNDS and CONFIG_FORTIFY_SOURCE. Increment nr_records before adding a new pointer to the records array. Signed-off-by: Thorsten Blum <[email protected]> Reviewed-by: "Gustavo A. R. Silva" <[email protected]> Reviewed-by: "Uladzislau Rezki (Sony)" <[email protected]> Reviewed-by: Paul E. McKenney <[email protected]> Signed-off-by: Neeraj Upadhyay <[email protected]>
1 parent 9aed3b5 commit fb579e6

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

kernel/rcu/tree.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3227,7 +3227,7 @@ struct kvfree_rcu_bulk_data {
32273227
struct list_head list;
32283228
struct rcu_gp_oldstate gp_snap;
32293229
unsigned long nr_records;
3230-
void *records[];
3230+
void *records[] __counted_by(nr_records);
32313231
};
32323232

32333233
/*
@@ -3767,7 +3767,8 @@ add_ptr_to_bulk_krc_lock(struct kfree_rcu_cpu **krcp,
37673767
}
37683768

37693769
// Finally insert and update the GP for this page.
3770-
bnode->records[bnode->nr_records++] = ptr;
3770+
bnode->nr_records++;
3771+
bnode->records[bnode->nr_records - 1] = ptr;
37713772
get_state_synchronize_rcu_full(&bnode->gp_snap);
37723773
atomic_inc(&(*krcp)->bulk_count[idx]);
37733774

0 commit comments

Comments
 (0)