]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
rcu: Annotate struct kvfree_rcu_bulk_data with __counted_by()
authorThorsten Blum <thorsten.blum@toblux.com>
Wed, 7 Aug 2024 09:55:00 +0000 (11:55 +0200)
committerNeeraj Upadhyay <neeraj.upadhyay@kernel.org>
Sun, 11 Aug 2024 06:04:47 +0000 (11:34 +0530)
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 <thorsten.blum@toblux.com>
Reviewed-by: "Gustavo A. R. Silva" <gustavoars@kernel.org>
Reviewed-by: "Uladzislau Rezki (Sony)" <urezki@gmail.com>
Reviewed-by: Paul E. McKenney <paulmck@kernel.org>
Signed-off-by: Neeraj Upadhyay <neeraj.upadhyay@kernel.org>
kernel/rcu/tree.c

index 0f41a81138dce91c6247c91588757e080bdd33f6..d5bf824159dab39ccff28c3b82f6387ca3dc1828 100644 (file)
@@ -3227,7 +3227,7 @@ struct kvfree_rcu_bulk_data {
        struct list_head list;
        struct rcu_gp_oldstate gp_snap;
        unsigned long nr_records;
-       void *records[];
+       void *records[] __counted_by(nr_records);
 };
 
 /*
@@ -3767,7 +3767,8 @@ add_ptr_to_bulk_krc_lock(struct kfree_rcu_cpu **krcp,
        }
 
        // Finally insert and update the GP for this page.
-       bnode->records[bnode->nr_records++] = ptr;
+       bnode->nr_records++;
+       bnode->records[bnode->nr_records - 1] = ptr;
        get_state_synchronize_rcu_full(&bnode->gp_snap);
        atomic_inc(&(*krcp)->bulk_count[idx]);