Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752580AbdGFA7m (ORCPT ); Wed, 5 Jul 2017 20:59:42 -0400 Received: from mail-bl2nam02on0121.outbound.protection.outlook.com ([104.47.38.121]:64144 "EHLO NAM02-BL2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751914AbdGFA7k (ORCPT ); Wed, 5 Jul 2017 20:59:40 -0400 From: Pavel Shilovskiy To: Rabin Vincent , "sfrench@samba.org" CC: "linux-cifs@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "viro@zeniv.linux.org.uk" , Rabin Vincent Subject: RE: [PATCH] CIFS: fix circular locking dependency Thread-Topic: [PATCH] CIFS: fix circular locking dependency Thread-Index: AQHS8OBBQyp0E2p7qkCnPIYiM6pDLKJGBEfQ Date: Thu, 6 Jul 2017 00:59:36 +0000 Message-ID: References: <1498744902-22754-1-git-send-email-rabin.vincent@axis.com> In-Reply-To: <1498744902-22754-1-git-send-email-rabin.vincent@axis.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: msip_labels: MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_Enabled=True; MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_SiteId=72f988bf-86f1-41af-91ab-2d7cd011db47; MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_Ref=https://api.informationprotection.azure.com/api/72f988bf-86f1-41af-91ab-2d7cd011db47; MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_Owner=pshilov@microsoft.com; MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_SetDate=2017-07-05T17:59:34.4753728-07:00; MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_Name=General; MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_Application=Microsoft Azure Information Protection; MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_Extended_MSFT_Method=Automatic; Sensitivity=General authentication-results: axis.com; dkim=none (message not signed) header.d=none;axis.com; dmarc=none action=none header.from=microsoft.com; x-originating-ip: [2601:600:897f:eccf:850d:837e:8c39:dce3] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;CY4PR21MB0168;7:dVH+06qbLDE9HQOJK3+JoPzZzPPJUlAN+9pRETPUHjOkNi1eu/0jb7hRf3h3TCnG4mpAN6Q6jleCoq16VOlXK6v64S5X6Cw6+9RIU73yyS93JwyADYcM6+nQL2N4zsbTrLF7EA9vInUTuVecGEzA0OkhxOAmYQhk7f5Tmibvhy9ePa+PzZ9yyEcox7sUrG9O+mM9ZCxpaug0n8qx+Q4yR7zmKRUrmlicClyq+yk5B2XcxODjepo1xBFKfkAmIS9GEFFG4cx9yMmuyWiRZ8z9swkEoySsQoZfJH5NWi4ggo1TKqwt+cvLbLnUrzTQbSFnVcGwhimiqzWIJSZ5nqc38nk7zZkvm06yRRi/lA8Zsb1IEQgcSOT8K6sD/nmknqq+MUges/Ph+u3HO8mJCkhjK6ZMNnnlJz/ozFdVp/aElCfA0gbUu13rOACNwbfaKmDijYqWk/9wjtZav7LO2cIXWuqhNAu4Rt3GTWr29Jk0cUMFvxj0sI/Hx0KLaC6rby2EYn1TZY3wgN8X6yYvpO7vIFuTkXkwrtFp1Fd3yNlZ3xkFZaLK++EVeFrqemkw7rQ5wnZQyRxdopaqv0Gf1EZy6eujNEG2+w+9KJL0EnOOJCVaBpxEr7rnWvf6KLRkqnudZtRhTpxb5z7jaRDDS52JzRoVKfYzW3UPnLILcsV6Ado8eUTvHcvPd9PsVvHILEMW2euR7jEGMUVMBV+J/0u6OqGDugPea2hQBgPExhvdzUtWk6Z/ZBpb8j0hPlpcSWeG0ibzwYTgCCrH3y/+MqASEpr+17RTVm1grvTeUTam+BNJriXagNq0ZbzgJa1kIlWe x-ms-office365-filtering-correlation-id: b6e0210a-59f5-44e3-79d4-08d4c40a45b7 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(300000500095)(300135000095)(300000501095)(300135300095)(22001)(300000502095)(300135100095)(2017030254075)(48565401081)(300000503095)(300135400095)(2017052603031)(201703131423075)(201703031133081)(201702281549075)(300000504095)(300135200095)(300000505095)(300135600095)(300000506095)(300135500095);SRVR:CY4PR21MB0168; x-ms-traffictypediagnostic: CY4PR21MB0168: x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(158342451672863)(236129657087228)(9452136761055)(148574349560750); x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(61425038)(6040450)(601004)(2401047)(5005006)(2017060910040)(8121501046)(3002001)(10201501046)(100000703101)(100105400095)(93006095)(93001095)(6055026)(61426038)(61427038)(6041248)(20161123564025)(20161123560025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123555025)(20161123558100)(20161123562025)(6072148)(100000704101)(100105200095)(100000705101)(100105500095);SRVR:CY4PR21MB0168;BCL:0;PCL:0;RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095);SRVR:CY4PR21MB0168; x-forefront-prvs: 03607C04F0 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(6009001)(39450400003)(39860400002)(39410400002)(39840400002)(39850400002)(39400400002)(25786009)(77096006)(10090500001)(966005)(229853002)(5660300001)(6506006)(8676002)(6436002)(50986999)(8990500004)(6246003)(478600001)(53936002)(54906002)(9686003)(86612001)(99286003)(33656002)(55016002)(86362001)(2906002)(6306002)(76176999)(54356999)(189998001)(10290500003)(81166006)(2900100001)(7736002)(2950100002)(5005710100001)(2501003)(3660700001)(74316002)(38730400002)(14454004)(7696004)(6116002)(4326008)(8936002)(102836003)(305945005)(3280700002);DIR:OUT;SFP:1102;SCL:1;SRVR:CY4PR21MB0168;H:CY4PR21MB0135.namprd21.prod.outlook.com;FPR:;SPF:None;MLV:sfv;LANG:en; spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-originalarrivaltime: 06 Jul 2017 00:59:36.2733 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR21MB0168 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from quoted-printable to 8bit by nfs id v660xqP5023893 Content-Length: 4654 Lines: 140 2017-06-29 7:01 GMT-07:00 Rabin Vincent : > From: Rabin Vincent > > When a CIFS filesystem is mounted with the forcemand option and the > following command is run on it, lockdep warns about a circular locking > dependency between CifsInodeInfo::lock_sem and the inode lock. > > while echo foo > hello; do :; done & while touch -c hello; do :; done > > cifs_writev() takes the locks in the wrong order, but note that we can't > only flip the order around because it releases the inode lock before the > call to generic_write_sync() while it holds the lock_sem across that > call. > > But, AFAICS, there is no need to hold the CifsInodeInfo::lock_sem across > the generic_write_sync() call either, so we can release both the locks > before generic_write_sync(), and change the order. > > ====================================================== > WARNING: possible circular locking dependency detected > 4.12.0-rc7+ #9 Not tainted > ------------------------------------------------------ > touch/487 is trying to acquire lock: > (&cifsi->lock_sem){++++..}, at: cifsFileInfo_put+0x88f/0x16a0 > > but task is already holding lock: > (&sb->s_type->i_mutex_key#11){+.+.+.}, at: utimes_common+0x3ad/0x870 > > which lock already depends on the new lock. > > the existing dependency chain (in reverse order) is: > > -> #1 (&sb->s_type->i_mutex_key#11){+.+.+.}: > __lock_acquire+0x1f74/0x38f0 > lock_acquire+0x1cc/0x600 > down_write+0x74/0x110 > cifs_strict_writev+0x3cb/0x8c0 > __vfs_write+0x4c1/0x930 > vfs_write+0x14c/0x2d0 > SyS_write+0xf7/0x240 > entry_SYSCALL_64_fastpath+0x1f/0xbe > > -> #0 (&cifsi->lock_sem){++++..}: > check_prevs_add+0xfa0/0x1d10 > __lock_acquire+0x1f74/0x38f0 > lock_acquire+0x1cc/0x600 > down_write+0x74/0x110 > cifsFileInfo_put+0x88f/0x16a0 > cifs_setattr+0x992/0x1680 > notify_change+0x61a/0xa80 > utimes_common+0x3d4/0x870 > do_utimes+0x1c1/0x220 > SyS_utimensat+0x84/0x1a0 > entry_SYSCALL_64_fastpath+0x1f/0xbe > > other info that might help us debug this: > > Possible unsafe locking scenario: > > CPU0 CPU1 > ---- ---- > lock(&sb->s_type->i_mutex_key#11); > lock(&cifsi->lock_sem); > lock(&sb->s_type->i_mutex_key#11); > lock(&cifsi->lock_sem); > > *** DEADLOCK *** > > 2 locks held by touch/487: > #0: (sb_writers#10){.+.+.+}, at: mnt_want_write+0x41/0xb0 > #1: (&sb->s_type->i_mutex_key#11){+.+.+.}, at: utimes_common+0x3ad/0x870 > > stack backtrace: > CPU: 0 PID: 487 Comm: touch Not tainted 4.12.0-rc7+ #9 > Call Trace: > dump_stack+0xdb/0x185 > print_circular_bug+0x45b/0x790 > __lock_acquire+0x1f74/0x38f0 > lock_acquire+0x1cc/0x600 > down_write+0x74/0x110 > cifsFileInfo_put+0x88f/0x16a0 > cifs_setattr+0x992/0x1680 > notify_change+0x61a/0xa80 > utimes_common+0x3d4/0x870 > do_utimes+0x1c1/0x220 > SyS_utimensat+0x84/0x1a0 > entry_SYSCALL_64_fastpath+0x1f/0xbe > > Fixes: 19dfc1f5f2ef03a52 ("cifs: fix the race in cifs_writev()") > Signed-off-by: Rabin Vincent > --- > fs/cifs/file.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/fs/cifs/file.c b/fs/cifs/file.c > index fcef706..d16fa55 100644 > --- a/fs/cifs/file.c > +++ b/fs/cifs/file.c > @@ -2810,12 +2810,12 @@ cifs_writev(struct kiocb *iocb, struct iov_iter *from) > struct TCP_Server_Info *server = tlink_tcon(cfile->tlink)->ses->server; > ssize_t rc; > > + inode_lock(inode); > /* > * We need to hold the sem to be sure nobody modifies lock list > * with a brlock that prevents writing. > */ > down_read(&cinode->lock_sem); > - inode_lock(inode); > > rc = generic_write_checks(iocb, from); > if (rc <= 0) > @@ -2828,11 +2828,11 @@ cifs_writev(struct kiocb *iocb, struct iov_iter *from) > else > rc = -EACCES; > out: > + up_read(&cinode->lock_sem); > inode_unlock(inode); > > if (rc > 0) > rc = generic_write_sync(iocb, rc); > - up_read(&cinode->lock_sem); > return rc; > } > > -- > 2.1.4 > > -- > To unsubscribe from this list: send the line "unsubscribe linux-cifs" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html Acked-by: Pavel Shilovsky -- Best regards, Pavel Shilovsky