From patchwork Sat Feb 11 15:45:25 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 9568019 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id E17876043D for ; Sat, 11 Feb 2017 15:45:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C655626247 for ; Sat, 11 Feb 2017 15:45:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B97CA2855E; Sat, 11 Feb 2017 15:45:37 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id ED46726247 for ; Sat, 11 Feb 2017 15:45:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750733AbdBKPpd (ORCPT ); Sat, 11 Feb 2017 10:45:33 -0500 Received: from us-smtp-delivery-194.mimecast.com ([63.128.21.194]:39050 "EHLO us-smtp-delivery-194.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750713AbdBKPpc (ORCPT ); Sat, 11 Feb 2017 10:45:32 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=PrimaryData.onmicrosoft.com; s=selector1-primarydata-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=+9vmLyMpxAtPrBo/peyMyPxHciBq6u6dAI1FnAqX9XE=; b=YDHpqZXoeMghbMUhcoBgkzKlJDXdhUpU9ruGPGkf0Z6lDd/GjQeDQW7KdMBDzdIXDv8jCzjnkblzM9H6bZKmwAtee97IQxKHt+udR6IXpwHv5lkCTa7FpjeyQgt+VEGx4k+DcKrgMGGLMU9l4c/Sx6ADfCNaq9R4v6OsWiEsheY= Received: from NAM03-CO1-obe.outbound.protection.outlook.com (mail-co1nam03lp0021.outbound.protection.outlook.com [216.32.181.21]) (Using TLS) by us-smtp-1.mimecast.com with ESMTP id us-mta-126-7qZZaACiOy6MWVQmQgcE5w-1; Sat, 11 Feb 2017 10:45:29 -0500 Received: from BN6PR11MB1570.namprd11.prod.outlook.com (10.172.22.149) by BN6PR11MB1571.namprd11.prod.outlook.com (10.172.22.150) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.888.16; Sat, 11 Feb 2017 15:45:26 +0000 Received: from BN6PR11MB1570.namprd11.prod.outlook.com ([10.172.22.149]) by BN6PR11MB1570.namprd11.prod.outlook.com ([10.172.22.149]) with mapi id 15.01.0888.029; Sat, 11 Feb 2017 15:45:25 +0000 From: Trond Myklebust To: "psingh.ait@gmail.com" CC: "linux-nfs@vger.kernel.org" Subject: Re: How NLM support posix threads? Thread-Topic: How NLM support posix threads? Thread-Index: AQHSg4MG42lRh8UZRUGtSh89yka/fqFiWLkAgAD95QCAAJ4RAA== Date: Sat, 11 Feb 2017 15:45:25 +0000 Message-ID: <1486827922.3490.2.camel@primarydata.com> References: <1486739454.19587.1.camel@primarydata.com> In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-messagesentrepresentingtype: 1 x-originating-ip: [68.49.162.121] x-ms-office365-filtering-correlation-id: af1caf62-deb7-425c-6621-08d45294ff39 x-microsoft-antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001); SRVR:BN6PR11MB1571; x-microsoft-exchange-diagnostics: 1; BN6PR11MB1571; 7:XWmO+/f/GPPcIRQflDmH/xTcxkkedPV3U5KhbjLMYqo5GMIpumqyUdRNqAlZMleixB8iZJnS8OKLyp/88gsivNNdECXbitoPQJrkfC0Tz2v62acTpeX9OcPeJwpcbyUS1ZfIEq/g6FEdHElYdq86a6LCw8ipYc3dk/GfA8RlD1RCfVMLRYvMIzW8h3UPl1zDvs++pZGSrTSuq7J9dIipyJaFZQ6ApdSi3UyAfd+6LrogU9I5OkXwESaP5Ess9X+IsvgTgpTh0JeS5+BLZNPnPeWc1NicjQ73J16GvvqcbYSjrKun4daJW4/CtIQycQr/QA5uoMipWtxRsFIH2DaieNs8GsZ5sMg3hxodTMQaG6fxvzBaVpurMeOWARqDss6sqgsbc1mna1YdaFulxE06y0dQXxYBiW41RVEXQokhjY+SmoRcFIrMopyrM8BdXMS5yIzWzj/LRgJXQrvqnjRpvhTfaF+qcXi5enITdhmiKsjVbHuHbrcng1AlIteoRj+7RlxTaJHU8hQYqWJ2NU7U0g==; 20:wwUNhnHk+hqhmsXRnyzuc33rcEyzR7pfNQsAvjjAFU6ObUOlDtggsjz9KjMnRipdeUlF2GyFNRXg/5GLhfAVzyPuSdOE3rhaeD8MhlnGj0oDvSawxC6hYLzriK5toxuzg9mBe1Gd0jLB4r/2PINA/pK1Jaf/SAF8NgesYuM168c= x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(158342451672863)(9452136761055); x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(6040375)(601004)(2401047)(8121501046)(5005006)(3002001)(10201501046)(6041248)(20161123558025)(2016111802025)(20161123562025)(20161123555025)(20161123564025)(20161123560025)(6043046)(6072148); SRVR:BN6PR11MB1571; BCL:0; PCL:0; RULEID:; SRVR:BN6PR11MB1571; x-forefront-prvs: 0215D7173F x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(6009001)(7916002)(39830400002)(39410400002)(39450400003)(199003)(24454002)(377424004)(189002)(103116003)(8936002)(97736004)(122556002)(8676002)(81156014)(33646002)(39060400001)(189998001)(66066001)(81166006)(6486002)(2501003)(77096006)(6116002)(102836003)(3846002)(305945005)(3660700001)(6506006)(229853002)(92566002)(7736002)(36756003)(4326007)(38730400002)(2900100001)(110136004)(86362001)(5640700003)(2906002)(6436002)(105586002)(53936002)(3280700002)(76176999)(106116001)(5660300001)(6246003)(2950100002)(68736007)(6916009)(101416001)(99286003)(6512007)(25786008)(2351001)(54356999)(50986999)(106356001); DIR:OUT; SFP:1102; SCL:1; SRVR:BN6PR11MB1571; H:BN6PR11MB1570.namprd11.prod.outlook.com; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX:1; LANG:en; spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-ID: MIME-Version: 1.0 X-OriginatorOrg: primarydata.com X-MS-Exchange-CrossTenant-originalarrivaltime: 11 Feb 2017 15:45:25.4149 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 03193ed6-8726-4bb3-a832-18ab0d28adb7 X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN6PR11MB1571 X-MC-Unique: 7qZZaACiOy6MWVQmQgcE5w-1 Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On Sat, 2017-02-11 at 11:49 +0530, Pankaj Singh wrote: > > During "fl_grant" callback wrong "block" will be compared hence > > this will result in lock failure even if lock is actually granted. > > "nlm_compare_locks" will compare the locks on the bases of pid, > owner, > start offset, end offset and type. In case of posix threads as pid is > same, also all other parameters can be same for locks of different > files. > > Now the scenario is, if there are two posix thread with pid p1 and > they try to take the lock on different files (say l1 and l2) then > different blocks will be created (say b1 and b2). In this case > underline filesystem may send "FILE_LOCK_DEFERRED" for both the locks > and these blocks will be added to deferred block list. > > So during "fl_grant" callback lock are compared with the blocks of > block list. Now lets say callback is called for l1 and the comparison > will succeed with b1 (this is as expected) and B_GOT_CALLBACK flag > will be set. But as b1 is still in block list, now when callback for > l2 arrives then also comparison with b1 can succeed instead of b2 > because b1 is prior to b2 in the list. Hence B_GOT_CALLBACK flag will > not be set for b2 and when NFS client will retry for lock then lock > will be denied. > > Below is the snipt fl_grant code where comparison happens. > list_for_each_entry(block, &nlm_blocked, b_list) { > if (nlm_compare_locks(&block->b_call->a_args.lock.fl, fl) OK. I see what you mean. You are saying, in essence, that in the lockd server code, nlmsvc_notify_blocked() needs to check that the files are the same (just like nlmsvc_lookup_block() already does). I agree. That is a bug and it needs to be fixed. How about the following? Cheers Trond 8<--------------------------------------------------------------- From fff75e35ed857b9ad211905fee2acffa528696d9 Mon Sep 17 00:00:00 2001 From: Trond Myklebust Date: Sat, 11 Feb 2017 10:37:38 -0500 Subject: [PATCH] nlm: Ensure callback code also checks that the files match It is not sufficient to just check that the lock pids match when granting a callback, we also need to ensure that we're granting the callback on the right file. Reported-by: Pankaj Singh Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Cc: stable@vger.kernel.org Signed-off-by: Trond Myklebust --- include/linux/lockd/lockd.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) -- 2.9.3 -- Trond Myklebust Linux NFS client maintainer, PrimaryData trond.myklebust@primarydata.com diff --git a/include/linux/lockd/lockd.h b/include/linux/lockd/lockd.h index c15373894a42..b37dee3acaba 100644 --- a/include/linux/lockd/lockd.h +++ b/include/linux/lockd/lockd.h @@ -355,7 +355,8 @@ static inline int nlm_privileged_requester(const struct svc_rqst *rqstp) static inline int nlm_compare_locks(const struct file_lock *fl1, const struct file_lock *fl2) { - return fl1->fl_pid == fl2->fl_pid + return file_inode(fl1->fl_file) == file_inode(fl2->fl_file) + && fl1->fl_pid == fl2->fl_pid && fl1->fl_owner == fl2->fl_owner && fl1->fl_start == fl2->fl_start && fl1->fl_end == fl2->fl_end