From: Tejun Heo <tj@kernel.org>
To: Kees Cook <keescook@chromium.org>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Zefan Li <lizefan.x@bytedance.com>,
Johannes Weiner <hannes@cmpxchg.org>,
Waiman Long <longman@redhat.com>,
cgroups@vger.kernel.org, Azeem Shaikh <azeemshaikh38@gmail.com>,
Christophe JAILLET <christophe.jaillet@wanadoo.fr>,
linux-kernel@vger.kernel.org, bpf@vger.kernel.org,
linux-hardening@vger.kernel.org
Subject: Re: [PATCH v3 3/3] kernfs: Convert kernfs_path_from_node_locked() from strlcpy() to strscpy()
Date: Fri, 22 Dec 2023 10:18:57 +0900 [thread overview]
Message-ID: <ZYTkAV-CE3ZslR7U@mtj.duckdns.org> (raw)
In-Reply-To: <20231212211741.164376-3-keescook@chromium.org>
Hello,
On Tue, Dec 12, 2023 at 01:17:40PM -0800, Kees Cook wrote:
...
> @@ -127,7 +127,7 @@ static struct kernfs_node *kernfs_common_ancestor(struct kernfs_node *a,
> *
> * [3] when @kn_to is %NULL result will be "(null)"
> *
> - * Return: the length of the full path. If the full length is equal to or
> + * Return: the length of the constructed path. If the path would have been
> * greater than @buflen, @buf contains the truncated path with the trailing
> * '\0'. On error, -errno is returned.
> */
...
> /* Calculate how many bytes we need for the rest */
We probably should drop this comment.
> for (i = depth_to - 1; i >= 0; i--) {
> for (kn = kn_to, j = 0; j < i; j++)
> kn = kn->parent;
> - len += strlcpy(buf + len, "/",
> - len < buflen ? buflen - len : 0);
> - len += strlcpy(buf + len, kn->name,
> - len < buflen ? buflen - len : 0);
> +
> + len += scnprintf(buf + len, buflen - len, "/%s", kn->name);
scnprintf doesn't return -E2BIG on overflow, right? It just returns the
truncated length, so the overflow behavior would be different depending on
where this function overflows, right? Not a huge problem but it may be
better to keep calling strscpy to keep things consistent?
> --- a/kernel/cgroup/cgroup.c
> +++ b/kernel/cgroup/cgroup.c
> @@ -1893,7 +1893,7 @@ int cgroup_show_path(struct seq_file *sf, struct kernfs_node *kf_node,
> len = kernfs_path_from_node(kf_node, ns_cgroup->kn, buf, PATH_MAX);
> spin_unlock_irq(&css_set_lock);
>
> - if (len >= PATH_MAX)
> + if (len == -E2BIG)
> len = -ERANGE;
I'd just pass up -E2BIG.
> else if (len > 0) {
> seq_escape(sf, buf, " \t\n\\");
> @@ -6301,7 +6301,7 @@ int proc_cgroup_show(struct seq_file *m, struct pid_namespace *ns,
> if (cgroup_on_dfl(cgrp) || !(tsk->flags & PF_EXITING)) {
> retval = cgroup_path_ns_locked(cgrp, buf, PATH_MAX,
> current->nsproxy->cgroup_ns);
> - if (retval >= PATH_MAX)
> + if (retval == -E2BIG)
> retval = -ENAMETOOLONG;
Ditto.
> diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c
> index 615daaf87f1f..fb29158ae825 100644
> --- a/kernel/cgroup/cpuset.c
> +++ b/kernel/cgroup/cpuset.c
> @@ -4941,7 +4941,7 @@ int proc_cpuset_show(struct seq_file *m, struct pid_namespace *ns,
> retval = cgroup_path_ns(css->cgroup, buf, PATH_MAX,
> current->nsproxy->cgroup_ns);
> css_put(css);
> - if (retval >= PATH_MAX)
> + if (retval == -E2BIG)
Ditto.
Thanks.
--
tejun
prev parent reply other threads:[~2023-12-22 1:19 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-12 21:17 [PATCH v3 0/3] kernfs: Convert from strlcpy() to strscpy() Kees Cook
2023-12-12 21:17 ` [PATCH v3 1/3] kernfs: Convert kernfs_walk_ns() " Kees Cook
2023-12-22 0:58 ` Tejun Heo
2023-12-12 21:17 ` [PATCH v3 2/3] kernfs: Convert kernfs_name_locked() " Kees Cook
2023-12-22 0:59 ` Tejun Heo
2023-12-12 21:17 ` [PATCH v3 3/3] kernfs: Convert kernfs_path_from_node_locked() " Kees Cook
2023-12-22 1:18 ` Tejun Heo [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ZYTkAV-CE3ZslR7U@mtj.duckdns.org \
--to=tj@kernel.org \
--cc=azeemshaikh38@gmail.com \
--cc=bpf@vger.kernel.org \
--cc=cgroups@vger.kernel.org \
--cc=christophe.jaillet@wanadoo.fr \
--cc=gregkh@linuxfoundation.org \
--cc=hannes@cmpxchg.org \
--cc=keescook@chromium.org \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lizefan.x@bytedance.com \
--cc=longman@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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 read-only IMAP folder(s) and NNTP newsgroup(s).