public inbox for linux-rdma@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] inifiniband: ucaps: avoid format-security warning
@ 2025-03-14 15:57 Arnd Bergmann
  2025-03-14 19:05 ` Zhu Yanjun
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Arnd Bergmann @ 2025-03-14 15:57 UTC (permalink / raw)
  To: Jason Gunthorpe, Leon Romanovsky, Yishai Hadas, Zhu Yanjun,
	Chiara Meiohas
  Cc: Arnd Bergmann, linux-rdma, linux-kernel

From: Arnd Bergmann <arnd@arndb.de>

Passing a non-constant format string to dev_set_name causes a warning:

drivers/infiniband/core/ucaps.c:173:33: error: format string is not a string literal (potentially insecure) [-Werror,-Wformat-security]
  173 |         ret = dev_set_name(&ucap->dev, ucap_names[type]);
      |                                        ^~~~~~~~~~~~~~~~
drivers/infiniband/core/ucaps.c:173:33: note: treat the string as an argument to avoid this
  173 |         ret = dev_set_name(&ucap->dev, ucap_names[type]);
      |                                        ^
      |                                        "%s",

Turn the name into thet %s argument as suggested by gcc.

Fixes: 61e51682816d ("RDMA/uverbs: Introduce UCAP (User CAPabilities) API")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 drivers/infiniband/core/ucaps.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/infiniband/core/ucaps.c b/drivers/infiniband/core/ucaps.c
index 6853c6d078f9..de5cb8bf0a61 100644
--- a/drivers/infiniband/core/ucaps.c
+++ b/drivers/infiniband/core/ucaps.c
@@ -170,7 +170,7 @@ int ib_create_ucap(enum rdma_user_cap type)
 	ucap->dev.class = &ucaps_class;
 	ucap->dev.devt = MKDEV(MAJOR(ucaps_base_dev), type);
 	ucap->dev.release = ucap_dev_release;
-	ret = dev_set_name(&ucap->dev, ucap_names[type]);
+	ret = dev_set_name(&ucap->dev, "%s", ucap_names[type]);
 	if (ret)
 		goto err_device;
 
-- 
2.39.5


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

* Re: [PATCH] inifiniband: ucaps: avoid format-security warning
  2025-03-14 15:57 [PATCH] inifiniband: ucaps: avoid format-security warning Arnd Bergmann
@ 2025-03-14 19:05 ` Zhu Yanjun
  2025-03-17 11:50 ` Leon Romanovsky
  2025-04-07 17:56 ` Jason Gunthorpe
  2 siblings, 0 replies; 5+ messages in thread
From: Zhu Yanjun @ 2025-03-14 19:05 UTC (permalink / raw)
  To: Arnd Bergmann, Jason Gunthorpe, Leon Romanovsky, Yishai Hadas,
	Chiara Meiohas
  Cc: Arnd Bergmann, linux-rdma, linux-kernel


在 2025/3/14 16:57, Arnd Bergmann 写道:
> From: Arnd Bergmann <arnd@arndb.de>
>
> Passing a non-constant format string to dev_set_name causes a warning:
>
> drivers/infiniband/core/ucaps.c:173:33: error: format string is not a string literal (potentially insecure) [-Werror,-Wformat-security]
>    173 |         ret = dev_set_name(&ucap->dev, ucap_names[type]);
>        |                                        ^~~~~~~~~~~~~~~~
> drivers/infiniband/core/ucaps.c:173:33: note: treat the string as an argument to avoid this
>    173 |         ret = dev_set_name(&ucap->dev, ucap_names[type]);
>        |                                        ^
>        |                                        "%s",
>
> Turn the name into thet %s argument as suggested by gcc.
>
> Fixes: 61e51682816d ("RDMA/uverbs: Introduce UCAP (User CAPabilities) API")

This patch should be for linux-next. In the subject, linux-next should 
be added.

Except the above, I am fine with this commit.

Reviewed-by: Zhu Yanjun <yanjun.zhu@linux.dev>

Zhu Yanjun

> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> ---
>   drivers/infiniband/core/ucaps.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/infiniband/core/ucaps.c b/drivers/infiniband/core/ucaps.c
> index 6853c6d078f9..de5cb8bf0a61 100644
> --- a/drivers/infiniband/core/ucaps.c
> +++ b/drivers/infiniband/core/ucaps.c
> @@ -170,7 +170,7 @@ int ib_create_ucap(enum rdma_user_cap type)
>   	ucap->dev.class = &ucaps_class;
>   	ucap->dev.devt = MKDEV(MAJOR(ucaps_base_dev), type);
>   	ucap->dev.release = ucap_dev_release;
> -	ret = dev_set_name(&ucap->dev, ucap_names[type]);
> +	ret = dev_set_name(&ucap->dev, "%s", ucap_names[type]);
>   	if (ret)
>   		goto err_device;
>   

-- 
Best Regards,
Yanjun.Zhu


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

* Re: [PATCH] inifiniband: ucaps: avoid format-security warning
  2025-03-14 15:57 [PATCH] inifiniband: ucaps: avoid format-security warning Arnd Bergmann
  2025-03-14 19:05 ` Zhu Yanjun
@ 2025-03-17 11:50 ` Leon Romanovsky
  2025-04-01 16:28   ` Jason Gunthorpe
  2025-04-07 17:56 ` Jason Gunthorpe
  2 siblings, 1 reply; 5+ messages in thread
From: Leon Romanovsky @ 2025-03-17 11:50 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Jason Gunthorpe, Yishai Hadas, Zhu Yanjun, Chiara Meiohas,
	Arnd Bergmann, linux-rdma, linux-kernel

On Fri, Mar 14, 2025 at 04:57:15PM +0100, Arnd Bergmann wrote:
> From: Arnd Bergmann <arnd@arndb.de>
> 
> Passing a non-constant format string to dev_set_name causes a warning:
> 
> drivers/infiniband/core/ucaps.c:173:33: error: format string is not a string literal (potentially insecure) [-Werror,-Wformat-security]
>   173 |         ret = dev_set_name(&ucap->dev, ucap_names[type]);
>       |                                        ^~~~~~~~~~~~~~~~
> drivers/infiniband/core/ucaps.c:173:33: note: treat the string as an argument to avoid this
>   173 |         ret = dev_set_name(&ucap->dev, ucap_names[type]);
>       |                                        ^
>       |                                        "%s",
> 
> Turn the name into thet %s argument as suggested by gcc.
> 
> Fixes: 61e51682816d ("RDMA/uverbs: Introduce UCAP (User CAPabilities) API")
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> ---
>  drivers/infiniband/core/ucaps.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Why don't you change ucap_names[] declaration instead?

diff --git a/drivers/infiniband/core/ucaps.c b/drivers/infiniband/core/ucaps.c
index 6853c6d078f9..90ac41bc0f07 100644
--- a/drivers/infiniband/core/ucaps.c
+++ b/drivers/infiniband/core/ucaps.c
@@ -23,7 +23,7 @@ struct ib_ucap {
        struct kref ref;
 };

-static const char *ucap_names[RDMA_UCAP_MAX] = {
+static const char *const ucap_names[RDMA_UCAP_MAX] = {
        [RDMA_UCAP_MLX5_CTRL_LOCAL] = "mlx5_perm_ctrl_local",
        [RDMA_UCAP_MLX5_CTRL_OTHER_VHCA] = "mlx5_perm_ctrl_other_vhca"
 };
(END)

Thanks

> 
> diff --git a/drivers/infiniband/core/ucaps.c b/drivers/infiniband/core/ucaps.c
> index 6853c6d078f9..de5cb8bf0a61 100644
> --- a/drivers/infiniband/core/ucaps.c
> +++ b/drivers/infiniband/core/ucaps.c
> @@ -170,7 +170,7 @@ int ib_create_ucap(enum rdma_user_cap type)
>  	ucap->dev.class = &ucaps_class;
>  	ucap->dev.devt = MKDEV(MAJOR(ucaps_base_dev), type);
>  	ucap->dev.release = ucap_dev_release;
> -	ret = dev_set_name(&ucap->dev, ucap_names[type]);
> +	ret = dev_set_name(&ucap->dev, "%s", ucap_names[type]);
>  	if (ret)
>  		goto err_device;
>  
> -- 
> 2.39.5
> 

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

* Re: [PATCH] inifiniband: ucaps: avoid format-security warning
  2025-03-17 11:50 ` Leon Romanovsky
@ 2025-04-01 16:28   ` Jason Gunthorpe
  0 siblings, 0 replies; 5+ messages in thread
From: Jason Gunthorpe @ 2025-04-01 16:28 UTC (permalink / raw)
  To: Leon Romanovsky
  Cc: Arnd Bergmann, Yishai Hadas, Zhu Yanjun, Chiara Meiohas,
	Arnd Bergmann, linux-rdma, linux-kernel

On Mon, Mar 17, 2025 at 01:50:00PM +0200, Leon Romanovsky wrote:
> On Fri, Mar 14, 2025 at 04:57:15PM +0100, Arnd Bergmann wrote:
> > From: Arnd Bergmann <arnd@arndb.de>
> > 
> > Passing a non-constant format string to dev_set_name causes a warning:
> > 
> > drivers/infiniband/core/ucaps.c:173:33: error: format string is not a string literal (potentially insecure) [-Werror,-Wformat-security]
> >   173 |         ret = dev_set_name(&ucap->dev, ucap_names[type]);
> >       |                                        ^~~~~~~~~~~~~~~~
> > drivers/infiniband/core/ucaps.c:173:33: note: treat the string as an argument to avoid this
> >   173 |         ret = dev_set_name(&ucap->dev, ucap_names[type]);
> >       |                                        ^
> >       |                                        "%s",
> > 
> > Turn the name into thet %s argument as suggested by gcc.
> > 
> > Fixes: 61e51682816d ("RDMA/uverbs: Introduce UCAP (User CAPabilities) API")
> > Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> > ---
> >  drivers/infiniband/core/ucaps.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> Why don't you change ucap_names[] declaration instead?
> 
> diff --git a/drivers/infiniband/core/ucaps.c b/drivers/infiniband/core/ucaps.c
> index 6853c6d078f9..90ac41bc0f07 100644
> --- a/drivers/infiniband/core/ucaps.c
> +++ b/drivers/infiniband/core/ucaps.c
> @@ -23,7 +23,7 @@ struct ib_ucap {
>         struct kref ref;
>  };
> 
> -static const char *ucap_names[RDMA_UCAP_MAX] = {
> +static const char *const ucap_names[RDMA_UCAP_MAX] = {
>         [RDMA_UCAP_MLX5_CTRL_LOCAL] = "mlx5_perm_ctrl_local",
>         [RDMA_UCAP_MLX5_CTRL_OTHER_VHCA] = "mlx5_perm_ctrl_other_vhca"
>  };

This should be done anyone, but it won't fix the warning. gcc is
worried that the format string could have an embedded "%XXX" or
something that would cause stack corruption. It is a security error to
push user controlled data into the format string. This isn't happening
here, but silencing gcc will need the %s.

Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>

For both

Jason

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

* Re: [PATCH] inifiniband: ucaps: avoid format-security warning
  2025-03-14 15:57 [PATCH] inifiniband: ucaps: avoid format-security warning Arnd Bergmann
  2025-03-14 19:05 ` Zhu Yanjun
  2025-03-17 11:50 ` Leon Romanovsky
@ 2025-04-07 17:56 ` Jason Gunthorpe
  2 siblings, 0 replies; 5+ messages in thread
From: Jason Gunthorpe @ 2025-04-07 17:56 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Leon Romanovsky, Yishai Hadas, Zhu Yanjun, Chiara Meiohas,
	Arnd Bergmann, linux-rdma, linux-kernel

On Fri, Mar 14, 2025 at 04:57:15PM +0100, Arnd Bergmann wrote:
> From: Arnd Bergmann <arnd@arndb.de>
> 
> Passing a non-constant format string to dev_set_name causes a warning:
> 
> drivers/infiniband/core/ucaps.c:173:33: error: format string is not a string literal (potentially insecure) [-Werror,-Wformat-security]
>   173 |         ret = dev_set_name(&ucap->dev, ucap_names[type]);
>       |                                        ^~~~~~~~~~~~~~~~
> drivers/infiniband/core/ucaps.c:173:33: note: treat the string as an argument to avoid this
>   173 |         ret = dev_set_name(&ucap->dev, ucap_names[type]);
>       |                                        ^
>       |                                        "%s",
> 
> Turn the name into thet %s argument as suggested by gcc.
> 
> Fixes: 61e51682816d ("RDMA/uverbs: Introduce UCAP (User CAPabilities) API")
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> Reviewed-by: Zhu Yanjun <yanjun.zhu@linux.dev>
> Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
> ---
>  drivers/infiniband/core/ucaps.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Applied to for-rc, thanks

Jason

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

end of thread, other threads:[~2025-04-07 17:56 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-14 15:57 [PATCH] inifiniband: ucaps: avoid format-security warning Arnd Bergmann
2025-03-14 19:05 ` Zhu Yanjun
2025-03-17 11:50 ` Leon Romanovsky
2025-04-01 16:28   ` Jason Gunthorpe
2025-04-07 17:56 ` Jason Gunthorpe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox