mbox series

[0/3] kernfs: Convert from strlcpy() to strscpy()

Message ID 20231116191718.work.246-kees@kernel.org (mailing list archive)
Headers show
Series kernfs: Convert from strlcpy() to strscpy() | expand

Message

Kees Cook Nov. 16, 2023, 7:21 p.m. UTC
Hi,

One of the last users of strlcpy() is kernfs, which has some complex
calling hierarchies that needed to be carefully examined. This series
refactors the strlcpy() calls into strscpy() calls, and bubbles up all
changes in return value checking for callers.

-Kees

Kees Cook (3):
  kernfs: Convert kernfs_walk_ns() from strlcpy() to strscpy()
  kernfs: Convert kernfs_name_locked() from strlcpy() to strscpy()
  kernfs: Convert kernfs_path_from_node_locked() from strlcpy() to
    strscpy()

 fs/kernfs/dir.c             | 53 ++++++++++++++++++++-----------------
 kernel/cgroup/cgroup-v1.c   |  2 +-
 kernel/cgroup/cgroup.c      |  4 +--
 kernel/cgroup/cpuset.c      |  2 +-
 kernel/trace/trace_uprobe.c |  2 +-
 5 files changed, 33 insertions(+), 30 deletions(-)

Comments

Greg KH Nov. 27, 2023, 1:43 p.m. UTC | #1
On Thu, Nov 16, 2023 at 11:21:22AM -0800, Kees Cook wrote:
> Hi,
> 
> One of the last users of strlcpy() is kernfs, which has some complex
> calling hierarchies that needed to be carefully examined. This series
> refactors the strlcpy() calls into strscpy() calls, and bubbles up all
> changes in return value checking for callers.

Why not work instead to convert kernfs (and by proxy cgroups) to use the
"safe" string functions based on seq_file?  This should be a simpler
patch series to review, and implement on a per-function basis, and then
we would not have any string functions in kernfs anymore.

thanks,

greg k-h
Kees Cook Nov. 28, 2023, 12:38 a.m. UTC | #2
On Mon, Nov 27, 2023 at 01:43:57PM +0000, Greg Kroah-Hartman wrote:
> On Thu, Nov 16, 2023 at 11:21:22AM -0800, Kees Cook wrote:
> > Hi,
> > 
> > One of the last users of strlcpy() is kernfs, which has some complex
> > calling hierarchies that needed to be carefully examined. This series
> > refactors the strlcpy() calls into strscpy() calls, and bubbles up all
> > changes in return value checking for callers.
> 
> Why not work instead to convert kernfs (and by proxy cgroups) to use the
> "safe" string functions based on seq_file?  This should be a simpler
> patch series to review, and implement on a per-function basis, and then
> we would not have any string functions in kernfs anymore.

One thing at a time. :) This lets us finish the strlcpy() removal. But
yes, replacing all of kernfs/sysfs to pass a seq_buf instead of a char *
is on the list. :) I think I see a way to transition to it, too.