From patchwork Fri Feb 21 07:39:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 230895 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 684B5C35642 for ; Fri, 21 Feb 2020 08:18:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3D6B124694 for ; Fri, 21 Feb 2020 08:18:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1582273102; bh=kfQa1v1OuiAExi15uWYc+fe150B8w8uPydminWzQMrE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=DFi6hlPbmNZ2F/fH1z5Gapf4K7Q/JkE+pejJVMoYoACr+tu+0nsl4LVyx0BMeUMhC 2QB5BdwSizr7o6Oi4i8+FVtqZnh/3xotj3upB61xBTYrsks5M7p4s2Rx6z4EIxCHHB T7I0gvoQk4sb7PI2eOgJRi6oH5sFSZBJ+UwGZ3AI= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387815AbgBUISU (ORCPT ); Fri, 21 Feb 2020 03:18:20 -0500 Received: from mail.kernel.org ([198.145.29.99]:56222 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387813AbgBUISU (ORCPT ); Fri, 21 Feb 2020 03:18:20 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 92C9E24695; Fri, 21 Feb 2020 08:18:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1582273099; bh=kfQa1v1OuiAExi15uWYc+fe150B8w8uPydminWzQMrE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=m7T0A0VTafgt0SKjazD70SEym5So/yHXS5NCX+hEGulso3GFNpoBG96EUBHhWpjtU C92uSeHNhkunFHBVzuh1zKUnTGs06RY8CixpTGJHtw/hmqNzGAG4fY3yBy2bWeKGHQ xP8LghGnJcswTSmJg1Ap9sbkur3yEnpr4FkEHrjc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dan Carpenter , "J. Bruce Fields" , Sasha Levin Subject: [PATCH 4.19 011/191] nfsd4: avoid NULL deference on strange COPY compounds Date: Fri, 21 Feb 2020 08:39:44 +0100 Message-Id: <20200221072252.497508893@linuxfoundation.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200221072250.732482588@linuxfoundation.org> References: <20200221072250.732482588@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@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 f35aa9f88b5ec..895123518fd42 100644 --- a/fs/nfsd/nfs4proc.c +++ b/fs/nfsd/nfs4proc.c @@ -1789,7 +1789,8 @@ nfsd4_proc_compound(struct svc_rqst *rqstp) if (op->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: