Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp557927pxj; Thu, 20 May 2021 16:11:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz1aRXjnHbBqjvvuaqlfWA8ob9PFbxkKfnX4+gsTSv95GSjZ0Lq7RcVpxQoqrtK78yRpfn2 X-Received: by 2002:a17:906:ccde:: with SMTP id ot30mr7189461ejb.353.1621552265360; Thu, 20 May 2021 16:11:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621552265; cv=none; d=google.com; s=arc-20160816; b=NaXfjs5W2RmrpeCBZUdDOn+ugk9dZjjs8Nn1O1j0yWuJjiDJi0U4COmdfaG5NQ/LkD RaWzWUODBpMB1TGcyZbD4wuGDNwkJzpfOjNIlVn/lfyUasr7QmOj8o/dCxA5A2UtKTOs oA0PLFXLtQXIU5K4b9X7loonp6b8xCMpu8VLL12nv6q3UZw6pfdd7EsKt98zkd8eal4x UGH6d0WLl0oqE8ZpnPG4wZ6agUIiTnho6OL3Q46tX/hcyuJnch7qB+7zwS4pdZ6NJXyD KSRq5LWj8+V2YAGQWOYr1G7kwzma7dbQV8K2p/rX7RMcrNc06+UPn9FJG/DWrnTX6NkE 9mrQ== 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=3vEoeB1QfOUl7SonyJidfBuEC9tg0qHOKDKbhQVdSEc=; b=ZXkzpYmF9Jjbp1I93YejdZSyD6CE0JZpiCusHZBq+t9NJ5hDpRAxNDwa/517lBHyKM qyP2kBCWSdHEkCVemPkCU+rQWB/T5jG3ADZeWwxPwDGEMCkKExdyeBjW5bdNCq7lh4/p MJe9SWXlgc1a/CpMqFr0tITJqBrAj4U9ZmU8B7bZjv+CXfGU6i14FTwSsFOll3Zmukv8 Hk2A+zqpYbJcm9DkR1usMkVoREdD6rD6eANcjUUSp3VhyormgBo0MKsOzcOdGsyrfdZx stGB5mVirFIf9y+FWujigCcOlU4xtZhJN3gwqlUku2/JGimcy+qoqXCWIQFT5AF7Ktxw 6TQQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ETggrugp; 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 by9si3212557edb.20.2021.05.20.16.10.41; Thu, 20 May 2021 16:11:05 -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=ETggrugp; 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 S239858AbhETLWq (ORCPT + 99 others); Thu, 20 May 2021 07:22:46 -0400 Received: from mail.kernel.org ([198.145.29.99]:57236 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239378AbhETLCD (ORCPT ); Thu, 20 May 2021 07:02:03 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 3D1C961432; Thu, 20 May 2021 10:04:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621505042; bh=WWBo8UnRCQSx3XWZF+Bt43b5M/OW9sejUddUF1uHJHg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ETggrugpf/+FU6JbpiFC3iMtjOH9a28jGPk9sUd8QgaX3QmwON9oFCyMCfde0uPlO FfT54IT8rRJDnJreoL8fkcw958/ZBp2YTzR5rhxzd1ajKaGmxC/IR5Q9ubWg/vmFtA pZqz8vGnN6p0/JNPpw+Ba9JiEmrq8OeSZv7CXxVc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Nikola Livic , Dan Carpenter , Trond Myklebust , Sasha Levin Subject: [PATCH 4.9 197/240] pNFS/flexfiles: fix incorrect size check in decode_nfs_fh() Date: Thu, 20 May 2021 11:23:09 +0200 Message-Id: <20210520092115.272871295@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210520092108.587553970@linuxfoundation.org> References: <20210520092108.587553970@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: Nikola Livic [ Upstream commit ed34695e15aba74f45247f1ee2cf7e09d449f925 ] We (adam zabrocki, alexander matrosov, alexander tereshkin, maksym bazalii) observed the check: if (fh->size > sizeof(struct nfs_fh)) should not use the size of the nfs_fh struct which includes an extra two bytes from the size field. struct nfs_fh { unsigned short size; unsigned char data[NFS_MAXFHSIZE]; } but should determine the size from data[NFS_MAXFHSIZE] so the memcpy will not write 2 bytes beyond destination. The proposed fix is to compare against the NFS_MAXFHSIZE directly, as is done elsewhere in fs code base. Fixes: d67ae825a59d ("pnfs/flexfiles: Add the FlexFile Layout Driver") Signed-off-by: Nikola Livic Signed-off-by: Dan Carpenter Signed-off-by: Trond Myklebust Signed-off-by: Sasha Levin --- fs/nfs/flexfilelayout/flexfilelayout.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/nfs/flexfilelayout/flexfilelayout.c b/fs/nfs/flexfilelayout/flexfilelayout.c index 83149cbae093..ee1225369700 100644 --- a/fs/nfs/flexfilelayout/flexfilelayout.c +++ b/fs/nfs/flexfilelayout/flexfilelayout.c @@ -93,7 +93,7 @@ static int decode_nfs_fh(struct xdr_stream *xdr, struct nfs_fh *fh) if (unlikely(!p)) return -ENOBUFS; fh->size = be32_to_cpup(p++); - if (fh->size > sizeof(struct nfs_fh)) { + if (fh->size > NFS_MAXFHSIZE) { printk(KERN_ERR "NFS flexfiles: Too big fh received %d\n", fh->size); return -EOVERFLOW; -- 2.30.2