* [PATCH] [RFC] cgroup: reject cgroup names with non-printing characters
@ 2014-07-21 15:11 Alban Crequy
2014-08-17 13:41 ` Tejun Heo
0 siblings, 1 reply; 2+ messages in thread
From: Alban Crequy @ 2014-07-21 15:11 UTC (permalink / raw)
To: cgroups; +Cc: linux-kernel, Tejun Heo, Li Zefan, Alban Crequy
/proc/<pid>/cgroup contains one cgroup path on each line. If cgroup names are
allowed to contain "\n", applications cannot parse /proc/<pid>/cgroup safely.
I use < 0x20 as seen in vfat_bad_char; is it safe to use isprint()?
Signed-off-by: Alban Crequy <alban.crequy@collabora.co.uk>
---
kernel/cgroup.c | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)
diff --git a/kernel/cgroup.c b/kernel/cgroup.c
index 70776ae..e2df5e7 100644
--- a/kernel/cgroup.c
+++ b/kernel/cgroup.c
@@ -4378,6 +4378,20 @@ err_free_css:
return err;
}
+/* Inspired by vfat_bad_char: do not accept non-printing characters. In
+ * particular, reject '\n' to prevent making /proc/<pid>/cgroup unparsable.
+ */
+static inline int cgroup_is_used_badchars(const char *s)
+{
+ int i;
+
+ for (i = 0; s[i] != '\0'; i++)
+ if (s[i] < 0x20)
+ return -EINVAL;
+
+ return 0;
+}
+
static int cgroup_mkdir(struct kernfs_node *parent_kn, const char *name,
umode_t mode)
{
@@ -4387,6 +4401,11 @@ static int cgroup_mkdir(struct kernfs_node *parent_kn, const char *name,
struct kernfs_node *kn;
int ssid, ret;
+ /* do not create cgroups with bad names */
+ ret = cgroup_is_used_badchars(name);
+ if (ret)
+ return ret;
+
parent = cgroup_kn_lock_live(parent_kn);
if (!parent)
return -ENODEV;
--
1.8.5.3
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] [RFC] cgroup: reject cgroup names with non-printing characters
2014-07-21 15:11 [PATCH] [RFC] cgroup: reject cgroup names with non-printing characters Alban Crequy
@ 2014-08-17 13:41 ` Tejun Heo
0 siblings, 0 replies; 2+ messages in thread
From: Tejun Heo @ 2014-08-17 13:41 UTC (permalink / raw)
To: Alban Crequy; +Cc: cgroups, linux-kernel, Li Zefan
Hello, Alban.
Sorry about the delay.
On Mon, Jul 21, 2014 at 04:11:56PM +0100, Alban Crequy wrote:
> @@ -4387,6 +4401,11 @@ static int cgroup_mkdir(struct kernfs_node *parent_kn, const char *name,
> struct kernfs_node *kn;
> int ssid, ret;
>
> + /* do not create cgroups with bad names */
> + ret = cgroup_is_used_badchars(name);
> + if (ret)
> + return ret;
Let's just reject '\n'. That should give us a way to parse the path
correctly and I don't want to put more-than-necessary interpretation
on the path string.
Thanks.
--
tejun
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2014-08-17 13:42 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-07-21 15:11 [PATCH] [RFC] cgroup: reject cgroup names with non-printing characters Alban Crequy
2014-08-17 13:41 ` Tejun Heo
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox