linux-hardening.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] cgroup: Replace all non-returning strlcpy with strscpy
@ 2023-05-17 14:49 Azeem Shaikh
  2023-05-17 19:14 ` Kees Cook
  2023-05-22 19:06 ` Tejun Heo
  0 siblings, 2 replies; 3+ messages in thread
From: Azeem Shaikh @ 2023-05-17 14:49 UTC (permalink / raw)
  To: Tejun Heo, Zefan Li, Johannes Weiner
  Cc: linux-hardening, Azeem Shaikh, cgroups, linux-kernel

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

Signed-off-by: Azeem Shaikh <azeemshaikh38@gmail.com>
---
 kernel/cgroup/cgroup-v1.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/kernel/cgroup/cgroup-v1.c b/kernel/cgroup/cgroup-v1.c
index aeef06c465ef..d55216c4cc2d 100644
--- a/kernel/cgroup/cgroup-v1.c
+++ b/kernel/cgroup/cgroup-v1.c
@@ -563,7 +563,7 @@ static ssize_t cgroup_release_agent_write(struct kernfs_open_file *of,
 	if (!cgrp)
 		return -ENODEV;
 	spin_lock(&release_agent_path_lock);
-	strlcpy(cgrp->root->release_agent_path, strstrip(buf),
+	strscpy(cgrp->root->release_agent_path, strstrip(buf),
 		sizeof(cgrp->root->release_agent_path));
 	spin_unlock(&release_agent_path_lock);
 	cgroup_kn_unlock(of->kn);
@@ -797,7 +797,7 @@ void cgroup1_release_agent(struct work_struct *work)
 		goto out_free;
 
 	spin_lock(&release_agent_path_lock);
-	strlcpy(agentbuf, cgrp->root->release_agent_path, PATH_MAX);
+	strscpy(agentbuf, cgrp->root->release_agent_path, PATH_MAX);
 	spin_unlock(&release_agent_path_lock);
 	if (!agentbuf[0])
 		goto out_free;


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] cgroup: Replace all non-returning strlcpy with strscpy
  2023-05-17 14:49 [PATCH] cgroup: Replace all non-returning strlcpy with strscpy Azeem Shaikh
@ 2023-05-17 19:14 ` Kees Cook
  2023-05-22 19:06 ` Tejun Heo
  1 sibling, 0 replies; 3+ messages in thread
From: Kees Cook @ 2023-05-17 19:14 UTC (permalink / raw)
  To: Azeem Shaikh
  Cc: Tejun Heo, Zefan Li, Johannes Weiner, linux-hardening, cgroups,
	linux-kernel

On Wed, May 17, 2023 at 02:49:10PM +0000, Azeem Shaikh wrote:
> 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
> 
> Signed-off-by: Azeem Shaikh <azeemshaikh38@gmail.com>

Reviewed-by: Kees Cook <keescook@chromium.org>

-- 
Kees Cook

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] cgroup: Replace all non-returning strlcpy with strscpy
  2023-05-17 14:49 [PATCH] cgroup: Replace all non-returning strlcpy with strscpy Azeem Shaikh
  2023-05-17 19:14 ` Kees Cook
@ 2023-05-22 19:06 ` Tejun Heo
  1 sibling, 0 replies; 3+ messages in thread
From: Tejun Heo @ 2023-05-22 19:06 UTC (permalink / raw)
  To: Azeem Shaikh
  Cc: Zefan Li, Johannes Weiner, linux-hardening, cgroups, linux-kernel

On Wed, May 17, 2023 at 02:49:10PM +0000, Azeem Shaikh wrote:
> 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
> 
> Signed-off-by: Azeem Shaikh <azeemshaikh38@gmail.com>

Applied to cgroup/for-6.5.

Thanks.

-- 
tejun

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-05-22 19:06 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-17 14:49 [PATCH] cgroup: Replace all non-returning strlcpy with strscpy Azeem Shaikh
2023-05-17 19:14 ` Kees Cook
2023-05-22 19:06 ` Tejun Heo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).