Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp323096imu; Tue, 27 Nov 2018 13:01:04 -0800 (PST) X-Google-Smtp-Source: AFSGD/UeGzjJkOaQsYrg85XR/WcvDUg/R1TO2a4UI8nYfMJVK41Asvubd53uSiXbYW26NcRXnu6N X-Received: by 2002:a17:902:f20d:: with SMTP id gn13mr32881434plb.11.1543352464712; Tue, 27 Nov 2018 13:01:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543352464; cv=none; d=google.com; s=arc-20160816; b=YYTle98yU5SNmnJNG1FUXMxJDuRyImfkJKvHMUnDt+YOFU7IwFgSTKfKyEFFI4mYJX 3oR6OIqn9p8n0bdWONDX/O6LVewCPA1A1fpbh1ZGHgSdvDv5rWQTxu/lXU2QTde/7QvP xtZxdcqZ5i5VsT+YFXTQ7Kfi3CDUmo59gWeBivwQl3ztwDXpYyzPKo92zZiLljp8BvFR /cZyjiYyct9fsefUwqc9dawEjZ/JENGGXQbeSXIeGsYRISv1Fi4o/LpYR7cMn/ofAgKz V8tP5nImEPgAvNc6hgYFi+MhiXhIJK4rqYfTgmICpxucSlZkY/M+eaQLSENfhgb/+MZj /laQ== 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=tHDKISPEuDIKfDHJfvuxtT66qHHWDStfwWJSKcRq7bA=; b=lcRcDyO2YGwy1PeTJe4NFjiaH5+cr4gccoZkTxavXwtQf16HT5jazMgTLV4r7Piuhg tbBjLsbChKwxgcUXWXJ0IOktFL68NUvEpQaD0xIHFtV6FIybdPu89BKKNSU8Pr0C7D1z THoaqYJKyhddzNd/nUjPe3KDKjXZ93aZz29VaLAzEtd63bVMEyz1JZIHb8wLDpZmJ+en tCMiiK2EcRY+qVWIuPxhOU0hMEXeYdI7MDxSncyKP1Pqm0Qwfrb5Zfo0Df6Dggv1eXoX OOf6G7zoXuo5TNJLr1DOEvY0/SJBDzGLyCr3RpYAyc7h1mc82VZZS9gNtnFyIeVxFqNA xvRg== 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 p127si1731433pfp.119.2018.11.27.13.00.48; Tue, 27 Nov 2018 13:01:04 -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 S1726772AbeK1H56 (ORCPT + 99 others); Wed, 28 Nov 2018 02:57:58 -0500 Received: from fieldses.org ([173.255.197.46]:43432 "EHLO fieldses.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726286AbeK1H56 (ORCPT ); Wed, 28 Nov 2018 02:57:58 -0500 Received: by fieldses.org (Postfix, from userid 2815) id 8D4E01EF6; Tue, 27 Nov 2018 15:58:49 -0500 (EST) Date: Tue, 27 Nov 2018 15:58:49 -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: <20181127205849.GB12810@fieldses.org> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: 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 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. --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;