From patchwork Tue Jan 18 22:00:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "J. Bruce Fields" X-Patchwork-Id: 12716950 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D7B68C433F5 for ; Tue, 18 Jan 2022 22:00:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349293AbiARWAT (ORCPT ); Tue, 18 Jan 2022 17:00:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48322 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234970AbiARWAT (ORCPT ); Tue, 18 Jan 2022 17:00:19 -0500 Received: from fieldses.org (fieldses.org [IPv6:2600:3c00:e000:2f7::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D837DC061574 for ; Tue, 18 Jan 2022 14:00:18 -0800 (PST) Received: by fieldses.org (Postfix, from userid 2815) id F22986C0C; Tue, 18 Jan 2022 17:00:16 -0500 (EST) DKIM-Filter: OpenDKIM Filter v2.11.0 fieldses.org F22986C0C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fieldses.org; s=default; t=1642543216; bh=MmPaJ7SQ/ZgnQfvgzMR+1YqgblqtTeDgmqRRh+vB2+g=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=KxO4E+xKAkWLKfofbLKYVIlWuNhnXy07/LqDId2t2pklLGb1aaWRsF0WHLaZpzQIw THDWEB6+J0Ul9wvqCT7pOsJXt/xNvZFj77qIcF44fyG98YzX6I2NtEoSLx89iHCeso SFrTDSIsL8PGwJ+s8g3EzpXzjU0a1F7OzoHQ4Ap4= Date: Tue, 18 Jan 2022 17:00:16 -0500 From: Bruce Fields To: Jonathan Woithe Cc: Chuck Lever III , Linux NFS Mailing List Subject: [PATCH 1/2] lockd: fix server crash on reboot of client holding lock Message-ID: <20220118220016.GB16108@fieldses.org> References: <20220114103901.GA22009@marvin.atrad.com.au> <20220115081420.GB8808@marvin.atrad.com.au> <927EED04-840E-4DA6-B2B1-B604A7577B4E@oracle.com> <20220115212336.GB30050@marvin.atrad.com.au> <20220116220627.GA19813@marvin.atrad.com.au> <1E71316C-9EE8-4C71-ADA1-71E2910CA070@oracle.com> <20220117074430.GA22026@marvin.atrad.com.au> <20220117220851.GA8494@marvin.atrad.com.au> <20220117221156.GB3090@fieldses.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20220117221156.GB3090@fieldses.org> User-Agent: Mutt/1.5.21 (2010-09-15) Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org From: "J. Bruce Fields" I thought I was iterating over the array when actually the iteration is over the values contained in the array? Ugh, keep it simple. Symptoms were a null deference in vfs_lock_file() when an NFSv3 client that previously held a lock came back up and sent a notify. Reported-by: Jonathan Woithe Fixes: 7f024fcd5c97 ("Keep read and write fds with each nlm_file") Signed-off-by: J. Bruce Fields --- fs/lockd/svcsubs.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/fs/lockd/svcsubs.c b/fs/lockd/svcsubs.c index cb3a7512c33e..54c2e42130ca 100644 --- a/fs/lockd/svcsubs.c +++ b/fs/lockd/svcsubs.c @@ -179,19 +179,20 @@ nlm_delete_file(struct nlm_file *file) static int nlm_unlock_files(struct nlm_file *file) { struct file_lock lock; - struct file *f; lock.fl_type = F_UNLCK; lock.fl_start = 0; lock.fl_end = OFFSET_MAX; - for (f = file->f_file[0]; f <= file->f_file[1]; f++) { - if (f && vfs_lock_file(f, F_SETLK, &lock, NULL) < 0) { - pr_warn("lockd: unlock failure in %s:%d\n", - __FILE__, __LINE__); - return 1; - } - } + if (file->f_file[O_RDONLY] && + vfs_lock_file(file->f_file[O_RDONLY], F_SETLK, &lock, NULL)) + goto out_err; + if (file->f_file[O_WRONLY] && + vfs_lock_file(file->f_file[O_WRONLY], F_SETLK, &lock, NULL)) + goto out_err; return 0; +out_err: + pr_warn("lockd: unlock failure in %s:%d\n", __FILE__, __LINE__); + return 1; } /* From patchwork Tue Jan 18 22:00:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "J. Bruce Fields" X-Patchwork-Id: 12716951 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4BEBFC433F5 for ; Tue, 18 Jan 2022 22:00:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349415AbiARWAw (ORCPT ); Tue, 18 Jan 2022 17:00:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48452 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234970AbiARWAw (ORCPT ); Tue, 18 Jan 2022 17:00:52 -0500 Received: from fieldses.org (fieldses.org [IPv6:2600:3c00:e000:2f7::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 24E18C061574 for ; Tue, 18 Jan 2022 14:00:52 -0800 (PST) Received: by fieldses.org (Postfix, from userid 2815) id AD1D47932; Tue, 18 Jan 2022 17:00:51 -0500 (EST) DKIM-Filter: OpenDKIM Filter v2.11.0 fieldses.org AD1D47932 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fieldses.org; s=default; t=1642543251; bh=WGOvI8IIj24h1+BSgxcdMP9CEenlhAccdKKTGcwDqEc=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=rPDCdIaXVEb4GjpFncvEpF46XlIHZZ2RU2K5Fvlk9WCGeC8YiSC5LTlXCg23KzNjd x8f3gOEOI4yjkAWzp5i0veruOj3hppZ5lAOcRWxiKi2ClJm3fFdS0rlg3YD54CZ5aP 7ankNBOEMy+bsQ/jhG4fhySnVuswdZ9KmBbpuJGY= Date: Tue, 18 Jan 2022 17:00:51 -0500 From: Bruce Fields To: Jonathan Woithe Cc: Chuck Lever III , Linux NFS Mailing List Subject: [PATCH 2/2] lockd: fix failure to cleanup client locks Message-ID: <20220118220051.GC16108@fieldses.org> References: <20220115081420.GB8808@marvin.atrad.com.au> <927EED04-840E-4DA6-B2B1-B604A7577B4E@oracle.com> <20220115212336.GB30050@marvin.atrad.com.au> <20220116220627.GA19813@marvin.atrad.com.au> <1E71316C-9EE8-4C71-ADA1-71E2910CA070@oracle.com> <20220117074430.GA22026@marvin.atrad.com.au> <20220117220851.GA8494@marvin.atrad.com.au> <20220117221156.GB3090@fieldses.org> <20220118220016.GB16108@fieldses.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20220118220016.GB16108@fieldses.org> User-Agent: Mutt/1.5.21 (2010-09-15) Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org From: "J. Bruce Fields" In my testing, we're sometimes hitting the request->fl_flags & FL_EXISTS case in posix_lock_inode, presumably just by random luck since we're not actually initializing fl_flags here. This probably didn't matter before 7f024fcd5c97 "Keep read and write fds with each nlm_file" since we wouldn't previously unlock unless we knew there were locks. But now it causes lockd to give up on removing more locks. We could just initialize fl_flags, but really it seems dubious to be calling vfs_lock_file with random values in some of the fields. Fixes: 7f024fcd5c97 ("Keep read and write fds with each nlm_file") Signed-off-by: J. Bruce Fields --- fs/lockd/svcsubs.c | 1 + 1 file changed, 1 insertion(+) diff --git a/fs/lockd/svcsubs.c b/fs/lockd/svcsubs.c index 54c2e42130ca..0a22a2faf552 100644 --- a/fs/lockd/svcsubs.c +++ b/fs/lockd/svcsubs.c @@ -180,6 +180,7 @@ static int nlm_unlock_files(struct nlm_file *file) { struct file_lock lock; + locks_init_lock(&lock); lock.fl_type = F_UNLCK; lock.fl_start = 0; lock.fl_end = OFFSET_MAX;