Skip to contentSkip to conversation

xfrm: replace deprecated strncpy with strscpy_pad

PATCH Applied Daniel Yang 3 participants 4 messages Nov 13, 2024 – Nov 15, 2024

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

PATCH 1/1 xfrm: replace deprecated strncpy with strscpy_pad

The function strncpy is deprecated since it does not guarantee the destination buffer is NULL terminated. Recommended replacement is strscpy. The padded version was used to remain consistent with the other strscpy_pad usage in the modified function.

---
 net/xfrm/xfrm_user.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/xfrm/xfrm_user.c +1 -1
index e3b8ce898..085f68e35 100644
@@ -1089,7 +1089,7 @@ static int copy_to_user_auth(struct xfrm_algo_auth *auth, struct sk_buff *skb)
 	if (!nla)
 		return -EMSGSIZE;
 	algo = nla_data(nla);
-	strncpy(algo->alg_name, auth->alg_name, sizeof(algo->alg_name));
+	strscpy_pad(algo->alg_name, auth->alg_name, sizeof(algo->alg_name));
 
 	if (redact_secret && auth->alg_key_len)
 		memset(algo->alg_key, 0, (auth->alg_key_len + 7) / 8);
Signature · 1 line
2.39.5
maintainer
#1 lore raw
Quoted 15 lines · Daniel Yang

The function strncpy is deprecated since it does not guarantee the destination buffer is NULL terminated. Recommended replacement is strscpy. The padded version was used to remain consistent with the other strscpy_pad usage in the modified function.

---
 net/xfrm/xfrm_user.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/xfrm/xfrm_user.c +0 -0
index e3b8ce898..085f68e35 100644

net/xfrm/xfrm_user.c static int copy_to_user_auth(struct xfrm_algo_auth *auth, struct sk_buff *skb) · line 1095

Quoted 8 lines
net/xfrm/xfrm_user.c +1 -1
@@ -1089,7 +1089,7 @@ static int copy_to_user_auth(struct xfrm_algo_auth *auth, struct sk_buff *skb)
 	if (!nla)
 		return -EMSGSIZE;
 	algo = nla_data(nla);
-	strncpy(algo->alg_name, auth->alg_name, sizeof(algo->alg_name));
+	strscpy_pad(algo->alg_name, auth->alg_name, sizeof(algo->alg_name));
 
 	if (redact_secret && auth->alg_key_len)
 		memset(algo->alg_key, 0, (auth->alg_key_len + 7) / 8);

@Steffen, @Herbert: I think this should go via your tree despite the prefix tag.

Please LMK otherwise!

Thanks,

Paolo

maintainer
#2 lore raw
Quoted 22 lines · Paolo Abeni
Quoted 21 lines · Daniel Yang

The function strncpy is deprecated since it does not guarantee the destination buffer is NULL terminated. Recommended replacement is strscpy. The padded version was used to remain consistent with the other strscpy_pad usage in the modified function.

---
 net/xfrm/xfrm_user.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/xfrm/xfrm_user.c +1 -1
index e3b8ce898..085f68e35 100644
@@ -1089,7 +1089,7 @@ static int copy_to_user_auth(struct xfrm_algo_auth *auth, struct sk_buff *skb)
 	if (!nla)
 		return -EMSGSIZE;
 	algo = nla_data(nla);
-	strncpy(algo->alg_name, auth->alg_name, sizeof(algo->alg_name));
+	strscpy_pad(algo->alg_name, auth->alg_name, sizeof(algo->alg_name));
 
Quoted 5 lines

net/xfrm/xfrm_user.c static int copy_to_user_auth(struct xfrm_algo_auth *auth, struct sk_buff *skb) · line 1095

Quoted 2 lines
net/xfrm/xfrm_user.c +0 -0
 	if (redact_secret && auth->alg_key_len)
 		memset(algo->alg_key, 0, (auth->alg_key_len + 7) / 8);

@Steffen, @Herbert: I think this should go via your tree despite the prefix tag.

I'll take it into ipsec-next.

Thanks!

maintainer Applied
#3 lore raw
In reply to Daniel Yang
Quoted 6 lines · Daniel Yang

The function strncpy is deprecated since it does not guarantee the destination buffer is NULL terminated. Recommended replacement is strscpy. The padded version was used to remain consistent with the other strscpy_pad usage in the modified function.

Applied to ipsec-next, thanks!