All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] rcu: Annotate struct kvfree_rcu_bulk_data with __counted_by()
@ 2024-08-07  9:55 Thorsten Blum
  2024-08-07 15:29 ` Gustavo A. R. Silva
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Thorsten Blum @ 2024-08-07  9:55 UTC (permalink / raw)
  To: paulmck, frederic, neeraj.upadhyay, joel, josh, boqun.feng,
	urezki, rostedt, mathieu.desnoyers, jiangshanlai, qiang.zhang1211,
	kees, gustavoars
  Cc: rcu, linux-kernel, linux-hardening, Thorsten Blum

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>
---
 kernel/rcu/tree.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c
index e641cc681901..76d8d75dd8b3 100644
--- a/kernel/rcu/tree.c
+++ b/kernel/rcu/tree.c
@@ -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]);
 
-- 
2.45.2


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] rcu: Annotate struct kvfree_rcu_bulk_data with __counted_by()
  2024-08-07  9:55 [PATCH] rcu: Annotate struct kvfree_rcu_bulk_data with __counted_by() Thorsten Blum
@ 2024-08-07 15:29 ` Gustavo A. R. Silva
  2024-08-07 15:35 ` Uladzislau Rezki
  2024-08-08 18:02 ` Paul E. McKenney
  2 siblings, 0 replies; 4+ messages in thread
From: Gustavo A. R. Silva @ 2024-08-07 15:29 UTC (permalink / raw)
  To: Thorsten Blum, paulmck, frederic, neeraj.upadhyay, joel, josh,
	boqun.feng, urezki, rostedt, mathieu.desnoyers, jiangshanlai,
	qiang.zhang1211, kees, gustavoars
  Cc: rcu, linux-kernel, linux-hardening



On 07/08/24 03:55, Thorsten Blum wrote:
> 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.
> 

Looks good.

> Signed-off-by: Thorsten Blum <thorsten.blum@toblux.com>

Reviewed-by: Gustavo A. R. Silva <gustavoars@kernel.org>

Thanks
--
Gustavo

> ---
>   kernel/rcu/tree.c | 5 +++--
>   1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c
> index e641cc681901..76d8d75dd8b3 100644
> --- a/kernel/rcu/tree.c
> +++ b/kernel/rcu/tree.c
> @@ -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]);
>   

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] rcu: Annotate struct kvfree_rcu_bulk_data with __counted_by()
  2024-08-07  9:55 [PATCH] rcu: Annotate struct kvfree_rcu_bulk_data with __counted_by() Thorsten Blum
  2024-08-07 15:29 ` Gustavo A. R. Silva
@ 2024-08-07 15:35 ` Uladzislau Rezki
  2024-08-08 18:02 ` Paul E. McKenney
  2 siblings, 0 replies; 4+ messages in thread
From: Uladzislau Rezki @ 2024-08-07 15:35 UTC (permalink / raw)
  To: Thorsten Blum
  Cc: paulmck, frederic, neeraj.upadhyay, joel, josh, boqun.feng,
	urezki, rostedt, mathieu.desnoyers, jiangshanlai, qiang.zhang1211,
	kees, gustavoars, rcu, linux-kernel, linux-hardening

On Wed, Aug 07, 2024 at 11:55:00AM +0200, Thorsten Blum wrote:
> 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>
> ---
>  kernel/rcu/tree.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c
> index e641cc681901..76d8d75dd8b3 100644
> --- a/kernel/rcu/tree.c
> +++ b/kernel/rcu/tree.c
> @@ -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]);
>  
> -- 
> 2.45.2
> 
Reviewed-by: Uladzislau Rezki (Sony) <urezki@gmail.com>

--
Uladzislau Rezki

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] rcu: Annotate struct kvfree_rcu_bulk_data with __counted_by()
  2024-08-07  9:55 [PATCH] rcu: Annotate struct kvfree_rcu_bulk_data with __counted_by() Thorsten Blum
  2024-08-07 15:29 ` Gustavo A. R. Silva
  2024-08-07 15:35 ` Uladzislau Rezki
@ 2024-08-08 18:02 ` Paul E. McKenney
  2 siblings, 0 replies; 4+ messages in thread
From: Paul E. McKenney @ 2024-08-08 18:02 UTC (permalink / raw)
  To: Thorsten Blum
  Cc: frederic, neeraj.upadhyay, joel, josh, boqun.feng, urezki,
	rostedt, mathieu.desnoyers, jiangshanlai, qiang.zhang1211, kees,
	gustavoars, rcu, linux-kernel, linux-hardening

On Wed, Aug 07, 2024 at 11:55:00AM +0200, Thorsten Blum wrote:
> 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: Paul E. McKenney <paulmck@kernel.org>

> ---
>  kernel/rcu/tree.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c
> index e641cc681901..76d8d75dd8b3 100644
> --- a/kernel/rcu/tree.c
> +++ b/kernel/rcu/tree.c
> @@ -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]);
>  
> -- 
> 2.45.2
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-08-08 18:02 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-07  9:55 [PATCH] rcu: Annotate struct kvfree_rcu_bulk_data with __counted_by() Thorsten Blum
2024-08-07 15:29 ` Gustavo A. R. Silva
2024-08-07 15:35 ` Uladzislau Rezki
2024-08-08 18:02 ` Paul E. McKenney

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.