This is a note to let you know that I've just added the patch titled NFS: fs_context: validate UDP retrans to prevent shift out-of-bounds to the 5.12-stable tree which can be found at: http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary The filename of the patch is: nfs-fs_context-validate-udp-retrans-to-prevent-shift-out-of-bounds.patch and it can be found in the queue-5.12 subdirectory. If you, or anyone else, feels it should not be added to the stable tree, please let <stable@xxxxxxxxxxxxxxx> know about it. >From c09f11ef35955785f92369e25819bf0629df2e59 Mon Sep 17 00:00:00 2001 From: Randy Dunlap <rdunlap@xxxxxxxxxxxxx> Date: Mon, 1 Mar 2021 16:19:30 -0800 Subject: NFS: fs_context: validate UDP retrans to prevent shift out-of-bounds From: Randy Dunlap <rdunlap@xxxxxxxxxxxxx> commit c09f11ef35955785f92369e25819bf0629df2e59 upstream. Fix shift out-of-bounds in xprt_calc_majortimeo(). This is caused by a garbage timeout (retrans) mount option being passed to nfs mount, in this case from syzkaller. If the protocol is XPRT_TRANSPORT_UDP, then 'retrans' is a shift value for a 64-bit long integer, so 'retrans' cannot be >= 64. If it is >= 64, fail the mount and return an error. Fixes: 9954bf92c0cd ("NFS: Move mount parameterisation bits into their own file") Reported-by: syzbot+ba2e91df8f74809417fa@xxxxxxxxxxxxxxxxxxxxxxxxx Reported-by: syzbot+f3a0fa110fd630ab56c8@xxxxxxxxxxxxxxxxxxxxxxxxx Signed-off-by: Randy Dunlap <rdunlap@xxxxxxxxxxxxx> Cc: Trond Myklebust <trond.myklebust@xxxxxxxxxxxxxxx> Cc: Anna Schumaker <anna.schumaker@xxxxxxxxxx> Cc: linux-nfs@xxxxxxxxxxxxxxx Cc: David Howells <dhowells@xxxxxxxxxx> Cc: Al Viro <viro@xxxxxxxxxxxxxxxxxx> Cc: stable@xxxxxxxxxxxxxxx Signed-off-by: Trond Myklebust <trond.myklebust@xxxxxxxxxxxxxxx> Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx> --- fs/nfs/fs_context.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) --- a/fs/nfs/fs_context.c +++ b/fs/nfs/fs_context.c @@ -974,6 +974,15 @@ static int nfs23_parse_monolithic(struct sizeof(mntfh->data) - mntfh->size); /* + * for proto == XPRT_TRANSPORT_UDP, which is what uses + * to_exponential, implying shift: limit the shift value + * to BITS_PER_LONG (majortimeo is unsigned long) + */ + if (!(data->flags & NFS_MOUNT_TCP)) /* this will be UDP */ + if (data->retrans >= 64) /* shift value is too large */ + goto out_invalid_data; + + /* * Translate to nfs_fs_context, which nfs_fill_super * can deal with. */ @@ -1073,6 +1082,9 @@ out_no_address: out_invalid_fh: return nfs_invalf(fc, "NFS: invalid root filehandle"); + +out_invalid_data: + return nfs_invalf(fc, "NFS: invalid binary mount data"); } #if IS_ENABLED(CONFIG_NFS_V4) Patches currently in stable-queue which might be from rdunlap@xxxxxxxxxxxxx are queue-5.12/nfs-fs_context-validate-udp-retrans-to-prevent-shift-out-of-bounds.patch