From patchwork Thu Oct 12 00:56:05 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liu Song X-Patchwork-Id: 824634 X-Patchwork-Delegate: dwmw2@infradead.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.infradead.org (client-ip=65.50.211.133; helo=bombadil.infradead.org; envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="acc4H6JQ"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3yCCDL3H3qz9s9Y for ; Thu, 12 Oct 2017 11:59:30 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=h4AQSS8adt5QU9ql16FjZjkHB0ZvlrpOD2oFM9oxugY=; b=acc 4H6JQCoF71Exq+UffXuqXHXWt75R8Gn9sCqGxZ9M4yu6mVJqbbIoqKHSFm2n7/OC72i4JM1q+cdyU P4+5H6ML6h/FxKeODDdKYBoYNjPjufJjt2cKwDCUthDFkiy9yBb4yGwWQWOAWCXWVS6SpZVQznrdl poSe6xm/4WXtTlpv62kdZSUeTaeaCOEDwo49V7H28BdxATt/aQa47WK0HffmceswqPsoN1grVQsiV Np6uaK/coggNaitfbprQKz+aCCohk7tE3VMKd/C4qN/AqGBJ/EvonHkQvOpp0oXqb4ZX+2d/fMwLy mM3ah9VvSntZd2ofrpeefoliKHv9l+Q==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1e2RqI-0004GG-EL; Thu, 12 Oct 2017 00:59:18 +0000 Received: from out1.zte.com.cn ([202.103.147.172] helo=mxct.zte.com.cn) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1e2RqC-0004Do-4T for linux-mtd@lists.infradead.org; Thu, 12 Oct 2017 00:59:16 +0000 Received: from mse01.zte.com.cn (unknown [10.30.3.20]) by Forcepoint Email with ESMTPS id 66C8CF3B6A1E0A929F3E; Thu, 12 Oct 2017 08:58:41 +0800 (CST) Received: from notes_smtp.zte.com.cn ([10.30.1.239]) by mse01.zte.com.cn with ESMTP id v9C0wLZJ081775; Thu, 12 Oct 2017 08:58:21 +0800 (GMT-8) (envelope-from liu.song11@zte.com.cn) Received: from localhost.localdomain ([10.75.10.200]) by szsmtp06.zte.com.cn (Lotus Domino Release 8.5.3FP6) with ESMTP id 2017101208582474-422736 ; Thu, 12 Oct 2017 08:58:24 +0800 From: Liu Song To: dwmw2@infradead.org Subject: [PATCH] jffs2: fix potential deadlock in jffs2_do_setattr Date: Thu, 12 Oct 2017 08:56:05 +0800 Message-Id: <1507769765-13478-1-git-send-email-liu.song11@zte.com.cn> X-Mailer: git-send-email 1.8.3.1 X-MIMETrack: Itemize by SMTP Server on SZSMTP06/server/zte_ltd(Release 8.5.3FP6|November 21, 2013) at 2017-10-12 08:58:25, Serialize by Router on notes_smtp/zte_ltd(Release 9.0.1FP7|August 17, 2016) at 2017-10-12 08:58:10, Serialize complete at 2017-10-12 08:58:10 X-MAIL: mse01.zte.com.cn v9C0wLZJ081775 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20171011_175912_360415_1B96A27D X-CRM114-Status: UNSURE ( 5.95 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -1.9 (-) X-Spam-Report: SpamAssassin version 3.4.1 on bombadil.infradead.org summary: Content analysis details: (-1.9 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record -0.0 RP_MATCHES_RCVD Envelope sender domain matches handover relay domain -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: jiang.biao2@zte.com.cn, linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org, zhong.weidong@zte.com.cn, liu.song11@zte.com.cn MIME-Version: 1.0 Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org In jffs2_do_setattr, we hold two mutexes which are A) c->alloc_sem B) f->sem If new_metadata is error, then we release mutexes in bad sequence which could cause ABAB deadlock. This patch adjusts release sequence which could avoid deadlock. Signed-off-by: Liu Song Reviewed-by: Jiang Biao --- fs/jffs2/fs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/jffs2/fs.c b/fs/jffs2/fs.c index 76fa814..f998126 100644 --- a/fs/jffs2/fs.c +++ b/fs/jffs2/fs.c @@ -140,9 +140,9 @@ int jffs2_do_setattr (struct inode *inode, struct iattr *iattr) kfree(mdata); if (IS_ERR(new_metadata)) { - jffs2_complete_reservation(c); jffs2_free_raw_inode(ri); mutex_unlock(&f->sem); + jffs2_complete_reservation(c); return PTR_ERR(new_metadata); } /* It worked. Update the inode */