Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp4256498pxb; Tue, 2 Mar 2021 10:20:59 -0800 (PST) X-Google-Smtp-Source: ABdhPJxYDp00lnuPwVY2IXc00uRU/I6DMojLpqnkztz/uWkMgmsBcg6mZ1D/FKNDDRR2Ep5Ub2/C X-Received: by 2002:a17:906:b2d6:: with SMTP id cf22mr5747847ejb.321.1614709259070; Tue, 02 Mar 2021 10:20:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614709259; cv=none; d=google.com; s=arc-20160816; b=z3wH4AZyTJQoi0c+3kV0sMrA2HuPT6bv06yQvruYrWlQMchPtIvI+X55aGm1Fpwv9p YT32w7XvvwHqSdubzlNdGbWfwBYHd+vHox8dn5KUCH5Y7QAPAaBC1aWay4KxBPA4oGot kCs/Hv98R+7y8ZDtbEiVDPFmMLV41B2p7b34Ayt4qocKcR0i9gq/9Bmxqc3Z3ShR+Blg ejg2wDw0vfhBrmsbY9qa8BkvaYLi2p7k4alDQCm9P+e4UjlMwIYfWs9cRinYdw6sTQbi 5GUOz8RDvkiDllT7NoGGDu1IEffD2rf3awXB0/rDBF1LZyaT5KTbkoKnG/P03ID2ZUSj 6ElA== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=T+DlXRF5bBzpgRo6D9piJcBL+4Ne8yKqxm/gj/HQjiY=; b=B1Dt6XDJzoeqTfkSTMsFqpCxivX3DdjSMTwlTEBYTXvIsN7n/NZhvttoMhllF5MfhC R84fgm9IZrxYQjuHBlRKvxFysf40g1hhkbqJfTrOZDxolP2yWT1za0bqORpBu665oN31 TgwGfPCSK3Np0Ghb7c9PCx8M38unLvgm6wq6uJrBmrPw/1s7murLHD5Vu/jBCAoA5H9p O6g4naPO2k2yC+8AFXRdG3+bUbMC5E/EQXtTKVmItCsXGl9xiTSCHfb7iATS5UVdZYwN d0WwPZpTSCIVcBnrt1J465dm3govIrxFOMjA6q5WPouN6HsC5IxAU2R5HWI89owAZXHO JQKA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=merlin.20170209 header.b=cQYeaPzj; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s20si1121269edd.177.2021.03.02.10.20.35; Tue, 02 Mar 2021 10:20:59 -0800 (PST) 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=@infradead.org header.s=merlin.20170209 header.b=cQYeaPzj; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1381153AbhCBEVk (ORCPT + 99 others); Mon, 1 Mar 2021 23:21:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53442 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344521AbhCBAUY (ORCPT ); Mon, 1 Mar 2021 19:20:24 -0500 Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:8b0:10b:1231::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3D1F4C061788; Mon, 1 Mar 2021 16:19:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=Content-Transfer-Encoding:MIME-Version: Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:In-Reply-To:References; bh=T+DlXRF5bBzpgRo6D9piJcBL+4Ne8yKqxm/gj/HQjiY=; b=cQYeaPzjgUUqWKvk+1OtVg8BC2 Mv9wiJp0xIGGvGbpLqn4rlobqTpN32KFrM3nG7cgw9gPwwhF+CzAGiUdzhItBf3Bxtw8BOlPPUlzg tBEyfeQId+Nmgb5D5V+Ml4x/TA1yO80Nfewaa0MVzHQhBSbj6vNx7w4dB7EDaNdAqh3viGttaBD9N OVVvbFuc/rCGUwjy6KjoafF8Jv8bSM7s06d7WIuVMyPj9ULLmDlc66vW/8DV+Zd+xrKDHsBm25c7K u8fXUyPBo4TgCf4BvOnZcNGW1r8r63/812Hj43/v+KoGFv3aeKUXbJk8yUZheQ91jyYbjRYqU9jIs 5llSPHdA==; Received: from [2601:1c0:6280:3f0::3ba4] (helo=merlin.infradead.org) by merlin.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1lGslF-0007vO-Q6; Tue, 02 Mar 2021 00:19:38 +0000 From: Randy Dunlap To: linux-kernel@vger.kernel.org Cc: Randy Dunlap , syzbot+ba2e91df8f74809417fa@syzkaller.appspotmail.com, syzbot+f3a0fa110fd630ab56c8@syzkaller.appspotmail.com, Trond Myklebust , Anna Schumaker , linux-nfs@vger.kernel.org, David Howells , Al Viro , stable@vger.kernel.org Subject: [PATCH] NFS: fs_context: validate UDP retrans to prevent shift out-of-bounds Date: Mon, 1 Mar 2021 16:19:30 -0800 Message-Id: <20210302001930.2253-1-rdunlap@infradead.org> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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@syzkaller.appspotmail.com Reported-by: syzbot+f3a0fa110fd630ab56c8@syzkaller.appspotmail.com Signed-off-by: Randy Dunlap Cc: Trond Myklebust Cc: Anna Schumaker Cc: linux-nfs@vger.kernel.org Cc: David Howells Cc: Al Viro Cc: stable@vger.kernel.org --- fs/nfs/fs_context.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) --- lnx-512-rc1.orig/fs/nfs/fs_context.c +++ lnx-512-rc1/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)