binfmt_misc: fix possible deadlock in bm_register_write
Lior Ribak authored
There is a deadlock in bm_register_write:

First, in the begining of the function, a lock is taken on the binfmt_misc
root inode with inode_lock(d_inode(root)).

Then, if the user used the MISC_FMT_OPEN_FILE flag, the function will call
open_exec on the user-provided interpreter.

open_exec will call a path lookup, and if the path lookup process includes
the root of binfmt_misc, it will try to take a shared lock on its inode
again, but it is already locked, and the code will get stuck in a deadlock

To reproduce the bug:
$ echo ":iiiii:E::ii::/proc/sys/fs/binfmt_misc/bla:F" > /proc/sys/fs/binfmt_misc/register

backtrace of where the lock occurs (#5):
0  schedule () at ./arch/x86/include/asm/current.h:15
1  0xffffffff81b51237 in rwsem_down_read_slowpath (sem=0xffff888003b202e0, count=<optimized out>, state=state@entry=2) at kernel/locking/rwsem.c:992
2  0xffffffff81b5150a in __down_read_common (state=2, sem=<optimized out>) at kernel/locking/rwsem.c:1...
e7850f4d
Name Last commit Last update
Documentation Merge tag 'drm-fixes-2021-03-12-1' of git://anongit.freedesktop.org/drm/drm
LICENSES LICENSES: Add the CC-BY-4.0 license
arch Merge tag 's390-5.12-3' of git://git.kernel.org/pub/scm/linux/kernel/git/s390/linux
block block/bfq: update comments and default value in docs for fifo_expire
certs certs: Replace K{U,G}IDT_INIT() with GLOBAL_ROOT_{U,G}ID
crypto crypto: mips/poly1305 - enable for all MIPS processors
drivers mm: use is_cow_mapping() across tree where proper
fs binfmt_misc: fix possible deadlock in bm_register_write
include mm: introduce page_needs_cow_for_dma() for deciding whether cow
init init/Kconfig: make COMPILE_TEST depend on HAS_IOMEM
ipc fs: make helpers idmap mount aware
kernel mm/fork: clear PASID for new mm
lib Merge git://git.kernel.org:/pub/scm/linux/kernel/git/davem/sparc
mm mm/highmem.c: fix zero_user_segments() with start > end
net Merge git://git.kernel.org:/pub/scm/linux/kernel/git/netdev/net
samples Merge git://git.kernel.org:/pub/scm/linux/kernel/git/netdev/net
scripts Merge tag 'gcc-plugins-v5.12-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux
security Merge tag 'keys-misc-20210126' of git://git.kernel.org/pub/scm/linux/kernel/git/dhowells/linux-fs
sound ALSA: hda/realtek: Apply dual codec quirks for MSI Godlike X570 board
tools Merge git://git.kernel.org:/pub/scm/linux/kernel/git/netdev/net
usr Merge tag 'kbuild-v5.12' of git://git.kernel.org/pub/scm/linux/kernel/git/masahiroy/linux-kbuild
virt KVM: x86/mmu: Consider the hva in mmu_notifier retry
.clang-format Merge tag 'cxl-for-5.12' of git://git.kernel.org/pub/scm/linux/kernel/git/nvdimm/nvdimm
.cocciconfig scripts: add Linux .cocciconfig for coccinelle
.get_maintainer.ignore Opt out of scripts/get_maintainer.pl
.gitattributes .gitattributes: use 'dts' diff driver for dts files
.gitignore Merge tag 'clang-lto-v5.12-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux
.mailmap treewide: Miguel has moved
COPYING COPYING: state that all contributions really are covered by this file
CREDITS treewide: Miguel has moved
Kbuild kbuild: rename hostprogs-y/always to hostprogs/always-y
Kconfig kbuild: ensure full rebuild when the compiler is updated
MAINTAINERS Merge tag 'drm-fixes-2021-03-12-1' of git://anongit.freedesktop.org/drm/drm
Makefile Linux 5.12-rc2
README Drop all 00-INDEX files from Documentation/
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.