Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp636871pxj; Thu, 20 May 2021 18:36:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwjoNtwMe1RPcqXXHMPUX5KAJky9yqfyB7rpyS3nppVSkqXOwuZRI4RSWndHHv7KgHMT6Or X-Received: by 2002:a6b:b409:: with SMTP id d9mr8014739iof.57.1621561001998; Thu, 20 May 2021 18:36:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621561001; cv=none; d=google.com; s=arc-20160816; b=p5/XBygK7kx6OwSKSIWlJXMwffsHJ2kls+DGfbaNJDB9PT+2wJangMSKyBlNPbzGfk KtgPVSkdxuozXKfGOe38X2YaCXVbnK8XdqLifbPKY9B4GyXjpYjOrZipA8p2G6gP9RPw nRNvnXDMw0/g6gV5ft5j3HVu5g2oiO4bBm7f7tAQ4rfa2akKYBs5QfcoHiiXhrycu3Qi n+YMmYyx5hy8WedUoPYS0ZI90qf9ey+2FvodBksKzjeMZxzEPR4mMinH15iaG8Lm1Y4j U+PQ+iWbbDXt6Vu/EbnWu8sJ2J8jAEZzstbtLuKql0UI44BKd1BtUF4lMgVmOzd136Yz HbPA== 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=nVbWLrQyt9g3d2Mmf3mCUBwZD/uhzk56a9SEGJoR4Os=; b=B668499vAiAi/17OnQ61o1o7m93mmeSFNqLm7Y1O8WvjisPTkPxKaBmDMwtW9TQyKw /Up/H3gE+UH63n228NE9GNDJ3eeEd92Mkyk1rC9nPhfilh5qI1cdS8C9X0Y8Tg/6yLXl n0yfRYvegPI71Pjv3UHitpkrYA4mCUd88bc0Un11F5Y0LYGggqkV38dnteY/HDVyos4a gWaPxiXjMex+x7qbmWrq2I91w1N3dK5C3b/rPhBXMZRhkDVHRRZNN7AcYW6rsHoeGSKw v4bYhqW5urwbY84j6H8ZBZk+xm3NxOSfmKaSPwmkbffX4SKeHur0f4XVZyFtAi2yG9nj on9Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=v50jtpU2; 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 s18si3002064ilp.146.2021.05.20.18.36.27; Thu, 20 May 2021 18:36:41 -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=v50jtpU2; 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 S240248AbhETLmN (ORCPT + 99 others); Thu, 20 May 2021 07:42:13 -0400 Received: from mail.kernel.org ([198.145.29.99]:44180 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240867AbhETLVX (ORCPT ); Thu, 20 May 2021 07:21:23 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 9C29461D82; Thu, 20 May 2021 10:11:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621505483; bh=GSebOZeX4Tq50O5UBwQlkzT8QNw3PvMo8DQWZmBtgps=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=v50jtpU2E7cpASS3ON+uRUhFq/VZOYhyVL7sqNQgD5PdBEwFn9cH1s1JhvaSJ2flL +8mQOsHaNl+PXMyd9ojHlcoYgWYJ3GtlYy1BlT/iD9AhUZwd49AAaGNQHO0580nrYn 8EuUdWY0cqlTO6qEH1t5oApVZ98ODxoTb3xgwmkM= 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.4 156/190] pNFS/flexfiles: fix incorrect size check in decode_nfs_fh() Date: Thu, 20 May 2021 11:23:40 +0200 Message-Id: <20210520092107.324748310@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210520092102.149300807@linuxfoundation.org> References: <20210520092102.149300807@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 17771e157e92..e7f8732895b7 100644 --- a/fs/nfs/flexfilelayout/flexfilelayout.c +++ b/fs/nfs/flexfilelayout/flexfilelayout.c @@ -86,7 +86,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