Commit 4a7ba45
memcg: fix possible use-after-free in memcg_write_event_control()
memcg_write_event_control() accesses the dentry->d_name of the specified
control fd to route the write call. As a cgroup interface file can't be
renamed, it's safe to access d_name as long as the specified file is a
regular cgroup file. Also, as these cgroup interface files can't be
removed before the directory, it's safe to access the parent too.
Prior to 347c4a8 ("memcg: remove cgroup_event->cft"), there was a
call to __file_cft() which verified that the specified file is a regular
cgroupfs file before further accesses. The cftype pointer returned from
__file_cft() was no longer necessary and the commit inadvertently dropped
the file type check with it allowing any file to slip through. With the
invarients broken, the d_name and parent accesses can now race against
renames and removals of arbitrary files and cause use-after-free's.
Fix the bug by resurrecting the file type check in __file_cft(). Now that
cgroupfs is implemented through kernfs, checking the file operations needs
to go through a layer of indirection. Instead, let's check the superblock
and dentry type.
Link: https://lkml.kernel.org/r/Y5FRm/[email protected]
Fixes: 347c4a8 ("memcg: remove cgroup_event->cft")
Signed-off-by: Tejun Heo <[email protected]>
Reported-by: Jann Horn <[email protected]>
Acked-by: Roman Gushchin <[email protected]>
Acked-by: Johannes Weiner <[email protected]>
Cc: Linus Torvalds <[email protected]>
Cc: Michal Hocko <[email protected]>
Cc: Muchun Song <[email protected]>
Cc: Shakeel Butt <[email protected]>
Cc: <[email protected]> [3.14+]
Signed-off-by: Andrew Morton <[email protected]>1 parent a501788 commit 4a7ba45
File tree
3 files changed
+14
-3
lines changed- include/linux
- kernel/cgroup
- mm
3 files changed
+14
-3
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
68 | 68 | | |
69 | 69 | | |
70 | 70 | | |
| 71 | + | |
71 | 72 | | |
72 | 73 | | |
73 | 74 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
167 | 167 | | |
168 | 168 | | |
169 | 169 | | |
170 | | - | |
171 | 170 | | |
172 | 171 | | |
173 | 172 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4832 | 4832 | | |
4833 | 4833 | | |
4834 | 4834 | | |
| 4835 | + | |
4835 | 4836 | | |
4836 | 4837 | | |
4837 | 4838 | | |
| |||
4885 | 4886 | | |
4886 | 4887 | | |
4887 | 4888 | | |
| 4889 | + | |
| 4890 | + | |
| 4891 | + | |
| 4892 | + | |
| 4893 | + | |
| 4894 | + | |
| 4895 | + | |
| 4896 | + | |
| 4897 | + | |
| 4898 | + | |
4888 | 4899 | | |
4889 | 4900 | | |
4890 | 4901 | | |
| |||
4893 | 4904 | | |
4894 | 4905 | | |
4895 | 4906 | | |
4896 | | - | |
| 4907 | + | |
4897 | 4908 | | |
4898 | 4909 | | |
4899 | 4910 | | |
| |||
4917 | 4928 | | |
4918 | 4929 | | |
4919 | 4930 | | |
4920 | | - | |
| 4931 | + | |
4921 | 4932 | | |
4922 | 4933 | | |
4923 | 4934 | | |
| |||
0 commit comments