Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp562039imu; Tue, 27 Nov 2018 17:20:39 -0800 (PST) X-Google-Smtp-Source: AFSGD/VyiO/1Kw4jFi2ySDxOetm3Ax+GmW1URO9/0rolyWx/89odNjgVExJUntzlqGg/56vUqOi/ X-Received: by 2002:a17:902:1105:: with SMTP id d5mr24004423pla.47.1543368039269; Tue, 27 Nov 2018 17:20:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543368039; cv=none; d=google.com; s=arc-20160816; b=JVwHTRuyIx11IssyVelwuaPAfBvrsVWVr0XCn/6A1rdQ+u+W0aMJAOToLA3XMAlpK3 5NAumHnMILq7uZDEKwTwZgxdfSHBEspaBUIh+DkuZX2ugR+k4sJz6swxnyqUwKmMXfzC XUtK3OfTgQgh9+QgZvt4RnX2Y5IY+ALR4/1tREeRj/uyuPS/P3ojuz2X6v8oX852mcLM Xs8T8WXoVzDgOWsS3Y87PE7IJl4buUVU6k1zryDpuVLyY8D+CnwtHiYkaFNFBmlCLmyM R9bxg3jpAC+B/EXhmlvBHrC+XUVLP7f+sIAP2VR7nU+lnH8aRgsONx9PU3OgqDc01MVu rsbw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=bUG3BXlqTV7jjdeCP5aBxJb9tjU/qkbhOMmkNaBmV3g=; b=MXfv0dWQnGeWVIzwabJKSxdqXlhVbD1umwpWEHQQ9+CN3Vv+wx7xCtkpJcQmbReGkB 5fB8OdckJg1VCSH1JHYvdvT9+uH3W9Zv751ZX1v5y/o6HZg8hTlQbPZNDLGW+5bSSsd3 yH47TlqC7z/B00f2VaT1oM1E6xktxJpy7FijkdH/+Z5e7eWPyc5McaiM5ijVyCJpzuT9 XLKJTmqi7fPz2WBGJIikcRmY73/t5Um3fB0P/ZMUVwc+HbVSVqPQNgXmHTX6xrtSh+08 ox/uLSSgylkvbPzDehqymNGgc0g6lCEaRcL0dNoXd2o91RVMTeS7n9by5lewO1yWX0NZ sP+Q== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t184si6053502pfb.22.2018.11.27.17.20.24; Tue, 27 Nov 2018 17:20:39 -0800 (PST) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727190AbeK1MTJ (ORCPT + 99 others); Wed, 28 Nov 2018 07:19:09 -0500 Received: from fieldses.org ([173.255.197.46]:43818 "EHLO fieldses.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726539AbeK1MTJ (ORCPT ); Wed, 28 Nov 2018 07:19:09 -0500 Received: by fieldses.org (Postfix, from userid 2815) id 3FF4A1E68; Tue, 27 Nov 2018 20:19:23 -0500 (EST) Date: Tue, 27 Nov 2018 20:19:23 -0500 From: "J. Bruce Fields" To: Anatoly Trosinenko Cc: Jeff Layton , linux-nfs@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: NFSd: NULL-dereference when writing to v4_end_grace when server is not yet started Message-ID: <20181128011923.GB15237@fieldses.org> References: <20181127205849.GB12810@fieldses.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20181127205849.GB12810@fieldses.org> User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Nov 27, 2018 at 03:58:49PM -0500, J. Bruce Fields wrote: > On Sun, Nov 25, 2018 at 09:17:10AM +0300, Anatoly Trosinenko wrote: > > When manually exploring the kernel NFSd feature, I have stumbled upon > > a NULL-dereference when writing to v4_end_grace when server is not yet > > started. > > Thanks for the report! > > I think this is what we want--it's what a lot of the other nfsctl > methods do. Hm, no, I'm getting a hang. It looks like in the nfsd4 state startup we call a cltrack upcall while holding the nfsd_mutex, then nfsdcltrack tries to write to end_grace. That's kind of ugly. --b. > commit ad5fdf47b4e3 > Author: J. Bruce Fields > Date: Tue Nov 27 15:54:17 2018 -0500 > > nfsd4: fix crash on writing v4_end_grace before nfsd startup > > Anatoly Trosinenko reports that this: > > 1) Checkout fresh master Linux branch (tested with commit e195ca6cb) > 2) Copy x84_64-config-4.14 to .config, then enable NFS server v4 and build > 3) From `kvm-xfstests shell`: > > results in NULL dereference in locks_end_grace. > > Check that nfsd has been started before trying to end the grace period. > > Reported-by: Anatoly Trosinenko > Signed-off-by: J. Bruce Fields > > diff --git a/fs/nfsd/nfsctl.c b/fs/nfsd/nfsctl.c > index 6384c9b94898..38b223c1378e 100644 > --- a/fs/nfsd/nfsctl.c > +++ b/fs/nfsd/nfsctl.c > @@ -1126,7 +1126,13 @@ static ssize_t write_v4_end_grace(struct file *file, char *buf, size_t size) > case 'Y': > case 'y': > case '1': > + mutex_lock(&nfsd_mutex); > + if (nn->nfsd_serv) { > + mutex_unlock(&nfsd_mutex); > + return -EBUSY; > + } > nfsd4_end_grace(nn); > + mutex_unlock(&nfsd_mutex); > break; > default: > return -EINVAL;