Skip to contentSkip to conversation

inifiniband: ucaps: avoid format-security warning

PATCH Applied Arnd Bergmann 4 participants 5 messages Mar 14, 2025 – Apr 7, 2025 InfiniBand

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 inifiniband: ucaps: avoid format-security warning

From: Arnd Bergmann <[email protected]>

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")
---
 drivers/infiniband/core/ucaps.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/infiniband/core/ucaps.c +1 -1
index 6853c6d078f9..de5cb8bf0a61 100644
@@ -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;
 
Signature · 1 line
2.39.5
Reviewed-by on v1 1/1
#1 lore raw
Quoted 12 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

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",
Quoted 3 lines

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.

Zhu Yanjun

Quoted 18 lines
---
  drivers/infiniband/core/ucaps.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/infiniband/core/ucaps.c +1 -1
index 6853c6d078f9..de5cb8bf0a61 100644
@@ -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;
 
Signature · 2 lines
Best Regards,
Yanjun.Zhu
#2 lore raw
In reply to Arnd Bergmann
Quoted 12 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

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",
Quoted 7 lines

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

Fixes 61e51682816d ("RDMA/uverbs: Introduce UCAP (User CAPabilities) API")
---
 drivers/infiniband/core/ucaps.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

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

drivers/infiniband/core/ucaps.c +1 -1
index 6853c6d078f9..90ac41bc0f07 100644
@@ -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

Quoted 17 lines
drivers/infiniband/core/ucaps.c +1 -1
index 6853c6d078f9..de5cb8bf0a61 100644
@@ -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;
 
Signature · 1 line
2.39.5
maintainer Reviewed-by
#3 lore raw
Quoted 28 lines · Leon Romanovsky
Quoted 12 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

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",
Quoted 7 lines

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

Fixes 61e51682816d ("RDMA/uverbs: Introduce UCAP (User CAPabilities) API")
---
 drivers/infiniband/core/ucaps.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

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

drivers/infiniband/core/ucaps.c +0 -0
index 6853c6d078f9..90ac41bc0f07 100644

drivers/infiniband/core/ucaps.c struct ib_ucap { · line 29

Quoted 8 lines
drivers/infiniband/core/ucaps.c +1 -1
@@ -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.

For both

Jason

maintainer Applied
#4 lore raw
In reply to Arnd Bergmann
Quoted 14 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

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.

Quoted 7 lines
Fixes 61e51682816d ("RDMA/uverbs: Introduce UCAP (User CAPabilities) API")
---
 drivers/infiniband/core/ucaps.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Applied to for-rc, thanks

Jason