Skip to contentSkip to conversation

devlink/param: replace deprecated strcpy() with strscpy()

PATCH In review Álvaro Costa 3 participants 6 messages May 6 – May 7

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 devlink/param: replace deprecated strcpy() with strscpy()

Replace strcpy() call used to extract a string parameter from param_data with strscpy(). Since strscpy() already performs bounds checking and ensures the destination string is NUL-terminated, remove the string length check as well.

---
 net/devlink/param.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
net/devlink/param.c +2 -4
index cf95268da5b0..26695b7e2861 100644
@@ -536,11 +536,9 @@ devlink_param_value_get_from_info(const struct devlink_param *param,
 		value->vu64 = nla_get_u64(param_data);
 		break;
 	case DEVLINK_PARAM_TYPE_STRING:
-		len = strnlen(nla_data(param_data), nla_len(param_data));
-		if (len == nla_len(param_data) ||
-		    len >= __DEVLINK_PARAM_MAX_STRING_VALUE)
+		len = strscpy(value->vstr, nla_data(param_data));
+		if (len < 0)
 			return -EINVAL;
-		strcpy(value->vstr, nla_data(param_data));
 		break;
 	case DEVLINK_PARAM_TYPE_BOOL:
 		if (param_data && nla_len(param_data))
Signature · 1 line
2.53.0
maintainer
#1 lore raw
Quoted 4 lines · On Wed, 6 May 2026 18:14:11 -0300 Álvaro Costa wrote:

Replace strcpy() call used to extract a string parameter from param_data with strscpy(). Since strscpy() already performs bounds checking and ensures the destination string is NUL-terminated, remove the string length check as well.

The current code validates the netlink attr is nul-terminated. I'm not sure if your patch retains current behavior. I am sure, however, that checking whether the change is correct is a poor use of everyone's time.
Please don't send these sort of patches for networking.

Signature · 1 line
pw-bot: reject
#2 lore raw
Quoted 7 lines · Jakub Kicinski

The current code validates the netlink attr is nul-terminated. I'm not sure if your patch retains current behavior. I am sure, however, that checking whether the change is correct is a poor use of everyone's time.
Please don't send these sort of patches for networking. --
pw-bot: reject

Ok, thank you for the quick feedback!

#3 lore raw
In reply to Álvaro Costa
Quoted 15 lines · On Wed, 6 May 2026 18:14:11 -0300 Álvaro Costa <[email protected]> wrote:

Replace strcpy() call used to extract a string parameter from param_data with strscpy(). Since strscpy() already performs bounds checking and ensures the destination string is NUL-terminated, remove the string length check as well.

---
 net/devlink/param.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
net/devlink/param.c +0 -0
index cf95268da5b0..26695b7e2861 100644

net/devlink/param.c devlink_param_value_get_from_info(const struct devlink_param *param, · line 543

Quoted 10 lines
net/devlink/param.c +2 -4
@@ -536,11 +536,9 @@ devlink_param_value_get_from_info(const struct devlink_param *param,
 		value->vu64 = nla_get_u64(param_data);
 		break;
 	case DEVLINK_PARAM_TYPE_STRING:
-		len = strnlen(nla_data(param_data), nla_len(param_data));
-		if (len == nla_len(param_data) ||
-		    len >= __DEVLINK_PARAM_MAX_STRING_VALUE)
+		len = strscpy(value->vstr, nla_data(param_data));
+		if (len < 0)
 			return -EINVAL;
-		strcpy(value->vstr, nla_data(param_data));

The only sensible thing here is to replace the strcpy() with:

		memcpy(value->vstr, nla_data(param_data), len + 1);

-- David

Quoted 3 lines
net/devlink/param.c +0 -0
 		break;
 	case DEVLINK_PARAM_TYPE_BOOL:
 		if (param_data && nla_len(param_data))
maintainer
#4 lore raw
Quoted 11 lines · On Thu, 7 May 2026 09:04:45 +0100 David Laight wrote:

net/devlink/param.c devlink_param_value_get_from_info(const struct devlink_param *param, · line 543

Quoted 8 lines
net/devlink/param.c +2 -4
 	case DEVLINK_PARAM_TYPE_STRING:
-		len = strnlen(nla_data(param_data), nla_len(param_data));
-		if (len == nla_len(param_data) ||
-		    len >= __DEVLINK_PARAM_MAX_STRING_VALUE)
+		len = strscpy(value->vstr, nla_data(param_data));
+		if (len < 0)
 			return -EINVAL;
-		strcpy(value->vstr, nla_data(param_data));  

The only sensible thing here is to replace the strcpy() with:

		memcpy(value->vstr, nla_data(param_data), len + 1);

That'd probably be a good move, to avoid getting the broken strscpy() conversion submissions. Care to send a patch?

#5 lore raw
Quoted 13 lines · On Thu, 7 May 2026 07:52:34 -0700 Jakub Kicinski <[email protected]> wrote:
Quoted 11 lines · On Thu, 7 May 2026 09:04:45 +0100 David Laight wrote:

net/devlink/param.c devlink_param_value_get_from_info(const struct devlink_param *param, · line 543

Quoted 8 lines
net/devlink/param.c +2 -4
 	case DEVLINK_PARAM_TYPE_STRING:
-		len = strnlen(nla_data(param_data), nla_len(param_data));
-		if (len == nla_len(param_data) ||
-		    len >= __DEVLINK_PARAM_MAX_STRING_VALUE)
+		len = strscpy(value->vstr, nla_data(param_data));
+		if (len < 0)
 			return -EINVAL;
-		strcpy(value->vstr, nla_data(param_data));    

The only sensible thing here is to replace the strcpy() with:

		memcpy(value->vstr, nla_data(param_data), len + 1);  
Quoted 2 lines

That'd probably be a good move, to avoid getting the broken strscpy() conversion submissions. Care to send a patch?

I'll lob one in soon.

I'm working my way through a compile that errors strcpy() except for constant strings into arrays (ie the safe ones).
Why is it that the worst examples is in the 'secerity code' :-)

-- David