All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net] net/tcp_sigpool: Fix some off by one bugs
@ 2023-10-31  9:51 Dan Carpenter
  2023-10-31 16:58 ` Dmitry Safonov
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Dan Carpenter @ 2023-10-31  9:51 UTC (permalink / raw)
  To: Dmitry Safonov
  Cc: Eric Dumazet, David S. Miller, David Ahern, Jakub Kicinski,
	Paolo Abeni, Steen Hegelund, netdev, kernel-janitors

The "cpool_populated" variable is the number of elements in the cpool[]
array that have been populated.  It is incremented in
tcp_sigpool_alloc_ahash() every time we populate a new element.
Unpopulated elements are NULL but if we have populated every element then
this code will read one element beyond the end of the array.

Fixes: 8c73b26315aa ("net/tcp: Prepare tcp_md5sig_pool for TCP-AO")
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
---
From static analysis and review.

 net/ipv4/tcp_sigpool.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/net/ipv4/tcp_sigpool.c b/net/ipv4/tcp_sigpool.c
index 65a8eaae2fec..55b310a722c7 100644
--- a/net/ipv4/tcp_sigpool.c
+++ b/net/ipv4/tcp_sigpool.c
@@ -231,7 +231,7 @@ static void cpool_schedule_cleanup(struct kref *kref)
  */
 void tcp_sigpool_release(unsigned int id)
 {
-	if (WARN_ON_ONCE(id > cpool_populated || !cpool[id].alg))
+	if (WARN_ON_ONCE(id >= cpool_populated || !cpool[id].alg))
 		return;
 
 	/* slow-path */
@@ -245,7 +245,7 @@ EXPORT_SYMBOL_GPL(tcp_sigpool_release);
  */
 void tcp_sigpool_get(unsigned int id)
 {
-	if (WARN_ON_ONCE(id > cpool_populated || !cpool[id].alg))
+	if (WARN_ON_ONCE(id >= cpool_populated || !cpool[id].alg))
 		return;
 	kref_get(&cpool[id].kref);
 }
@@ -256,7 +256,7 @@ int tcp_sigpool_start(unsigned int id, struct tcp_sigpool *c) __cond_acquires(RC
 	struct crypto_ahash *hash;
 
 	rcu_read_lock_bh();
-	if (WARN_ON_ONCE(id > cpool_populated || !cpool[id].alg)) {
+	if (WARN_ON_ONCE(id >= cpool_populated || !cpool[id].alg)) {
 		rcu_read_unlock_bh();
 		return -EINVAL;
 	}
@@ -301,7 +301,7 @@ EXPORT_SYMBOL_GPL(tcp_sigpool_end);
  */
 size_t tcp_sigpool_algo(unsigned int id, char *buf, size_t buf_len)
 {
-	if (WARN_ON_ONCE(id > cpool_populated || !cpool[id].alg))
+	if (WARN_ON_ONCE(id >= cpool_populated || !cpool[id].alg))
 		return -EINVAL;
 
 	return strscpy(buf, cpool[id].alg, buf_len);
-- 
2.42.0


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

* Re: [PATCH net] net/tcp_sigpool: Fix some off by one bugs
  2023-10-31  9:51 [PATCH net] net/tcp_sigpool: Fix some off by one bugs Dan Carpenter
@ 2023-10-31 16:58 ` Dmitry Safonov
  2023-11-01  4:51 ` Eric Dumazet
  2023-11-02  5:51 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 4+ messages in thread
From: Dmitry Safonov @ 2023-10-31 16:58 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Eric Dumazet, David S. Miller, David Ahern, Jakub Kicinski,
	Paolo Abeni, Steen Hegelund, netdev, kernel-janitors

Hi Dan,

On 10/31/23 09:51, Dan Carpenter wrote:
> The "cpool_populated" variable is the number of elements in the cpool[]
> array that have been populated.  It is incremented in
> tcp_sigpool_alloc_ahash() every time we populate a new element.
> Unpopulated elements are NULL but if we have populated every element then
> this code will read one element beyond the end of the array.
> 
> Fixes: 8c73b26315aa ("net/tcp: Prepare tcp_md5sig_pool for TCP-AO")
> Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>

Yeah, those are barriers for any issues in the caller-code, so that's
not too critical but nice to have. Thanks for the patch!

Reviewed-by: Dmitry Safonov <dima@arista.com>

> ---
> From static analysis and review.
> 
>  net/ipv4/tcp_sigpool.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/net/ipv4/tcp_sigpool.c b/net/ipv4/tcp_sigpool.c
> index 65a8eaae2fec..55b310a722c7 100644
> --- a/net/ipv4/tcp_sigpool.c
> +++ b/net/ipv4/tcp_sigpool.c
> @@ -231,7 +231,7 @@ static void cpool_schedule_cleanup(struct kref *kref)
>   */
>  void tcp_sigpool_release(unsigned int id)
>  {
> -	if (WARN_ON_ONCE(id > cpool_populated || !cpool[id].alg))
> +	if (WARN_ON_ONCE(id >= cpool_populated || !cpool[id].alg))
>  		return;
>  
>  	/* slow-path */
> @@ -245,7 +245,7 @@ EXPORT_SYMBOL_GPL(tcp_sigpool_release);
>   */
>  void tcp_sigpool_get(unsigned int id)
>  {
> -	if (WARN_ON_ONCE(id > cpool_populated || !cpool[id].alg))
> +	if (WARN_ON_ONCE(id >= cpool_populated || !cpool[id].alg))
>  		return;
>  	kref_get(&cpool[id].kref);
>  }
> @@ -256,7 +256,7 @@ int tcp_sigpool_start(unsigned int id, struct tcp_sigpool *c) __cond_acquires(RC
>  	struct crypto_ahash *hash;
>  
>  	rcu_read_lock_bh();
> -	if (WARN_ON_ONCE(id > cpool_populated || !cpool[id].alg)) {
> +	if (WARN_ON_ONCE(id >= cpool_populated || !cpool[id].alg)) {
>  		rcu_read_unlock_bh();
>  		return -EINVAL;
>  	}
> @@ -301,7 +301,7 @@ EXPORT_SYMBOL_GPL(tcp_sigpool_end);
>   */
>  size_t tcp_sigpool_algo(unsigned int id, char *buf, size_t buf_len)
>  {
> -	if (WARN_ON_ONCE(id > cpool_populated || !cpool[id].alg))
> +	if (WARN_ON_ONCE(id >= cpool_populated || !cpool[id].alg))
>  		return -EINVAL;
>  
>  	return strscpy(buf, cpool[id].alg, buf_len);

Thanks,
            Dmitry


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

* Re: [PATCH net] net/tcp_sigpool: Fix some off by one bugs
  2023-10-31  9:51 [PATCH net] net/tcp_sigpool: Fix some off by one bugs Dan Carpenter
  2023-10-31 16:58 ` Dmitry Safonov
@ 2023-11-01  4:51 ` Eric Dumazet
  2023-11-02  5:51 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 4+ messages in thread
From: Eric Dumazet @ 2023-11-01  4:51 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Dmitry Safonov, David S. Miller, David Ahern, Jakub Kicinski,
	Paolo Abeni, Steen Hegelund, netdev, kernel-janitors

On Tue, Oct 31, 2023 at 10:51 AM Dan Carpenter <dan.carpenter@linaro.org> wrote:
>
> The "cpool_populated" variable is the number of elements in the cpool[]
> array that have been populated.  It is incremented in
> tcp_sigpool_alloc_ahash() every time we populate a new element.
> Unpopulated elements are NULL but if we have populated every element then
> this code will read one element beyond the end of the array.
>
> Fixes: 8c73b26315aa ("net/tcp: Prepare tcp_md5sig_pool for TCP-AO")
> Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
> ---
> From static analysis and review.
>

Reviewed-by: Eric Dumazet <edumazet@google.com>

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

* Re: [PATCH net] net/tcp_sigpool: Fix some off by one bugs
  2023-10-31  9:51 [PATCH net] net/tcp_sigpool: Fix some off by one bugs Dan Carpenter
  2023-10-31 16:58 ` Dmitry Safonov
  2023-11-01  4:51 ` Eric Dumazet
@ 2023-11-02  5:51 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 4+ messages in thread
From: patchwork-bot+netdevbpf @ 2023-11-02  5:51 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: 0x7f454c46, edumazet, davem, dsahern, kuba, pabeni,
	Steen.Hegelund, netdev, kernel-janitors

Hello:

This patch was applied to netdev/net.git (main)
by Jakub Kicinski <kuba@kernel.org>:

On Tue, 31 Oct 2023 12:51:09 +0300 you wrote:
> The "cpool_populated" variable is the number of elements in the cpool[]
> array that have been populated.  It is incremented in
> tcp_sigpool_alloc_ahash() every time we populate a new element.
> Unpopulated elements are NULL but if we have populated every element then
> this code will read one element beyond the end of the array.
> 
> Fixes: 8c73b26315aa ("net/tcp: Prepare tcp_md5sig_pool for TCP-AO")
> Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
> 
> [...]

Here is the summary with links:
  - [net] net/tcp_sigpool: Fix some off by one bugs
    https://git.kernel.org/netdev/net/c/74da77921333

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



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

end of thread, other threads:[~2023-11-02  5:51 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-10-31  9:51 [PATCH net] net/tcp_sigpool: Fix some off by one bugs Dan Carpenter
2023-10-31 16:58 ` Dmitry Safonov
2023-11-01  4:51 ` Eric Dumazet
2023-11-02  5:51 ` patchwork-bot+netdevbpf

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.