All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 1/1] virtio_net: Fix "‘%d’ directive writing between 1 and 11 bytes into a region of size 10" warnings
@ 2023-12-27 14:26 Zhu Yanjun
  2023-12-27 14:41 ` Zhu Yanjun
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Zhu Yanjun @ 2023-12-27 14:26 UTC (permalink / raw)
  To: mst, jasowang, xuanzhuo, davem, edumazet, kuba, pabeni,
	virtualization, netdev
  Cc: Zhu Yanjun

From: Zhu Yanjun <yanjun.zhu@linux.dev>

Fix the warnings when building virtio_net driver.

"
drivers/net/virtio_net.c: In function ‘init_vqs’:
drivers/net/virtio_net.c:4551:48: warning: ‘%d’ directive writing between 1 and 11 bytes into a region of size 10 [-Wformat-overflow=]
 4551 |                 sprintf(vi->rq[i].name, "input.%d", i);
      |                                                ^~
In function ‘virtnet_find_vqs’,
    inlined from ‘init_vqs’ at drivers/net/virtio_net.c:4645:8:
drivers/net/virtio_net.c:4551:41: note: directive argument in the range [-2147483643, 65534]
 4551 |                 sprintf(vi->rq[i].name, "input.%d", i);
      |                                         ^~~~~~~~~~
drivers/net/virtio_net.c:4551:17: note: ‘sprintf’ output between 8 and 18 bytes into a destination of size 16
 4551 |                 sprintf(vi->rq[i].name, "input.%d", i);
      |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/net/virtio_net.c: In function ‘init_vqs’:
drivers/net/virtio_net.c:4552:49: warning: ‘%d’ directive writing between 1 and 11 bytes into a region of size 9 [-Wformat-overflow=]
 4552 |                 sprintf(vi->sq[i].name, "output.%d", i);
      |                                                 ^~
In function ‘virtnet_find_vqs’,
    inlined from ‘init_vqs’ at drivers/net/virtio_net.c:4645:8:
drivers/net/virtio_net.c:4552:41: note: directive argument in the range [-2147483643, 65534]
 4552 |                 sprintf(vi->sq[i].name, "output.%d", i);
      |                                         ^~~~~~~~~~~
drivers/net/virtio_net.c:4552:17: note: ‘sprintf’ output between 9 and 19 bytes into a destination of size 16
 4552 |                 sprintf(vi->sq[i].name, "output.%d", i);

"

Reviewed-by: Xuan Zhuo <xuanzhuo@linux.alibaba.com>
Signed-off-by: Zhu Yanjun <yanjun.zhu@linux.dev>
---
 drivers/net/virtio_net.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
index d16f592c2061..89a15cc81396 100644
--- a/drivers/net/virtio_net.c
+++ b/drivers/net/virtio_net.c
@@ -4096,10 +4096,11 @@ static int virtnet_find_vqs(struct virtnet_info *vi)
 {
 	vq_callback_t **callbacks;
 	struct virtqueue **vqs;
-	int ret = -ENOMEM;
-	int i, total_vqs;
 	const char **names;
+	int ret = -ENOMEM;
+	int total_vqs;
 	bool *ctx;
+	u16 i;
 
 	/* We expect 1 RX virtqueue followed by 1 TX virtqueue, followed by
 	 * possible N-1 RX/TX queue pairs used in multiqueue mode, followed by
@@ -4136,8 +4137,8 @@ static int virtnet_find_vqs(struct virtnet_info *vi)
 	for (i = 0; i < vi->max_queue_pairs; i++) {
 		callbacks[rxq2vq(i)] = skb_recv_done;
 		callbacks[txq2vq(i)] = skb_xmit_done;
-		sprintf(vi->rq[i].name, "input.%d", i);
-		sprintf(vi->sq[i].name, "output.%d", i);
+		sprintf(vi->rq[i].name, "input.%u", i);
+		sprintf(vi->sq[i].name, "output.%u", i);
 		names[rxq2vq(i)] = vi->rq[i].name;
 		names[txq2vq(i)] = vi->sq[i].name;
 		if (ctx)
-- 
2.27.0


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

* Re: [PATCH v2 1/1] virtio_net: Fix "‘%d’ directive writing between 1 and 11 bytes into a region of size 10" warnings
  2023-12-27 14:26 [PATCH v2 1/1] virtio_net: Fix "‘%d’ directive writing between 1 and 11 bytes into a region of size 10" warnings Zhu Yanjun
@ 2023-12-27 14:41 ` Zhu Yanjun
  2023-12-28  1:26   ` Xuan Zhuo
  2023-12-28 13:49 ` kernel test robot
  2024-01-04  0:55 ` Jakub Kicinski
  2 siblings, 1 reply; 7+ messages in thread
From: Zhu Yanjun @ 2023-12-27 14:41 UTC (permalink / raw)
  To: Zhu Yanjun, mst, jasowang, xuanzhuo, davem, edumazet, kuba,
	pabeni, virtualization, netdev


在 2023/12/27 22:26, Zhu Yanjun 写道:
> From: Zhu Yanjun <yanjun.zhu@linux.dev>
>
> Fix the warnings when building virtio_net driver.
>
> "
> drivers/net/virtio_net.c: In function ‘init_vqs’:
> drivers/net/virtio_net.c:4551:48: warning: ‘%d’ directive writing between 1 and 11 bytes into a region of size 10 [-Wformat-overflow=]
>   4551 |                 sprintf(vi->rq[i].name, "input.%d", i);
>        |                                                ^~
> In function ‘virtnet_find_vqs’,
>      inlined from ‘init_vqs’ at drivers/net/virtio_net.c:4645:8:
> drivers/net/virtio_net.c:4551:41: note: directive argument in the range [-2147483643, 65534]
>   4551 |                 sprintf(vi->rq[i].name, "input.%d", i);
>        |                                         ^~~~~~~~~~
> drivers/net/virtio_net.c:4551:17: note: ‘sprintf’ output between 8 and 18 bytes into a destination of size 16
>   4551 |                 sprintf(vi->rq[i].name, "input.%d", i);
>        |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> drivers/net/virtio_net.c: In function ‘init_vqs’:
> drivers/net/virtio_net.c:4552:49: warning: ‘%d’ directive writing between 1 and 11 bytes into a region of size 9 [-Wformat-overflow=]
>   4552 |                 sprintf(vi->sq[i].name, "output.%d", i);
>        |                                                 ^~
> In function ‘virtnet_find_vqs’,
>      inlined from ‘init_vqs’ at drivers/net/virtio_net.c:4645:8:
> drivers/net/virtio_net.c:4552:41: note: directive argument in the range [-2147483643, 65534]
>   4552 |                 sprintf(vi->sq[i].name, "output.%d", i);
>        |                                         ^~~~~~~~~~~
> drivers/net/virtio_net.c:4552:17: note: ‘sprintf’ output between 9 and 19 bytes into a destination of size 16
>   4552 |                 sprintf(vi->sq[i].name, "output.%d", i);
>
> "

Hi, all

V1->V2: Add commit logs. Format string is changed.

Best Regards,

Zhu Yanjun

> Reviewed-by: Xuan Zhuo <xuanzhuo@linux.alibaba.com>
> Signed-off-by: Zhu Yanjun <yanjun.zhu@linux.dev>
> ---
>   drivers/net/virtio_net.c | 9 +++++----
>   1 file changed, 5 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
> index d16f592c2061..89a15cc81396 100644
> --- a/drivers/net/virtio_net.c
> +++ b/drivers/net/virtio_net.c
> @@ -4096,10 +4096,11 @@ static int virtnet_find_vqs(struct virtnet_info *vi)
>   {
>   	vq_callback_t **callbacks;
>   	struct virtqueue **vqs;
> -	int ret = -ENOMEM;
> -	int i, total_vqs;
>   	const char **names;
> +	int ret = -ENOMEM;
> +	int total_vqs;
>   	bool *ctx;
> +	u16 i;
>   
>   	/* We expect 1 RX virtqueue followed by 1 TX virtqueue, followed by
>   	 * possible N-1 RX/TX queue pairs used in multiqueue mode, followed by
> @@ -4136,8 +4137,8 @@ static int virtnet_find_vqs(struct virtnet_info *vi)
>   	for (i = 0; i < vi->max_queue_pairs; i++) {
>   		callbacks[rxq2vq(i)] = skb_recv_done;
>   		callbacks[txq2vq(i)] = skb_xmit_done;
> -		sprintf(vi->rq[i].name, "input.%d", i);
> -		sprintf(vi->sq[i].name, "output.%d", i);
> +		sprintf(vi->rq[i].name, "input.%u", i);
> +		sprintf(vi->sq[i].name, "output.%u", i);
>   		names[rxq2vq(i)] = vi->rq[i].name;
>   		names[txq2vq(i)] = vi->sq[i].name;
>   		if (ctx)

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

* Re: [PATCH v2 1/1] virtio_net: Fix "‘%d’ directive writing between 1 and 11 bytes into a region of size 10" warnings
  2023-12-27 14:41 ` Zhu Yanjun
@ 2023-12-28  1:26   ` Xuan Zhuo
  0 siblings, 0 replies; 7+ messages in thread
From: Xuan Zhuo @ 2023-12-28  1:26 UTC (permalink / raw)
  To: Zhu Yanjun
  Cc: Zhu Yanjun, mst, jasowang, davem, edumazet, kuba, pabeni,
	virtualization, netdev

On Wed, 27 Dec 2023 22:41:07 +0800, Zhu Yanjun <yanjun.zhu@linux.dev> wrote:
>
> 在 2023/12/27 22:26, Zhu Yanjun 写道:
> > From: Zhu Yanjun <yanjun.zhu@linux.dev>
> >
> > Fix the warnings when building virtio_net driver.
> >
> > "
> > drivers/net/virtio_net.c: In function ‘init_vqs’:
> > drivers/net/virtio_net.c:4551:48: warning: ‘%d’ directive writing between 1 and 11 bytes into a region of size 10 [-Wformat-overflow=]
> >   4551 |                 sprintf(vi->rq[i].name, "input.%d", i);
> >        |                                                ^~
> > In function ‘virtnet_find_vqs’,
> >      inlined from ‘init_vqs’ at drivers/net/virtio_net.c:4645:8:
> > drivers/net/virtio_net.c:4551:41: note: directive argument in the range [-2147483643, 65534]
> >   4551 |                 sprintf(vi->rq[i].name, "input.%d", i);
> >        |                                         ^~~~~~~~~~
> > drivers/net/virtio_net.c:4551:17: note: ‘sprintf’ output between 8 and 18 bytes into a destination of size 16
> >   4551 |                 sprintf(vi->rq[i].name, "input.%d", i);
> >        |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> > drivers/net/virtio_net.c: In function ‘init_vqs’:
> > drivers/net/virtio_net.c:4552:49: warning: ‘%d’ directive writing between 1 and 11 bytes into a region of size 9 [-Wformat-overflow=]
> >   4552 |                 sprintf(vi->sq[i].name, "output.%d", i);
> >        |                                                 ^~
> > In function ‘virtnet_find_vqs’,
> >      inlined from ‘init_vqs’ at drivers/net/virtio_net.c:4645:8:
> > drivers/net/virtio_net.c:4552:41: note: directive argument in the range [-2147483643, 65534]
> >   4552 |                 sprintf(vi->sq[i].name, "output.%d", i);
> >        |                                         ^~~~~~~~~~~
> > drivers/net/virtio_net.c:4552:17: note: ‘sprintf’ output between 9 and 19 bytes into a destination of size 16
> >   4552 |                 sprintf(vi->sq[i].name, "output.%d", i);
> >
> > "
>
> Hi, all
>
> V1->V2: Add commit logs. Format string is changed.
>
> Best Regards,
>
> Zhu Yanjun
>
> > Reviewed-by: Xuan Zhuo <xuanzhuo@linux.alibaba.com>
> > Signed-off-by: Zhu Yanjun <yanjun.zhu@linux.dev>
> > ---

You can put the changes log after "---" inside the patch.

Thanks.

> >   drivers/net/virtio_net.c | 9 +++++----
> >   1 file changed, 5 insertions(+), 4 deletions(-)
> >
> > diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
> > index d16f592c2061..89a15cc81396 100644
> > --- a/drivers/net/virtio_net.c
> > +++ b/drivers/net/virtio_net.c
> > @@ -4096,10 +4096,11 @@ static int virtnet_find_vqs(struct virtnet_info *vi)
> >   {
> >   	vq_callback_t **callbacks;
> >   	struct virtqueue **vqs;
> > -	int ret = -ENOMEM;
> > -	int i, total_vqs;
> >   	const char **names;
> > +	int ret = -ENOMEM;
> > +	int total_vqs;
> >   	bool *ctx;
> > +	u16 i;
> >
> >   	/* We expect 1 RX virtqueue followed by 1 TX virtqueue, followed by
> >   	 * possible N-1 RX/TX queue pairs used in multiqueue mode, followed by
> > @@ -4136,8 +4137,8 @@ static int virtnet_find_vqs(struct virtnet_info *vi)
> >   	for (i = 0; i < vi->max_queue_pairs; i++) {
> >   		callbacks[rxq2vq(i)] = skb_recv_done;
> >   		callbacks[txq2vq(i)] = skb_xmit_done;
> > -		sprintf(vi->rq[i].name, "input.%d", i);
> > -		sprintf(vi->sq[i].name, "output.%d", i);
> > +		sprintf(vi->rq[i].name, "input.%u", i);
> > +		sprintf(vi->sq[i].name, "output.%u", i);
> >   		names[rxq2vq(i)] = vi->rq[i].name;
> >   		names[txq2vq(i)] = vi->sq[i].name;
> >   		if (ctx)

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

* Re: [PATCH v2 1/1] virtio_net: Fix "‘%d’ directive writing between 1 and 11 bytes into a region of size 10" warnings
  2023-12-27 14:26 [PATCH v2 1/1] virtio_net: Fix "‘%d’ directive writing between 1 and 11 bytes into a region of size 10" warnings Zhu Yanjun
  2023-12-27 14:41 ` Zhu Yanjun
@ 2023-12-28 13:49 ` kernel test robot
  2023-12-29  4:44   ` Zhu, Yanjun
  2024-01-04  0:55 ` Jakub Kicinski
  2 siblings, 1 reply; 7+ messages in thread
From: kernel test robot @ 2023-12-28 13:49 UTC (permalink / raw)
  To: Zhu Yanjun; +Cc: oe-kbuild-all

Hi Zhu,

kernel test robot noticed the following build warnings:

[auto build test WARNING on mst-vhost/linux-next]
[also build test WARNING on linus/master v6.7-rc7 next-20231222]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Zhu-Yanjun/virtio_net-Fix-d-directive-writing-between-1-and-11-bytes-into-a-region-of-size-10-warnings/20231227-223431
base:   https://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost.git linux-next
patch link:    https://lore.kernel.org/r/20231227142637.2479149-1-yanjun.zhu%40intel.com
patch subject: [PATCH v2 1/1] virtio_net: Fix "‘%d’ directive writing between 1 and 11 bytes into a region of size 10" warnings
config: x86_64-randconfig-015-20231228 (https://download.01.org/0day-ci/archive/20231228/202312282156.wb5beuAb-lkp@intel.com/config)
compiler: gcc-7 (Ubuntu 7.5.0-6ubuntu2) 7.5.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231228/202312282156.wb5beuAb-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202312282156.wb5beuAb-lkp@intel.com/

All warnings (new ones prefixed by >>):

   drivers/net/virtio_net.c: In function 'init_vqs':
   drivers/net/virtio_net.c:4140:36: warning: 'sprintf' may write a terminating nul past the end of the destination [-Wformat-overflow=]
      sprintf(vi->rq[i].name, "input.%u", i);
                                       ^
   drivers/net/virtio_net.c:4140:3: note: 'sprintf' output between 8 and 17 bytes into a destination of size 16
      sprintf(vi->rq[i].name, "input.%u", i);
      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>> drivers/net/virtio_net.c:4141:35: warning: '%u' directive writing between 1 and 10 bytes into a region of size 9 [-Wformat-overflow=]
      sprintf(vi->sq[i].name, "output.%u", i);
                                      ^~
   drivers/net/virtio_net.c:4141:27: note: directive argument in the range [0, 2147483647]
      sprintf(vi->sq[i].name, "output.%u", i);
                              ^~~~~~~~~~~
   drivers/net/virtio_net.c:4141:3: note: 'sprintf' output between 9 and 18 bytes into a destination of size 16
      sprintf(vi->sq[i].name, "output.%u", i);
      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Kconfig warnings: (for reference only)
   WARNING: unmet direct dependencies detected for DRM_I915_DEBUG_GEM
   Depends on [n]: HAS_IOMEM [=y] && DRM_I915 [=m] && EXPERT [=y] && DRM_I915_WERROR [=n]
   Selected by [m]:
   - DRM_I915_DEBUG [=y] && HAS_IOMEM [=y] && DRM_I915 [=m] && EXPERT [=y] && !COMPILE_TEST [=n]


vim +4141 drivers/net/virtio_net.c

  4094	
  4095	static int virtnet_find_vqs(struct virtnet_info *vi)
  4096	{
  4097		vq_callback_t **callbacks;
  4098		struct virtqueue **vqs;
  4099		const char **names;
  4100		int ret = -ENOMEM;
  4101		int total_vqs;
  4102		bool *ctx;
  4103		u16 i;
  4104	
  4105		/* We expect 1 RX virtqueue followed by 1 TX virtqueue, followed by
  4106		 * possible N-1 RX/TX queue pairs used in multiqueue mode, followed by
  4107		 * possible control vq.
  4108		 */
  4109		total_vqs = vi->max_queue_pairs * 2 +
  4110			    virtio_has_feature(vi->vdev, VIRTIO_NET_F_CTRL_VQ);
  4111	
  4112		/* Allocate space for find_vqs parameters */
  4113		vqs = kcalloc(total_vqs, sizeof(*vqs), GFP_KERNEL);
  4114		if (!vqs)
  4115			goto err_vq;
  4116		callbacks = kmalloc_array(total_vqs, sizeof(*callbacks), GFP_KERNEL);
  4117		if (!callbacks)
  4118			goto err_callback;
  4119		names = kmalloc_array(total_vqs, sizeof(*names), GFP_KERNEL);
  4120		if (!names)
  4121			goto err_names;
  4122		if (!vi->big_packets || vi->mergeable_rx_bufs) {
  4123			ctx = kcalloc(total_vqs, sizeof(*ctx), GFP_KERNEL);
  4124			if (!ctx)
  4125				goto err_ctx;
  4126		} else {
  4127			ctx = NULL;
  4128		}
  4129	
  4130		/* Parameters for control virtqueue, if any */
  4131		if (vi->has_cvq) {
  4132			callbacks[total_vqs - 1] = NULL;
  4133			names[total_vqs - 1] = "control";
  4134		}
  4135	
  4136		/* Allocate/initialize parameters for send/receive virtqueues */
  4137		for (i = 0; i < vi->max_queue_pairs; i++) {
  4138			callbacks[rxq2vq(i)] = skb_recv_done;
  4139			callbacks[txq2vq(i)] = skb_xmit_done;
  4140			sprintf(vi->rq[i].name, "input.%u", i);
> 4141			sprintf(vi->sq[i].name, "output.%u", i);
  4142			names[rxq2vq(i)] = vi->rq[i].name;
  4143			names[txq2vq(i)] = vi->sq[i].name;
  4144			if (ctx)
  4145				ctx[rxq2vq(i)] = true;
  4146		}
  4147	
  4148		ret = virtio_find_vqs_ctx(vi->vdev, total_vqs, vqs, callbacks,
  4149					  names, ctx, NULL);
  4150		if (ret)
  4151			goto err_find;
  4152	
  4153		if (vi->has_cvq) {
  4154			vi->cvq = vqs[total_vqs - 1];
  4155			if (virtio_has_feature(vi->vdev, VIRTIO_NET_F_CTRL_VLAN))
  4156				vi->dev->features |= NETIF_F_HW_VLAN_CTAG_FILTER;
  4157		}
  4158	
  4159		for (i = 0; i < vi->max_queue_pairs; i++) {
  4160			vi->rq[i].vq = vqs[rxq2vq(i)];
  4161			vi->rq[i].min_buf_len = mergeable_min_buf_len(vi, vi->rq[i].vq);
  4162			vi->sq[i].vq = vqs[txq2vq(i)];
  4163		}
  4164	
  4165		/* run here: ret == 0. */
  4166	
  4167	
  4168	err_find:
  4169		kfree(ctx);
  4170	err_ctx:
  4171		kfree(names);
  4172	err_names:
  4173		kfree(callbacks);
  4174	err_callback:
  4175		kfree(vqs);
  4176	err_vq:
  4177		return ret;
  4178	}
  4179	

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

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

* RE: [PATCH v2 1/1] virtio_net: Fix "‘%d’ directive writing between 1 and 11 bytes into a region of size 10" warnings
  2023-12-28 13:49 ` kernel test robot
@ 2023-12-29  4:44   ` Zhu, Yanjun
  0 siblings, 0 replies; 7+ messages in thread
From: Zhu, Yanjun @ 2023-12-29  4:44 UTC (permalink / raw)
  To: lkp; +Cc: oe-kbuild-all@lists.linux.dev

Hi, lkp

I can reproduce this problem in my local host. 

It seems that this problem is related with gcc-7. In the same test environment, with gcc-7, this problem will occur. With gcc later than version 9, this problem will not occur.

And with u16, the range of %u should be [0, 65535]. Not the following:
"
   drivers/net/virtio_net.c:4141:27: note: directive argument in the range [0, 2147483647]
      sprintf(vi->sq[i].name, "output.%u", i);
"

And the size of name is 16. That is, the name string can contain 15 bytes characters.
When the variable i is set to the maximum 65535, the string should be "output.65535". The size of the string is 12 + 1 = 13 bytes.
The size of the name is greater than the maximum string "output.65535".

In short, from the above, this problem results from gcc-7. It is a problem with gcc-7. Based on my tests with gcc-9, gcc-13, this problem is fixed in later gcc versions.
And the warning is a false warning to this commit.

Best Regards
Zhu Yanjun

-----Original Message-----
From: lkp <lkp@intel.com> 
Sent: Thursday, December 28, 2023 9:49 PM
To: Zhu, Yanjun <yanjun.zhu@intel.com>
Cc: oe-kbuild-all@lists.linux.dev
Subject: Re: [PATCH v2 1/1] virtio_net: Fix "‘%d’ directive writing between 1 and 11 bytes into a region of size 10" warnings

Hi Zhu,

kernel test robot noticed the following build warnings:

[auto build test WARNING on mst-vhost/linux-next] [also build test WARNING on linus/master v6.7-rc7 next-20231222] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Zhu-Yanjun/virtio_net-Fix-d-directive-writing-between-1-and-11-bytes-into-a-region-of-size-10-warnings/20231227-223431
base:   https://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost.git linux-next
patch link:    https://lore.kernel.org/r/20231227142637.2479149-1-yanjun.zhu%40intel.com
patch subject: [PATCH v2 1/1] virtio_net: Fix "‘%d’ directive writing between 1 and 11 bytes into a region of size 10" warnings
config: x86_64-randconfig-015-20231228 (https://download.01.org/0day-ci/archive/20231228/202312282156.wb5beuAb-lkp@intel.com/config)
compiler: gcc-7 (Ubuntu 7.5.0-6ubuntu2) 7.5.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231228/202312282156.wb5beuAb-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: 
| https://lore.kernel.org/oe-kbuild-all/202312282156.wb5beuAb-lkp@intel.
| com/

All warnings (new ones prefixed by >>):

   drivers/net/virtio_net.c: In function 'init_vqs':
   drivers/net/virtio_net.c:4140:36: warning: 'sprintf' may write a terminating nul past the end of the destination [-Wformat-overflow=]
      sprintf(vi->rq[i].name, "input.%u", i);
                                       ^
   drivers/net/virtio_net.c:4140:3: note: 'sprintf' output between 8 and 17 bytes into a destination of size 16
      sprintf(vi->rq[i].name, "input.%u", i);
      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>> drivers/net/virtio_net.c:4141:35: warning: '%u' directive writing 
>> between 1 and 10 bytes into a region of size 9 [-Wformat-overflow=]
      sprintf(vi->sq[i].name, "output.%u", i);
                                      ^~
   drivers/net/virtio_net.c:4141:27: note: directive argument in the range [0, 2147483647]
      sprintf(vi->sq[i].name, "output.%u", i);
                              ^~~~~~~~~~~
   drivers/net/virtio_net.c:4141:3: note: 'sprintf' output between 9 and 18 bytes into a destination of size 16
      sprintf(vi->sq[i].name, "output.%u", i);
      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Kconfig warnings: (for reference only)
   WARNING: unmet direct dependencies detected for DRM_I915_DEBUG_GEM
   Depends on [n]: HAS_IOMEM [=y] && DRM_I915 [=m] && EXPERT [=y] && DRM_I915_WERROR [=n]
   Selected by [m]:
   - DRM_I915_DEBUG [=y] && HAS_IOMEM [=y] && DRM_I915 [=m] && EXPERT [=y] && !COMPILE_TEST [=n]


vim +4141 drivers/net/virtio_net.c

  4094	
  4095	static int virtnet_find_vqs(struct virtnet_info *vi)
  4096	{
  4097		vq_callback_t **callbacks;
  4098		struct virtqueue **vqs;
  4099		const char **names;
  4100		int ret = -ENOMEM;
  4101		int total_vqs;
  4102		bool *ctx;
  4103		u16 i;
  4104	
  4105		/* We expect 1 RX virtqueue followed by 1 TX virtqueue, followed by
  4106		 * possible N-1 RX/TX queue pairs used in multiqueue mode, followed by
  4107		 * possible control vq.
  4108		 */
  4109		total_vqs = vi->max_queue_pairs * 2 +
  4110			    virtio_has_feature(vi->vdev, VIRTIO_NET_F_CTRL_VQ);
  4111	
  4112		/* Allocate space for find_vqs parameters */
  4113		vqs = kcalloc(total_vqs, sizeof(*vqs), GFP_KERNEL);
  4114		if (!vqs)
  4115			goto err_vq;
  4116		callbacks = kmalloc_array(total_vqs, sizeof(*callbacks), GFP_KERNEL);
  4117		if (!callbacks)
  4118			goto err_callback;
  4119		names = kmalloc_array(total_vqs, sizeof(*names), GFP_KERNEL);
  4120		if (!names)
  4121			goto err_names;
  4122		if (!vi->big_packets || vi->mergeable_rx_bufs) {
  4123			ctx = kcalloc(total_vqs, sizeof(*ctx), GFP_KERNEL);
  4124			if (!ctx)
  4125				goto err_ctx;
  4126		} else {
  4127			ctx = NULL;
  4128		}
  4129	
  4130		/* Parameters for control virtqueue, if any */
  4131		if (vi->has_cvq) {
  4132			callbacks[total_vqs - 1] = NULL;
  4133			names[total_vqs - 1] = "control";
  4134		}
  4135	
  4136		/* Allocate/initialize parameters for send/receive virtqueues */
  4137		for (i = 0; i < vi->max_queue_pairs; i++) {
  4138			callbacks[rxq2vq(i)] = skb_recv_done;
  4139			callbacks[txq2vq(i)] = skb_xmit_done;
  4140			sprintf(vi->rq[i].name, "input.%u", i);
> 4141			sprintf(vi->sq[i].name, "output.%u", i);
  4142			names[rxq2vq(i)] = vi->rq[i].name;
  4143			names[txq2vq(i)] = vi->sq[i].name;
  4144			if (ctx)
  4145				ctx[rxq2vq(i)] = true;
  4146		}
  4147	
  4148		ret = virtio_find_vqs_ctx(vi->vdev, total_vqs, vqs, callbacks,
  4149					  names, ctx, NULL);
  4150		if (ret)
  4151			goto err_find;
  4152	
  4153		if (vi->has_cvq) {
  4154			vi->cvq = vqs[total_vqs - 1];
  4155			if (virtio_has_feature(vi->vdev, VIRTIO_NET_F_CTRL_VLAN))
  4156				vi->dev->features |= NETIF_F_HW_VLAN_CTAG_FILTER;
  4157		}
  4158	
  4159		for (i = 0; i < vi->max_queue_pairs; i++) {
  4160			vi->rq[i].vq = vqs[rxq2vq(i)];
  4161			vi->rq[i].min_buf_len = mergeable_min_buf_len(vi, vi->rq[i].vq);
  4162			vi->sq[i].vq = vqs[txq2vq(i)];
  4163		}
  4164	
  4165		/* run here: ret == 0. */
  4166	
  4167	
  4168	err_find:
  4169		kfree(ctx);
  4170	err_ctx:
  4171		kfree(names);
  4172	err_names:
  4173		kfree(callbacks);
  4174	err_callback:
  4175		kfree(vqs);
  4176	err_vq:
  4177		return ret;
  4178	}
  4179	

--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

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

* Re: [PATCH v2 1/1] virtio_net: Fix "‘%d’ directive writing between 1 and 11 bytes into a region of size 10" warnings
  2023-12-27 14:26 [PATCH v2 1/1] virtio_net: Fix "‘%d’ directive writing between 1 and 11 bytes into a region of size 10" warnings Zhu Yanjun
  2023-12-27 14:41 ` Zhu Yanjun
  2023-12-28 13:49 ` kernel test robot
@ 2024-01-04  0:55 ` Jakub Kicinski
  2024-01-04  1:30   ` Zhu Yanjun
  2 siblings, 1 reply; 7+ messages in thread
From: Jakub Kicinski @ 2024-01-04  0:55 UTC (permalink / raw)
  To: Zhu Yanjun
  Cc: mst, jasowang, xuanzhuo, davem, edumazet, pabeni, virtualization,
	netdev, Zhu Yanjun

On Wed, 27 Dec 2023 22:26:37 +0800 Zhu Yanjun wrote:
> From: Zhu Yanjun <yanjun.zhu@linux.dev>
> 
> Fix the warnings when building virtio_net driver.

This got marked as Not Applicable in patchwork, not sure why.
Could you repost?

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

* Re: [PATCH v2 1/1] virtio_net: Fix "‘%d’ directive writing between 1 and 11 bytes into a region of size 10" warnings
  2024-01-04  0:55 ` Jakub Kicinski
@ 2024-01-04  1:30   ` Zhu Yanjun
  0 siblings, 0 replies; 7+ messages in thread
From: Zhu Yanjun @ 2024-01-04  1:30 UTC (permalink / raw)
  To: Jakub Kicinski, Zhu Yanjun
  Cc: mst, jasowang, xuanzhuo, davem, edumazet, pabeni, virtualization,
	netdev


在 2024/1/4 8:55, Jakub Kicinski 写道:
> On Wed, 27 Dec 2023 22:26:37 +0800 Zhu Yanjun wrote:
>> From: Zhu Yanjun <yanjun.zhu@linux.dev>
>>
>> Fix the warnings when building virtio_net driver.
> This got marked as Not Applicable in patchwork, not sure why.
> Could you repost?

Got it. I will resend this commit very soon.

Best Regards,

Zhu Yanjun


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

end of thread, other threads:[~2024-01-04  1:31 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-12-27 14:26 [PATCH v2 1/1] virtio_net: Fix "‘%d’ directive writing between 1 and 11 bytes into a region of size 10" warnings Zhu Yanjun
2023-12-27 14:41 ` Zhu Yanjun
2023-12-28  1:26   ` Xuan Zhuo
2023-12-28 13:49 ` kernel test robot
2023-12-29  4:44   ` Zhu, Yanjun
2024-01-04  0:55 ` Jakub Kicinski
2024-01-04  1:30   ` Zhu Yanjun

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.