Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2721236pxj; Mon, 31 May 2021 09:05:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxtZECZemeLYqs5FXxqTp66xcmKu9J0gXBCQSwxTbZPGyZ0rkPM76OERPfXqMYoJKO6spr+ X-Received: by 2002:a05:6638:a48:: with SMTP id 8mr21579864jap.38.1622477111593; Mon, 31 May 2021 09:05:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622477111; cv=none; d=google.com; s=arc-20160816; b=TQD/zFauEnJAnNflU8CSIo4bM5HOk2FZZ1ZWUiJfgAoaMbn17Hs5oYb9ZAY+8PDHaT Fj2s9GbOgYxEk3DxzlHQ+Qp8jJAU1KXpMqkohrO7eiO4zWIFnJ4ABF3/zOJXcgATuVy9 ZWAreynF3r6qA7vUPkpNr9RKTpu37+0P/H/LAfDqoanTFK6q+KvS9MPmm1/5vRi02jSy qGySGLz/z0pte6oKfbpFLCaIfb+gnvHCoDOut3HNMAHB519yDU32GYHc/3imwAOkSkjF ZP7fIXnZLzKm8vY7+DBx2zgk+w4fOF9CNWucs9xRk7TtP0dnf9agH0+7RjnRqDLltLAL vCfw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=NYpHN00p15SrToRFZQM0rAqJbwAF9n7eEPMro3i4yow=; b=KCIi8gwzak9/M6aMlrHo3JxEQmAlrvr+9nYYIH5UZA4EhXJBYBrXzsFVoowGxoyV9J tKJqPDSXxNHDsEZC3vuXAuWh6YjFFiKPMhYmmU5J5CjWmdMUEX/2imnRAbkTSW92Epf1 qLdJuExpfoskbtP1AXJnGJ4u3yTccZZpTlc1AijZaWymOuaUeyczAdpr08RChRdJg9WF XxdMgiXVQbRhhVqy66LHYjctMBLzezGBSqYjLoClmTK9alCbk0GM46tmJhFXIL8XktxA eP4PgXpuiJLy4+eq33SS7Ngp6fP+no2ekopOPH8K8aJj/wulkL5ipYGA65XcQ3zjLfcd 18hA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=w39LXnAs; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k10si14070988iow.62.2021.05.31.09.04.57; Mon, 31 May 2021 09:05:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=w39LXnAs; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233057AbhEaQFx (ORCPT + 99 others); Mon, 31 May 2021 12:05:53 -0400 Received: from mail.kernel.org ([198.145.29.99]:33126 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230162AbhEaOf3 (ORCPT ); Mon, 31 May 2021 10:35:29 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 7C48061C48; Mon, 31 May 2021 13:50:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1622469045; bh=ZZn6gAXd2LtIgYDetsil5HNXegsJcOEU4gvJpdG9hJA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=w39LXnAsSzqjCl6a4FmEl4FT+SEYbScX875gyMqudZ2O1sAjLWefWZ/7QvHfLOm92 EWvVCnrcRS9QoVuTQVbNOFRKIp3GI9OEG9Xv1NyKL88Or+AFDtfSOjbHUZw2cGxosG 5Fta5mVHqCkX5pvIDeDoC74IJsmGImau5QziNzAI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Anna Schumaker , Trond Myklebust Subject: [PATCH 5.12 021/296] NFSv4: Fix a NULL pointer dereference in pnfs_mark_matching_lsegs_return() Date: Mon, 31 May 2021 15:11:16 +0200 Message-Id: <20210531130704.481153525@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210531130703.762129381@linuxfoundation.org> References: <20210531130703.762129381@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Anna Schumaker commit a421d218603ffa822a0b8045055c03eae394a7eb upstream. Commit de144ff4234f changes _pnfs_return_layout() to call pnfs_mark_matching_lsegs_return() passing NULL as the struct pnfs_layout_range argument. Unfortunately, pnfs_mark_matching_lsegs_return() doesn't check if we have a value here before dereferencing it, causing an oops. I'm able to hit this crash consistently when running connectathon basic tests on NFS v4.1/v4.2 against Ontap. Fixes: de144ff4234f ("NFSv4: Don't discard segments marked for return in _pnfs_return_layout()") Cc: stable@vger.kernel.org Signed-off-by: Anna Schumaker Signed-off-by: Trond Myklebust Signed-off-by: Greg Kroah-Hartman --- fs/nfs/pnfs.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) --- a/fs/nfs/pnfs.c +++ b/fs/nfs/pnfs.c @@ -1317,6 +1317,11 @@ _pnfs_return_layout(struct inode *ino) { struct pnfs_layout_hdr *lo = NULL; struct nfs_inode *nfsi = NFS_I(ino); + struct pnfs_layout_range range = { + .iomode = IOMODE_ANY, + .offset = 0, + .length = NFS4_MAX_UINT64, + }; LIST_HEAD(tmp_list); const struct cred *cred; nfs4_stateid stateid; @@ -1344,16 +1349,10 @@ _pnfs_return_layout(struct inode *ino) } valid_layout = pnfs_layout_is_valid(lo); pnfs_clear_layoutcommit(ino, &tmp_list); - pnfs_mark_matching_lsegs_return(lo, &tmp_list, NULL, 0); + pnfs_mark_matching_lsegs_return(lo, &tmp_list, &range, 0); - if (NFS_SERVER(ino)->pnfs_curr_ld->return_range) { - struct pnfs_layout_range range = { - .iomode = IOMODE_ANY, - .offset = 0, - .length = NFS4_MAX_UINT64, - }; + if (NFS_SERVER(ino)->pnfs_curr_ld->return_range) NFS_SERVER(ino)->pnfs_curr_ld->return_range(lo, &range); - } /* Don't send a LAYOUTRETURN if list was initially empty */ if (!test_bit(NFS_LAYOUT_RETURN_REQUESTED, &lo->plh_flags) ||