linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: linux-kernel@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	stable@vger.kernel.org, Miklos Szeredi <miklos@szeredi.hu>,
	Eric Biggers <ebiggers@google.com>,
	Al Viro <viro@zeniv.linux.org.uk>,
	Sasha Levin <sashal@kernel.org>
Subject: [PATCH 5.10 50/63] fs/namespace.c: WARN if mnt_count has become negative
Date: Mon,  4 Jan 2021 16:57:43 +0100	[thread overview]
Message-ID: <20210104155711.239399679@linuxfoundation.org> (raw)
In-Reply-To: <20210104155708.800470590@linuxfoundation.org>

From: Eric Biggers <ebiggers@google.com>

[ Upstream commit edf7ddbf1c5eb98b720b063b73e20e8a4a1ce673 ]

Missing calls to mntget() (or equivalently, too many calls to mntput())
are hard to detect because mntput() delays freeing mounts using
task_work_add(), then again using call_rcu().  As a result, mnt_count
can often be decremented to -1 without getting a KASAN use-after-free
report.  Such cases are still bugs though, and they point to real
use-after-frees being possible.

For an example of this, see the bug fixed by commit 1b0b9cc8d379
("vfs: fsmount: add missing mntget()"), discussed at
https://lkml.kernel.org/linux-fsdevel/20190605135401.GB30925@xxxxxxxxxxxxxxxxxxxxxxxxx/T/#u.
This bug *should* have been trivial to find.  But actually, it wasn't
found until syzkaller happened to use fchdir() to manipulate the
reference count just right for the bug to be noticeable.

Address this by making mntput_no_expire() issue a WARN if mnt_count has
become negative.

Suggested-by: Miklos Szeredi <miklos@szeredi.hu>
Signed-off-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 fs/namespace.c | 9 ++++++---
 fs/pnode.h     | 2 +-
 2 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/fs/namespace.c b/fs/namespace.c
index cebaa3e817940..93006abe7946a 100644
--- a/fs/namespace.c
+++ b/fs/namespace.c
@@ -156,10 +156,10 @@ static inline void mnt_add_count(struct mount *mnt, int n)
 /*
  * vfsmount lock must be held for write
  */
-unsigned int mnt_get_count(struct mount *mnt)
+int mnt_get_count(struct mount *mnt)
 {
 #ifdef CONFIG_SMP
-	unsigned int count = 0;
+	int count = 0;
 	int cpu;
 
 	for_each_possible_cpu(cpu) {
@@ -1139,6 +1139,7 @@ static DECLARE_DELAYED_WORK(delayed_mntput_work, delayed_mntput);
 static void mntput_no_expire(struct mount *mnt)
 {
 	LIST_HEAD(list);
+	int count;
 
 	rcu_read_lock();
 	if (likely(READ_ONCE(mnt->mnt_ns))) {
@@ -1162,7 +1163,9 @@ static void mntput_no_expire(struct mount *mnt)
 	 */
 	smp_mb();
 	mnt_add_count(mnt, -1);
-	if (mnt_get_count(mnt)) {
+	count = mnt_get_count(mnt);
+	if (count != 0) {
+		WARN_ON(count < 0);
 		rcu_read_unlock();
 		unlock_mount_hash();
 		return;
diff --git a/fs/pnode.h b/fs/pnode.h
index 49a058c73e4c7..26f74e092bd98 100644
--- a/fs/pnode.h
+++ b/fs/pnode.h
@@ -44,7 +44,7 @@ int propagate_mount_busy(struct mount *, int);
 void propagate_mount_unlock(struct mount *);
 void mnt_release_group_id(struct mount *);
 int get_dominating_id(struct mount *mnt, const struct path *root);
-unsigned int mnt_get_count(struct mount *mnt);
+int mnt_get_count(struct mount *mnt);
 void mnt_set_mountpoint(struct mount *, struct mountpoint *,
 			struct mount *);
 void mnt_change_mountpoint(struct mount *parent, struct mountpoint *mp,
-- 
2.27.0




  parent reply	other threads:[~2021-01-04 16:03 UTC|newest]

Thread overview: 75+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-04 15:56 [PATCH 5.10 00/63] 5.10.5-rc1 review Greg Kroah-Hartman
2021-01-04 15:56 ` [PATCH 5.10 01/63] net/sched: sch_taprio: reset child qdiscs before freeing them Greg Kroah-Hartman
2021-01-04 22:58   ` Sasha Levin
2021-01-04 23:06     ` Jakub Kicinski
2021-01-04 15:56 ` [PATCH 5.10 02/63] mptcp: fix security context on server socket Greg Kroah-Hartman
2021-01-04 15:56 ` [PATCH 5.10 03/63] ethtool: fix error paths in ethnl_set_channels() Greg Kroah-Hartman
2021-01-04 15:56 ` [PATCH 5.10 04/63] ethtool: fix string set id check Greg Kroah-Hartman
2021-01-04 15:56 ` [PATCH 5.10 05/63] md/raid10: initialize r10_bio->read_slot before use Greg Kroah-Hartman
2021-01-04 15:56 ` [PATCH 5.10 06/63] drm/amd/display: Add get_dig_frontend implementation for DCEx Greg Kroah-Hartman
2021-01-04 15:57 ` [PATCH 5.10 07/63] io_uring: close a small race gap for files cancel Greg Kroah-Hartman
2021-01-04 15:57 ` [PATCH 5.10 08/63] jffs2: Allow setting rp_size to zero during remounting Greg Kroah-Hartman
2021-01-04 15:57 ` [PATCH 5.10 09/63] jffs2: Fix NULL pointer dereference in rp_size fs option parsing Greg Kroah-Hartman
2021-01-04 15:57 ` [PATCH 5.10 10/63] spi: dw-bt1: Fix undefined devm_mux_control_get symbol Greg Kroah-Hartman
2021-01-04 15:57 ` [PATCH 5.10 11/63] opp: fix memory leak in _allocate_opp_table Greg Kroah-Hartman
2021-01-04 15:57 ` [PATCH 5.10 12/63] opp: Call the missing clk_put() on error Greg Kroah-Hartman
2021-01-04 15:57 ` [PATCH 5.10 13/63] scsi: block: Fix a race in the runtime power management code Greg Kroah-Hartman
2021-01-04 15:57 ` [PATCH 5.10 14/63] mm/hugetlb: fix deadlock in hugetlb_cow error path Greg Kroah-Hartman
2021-01-04 15:57 ` [PATCH 5.10 15/63] mm: memmap defer init doesnt work as expected Greg Kroah-Hartman
2021-01-04 15:57 ` [PATCH 5.10 16/63] lib/zlib: fix inflating zlib streams on s390 Greg Kroah-Hartman
2021-01-04 15:57 ` [PATCH 5.10 17/63] io_uring: dont assume mm is constant across submits Greg Kroah-Hartman
2021-01-04 15:57 ` [PATCH 5.10 18/63] io_uring: use bottom half safe lock for fixed file data Greg Kroah-Hartman
2021-01-04 15:57 ` [PATCH 5.10 19/63] io_uring: add a helper for setting a ref node Greg Kroah-Hartman
2021-01-04 15:57 ` [PATCH 5.10 20/63] io_uring: fix io_sqe_files_unregister() hangs Greg Kroah-Hartman
2021-01-04 15:57 ` [PATCH 5.10 21/63] kernel/io_uring: cancel io_uring before task works Greg Kroah-Hartman
2021-01-04 16:06   ` Pavel Begunkov
2021-01-04 17:43     ` Sasha Levin
2021-01-04 15:57 ` [PATCH 5.10 22/63] uapi: move constants from <linux/kernel.h> to <linux/const.h> Greg Kroah-Hartman
2021-01-04 15:57 ` [PATCH 5.10 23/63] tools headers UAPI: Sync linux/const.h with the kernel headers Greg Kroah-Hartman
2021-01-04 15:57 ` [PATCH 5.10 24/63] cgroup: Fix memory leak when parsing multiple source parameters Greg Kroah-Hartman
2021-01-04 15:57 ` [PATCH 5.10 25/63] zlib: move EXPORT_SYMBOL() and MODULE_LICENSE() out of dfltcc_syms.c Greg Kroah-Hartman
2021-01-04 15:57 ` [PATCH 5.10 26/63] scsi: cxgb4i: Fix TLS dependency Greg Kroah-Hartman
2021-01-04 15:57 ` [PATCH 5.10 27/63] Bluetooth: hci_h5: close serdev device and free hu in h5_close Greg Kroah-Hartman
2021-01-04 15:57 ` [PATCH 5.10 28/63] fbcon: Disable accelerated scrolling Greg Kroah-Hartman
2021-01-07  8:13   ` Geert Uytterhoeven
2021-01-04 15:57 ` [PATCH 5.10 29/63] reiserfs: add check for an invalid ih_entry_count Greg Kroah-Hartman
2021-01-04 15:57 ` [PATCH 5.10 30/63] misc: vmw_vmci: fix kernel info-leak by initializing dbells in vmci_ctx_get_chkpt_doorbells() Greg Kroah-Hartman
2021-01-04 15:57 ` [PATCH 5.10 31/63] media: gp8psk: initialize stats at power control logic Greg Kroah-Hartman
2021-01-04 15:57 ` [PATCH 5.10 32/63] f2fs: fix shift-out-of-bounds in sanity_check_raw_super() Greg Kroah-Hartman
2021-01-04 15:57 ` [PATCH 5.10 33/63] ALSA: seq: Use bool for snd_seq_queue internal flags Greg Kroah-Hartman
2021-01-04 15:57 ` [PATCH 5.10 34/63] ALSA: rawmidi: Access runtime->avail always in spinlock Greg Kroah-Hartman
2021-01-04 15:57 ` [PATCH 5.10 35/63] bfs: dont use WARNING: string when its just info Greg Kroah-Hartman
2021-01-04 15:57 ` [PATCH 5.10 36/63] ext4: check for invalid block size early when mounting a file system Greg Kroah-Hartman
2021-01-04 15:57 ` [PATCH 5.10 37/63] fcntl: Fix potential deadlock in send_sig{io, urg}() Greg Kroah-Hartman
2021-01-04 15:57 ` [PATCH 5.10 38/63] io_uring: check kthread stopped flag when sq thread is unparked Greg Kroah-Hartman
2021-01-04 15:57 ` [PATCH 5.10 39/63] rtc: sun6i: Fix memleak in sun6i_rtc_clk_init Greg Kroah-Hartman
2021-01-04 15:57 ` [PATCH 5.10 40/63] module: set MODULE_STATE_GOING state when a module fails to load Greg Kroah-Hartman
2021-01-04 15:57 ` [PATCH 5.10 41/63] quota: Dont overflow quota file offsets Greg Kroah-Hartman
2021-01-04 15:57 ` [PATCH 5.10 42/63] rtc: pl031: fix resource leak in pl031_probe Greg Kroah-Hartman
2021-01-04 15:57 ` [PATCH 5.10 43/63] powerpc: sysdev: add missing iounmap() on error in mpic_msgr_probe() Greg Kroah-Hartman
2021-01-04 15:57 ` [PATCH 5.10 44/63] i3c master: fix missing destroy_workqueue() on error in i3c_master_register Greg Kroah-Hartman
2021-01-04 15:57 ` [PATCH 5.10 45/63] NFSv4: Fix a pNFS layout related use-after-free race when freeing the inode Greg Kroah-Hartman
2021-01-04 15:57 ` [PATCH 5.10 46/63] f2fs: avoid race condition for shrinker count Greg Kroah-Hartman
2021-01-04 15:57 ` [PATCH 5.10 47/63] f2fs: fix race of pending_pages in decompression Greg Kroah-Hartman
2021-01-04 15:57 ` [PATCH 5.10 48/63] module: delay kobject uevent until after module init call Greg Kroah-Hartman
2021-01-04 15:57 ` [PATCH 5.10 49/63] powerpc/64: irq replay remove decrementer overflow check Greg Kroah-Hartman
2021-01-04 15:57 ` Greg Kroah-Hartman [this message]
2021-01-04 15:57 ` [PATCH 5.10 51/63] watchdog: rti-wdt: fix reference leak in rti_wdt_probe Greg Kroah-Hartman
2021-01-04 15:57 ` [PATCH 5.10 52/63] um: random: Register random as hwrng-core device Greg Kroah-Hartman
2021-01-04 15:57 ` [PATCH 5.10 53/63] um: ubd: Submit all data segments atomically Greg Kroah-Hartman
2021-01-04 15:57 ` [PATCH 5.10 54/63] NFSv4.2: Dont error when exiting early on a READ_PLUS buffer overflow Greg Kroah-Hartman
2021-01-04 15:57 ` [PATCH 5.10 55/63] ceph: fix inode refcount leak when ceph_fill_inode on non-I_NEW inode fails Greg Kroah-Hartman
2021-01-04 15:57 ` [PATCH 5.10 56/63] drm/amd/display: updated wm table for Renoir Greg Kroah-Hartman
2021-01-04 15:57 ` [PATCH 5.10 57/63] tick/sched: Remove bogus boot "safety" check Greg Kroah-Hartman
2021-01-04 15:57 ` [PATCH 5.10 58/63] s390: always clear kernel stack backchain before calling functions Greg Kroah-Hartman
2021-01-04 15:57 ` [PATCH 5.10 59/63] io_uring: remove racy overflow list fast checks Greg Kroah-Hartman
2021-01-04 15:57 ` [PATCH 5.10 60/63] ALSA: pcm: Clear the full allocated memory at hw_params Greg Kroah-Hartman
2021-01-04 15:57 ` [PATCH 5.10 61/63] dm verity: skip verity work if I/O error when system is shutting down Greg Kroah-Hartman
2021-01-04 15:57 ` [PATCH 5.10 62/63] ext4: avoid s_mb_prefetch to be zero in individual scenarios Greg Kroah-Hartman
2021-01-04 15:57 ` [PATCH 5.10 63/63] device-dax: Fix range release Greg Kroah-Hartman
2021-01-05  6:06 ` [PATCH 5.10 00/63] 5.10.5-rc1 review Daniel Díaz
2021-01-05 12:55 ` Jeffrin Jose T
2021-01-05 13:05   ` Greg Kroah-Hartman
2021-01-06 18:43     ` Jeffrin Jose T
2021-01-05 16:38 ` Shuah Khan
2021-01-05 18:17 ` Guenter Roeck

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210104155711.239399679@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=ebiggers@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=miklos@szeredi.hu \
    --cc=sashal@kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).