Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp2686605ybl; Thu, 29 Aug 2019 11:28:21 -0700 (PDT) X-Google-Smtp-Source: APXvYqyUUQ4N/jLun7DfTfOY1rD9nP+70761lpElhaBDhngwu7oRqumHwKXI4zpzUqpeXRsRVmY9 X-Received: by 2002:a17:902:2be7:: with SMTP id l94mr6234339plb.55.1567103301775; Thu, 29 Aug 2019 11:28:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567103301; cv=none; d=google.com; s=arc-20160816; b=W1RA7aRWfjEEZfTio8th1NhWUz/4yykcHYDn55qPpLpWTjVj1wvqvAEO6h/3PaJaQp ywmWuWeBqPan5lZHiPTNXC1Emx4GompxEUes0a3RlcBbSZwRbP3ztkA762hzlqjhsfw1 HVmejESbxN7SRwnvX+7+9XWraJU1VXOct4Ex2vq6gKiI1imDQyGUiDTZUoKxBQUtkCTC ZEQ2YNFOkSv1oC6gFTTKBjbQpJQUqOj8669TDh7YOx1kyymY9kZCUBFU7DYYxdj04wJl b6lIIP3CkqSpEWPNQZcjn17jRnvNdlzdOH9P08yZuir4F7EvPGEXXsDXo8SAF5ukwYho GsSg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=KziH+pQH+wMpcVxIX3N1OVbkNc1lN7JIC2QsKJPQ+BE=; b=ukK6zsZCYHJQN8HWJlgsKcoG8Xujfl67W1jptnuW1xImn2Y4NH+C6T3m0CNJx4BlZd 1TjL+aczj1eZMTLr2VVp2ADfT2W9jRTrmhaiZVp5kSCLUZSpVy6nGhsg9kPhTOfDeWqi A/0skFIXKfE1eqv35YjfBA/DGaFUhKPJ4Acf657EcrllkCaWPvFJVGJ4aRFXSqDOPYa9 9lw3Uyj0YtNN9XbSaSPsQBpoRx3RZOFKoHD6pX9eJet1eY/dGJ0b1BWFHdvzGHSW+TOf c1W6AQv9++xXxtSp1xHzL7T8OFOidA+yo4HztD9U8Eq4ilTXLmEV3CCqLpie6/68mof4 Yddg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="Ew2xJK/o"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v11si2603760pgr.237.2019.08.29.11.28.06; Thu, 29 Aug 2019 11:28:21 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="Ew2xJK/o"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729422AbfH2S1U (ORCPT + 99 others); Thu, 29 Aug 2019 14:27:20 -0400 Received: from mail.kernel.org ([198.145.29.99]:57302 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729326AbfH2SPe (ORCPT ); Thu, 29 Aug 2019 14:15:34 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id B06FD2342B; Thu, 29 Aug 2019 18:15:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1567102533; bh=1AygM8Vd3GSX/fOlcCAGnWCFxkFENZvDPuie4ftI3pU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ew2xJK/o3U8uUfOIFSwJe4dgI6VxNIxRq/0FAzOE6vA/CBP1WSbBWcH2fYHCjStja 6/h1WxWsBq/+Gkc9Zl8txUH33gq+60mv5mlre410UkPF53H4gsMamWz3nhem/IaImr YPkh5t5zfVXpoof/W3lGT8cw6GSxf3uHvAkNdOXA= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Luis Henriques , Jeff Layton , Ilya Dryomov , Sasha Levin , ceph-devel@vger.kernel.org Subject: [PATCH AUTOSEL 5.2 68/76] ceph: fix buffer free while holding i_ceph_lock in fill_inode() Date: Thu, 29 Aug 2019 14:13:03 -0400 Message-Id: <20190829181311.7562-68-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190829181311.7562-1-sashal@kernel.org> References: <20190829181311.7562-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Luis Henriques [ Upstream commit af8a85a41734f37b67ba8ce69d56b685bee4ac48 ] Calling ceph_buffer_put() in fill_inode() may result in freeing the i_xattrs.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/070. BUG: sleeping function called from invalid context at mm/vmalloc.c:2283 in_atomic(): 1, irqs_disabled(): 0, pid: 3852, name: kworker/0:4 6 locks held by kworker/0:4/3852: #0: 000000004270f6bb ((wq_completion)ceph-msgr){+.+.}, at: process_one_work+0x1b8/0x5f0 #1: 00000000eb420803 ((work_completion)(&(&con->work)->work)){+.+.}, at: process_one_work+0x1b8/0x5f0 #2: 00000000be1c53a4 (&s->s_mutex){+.+.}, at: dispatch+0x288/0x1476 #3: 00000000559cb958 (&mdsc->snap_rwsem){++++}, at: dispatch+0x2eb/0x1476 #4: 000000000d5ebbae (&req->r_fill_mutex){+.+.}, at: dispatch+0x2fc/0x1476 #5: 00000000a83d0514 (&(&ci->i_ceph_lock)->rlock){+.+.}, at: fill_inode.isra.0+0xf8/0xf70 CPU: 0 PID: 3852 Comm: kworker/0:4 Not tainted 5.2.0+ #441 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.12.1-0-ga5cab58-prebuilt.qemu.org 04/01/2014 Workqueue: ceph-msgr ceph_con_workfn Call Trace: dump_stack+0x67/0x90 ___might_sleep.cold+0x9f/0xb1 vfree+0x4b/0x60 ceph_buffer_release+0x1b/0x60 fill_inode.isra.0+0xa9b/0xf70 ceph_fill_trace+0x13b/0xc70 ? dispatch+0x2eb/0x1476 dispatch+0x320/0x1476 ? __mutex_unlock_slowpath+0x4d/0x2a0 ceph_con_workfn+0xc97/0x2ec0 ? process_one_work+0x1b8/0x5f0 process_one_work+0x244/0x5f0 worker_thread+0x4d/0x3e0 kthread+0x105/0x140 ? process_one_work+0x5f0/0x5f0 ? kthread_park+0x90/0x90 ret_from_fork+0x3a/0x50 Signed-off-by: Luis Henriques Reviewed-by: Jeff Layton Signed-off-by: Ilya Dryomov Signed-off-by: Sasha Levin --- fs/ceph/inode.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/fs/ceph/inode.c b/fs/ceph/inode.c index 3c7a32779574b..ca3821b0309f7 100644 --- a/fs/ceph/inode.c +++ b/fs/ceph/inode.c @@ -743,6 +743,7 @@ static int fill_inode(struct inode *inode, struct page *locked_page, int issued, new_issued, info_caps; struct timespec64 mtime, atime, ctime; struct ceph_buffer *xattr_blob = NULL; + struct ceph_buffer *old_blob = NULL; struct ceph_string *pool_ns = NULL; struct ceph_cap *new_cap = NULL; int err = 0; @@ -883,7 +884,7 @@ static int fill_inode(struct inode *inode, struct page *locked_page, if ((ci->i_xattrs.version == 0 || !(issued & CEPH_CAP_XATTR_EXCL)) && le64_to_cpu(info->xattr_version) > ci->i_xattrs.version) { if (ci->i_xattrs.blob) - ceph_buffer_put(ci->i_xattrs.blob); + old_blob = ci->i_xattrs.blob; ci->i_xattrs.blob = xattr_blob; if (xattr_blob) memcpy(ci->i_xattrs.blob->vec.iov_base, @@ -1023,8 +1024,8 @@ static int fill_inode(struct inode *inode, struct page *locked_page, out: if (new_cap) ceph_put_cap(mdsc, new_cap); - if (xattr_blob) - ceph_buffer_put(xattr_blob); + ceph_buffer_put(old_blob); + ceph_buffer_put(xattr_blob); ceph_put_string(pool_ns); return err; } -- 2.20.1