linux-stable/include
Tejun Heo aad8bbd17a memcg: fix possible use-after-free in memcg_write_event_control()
commit 4a7ba45b1a upstream.

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 347c4a8747 ("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/cfcKPGzWwl@slm.duckdns.org
Fixes: 347c4a8747 ("memcg: remove cgroup_event->cft")
Signed-off-by: Tejun Heo <tj@kernel.org>
Reported-by: Jann Horn <jannh@google.com>
Acked-by: Roman Gushchin <roman.gushchin@linux.dev>
Acked-by: Johannes Weiner <hannes@cmpxchg.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Michal Hocko <mhocko@kernel.org>
Cc: Muchun Song <songmuchun@bytedance.com>
Cc: Shakeel Butt <shakeelb@google.com>
Cc: <stable@vger.kernel.org>	[3.14+]
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2022-12-14 11:37:19 +01:00
..
acpi ACPI: APEI: Fix integer overflow in ghes_estatus_pool_init() 2022-11-10 18:15:34 +01:00
asm-generic mm/khugepaged: fix GUP-fast interaction by sending IPI 2022-12-14 11:37:17 +01:00
clocksource
crypto
drm drm/bridge: Add stubs for devm_drm_of_get_bridge when OF is disabled 2022-09-05 10:30:03 +02:00
dt-bindings
keys
kunit
kvm
linux memcg: fix possible use-after-free in memcg_write_event_control() 2022-12-14 11:37:19 +01:00
math-emu
media media: v4l: subdev: Fail graciously when getting try data for NULL state 2022-11-10 18:15:34 +01:00
memory
misc
net sctp: fix memory leak in sctp_stream_outq_migrate() 2022-12-08 11:28:41 +01:00
pcmcia
ras
rdma
scsi scsi: iscsi: Add recv workqueue helpers 2022-10-26 12:35:15 +02:00
soc ARM: at91: pm: avoid soft resetting AC DLL 2022-11-26 09:24:34 +01:00
sound ALSA: control: Use deferred fasync helper 2022-08-25 11:40:44 +02:00
target
trace rxrpc: Use refcount_t rather than atomic_t 2022-12-02 17:41:04 +01:00
uapi audit: fix undefined behavior in bit shift for AUDIT_BIT 2022-12-02 17:41:01 +01:00
vdso
video
xen