Andrea Arcangeli
c3f3ce049f
userfaultfd: use RCU to free the task struct when fork fails
...
The task structure is freed while get_mem_cgroup_from_mm() holds
rcu_read_lock() and dereferences mm->owner.
get_mem_cgroup_from_mm() failing fork()
---- ---
task = mm->owner
mm->owner = NULL;
free(task)
if (task) *task; /* use after free */
The fix consists in freeing the task with RCU also in the fork failure
case, exactly like it always happens for the regular exit(2) path. That
is enough to make the rcu_read_lock hold in get_mem_cgroup_from_mm()
(left side above) effective to avoid a use after free when dereferencing
the task structure.
An alternate possible fix would be to defer the delivery of the
userfaultfd contexts to the monitor until after fork() is guaranteed to
succeed. Such a change would require more changes because it would
create a strict ordering dependency where the uffd methods would need to
be called beyond the last potentially failing branch in order to be
safe. This solution as opposed only adds the dependency to common code
to set mm->owner to NULL and to free the task struct that was pointed by
mm->owner with RCU, if fork ends up failing. The userfaultfd methods
can still be called anywhere during the fork runtime and the monitor
will keep discarding orphaned "mm" coming from failed forks in userland.
This race condition couldn't trigger if CONFIG_MEMCG was set =n at build
time.
[aarcange@redhat.com: improve changelog, reduce #ifdefs per Michal]
Link: http://lkml.kernel.org/r/20190429035752.4508-1-aarcange@redhat.com
Link: http://lkml.kernel.org/r/20190325225636.11635-2-aarcange@redhat.com
Fixes: 893e26e61d ("userfaultfd: non-cooperative: Add fork() event")
Signed-off-by: Andrea Arcangeli <aarcange@redhat.com>
Tested-by: zhong jiang <zhongjiang@huawei.com>
Reported-by: syzbot+cbb52e396df3e565ab02@syzkaller.appspotmail.com
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Jann Horn <jannh@google.com>
Cc: Hugh Dickins <hughd@google.com>
Cc: Mike Rapoport <rppt@linux.vnet.ibm.com>
Cc: Mike Kravetz <mike.kravetz@oracle.com>
Cc: Peter Xu <peterx@redhat.com>
Cc: Jason Gunthorpe <jgg@mellanox.com>
Cc: "Kirill A . Shutemov" <kirill.shutemov@linux.intel.com>
Cc: Michal Hocko <mhocko@suse.com>
Cc: zhong jiang <zhongjiang@huawei.com>
Cc: syzbot+cbb52e396df3e565ab02@syzkaller.appspotmail.com
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2019-05-14 19:52:47 -07:00
..
bpf
bpf: fix undefined behavior in narrow load handling
2019-05-13 02:05:50 +02:00
cgroup
Merge branch 'for-5.2' of git://git.kernel.org/pub/scm/linux/kernel/git/tj/cgroup
2019-05-09 13:52:12 -07:00
configs
debug
dma
DMA mapping updates for 5.2
2019-05-09 08:40:55 -07:00
events
mm/mmu_notifier: use correct mmu_notifier events for each invalidation
2019-05-14 09:47:49 -07:00
gcov
kernel/gcov/gcc_3_4.c: use struct_size() in kzalloc()
2019-03-07 18:32:02 -08:00
irq
Driver core/kobject patches for 5.2-rc1
2019-05-07 13:01:40 -07:00
livepatch
Driver core/kobject patches for 5.2-rc1
2019-05-07 13:01:40 -07:00
locking
Remove Mysterious Macro Intended to Obscure Weird Behaviours (mmiowb())
2019-05-06 16:57:52 -07:00
power
Power management updates for 5.2-rc1
2019-05-06 19:40:31 -07:00
printk
fbdev changes for v5.1:
2019-03-15 14:22:59 -07:00
rcu
Printk changes for 5.2
2019-05-07 09:18:12 -07:00
sched
Driver core/kobject patches for 5.2-rc1
2019-05-07 13:01:40 -07:00
time
Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next
2019-05-07 22:03:58 -07:00
trace
This is the bulk of the GPIO changes for the v5.2 kernel cycle:
2019-05-11 10:54:43 -04:00
.gitignore
Provide in-kernel headers to make extending kernel easier
2019-04-29 16:48:03 +02:00
acct.c
acct_on(): don't mess with freeze protection
2019-04-04 21:04:13 -04:00
async.c
treewide: Switch printk users from %pf and %pF to %ps and %pS, respectively
2019-04-09 14:19:06 +02:00
audit.c
audit: connect LOGIN record to its syscall record
2019-03-20 20:57:48 -04:00
audit.h
audit_compare_dname_path(): switch to const struct qstr *
2019-04-28 20:33:43 -04:00
audit_fsnotify.c
audit_compare_dname_path(): switch to const struct qstr *
2019-04-28 20:33:43 -04:00
audit_tree.c
fsnotify: switch send_to_group() and ->handle_event to const struct qstr *
2019-04-26 13:51:03 -04:00
audit_watch.c
audit_compare_dname_path(): switch to const struct qstr *
2019-04-28 20:33:43 -04:00
auditfilter.c
Merge branch 'work.dcache' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs
2019-05-07 20:03:32 -07:00
auditsc.c
Merge branch 'work.dcache' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs
2019-05-07 20:03:32 -07:00
backtracetest.c
backtrace-test: Simplify stack trace handling
2019-04-29 12:37:47 +02:00
bounds.c
capability.c
compat.c
configs.c
kernel/configs: use .incbin directive to embed config_data.gz
2019-03-07 18:32:02 -08:00
context_tracking.c
cpu.c
Merge branch 'timers-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
2019-05-06 14:50:46 -07:00
cpu_pm.c
crash_core.c
kexec: export PG_offline to VMCOREINFO
2019-03-05 21:07:14 -08:00
crash_dump.c
cred.c
delayacct.c
dma.c
elfcore.c
exec_domain.c
exit.c
Merge branch 'for-5.1' of git://git.kernel.org/pub/scm/linux/kernel/git/tj/cgroup
2019-03-07 10:11:41 -08:00
extable.c
fail_function.c
treewide: Switch printk users from %pf and %pF to %ps and %pS, respectively
2019-04-09 14:19:06 +02:00
fork.c
userfaultfd: use RCU to free the task struct when fork fails
2019-05-14 19:52:47 -07:00
freezer.c
futex.c
mm/gup: change GUP fast to use flags rather than a write 'bool'
2019-05-14 09:47:46 -07:00
gen_ikh_data.sh
Provide in-kernel headers to make extending kernel easier
2019-04-29 16:48:03 +02:00
groups.c
hung_task.c
kernel/hung_task.c: Use continuously blocked time when reporting.
2019-03-07 18:31:59 -08:00
iomem.c
mm/resource: Use resource_overlaps() to simplify region_intersects()
2019-04-19 12:59:36 +02:00
irq_work.c
irq_work: Do not raise an IPI when queueing work on the local CPU
2019-04-18 14:07:52 +02:00
jump_label.c
locking/static_key: Don't take sleeping locks in __static_key_slow_dec_deferred()
2019-04-29 08:29:21 +02:00
kallsyms.c
kcmp.c
Kconfig.freezer
Kconfig.hz
Kconfig.locks
Remove Mysterious Macro Intended to Obscure Weird Behaviours (mmiowb())
2019-05-06 16:57:52 -07:00
Kconfig.preempt
kcov.c
kcov: convert kcov.refcount to refcount_t
2019-03-07 18:32:02 -08:00
kexec.c
kexec_core.c
power/suspend: Add function to disable secondaries for suspend
2019-05-03 19:42:41 +02:00
kexec_file.c
mm: memblock: make keeping memblock memory opt-in rather than opt-out
2019-05-14 09:47:50 -07:00
kexec_internal.h
kheaders.c
Provide in-kernel headers to make extending kernel easier
2019-04-29 16:48:03 +02:00
kmod.c
kprobes.c
kprobes: Fix error check when reusing optimized probes
2019-04-16 09:38:16 +02:00
ksysfs.c
kthread.c
Merge branch 'akpm' (patches from Andrew)
2019-03-06 10:31:36 -08:00
latencytop.c
latency_top: Simplify stack trace handling
2019-04-29 12:37:48 +02:00
Makefile
kernel/Makefile: don't assume that kernel/gen_ikh_data.sh is executable
2019-05-14 19:52:47 -07:00
memremap.c
kernel/memremap.c: remove the unused device_private_entry_fault() export
2019-05-14 09:47:51 -07:00
module-internal.h
module.c
Merge branch 'next-integrity' of git://git.kernel.org/pub/scm/linux/kernel/git/jmorris/linux-security
2019-05-09 12:54:40 -07:00
module_signing.c
notifier.c
nsproxy.c
padata.c
padata: Replace padata_attr_type default_attrs field with groups
2019-04-25 22:06:11 +02:00
panic.c
s390: simplify disabled_wait
2019-05-02 13:54:11 +02:00
params.c
pid.c
pid_namespace.c
profile.c
ptrace.c
ptrace: take into account saved_sigmask in PTRACE{GET,SET}SIGMASK
2019-03-29 10:01:37 -07:00
range.c
reboot.c
relay.c
Merge branch 'work.misc' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs
2019-03-12 13:27:20 -07:00
resource.c
mm/resource: Use resource_overlaps() to simplify region_intersects()
2019-04-19 12:59:36 +02:00
rseq.c
rseq: Remove superfluous rseq_len from task_struct
2019-04-19 12:39:32 +02:00
seccomp.c
audit/stable-5.2 PR 20190507
2019-05-07 19:06:04 -07:00
signal.c
Merge branch 'for-5.2' of git://git.kernel.org/pub/scm/linux/kernel/git/tj/cgroup
2019-05-09 13:52:12 -07:00
smp.c
smpboot.c
smpboot.h
softirq.c
softirq: Remove tasklet_hrtimer
2019-03-22 14:36:02 +01:00
stackleak.c
stacktrace.c
stacktrace: Provide common infrastructure
2019-04-29 12:37:57 +02:00
stop_machine.c
treewide: Switch printk users from %pf and %pF to %ps and %pS, respectively
2019-04-09 14:19:06 +02:00
sys.c
kernel/sys.c: prctl: fix false positive in validate_prctl_map()
2019-05-14 09:47:44 -07:00
sys_ni.c
signal: support CLONE_PIDFD with pidfd_send_signal
2019-05-07 14:31:03 +02:00
sysctl.c
userfaultfd/sysctl: add vm.unprivileged_userfaultfd
2019-05-14 09:47:45 -07:00
sysctl_binary.c
task_work.c
taskstats.c
genetlink: optionally validate strictly/dumps
2019-04-27 17:07:22 -04:00
test_kprobes.c
torture.c
torture: Don't try to offline the last CPU
2019-03-26 14:42:53 -07:00
tracepoint.c
tsacct.c
ucount.c
uid16.c
uid16.h
umh.c
up.c
user-return-notifier.c
user.c
user_namespace.c
utsname.c
utsname_sysctl.c
watchdog.c
watchdog: Fix typo in comment
2019-04-18 14:05:51 +02:00
watchdog_hld.c
kernel/watchdog_hld.c: hard lockup message should end with a newline
2019-04-19 09:46:05 -07:00
workqueue.c
Merge branch 'for-5.2' of git://git.kernel.org/pub/scm/linux/kernel/git/tj/wq
2019-05-09 13:48:52 -07:00
workqueue_internal.h
sched/core, workqueues: Distangle worker accounting from rq lock
2019-04-16 16:55:15 +02:00