dlm: Replace all non-returning strlcpy with strscpy
PATCH 1/1 dlm: 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
--- fs/dlm/config.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
fs/dlm/config.c +2 -2
@@ -116,9 +116,9 @@ static ssize_t cluster_cluster_name_store(struct config_item *item, {struct dlm_cluster *cl =config_item_to_cluster (item); -strlcpy (dlm_config.ci_cluster_name, buf, +strscpy (dlm_config.ci_cluster_name, buf,sizeof (dlm_config.ci_cluster_name)); -strlcpy (cl->cl_cluster_name, buf,sizeof (cl->cl_cluster_name)); +strscpy (cl->cl_cluster_name, buf,sizeof (cl->cl_cluster_name));return len; }
Quoted 8 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.
Quoted 4 lines
[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]>
Signature · 1 line
Kees Cook
Quoted 13 lines · On Thu, May 11, 2023 at 12:26?PM Kees Cook <[email protected]> wrote:
Quoted 11 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/89
Quoted 6 lines
Quoted 1 line
Signed-off-by Azeem Shaikh <[email protected]>Reviewed-by Kees Cook <[email protected]>--
Kees Cook
Friendly ping on this.
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] dlm: Replace all non-returning strlcpy with strscpy
https://git.kernel.org/kees/c/30ad0627f169
Signature · 1 line
Kees Cook