Skip to contentSkip to conversation

KEYS: Replace all non-returning strlcpy with strscpy

PATCH Applied Azeem Shaikh 4 participants 7 messages May 18, 2023 – May 24, 2023

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

PATCH 1/1 KEYS: Replace all non-returning strlcpy with strscpy

strlcpy() reads the entire source buffer first. This read may exceed the destination size limit. This is both inefficient and can lead to linear read overflows if a source string is not NUL-terminated [1]. In an effort to remove strlcpy() completely [2], replace strlcpy() here with strscpy().
No return values were used, so direct replacement is safe.

[1] https://www.kernel.org/doc/html/latest/process/deprecated.html#strlcpy
[2] https://github.com/KSPP/linux/issues/89

---
 security/keys/request_key_auth.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
security/keys/request_key_auth.c +1 -1
index 41e9735006d0..8f33cd170e42 100644
@@ -178,7 +178,7 @@ struct key *request_key_auth_new(struct key *target, const char *op,
 	if (!rka->callout_info)
 		goto error_free_rka;
 	rka->callout_len = callout_len;
-	strlcpy(rka->op, op, sizeof(rka->op));
+	strscpy(rka->op, op, sizeof(rka->op));
 
 	/* see if the calling process is already servicing the key request of
 	 * another process */
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 20 lines · Azeem Shaikh

strlcpy() reads the entire source buffer first. This read may exceed the destination size limit. This is both inefficient and can lead to linear read
overflows if a source string is not NUL-terminated [1].
In an effort to remove strlcpy() completely [2], replace
strlcpy() here with strscpy().
No return values were used, so direct replacement is safe.

[1] https://www.kernel.org/doc/html/latest/process/deprecated.html#strlcpy
[2] https://github.com/KSPP/linux/issues/89

---
 security/keys/request_key_auth.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
security/keys/request_key_auth.c +0 -0
index 41e9735006d0..8f33cd170e42 100644

security/keys/request_key_auth.c struct key *request_key_auth_new(struct key *target, const char *op, · line 184

Quoted 8 lines
security/keys/request_key_auth.c +1 -1
@@ -178,7 +178,7 @@ struct key *request_key_auth_new(struct key *target, const char *op,
 	if (!rka->callout_info)
 		goto error_free_rka;
 	rka->callout_len = callout_len;
-	strlcpy(rka->op, op, sizeof(rka->op));
+	strscpy(rka->op, op, sizeof(rka->op));
 
 	/* see if the calling process is already servicing the key request of
 	 * another process */

BR, Jarkko

maintainer Reviewed-by on v1 1/1
#2 lore raw
In reply to Azeem Shaikh
Quoted 21 lines · Azeem Shaikh

strlcpy() reads the entire source buffer first. This read may exceed the destination size limit. This is both inefficient and can lead to linear read overflows if a source string is not NUL-terminated [1]. In an effort to remove strlcpy() completely [2], replace strlcpy() here with strscpy().
No return values were used, so direct replacement is safe.

[1] https://www.kernel.org/doc/html/latest/process/deprecated.html#strlcpy
[2] https://github.com/KSPP/linux/issues/89

---
 security/keys/request_key_auth.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
security/keys/request_key_auth.c +0 -0
index 41e9735006d0..8f33cd170e42 100644

security/keys/request_key_auth.c struct key *request_key_auth_new(struct key *target, const char *op, · line 184

Quoted 8 lines
security/keys/request_key_auth.c +1 -1
@@ -178,7 +178,7 @@ struct key *request_key_auth_new(struct key *target, const char *op,
 	if (!rka->callout_info)
 		goto error_free_rka;
 	rka->callout_len = callout_len;
-	strlcpy(rka->op, op, sizeof(rka->op));
+	strscpy(rka->op, op, sizeof(rka->op));
 
 	/* see if the calling process is already servicing the key request of
 	 * another process */

BR, Jarkko

maintainer
#3 lore raw
Quoted 28 lines · Jarkko Sakkinen
Quoted 27 lines · Azeem Shaikh

strlcpy() reads the entire source buffer first. This read may exceed the destination size limit. This is both inefficient and can lead to linear read overflows if a source string is not NUL-terminated [1]. In an effort to remove strlcpy() completely [2], replace strlcpy() here with strscpy().
No return values were used, so direct replacement is safe.

[1] https://www.kernel.org/doc/html/latest/process/deprecated.html#strlcpy
[2] https://github.com/KSPP/linux/issues/89

---
 security/keys/request_key_auth.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
security/keys/request_key_auth.c +1 -1
index 41e9735006d0..8f33cd170e42 100644
@@ -178,7 +178,7 @@ struct key *request_key_auth_new(struct key *target, const char *op,
      if (!rka->callout_info)
              goto error_free_rka;
      rka->callout_len = callout_len;
-     strlcpy(rka->op, op, sizeof(rka->op));
+     strscpy(rka->op, op, sizeof(rka->op));
 
Quoted 5 lines

security/keys/request_key_auth.c struct key *request_key_auth_new(struct key *target, const char *op, · line 184

Quoted 2 lines
security/keys/request_key_auth.c +0 -0
      /* see if the calling process is already servicing the key request of
       * another process */

Since you maintain this code Jarkko, are you planning to merge this into your tree or would you prefer the KSPP folks merge it?

Signature · 1 line
paul-moore.com
maintainer
#4 lore raw
Quoted 29 lines · Paul Moore
Quoted 28 lines · Jarkko Sakkinen
Quoted 27 lines · Azeem Shaikh

strlcpy() reads the entire source buffer first. This read may exceed the destination size limit. This is both inefficient and can lead to linear read overflows if a source string is not NUL-terminated [1]. In an effort to remove strlcpy() completely [2], replace strlcpy() here with strscpy().
No return values were used, so direct replacement is safe.

[1] https://www.kernel.org/doc/html/latest/process/deprecated.html#strlcpy
[2] https://github.com/KSPP/linux/issues/89

---
 security/keys/request_key_auth.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
security/keys/request_key_auth.c +1 -1
index 41e9735006d0..8f33cd170e42 100644
@@ -178,7 +178,7 @@ struct key *request_key_auth_new(struct key *target, const char *op,
      if (!rka->callout_info)
              goto error_free_rka;
      rka->callout_len = callout_len;
-     strlcpy(rka->op, op, sizeof(rka->op));
+     strscpy(rka->op, op, sizeof(rka->op));
 
Quoted 8 lines
Quoted 5 lines

security/keys/request_key_auth.c struct key *request_key_auth_new(struct key *target, const char *op, · line 184

Quoted 2 lines
security/keys/request_key_auth.c +0 -0
      /* see if the calling process is already servicing the key request of
       * another process */

Since you maintain this code Jarkko, are you planning to merge this into your tree or would you prefer the KSPP folks merge it?

I can pick it.

BR, Jarkko

maintainer Applied
#5 lore raw
Quoted 36 lines · Jarkko Sakkinen
Quoted 35 lines · Paul Moore
Quoted 33 lines · Jarkko Sakkinen
Quoted 21 lines · Azeem Shaikh

strlcpy() reads the entire source buffer first. This read may exceed the destination size limit. This is both inefficient and can lead to linear read overflows if a source string is not NUL-terminated [1]. In an effort to remove strlcpy() completely [2], replace strlcpy() here with strscpy().
No return values were used, so direct replacement is safe.

[1] https://www.kernel.org/doc/html/latest/process/deprecated.html#strlcpy
[2] https://github.com/KSPP/linux/issues/89

---
 security/keys/request_key_auth.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
security/keys/request_key_auth.c +0 -0
index 41e9735006d0..8f33cd170e42 100644

security/keys/request_key_auth.c struct key *request_key_auth_new(struct key *target, const char *op, · line 184

Quoted 8 lines
security/keys/request_key_auth.c +1 -1
@@ -178,7 +178,7 @@ struct key *request_key_auth_new(struct key *target, const char *op,
      if (!rka->callout_info)
              goto error_free_rka;
      rka->callout_len = callout_len;
-     strlcpy(rka->op, op, sizeof(rka->op));
+     strscpy(rka->op, op, sizeof(rka->op));
 
      /* see if the calling process is already servicing the key request of
       * another process */
Quoted 4 lines
Quoted 2 lines

Since you maintain this code Jarkko, are you planning to merge this into your tree or would you prefer the KSPP folks merge it?

I can pick it.

Applied.

BR, Jarkko

Applied
#6 lore raw
In reply to Azeem Shaikh
Quoted 9 lines · Azeem Shaikh

strlcpy() reads the entire source buffer first. This read may exceed the destination size limit. This is both inefficient and can lead to linear read overflows if a source string is not NUL-terminated [1]. In an effort to remove strlcpy() completely [2], replace strlcpy() here with strscpy().
No return values were used, so direct replacement is safe.

[...]

Applied to for-next/hardening, thanks!

[1/1] KEYS: Replace all non-returning strlcpy with strscpy

      https://git.kernel.org/kees/c/8d27fcac4a08
Signature · 1 line
Kees Cook