KEYS: Replace all non-returning strlcpy with strscpy
Subsystems (2)
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
@@ -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 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 removestrlcpy()completely [2], replacestrlcpy()here withstrscpy().
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/89Signed-off-by Azeem Shaikh <[email protected]>--- security/keys/request_key_auth.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)security/keys/request_key_auth.c +0
-0
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
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 removestrlcpy()completely [2], replacestrlcpy()here withstrscpy().
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/89Signed-off-by Azeem Shaikh <[email protected]>--- security/keys/request_key_auth.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)security/keys/request_key_auth.c +0
-0
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
Paul Moore
maintainerQuoted 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 removestrlcpy()completely [2], replacestrlcpy()here withstrscpy().
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/89Signed-off-by Azeem Shaikh <[email protected]>--- security/keys/request_key_auth.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)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));
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 */ Reviewed-by Jarkko Sakkinen <[email protected]>
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
Jarkko Sakkinen
maintainerQuoted 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 removestrlcpy()completely [2], replacestrlcpy()here withstrscpy().
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/89Signed-off-by Azeem Shaikh <[email protected]>--- security/keys/request_key_auth.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)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));
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 */ Reviewed-by Jarkko Sakkinen <[email protected]>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
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 removestrlcpy()completely [2], replacestrlcpy()here withstrscpy().
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/89Signed-off-by Azeem Shaikh <[email protected]>--- security/keys/request_key_auth.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)security/keys/request_key_auth.c +0
-0security/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 */ Reviewed-by Jarkko Sakkinen <[email protected]>
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
Kees Cook
AppliedQuoted 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 removestrlcpy()completely [2], replacestrlcpy()here withstrscpy().
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