linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] afs: Increase buffer size in afs_update_volume_status()
@ 2024-02-12  8:33 Daniil Dulov
  2024-02-12 14:56 ` Jeffrey E Altman
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Daniil Dulov @ 2024-02-12  8:33 UTC (permalink / raw)
  To: Jeffrey E Altman
  Cc: Daniil Dulov, linux-afs, Marc Dionne, David Howells,
	linux-kernel, lvc-project

The max length of volume->vid value is 20 characters.
So increase idbuf[] size up to 20 to avoid overflow.

Found by Linux Verification Center (linuxtesting.org) with SVACE.

Fixes: d2ddc776a458 ("afs: Overhaul volume and server record caching and fileserver rotation")
Signed-off-by: Daniil Dulov <d.dulov@aladdin.ru>
---
 fs/afs/volume.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/afs/volume.c b/fs/afs/volume.c
index 020ecd45e476..d4a379bfd54e 100644
--- a/fs/afs/volume.c
+++ b/fs/afs/volume.c
@@ -353,7 +353,7 @@ static int afs_update_volume_status(struct afs_volume *volume, struct key *key)
 {
 	struct afs_server_list *new, *old, *discard;
 	struct afs_vldb_entry *vldb;
-	char idbuf[16];
+	char idbuf[20];
 	int ret, idsz;
 
 	_enter("");
-- 
2.25.1


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

* Re: [PATCH v2] afs: Increase buffer size in afs_update_volume_status()
  2024-02-12  8:33 [PATCH v2] afs: Increase buffer size in afs_update_volume_status() Daniil Dulov
@ 2024-02-12 14:56 ` Jeffrey E Altman
  2024-02-19 10:28 ` David Howells
  2024-02-19 10:33 ` David Howells
  2 siblings, 0 replies; 6+ messages in thread
From: Jeffrey E Altman @ 2024-02-12 14:56 UTC (permalink / raw)
  To: Daniil Dulov
  Cc: linux-afs, Marc Dionne, David Howells, linux-kernel, lvc-project

On 2/12/2024 3:33 AM, Daniil Dulov wrote:
> The max length of volume->vid value is 20 characters.
> So increase idbuf[] size up to 20 to avoid overflow.
>
> Found by Linux Verification Center (linuxtesting.org) with SVACE.
>
> Fixes: d2ddc776a458 ("afs: Overhaul volume and server record caching and fileserver rotation")
> Signed-off-by: Daniil Dulov <d.dulov@aladdin.ru>
> ---
>   fs/afs/volume.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/fs/afs/volume.c b/fs/afs/volume.c
> index 020ecd45e476..d4a379bfd54e 100644
> --- a/fs/afs/volume.c
> +++ b/fs/afs/volume.c
> @@ -353,7 +353,7 @@ static int afs_update_volume_status(struct afs_volume *volume, struct key *key)
>   {
>   	struct afs_server_list *new, *old, *discard;
>   	struct afs_vldb_entry *vldb;
> -	char idbuf[16];
> +	char idbuf[20];
>   	int ret, idsz;
>   
>   	_enter("");

Reviewed-by: Jeffrey Altman <jaltman@auristor.com>



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

* Re: [PATCH v2] afs: Increase buffer size in afs_update_volume_status()
  2024-02-12  8:33 [PATCH v2] afs: Increase buffer size in afs_update_volume_status() Daniil Dulov
  2024-02-12 14:56 ` Jeffrey E Altman
@ 2024-02-19 10:28 ` David Howells
  2024-02-19 10:33 ` David Howells
  2 siblings, 0 replies; 6+ messages in thread
From: David Howells @ 2024-02-19 10:28 UTC (permalink / raw)
  To: Daniil Dulov
  Cc: dhowells, Jeffrey E Altman, linux-afs, Marc Dionne, linux-kernel,
	lvc-project

Daniil Dulov <d.dulov@aladdin.ru> wrote:

> The max length of volume->vid value is 20 characters.
> So increase idbuf[] size up to 20 to avoid overflow.

Is that 20 including the NUL?  If not, I'd increase it to 24 (it's likely to
get rounded up to a multiple of 4 or 8 by the compiler).

David


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

* Re: [PATCH v2] afs: Increase buffer size in afs_update_volume_status()
  2024-02-12  8:33 [PATCH v2] afs: Increase buffer size in afs_update_volume_status() Daniil Dulov
  2024-02-12 14:56 ` Jeffrey E Altman
  2024-02-19 10:28 ` David Howells
@ 2024-02-19 10:33 ` David Howells
  2024-02-19 15:07   ` Daniil Dulov
  2024-02-19 16:01   ` David Howells
  2 siblings, 2 replies; 6+ messages in thread
From: David Howells @ 2024-02-19 10:33 UTC (permalink / raw)
  To: Daniil Dulov
  Cc: dhowells, Jeffrey E Altman, linux-afs, Marc Dionne, linux-kernel,
	lvc-project

I suggest the attached instead.

David
---
diff --git a/fs/afs/volume.c b/fs/afs/volume.c
index 020ecd45e476..af3a3f57c1b3 100644
--- a/fs/afs/volume.c
+++ b/fs/afs/volume.c
@@ -353,7 +353,7 @@ static int afs_update_volume_status(struct afs_volume *volume, struct key *key)
 {
 	struct afs_server_list *new, *old, *discard;
 	struct afs_vldb_entry *vldb;
-	char idbuf[16];
+	char idbuf[24];
 	int ret, idsz;
 
 	_enter("");
@@ -361,7 +361,7 @@ static int afs_update_volume_status(struct afs_volume *volume, struct key *key)
 	/* We look up an ID by passing it as a decimal string in the
 	 * operation's name parameter.
 	 */
-	idsz = sprintf(idbuf, "%llu", volume->vid);
+	idsz = snprintf(idbuf, sizeof(idbuf), "%llu", volume->vid);
 
 	vldb = afs_vl_lookup_vldb(volume->cell, key, idbuf, idsz);
 	if (IS_ERR(vldb)) {


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

* RE: [PATCH v2] afs: Increase buffer size in afs_update_volume_status()
  2024-02-19 10:33 ` David Howells
@ 2024-02-19 15:07   ` Daniil Dulov
  2024-02-19 16:01   ` David Howells
  1 sibling, 0 replies; 6+ messages in thread
From: Daniil Dulov @ 2024-02-19 15:07 UTC (permalink / raw)
  To: David Howells
  Cc: Jeffrey E Altman, linux-afs, Marc Dionne, linux-kernel, lvc-project

Hello!

Thank you for your feedback. I agree with the suggested improvement. I will send v3 a bit later today.

-----Original Message-----
From: David Howells [mailto:dhowells@redhat.com] 
Sent: Monday, February 19, 2024 1:34 PM
To: Daniil Dulov <D.Dulov@aladdin.ru>
Cc: dhowells@redhat.com; Jeffrey E Altman <jaltman@auristor.com>; linux-afs@lists.infradead.org; Marc Dionne <marc.dionne@auristor.com>; linux-kernel@vger.kernel.org; lvc-project@linuxtesting.org
Subject: Re: [PATCH v2] afs: Increase buffer size in afs_update_volume_status()

I suggest the attached instead.

David
---
diff --git a/fs/afs/volume.c b/fs/afs/volume.c index 020ecd45e476..af3a3f57c1b3 100644
--- a/fs/afs/volume.c
+++ b/fs/afs/volume.c
@@ -353,7 +353,7 @@ static int afs_update_volume_status(struct afs_volume *volume, struct key *key)  {
 	struct afs_server_list *new, *old, *discard;
 	struct afs_vldb_entry *vldb;
-	char idbuf[16];
+	char idbuf[24];
 	int ret, idsz;
 
 	_enter("");
@@ -361,7 +361,7 @@ static int afs_update_volume_status(struct afs_volume *volume, struct key *key)
 	/* We look up an ID by passing it as a decimal string in the
 	 * operation's name parameter.
 	 */
-	idsz = sprintf(idbuf, "%llu", volume->vid);
+	idsz = snprintf(idbuf, sizeof(idbuf), "%llu", volume->vid);
 
 	vldb = afs_vl_lookup_vldb(volume->cell, key, idbuf, idsz);
 	if (IS_ERR(vldb)) {


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

* Re: [PATCH v2] afs: Increase buffer size in afs_update_volume_status()
  2024-02-19 10:33 ` David Howells
  2024-02-19 15:07   ` Daniil Dulov
@ 2024-02-19 16:01   ` David Howells
  1 sibling, 0 replies; 6+ messages in thread
From: David Howells @ 2024-02-19 16:01 UTC (permalink / raw)
  To: Daniil Dulov
  Cc: dhowells, Jeffrey E Altman, linux-afs, Marc Dionne, linux-kernel,
	lvc-project

Daniil Dulov <D.Dulov@aladdin.ru> wrote:

> Thank you for your feedback. I agree with the suggested improvement. I will send v3 a bit later today.

I posted an updated patch:

https://lore.kernel.org/linux-fsdevel/20240219143906.138346-3-dhowells@redhat.com/T/#u


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

end of thread, other threads:[~2024-02-19 16:01 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-12  8:33 [PATCH v2] afs: Increase buffer size in afs_update_volume_status() Daniil Dulov
2024-02-12 14:56 ` Jeffrey E Altman
2024-02-19 10:28 ` David Howells
2024-02-19 10:33 ` David Howells
2024-02-19 15:07   ` Daniil Dulov
2024-02-19 16:01   ` David Howells

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).