Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp1928505ybv; Fri, 14 Feb 2020 08:23:13 -0800 (PST) X-Google-Smtp-Source: APXvYqzNBbAGh3fjw2zcoDsb+X1ATDAaxtqRKXcdOUr/rLBlTf+XbvNoony9T/V9w/2M6CSgbUk0 X-Received: by 2002:a9d:1c9c:: with SMTP id l28mr2897812ota.210.1581697393657; Fri, 14 Feb 2020 08:23:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581697393; cv=none; d=google.com; s=arc-20160816; b=mF2z2SkQu4imVMqdYXgqNvHtWHhFpRVbQ1DtvCR3/xEKO56SmvYBO3/kEd66YEpKnV Q+bOrVTxP4gD00NciqhzbgyzphnoA5F6T4DUWwo/5bXwFXpT21a5p0GsrQ9To8tIJvn7 AOqG/xVZbA2J6q2m9xJWzPqaJ1zO3FDEBnOr+MwsuLH6F+joRWvn78mJW3sDucePkpFi 2rpEhCAzlU5YPW/0c/f79gfHQ2PpWqNZLuBtYRuqBVMNnPAU1y0z5yTgMzFvDXWY3C/H 2U/+0k9wm4s9b6EK6PhkCji8sf3bg1El8Ge3YAYTEYybPU89TKMaL8EyURJP4aCvdltt 1R4A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=BhTqCDJKdJYzAZBrTX/f2HXiURUOW4PmROVl1YVqQME=; b=OMWf001RZ50H0vnT7QteFNnjFrxHYckEZnzgZZQTal3r2+dtURLAADcjsnsmcEb1LI xpc0WMMSWzXnN52lBgvNsNsO9Bw6KajvbarYo90U30Kr/BESJQ7jbd6/k7neoKeVbbl+ zfI3sxRs3sF6Bx2Tf35P9sqK5NCONy3LmgUAUlUBLWxR8MsULZgk29a+85CKzaBJXQfq 0rVEEzSYAx6+Neo8wa4TDekPlV/FV1uMYEggXiW/cIhG6AxVa2h0J9MLgBVyni/VGDNS LSA4r1Iehr4mAXqD+98UILiJwEpKEGXk3hDVsitUnYIyfZlMCdKrwWfVxfFUH2j7YlBu 3Ihw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="rBu/0/HE"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r10si2903749otn.241.2020.02.14.08.23.01; Fri, 14 Feb 2020 08:23:13 -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; dkim=pass header.i=@kernel.org header.s=default header.b="rBu/0/HE"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2405471AbgBNQWc (ORCPT + 99 others); Fri, 14 Feb 2020 11:22:32 -0500 Received: from mail.kernel.org ([198.145.29.99]:55882 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2405375AbgBNQV0 (ORCPT ); Fri, 14 Feb 2020 11:21:26 -0500 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 6DDFE246AE; Fri, 14 Feb 2020 16:21:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1581697285; bh=r6PZK6eZxmiLBusEq9dbpk9JS+rlZUqk08fcxqmtm2I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rBu/0/HEb0Qh+ud/eOGcejSXFeczjskyzV9JC6LXHcDMf4+6Yae0LcL5H/zkQxbaF vKX8n/oGawTeDhhKYbtyBstWRL+48MZFhaB8yQFgXHBgupHF04eAP9Imq3DSeQHuhj Rdl8Mjg+e+NHX/PZglVJc/7XpJEABG5TcjRCkbaw= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: "J. Bruce Fields" , Dan Carpenter , Sasha Levin , linux-nfs@vger.kernel.org Subject: [PATCH AUTOSEL 4.9 002/141] nfsd4: avoid NULL deference on strange COPY compounds Date: Fri, 14 Feb 2020 11:19:02 -0500 Message-Id: <20200214162122.19794-2-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200214162122.19794-1-sashal@kernel.org> References: <20200214162122.19794-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: "J. Bruce Fields" [ Upstream commit d781e3df710745fbbaee4eb07fd5b64331a1b175 ] With cross-server COPY we've introduced the possibility that the current or saved filehandle might not have fh_dentry/fh_export filled in, but we missed a place that assumed it was. I think this could be triggered by a compound like: PUTFH(foreign filehandle) GETATTR SAVEFH COPY First, check_if_stalefh_allowed sets no_verify on the first (PUTFH) op. Then op_func = nfsd4_putfh runs and leaves current_fh->fh_export NULL. need_wrongsec_check returns true, since this PUTFH has OP_IS_PUTFH_LIKE set and GETATTR does not have OP_HANDLES_WRONGSEC set. We should probably also consider tightening the checks in check_if_stalefh_allowed and double-checking that we don't assume the filehandle is verified elsewhere in the compound. But I think this fixes the immediate issue. Reported-by: Dan Carpenter Fixes: 4e48f1cccab3 "NFSD: allow inter server COPY to have... " Signed-off-by: J. Bruce Fields Signed-off-by: Sasha Levin --- fs/nfsd/nfs4proc.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c index 66985a6a7047b..33537bbb70b36 100644 --- a/fs/nfsd/nfs4proc.c +++ b/fs/nfsd/nfs4proc.c @@ -1800,7 +1800,8 @@ nfsd4_proc_compound(struct svc_rqst *rqstp, if (opdesc->op_flags & OP_CLEAR_STATEID) clear_current_stateid(cstate); - if (need_wrongsec_check(rqstp)) + if (current_fh->fh_export && + need_wrongsec_check(rqstp)) op->status = check_nfsd_access(current_fh->fh_export, rqstp); } encode_op: -- 2.20.1