Commit 5a3eb9f6 authored by Li Zefan's avatar Li Zefan Committed by Linus Torvalds

cgroup: fix possible memory leak

There's a leak if copy_from_user() returns failure.
Signed-off-by: default avatarLi Zefan <lizf@cn.fujitsu.com>
Cc: Paul Menage <menage@google.com>
Cc: Cedric Le Goater <clg@fr.ibm.com>
Cc: Balbir Singh <balbir@in.ibm.com>
Cc: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 1d1958f0
...@@ -1424,14 +1424,17 @@ static ssize_t cgroup_write_string(struct cgroup *cgrp, struct cftype *cft, ...@@ -1424,14 +1424,17 @@ static ssize_t cgroup_write_string(struct cgroup *cgrp, struct cftype *cft,
if (buffer == NULL) if (buffer == NULL)
return -ENOMEM; return -ENOMEM;
} }
if (nbytes && copy_from_user(buffer, userbuf, nbytes)) if (nbytes && copy_from_user(buffer, userbuf, nbytes)) {
return -EFAULT; retval = -EFAULT;
goto out;
}
buffer[nbytes] = 0; /* nul-terminate */ buffer[nbytes] = 0; /* nul-terminate */
strstrip(buffer); strstrip(buffer);
retval = cft->write_string(cgrp, cft, buffer); retval = cft->write_string(cgrp, cft, buffer);
if (!retval) if (!retval)
retval = nbytes; retval = nbytes;
out:
if (buffer != local_buffer) if (buffer != local_buffer)
kfree(buffer); kfree(buffer);
return retval; return retval;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment