NeilBrown 21a6c2
From: Dan Carpenter <dan.carpenter@oracle.com>
NeilBrown 21a6c2
Date: Tue, 11 May 2021 11:49:42 +0300
NeilBrown 21a6c2
Subject: [PATCH] NFS: fix an incorrect limit in filelayout_decode_layout()
NeilBrown 21a6c2
Git-commit: 769b01ea68b6c49dc3cde6adf7e53927dacbd3a8
Michal Kubecek 08c81d
Patch-mainline: v5.13-rc4
NeilBrown 21a6c2
References: git-fixes
NeilBrown 21a6c2
NeilBrown 21a6c2
The "sizeof(struct nfs_fh)" is two bytes too large and could lead to
NeilBrown 21a6c2
memory corruption.  It should be NFS_MAXFHSIZE because that's the size
NeilBrown 21a6c2
of the ->data[] buffer.
NeilBrown 21a6c2
NeilBrown 21a6c2
I reversed the size of the arguments to put the variable on the left.
NeilBrown 21a6c2
NeilBrown 21a6c2
Fixes: 16b374ca439f ("NFSv4.1: pnfs: filelayout: add driver's LAYOUTGET and GETDEVICEINFO infrastructure")
NeilBrown 21a6c2
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
NeilBrown 21a6c2
Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
NeilBrown 21a6c2
Acked-by: NeilBrown <neilb@suse.com>
NeilBrown 21a6c2
NeilBrown 21a6c2
---
NeilBrown 21a6c2
 fs/nfs/filelayout/filelayout.c |    2 +-
NeilBrown 21a6c2
 1 file changed, 1 insertion(+), 1 deletion(-)
NeilBrown 21a6c2
NeilBrown 21a6c2
--- a/fs/nfs/filelayout/filelayout.c
NeilBrown 21a6c2
+++ b/fs/nfs/filelayout/filelayout.c
NeilBrown 21a6c2
@@ -717,7 +717,7 @@ filelayout_decode_layout(struct pnfs_lay
NeilBrown 21a6c2
 		if (unlikely(!p))
NeilBrown 21a6c2
 			goto out_err;
NeilBrown 21a6c2
 		fl->fh_array[i]->size = be32_to_cpup(p++);
NeilBrown 21a6c2
-		if (sizeof(struct nfs_fh) < fl->fh_array[i]->size) {
NeilBrown 21a6c2
+		if (fl->fh_array[i]->size > NFS_MAXFHSIZE) {
NeilBrown 21a6c2
 			printk(KERN_ERR "NFS: Too big fh %d received %d\n",
NeilBrown 21a6c2
 			       i, fl->fh_array[i]->size);
NeilBrown 21a6c2
 			goto out_err;