lkml.org 
[lkml]   [2014]   [Jul]   [21]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH] [RFC] cgroup: reject cgroup names with non-printing characters
Date
/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


\
 
 \ /
  Last update: 2014-07-21 18:01    [W:0.036 / U:0.228 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site