No description
Find a file
Alistair Popple 5f340d8c1e mm/mmu_notifier.c: fix race in mmu_interval_notifier_remove()
commit 319561669a upstream.

In some cases it is possible for mmu_interval_notifier_remove() to race
with mn_tree_inv_end() allowing it to return while the notifier data
structure is still in use.  Consider the following sequence:

  CPU0 - mn_tree_inv_end()            CPU1 - mmu_interval_notifier_remove()
  ----------------------------------- ------------------------------------
                                      spin_lock(subscriptions->lock);
                                      seq = subscriptions->invalidate_seq;
  spin_lock(subscriptions->lock);     spin_unlock(subscriptions->lock);
  subscriptions->invalidate_seq++;
                                      wait_event(invalidate_seq != seq);
                                      return;
  interval_tree_remove(interval_sub); kfree(interval_sub);
  spin_unlock(subscriptions->lock);
  wake_up_all();

As the wait_event() condition is true it will return immediately.  This
can lead to use-after-free type errors if the caller frees the data
structure containing the interval notifier subscription while it is
still on a deferred list.  Fix this by taking the appropriate lock when
reading invalidate_seq to ensure proper synchronisation.

I observed this whilst running stress testing during some development.
You do have to be pretty unlucky, but it leads to the usual problems of
use-after-free (memory corruption, kernel crash, difficult to diagnose
WARN_ON, etc).

Link: https://lkml.kernel.org/r/20220420043734.476348-1-apopple@nvidia.com
Fixes: 99cb252f5e ("mm/mmu_notifier: add an interval tree notifier")
Signed-off-by: Alistair Popple <apopple@nvidia.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
Cc: Christian König <christian.koenig@amd.com>
Cc: John Hubbard <jhubbard@nvidia.com>
Cc: Ralph Campbell <rcampbell@nvidia.com>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2023-04-19 17:48:13 +08:00
arch stat: fix inconsistency between struct stat and struct compat_stat 2023-04-19 17:48:13 +08:00
block block: simplify the block device syncing code 2023-04-19 17:48:07 +08:00
certs certs: Add support for using elliptic curve keys for signing modules 2021-08-23 19:55:42 +03:00
crypto crypto: xts - Add softdep on ecb 2023-04-19 17:47:16 +08:00
Documentation dt-bindings: net: snps: remove duplicate name 2023-04-19 17:48:06 +08:00
drivers EDAC/synopsys: Read the error count from the correct register 2023-04-19 17:48:13 +08:00
fs mm, hugetlb: allow for "high" userspace addresses 2023-04-19 17:48:13 +08:00
include oom_kill.c: futex: delay the OOM reaper to allow time for proper futex cleanup 2023-04-19 17:48:13 +08:00
init init/main.c: return 1 from handled __setup() functions 2023-04-19 17:47:40 +08:00
ipc ipc/sem: do not sleep with a spin lock held 2023-04-19 17:45:01 +08:00
kernel dma-mapping: remove bogus test for pfn_valid from dma_map_resource 2023-04-19 17:48:08 +08:00
lib stacktrace: move filter_irq_stacks() to kernel/stacktrace.c 2023-04-19 17:47:53 +08:00
LICENSES LICENSES/dual/CC-BY-4.0: Git rid of "smart quotes" 2021-07-15 06:31:24 -06:00
mm mm/mmu_notifier.c: fix race in mmu_interval_notifier_remove() 2023-04-19 17:48:13 +08:00
net netlink: reset network and mac headers in netlink_dump() 2023-04-19 17:48:11 +08:00
samples samples/bpf, xdpsock: Fix race when running for fix duration of time 2023-04-19 17:47:05 +08:00
scripts gcc-plugins: latent_entropy: use /dev/urandom 2023-04-19 17:48:04 +08:00
security Fix incorrect type in assignment of ipv6 port for audit 2023-04-19 17:47:16 +08:00
sound ALSA: usb-audio: Fix undefined behavior due to shift overflowing the constant 2023-04-19 17:48:12 +08:00
tools selftests: mlxsw: vxlan_flooding: Prevent flooding of unwanted packets 2023-04-19 17:48:11 +08:00
usr usr/include/Makefile: add linux/nfc.h to the compile-test coverage 2023-04-19 17:44:58 +08:00
virt KVM: avoid NULL pointer dereference in kvm_dirty_ring_push 2023-04-19 17:47:52 +08:00
.clang-format clang-format: Update with the latest for_each macro list 2021-05-12 23:32:39 +02:00
.cocciconfig
.get_maintainer.ignore Opt out of scripts/get_maintainer.pl 2019-05-16 10:53:40 -07:00
.gitattributes .gitattributes: use 'dts' diff driver for dts files 2019-12-04 19:44:11 -08:00
.gitignore .gitignore: ignore only top-level modules.builtin 2021-05-02 00:43:35 +09:00
.mailmap mailmap: add Andrej Shadura 2021-10-18 20:22:03 -10:00
COPYING COPYING: state that all contributions really are covered by this file 2020-02-10 13:32:20 -08:00
CREDITS MAINTAINERS: Move Daniel Drake to credits 2021-09-21 08:34:58 +03:00
Kbuild kbuild: rename hostprogs-y/always to hostprogs/always-y 2020-02-04 01:53:07 +09:00
Kconfig kbuild: ensure full rebuild when the compiler is updated 2020-05-12 13:28:33 +09:00
MAINTAINERS MAINTAINERS: adjust file entry for of_net.c after movement 2023-04-19 17:46:04 +08:00
Makefile Linux 5.15.35 2023-04-19 17:48:07 +08:00
README Drop all 00-INDEX files from Documentation/ 2018-09-09 15:08:58 -06:00

Linux kernel
============

There are several guides for kernel developers and users. These guides can
be rendered in a number of formats, like HTML and PDF. Please read
Documentation/admin-guide/README.rst first.

In order to build the documentation, use ``make htmldocs`` or
``make pdfdocs``.  The formatted documentation can also be read online at:

    https://www.kernel.org/doc/html/latest/

There are various text files in the Documentation/ subdirectory,
several of them using the Restructured Text markup notation.

Please read the Documentation/process/changes.rst file, as it contains the
requirements for building and running the kernel, and information about
the problems which may result by upgrading your kernel.