From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Luis Henriques <lhenriques@suse.com>,
Jeff Layton <jlayton@kernel.org>,
Ilya Dryomov <idryomov@gmail.com>,
Sasha Levin <sashal@kernel.org>,
ceph-devel@vger.kernel.org
Subject: [PATCH AUTOSEL 4.14 24/27] ceph: fix buffer free while holding i_ceph_lock in __ceph_setxattr()
Date: Thu, 29 Aug 2019 14:16:50 -0400 [thread overview]
Message-ID: <20190829181655.8741-24-sashal@kernel.org> (raw)
In-Reply-To: <20190829181655.8741-1-sashal@kernel.org>
From: Luis Henriques <lhenriques@suse.com>
[ Upstream commit 86968ef21596515958d5f0a40233d02be78ecec0 ]
Calling ceph_buffer_put() in __ceph_setxattr() may end up freeing the
i_xattrs.prealloc_blob buffer while holding the i_ceph_lock. This can be
fixed by postponing the call until later, when the lock is released.
The following backtrace was triggered by fstests generic/117.
BUG: sleeping function called from invalid context at mm/vmalloc.c:2283
in_atomic(): 1, irqs_disabled(): 0, pid: 650, name: fsstress
3 locks held by fsstress/650:
#0: 00000000870a0fe8 (sb_writers#8){.+.+}, at: mnt_want_write+0x20/0x50
#1: 00000000ba0c4c74 (&type->i_mutex_dir_key#6){++++}, at: vfs_setxattr+0x55/0xa0
#2: 000000008dfbb3f2 (&(&ci->i_ceph_lock)->rlock){+.+.}, at: __ceph_setxattr+0x297/0x810
CPU: 1 PID: 650 Comm: fsstress Not tainted 5.2.0+ #437
Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.12.1-0-ga5cab58-prebuilt.qemu.org 04/01/2014
Call Trace:
dump_stack+0x67/0x90
___might_sleep.cold+0x9f/0xb1
vfree+0x4b/0x60
ceph_buffer_release+0x1b/0x60
__ceph_setxattr+0x2b4/0x810
__vfs_setxattr+0x66/0x80
__vfs_setxattr_noperm+0x59/0xf0
vfs_setxattr+0x81/0xa0
setxattr+0x115/0x230
? filename_lookup+0xc9/0x140
? rcu_read_lock_sched_held+0x74/0x80
? rcu_sync_lockdep_assert+0x2e/0x60
? __sb_start_write+0x142/0x1a0
? mnt_want_write+0x20/0x50
path_setxattr+0xba/0xd0
__x64_sys_lsetxattr+0x24/0x30
do_syscall_64+0x50/0x1c0
entry_SYSCALL_64_after_hwframe+0x49/0xbe
RIP: 0033:0x7ff23514359a
Signed-off-by: Luis Henriques <lhenriques@suse.com>
Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
fs/ceph/xattr.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/fs/ceph/xattr.c b/fs/ceph/xattr.c
index 0376db8a74f85..932c6cdc22d66 100644
--- a/fs/ceph/xattr.c
+++ b/fs/ceph/xattr.c
@@ -955,6 +955,7 @@ int __ceph_setxattr(struct inode *inode, const char *name,
struct ceph_inode_info *ci = ceph_inode(inode);
struct ceph_mds_client *mdsc = ceph_sb_to_client(inode->i_sb)->mdsc;
struct ceph_cap_flush *prealloc_cf = NULL;
+ struct ceph_buffer *old_blob = NULL;
int issued;
int err;
int dirty = 0;
@@ -1023,13 +1024,15 @@ int __ceph_setxattr(struct inode *inode, const char *name,
struct ceph_buffer *blob;
spin_unlock(&ci->i_ceph_lock);
- dout(" preaallocating new blob size=%d\n", required_blob_size);
+ ceph_buffer_put(old_blob); /* Shouldn't be required */
+ dout(" pre-allocating new blob size=%d\n", required_blob_size);
blob = ceph_buffer_new(required_blob_size, GFP_NOFS);
if (!blob)
goto do_sync_unlocked;
spin_lock(&ci->i_ceph_lock);
+ /* prealloc_blob can't be released while holding i_ceph_lock */
if (ci->i_xattrs.prealloc_blob)
- ceph_buffer_put(ci->i_xattrs.prealloc_blob);
+ old_blob = ci->i_xattrs.prealloc_blob;
ci->i_xattrs.prealloc_blob = blob;
goto retry;
}
@@ -1045,6 +1048,7 @@ int __ceph_setxattr(struct inode *inode, const char *name,
}
spin_unlock(&ci->i_ceph_lock);
+ ceph_buffer_put(old_blob);
if (lock_snap_rwsem)
up_read(&mdsc->snap_rwsem);
if (dirty)
--
2.20.1
next prev parent reply other threads:[~2019-08-29 18:17 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-08-29 18:16 [PATCH AUTOSEL 4.14 01/27] net: tundra: tsi108: use spin_lock_irqsave instead of spin_lock_irq in IRQ context Sasha Levin
2019-08-29 18:16 ` [PATCH AUTOSEL 4.14 02/27] hv_netvsc: Fix a warning of suspicious RCU usage Sasha Levin
2019-08-29 18:16 ` [PATCH AUTOSEL 4.14 03/27] net: tc35815: Explicitly check NET_IP_ALIGN is not zero in tc35815_rx Sasha Levin
2019-08-29 18:16 ` [PATCH AUTOSEL 4.14 04/27] Bluetooth: btqca: Add a short delay before downloading the NVM Sasha Levin
2019-08-29 18:16 ` [PATCH AUTOSEL 4.14 05/27] Bluetooth: hidp: Let hidp_send_message return number of queued bytes Sasha Levin
2019-08-29 18:16 ` [PATCH AUTOSEL 4.14 06/27] ibmveth: Convert multicast list size for little-endian system Sasha Levin
2019-08-29 18:16 ` [PATCH AUTOSEL 4.14 07/27] gpio: Fix build error of function redefinition Sasha Levin
2019-08-29 18:16 ` [PATCH AUTOSEL 4.14 08/27] drm/mediatek: use correct device to import PRIME buffers Sasha Levin
2019-08-29 18:16 ` [PATCH AUTOSEL 4.14 09/27] drm/mediatek: set DMA max segment size Sasha Levin
2019-08-29 18:16 ` [PATCH AUTOSEL 4.14 10/27] cxgb4: fix a memory leak bug Sasha Levin
2019-08-29 18:16 ` [PATCH AUTOSEL 4.14 11/27] liquidio: add cleanup in octeon_setup_iq() Sasha Levin
2019-08-29 18:16 ` [PATCH AUTOSEL 4.14 12/27] net: myri10ge: fix memory leaks Sasha Levin
2019-08-29 18:16 ` [PATCH AUTOSEL 4.14 13/27] lan78xx: Fix " Sasha Levin
2019-08-29 18:16 ` [PATCH AUTOSEL 4.14 14/27] vfs: fix page locking deadlocks when deduping files Sasha Levin
2019-08-29 18:16 ` [PATCH AUTOSEL 4.14 15/27] cx82310_eth: fix a memory leak bug Sasha Levin
2019-08-29 18:16 ` [PATCH AUTOSEL 4.14 16/27] net: kalmia: fix memory leaks Sasha Levin
2019-08-29 18:16 ` [PATCH AUTOSEL 4.14 17/27] wimax/i2400m: fix a memory leak bug Sasha Levin
2019-08-29 18:16 ` [PATCH AUTOSEL 4.14 18/27] ravb: Fix use-after-free ravb_tstamp_skb Sasha Levin
2019-08-29 18:16 ` [PATCH AUTOSEL 4.14 19/27] kprobes: Fix potential deadlock in kprobe_optimizer() Sasha Levin
2019-08-29 18:16 ` [PATCH AUTOSEL 4.14 20/27] HID: cp2112: prevent sleeping function called from invalid context Sasha Levin
2019-08-29 18:16 ` [PATCH AUTOSEL 4.14 21/27] Input: hyperv-keyboard: Use in-place iterator API in the channel callback Sasha Levin
2019-08-29 18:16 ` [PATCH AUTOSEL 4.14 22/27] Tools: hv: kvp: eliminate 'may be used uninitialized' warning Sasha Levin
2019-08-29 18:16 ` [PATCH AUTOSEL 4.14 23/27] IB/mlx4: Fix memory leaks Sasha Levin
2019-08-29 18:16 ` Sasha Levin [this message]
2019-08-29 18:16 ` [PATCH AUTOSEL 4.14 25/27] ceph: fix buffer free while holding i_ceph_lock in __ceph_build_xattrs_blob() Sasha Levin
2019-08-29 18:16 ` [PATCH AUTOSEL 4.14 26/27] ceph: fix buffer free while holding i_ceph_lock in fill_inode() Sasha Levin
2019-08-29 18:16 ` [PATCH AUTOSEL 4.14 27/27] KVM: arm/arm64: Only skip MMIO insn once Sasha Levin
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=20190829181655.8741-24-sashal@kernel.org \
--to=sashal@kernel.org \
--cc=ceph-devel@vger.kernel.org \
--cc=idryomov@gmail.com \
--cc=jlayton@kernel.org \
--cc=lhenriques@suse.com \
--cc=linux-kernel@vger.kernel.org \
--cc=stable@vger.kernel.org \
/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).