]> git.kernelconcepts.de Git - karo-tx-linux.git/blobdiff - kernel/cgroup.c
cgroup: fix subsystem file accesses on the root cgroup
[karo-tx-linux.git] / kernel / cgroup.c
index ff7d642a070a4b78f2ef96633f1bee7836db3937..896e035eb6e40e4eea4e232bf73dbcd24c7caaaf 100644 (file)
@@ -2490,10 +2490,18 @@ static int cgroup_file_open(struct inode *inode, struct file *file)
        }
        rcu_read_unlock();
 
-       /* css should match @cfe->css, see cgroup_add_file() for details */
-       if (!css || WARN_ON_ONCE(css != cfe->css))
+       if (!css)
                return -ENODEV;
 
+       /*
+        * @cfe->css is used by read/write/close to determine the
+        * associated css.  @file->private_data would be a better place but
+        * that's already used by seqfile.  Multiple accessors may use it
+        * simultaneously which is okay as the association never changes.
+        */
+       WARN_ON_ONCE(cfe->css && cfe->css != css);
+       cfe->css = css;
+
        if (cft->read_map || cft->read_seq_string) {
                file->f_op = &cgroup_seqfile_operations;
                err = single_open(file, cgroup_seqfile_show, cfe);
@@ -2772,18 +2780,6 @@ static int cgroup_add_file(struct cgroup *cgrp, struct cftype *cft)
        dentry->d_fsdata = cfe;
        simple_xattrs_init(&cfe->xattrs);
 
-       /*
-        * cfe->css is used by read/write/close to determine the associated
-        * css.  file->private_data would be a better place but that's
-        * already used by seqfile.  Note that open will use the usual
-        * cgroup_css() and css_tryget() to acquire the css and this
-        * caching doesn't affect css lifetime management.
-        */
-       if (cft->ss)
-               cfe->css = cgroup_css(cgrp, cft->ss->subsys_id);
-       else
-               cfe->css = &cgrp->dummy_css;
-
        mode = cgroup_file_mode(cft);
        error = cgroup_create_file(dentry, mode | S_IFREG, cgrp->root->sb);
        if (!error) {