From owner-dev-commits-src-all@freebsd.org Fri Aug 27 01:08:58 2021 Return-Path: Delivered-To: dev-commits-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 5B36667461E; Fri, 27 Aug 2021 01:08:58 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4GwhSB1vmgz4ht3; Fri, 27 Aug 2021 01:08:58 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 287D01A2BF; Fri, 27 Aug 2021 01:08:58 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 17R18wOv025206; Fri, 27 Aug 2021 01:08:58 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 17R18wBY025205; Fri, 27 Aug 2021 01:08:58 GMT (envelope-from git) Date: Fri, 27 Aug 2021 01:08:58 GMT Message-Id: <202108270108.17R18wBY025205@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Rick Macklem Subject: git: 96f65d85d431 - stable/13 - nfsd: Fix sanity check for NFSv4.2 Allocate operations MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: rmacklem X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 96f65d85d43167e3e65738c2b93414dea071015a Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-all@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commit messages for all branches of the src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 27 Aug 2021 01:08:58 -0000 The branch stable/13 has been updated by rmacklem: URL: https://cgit.FreeBSD.org/src/commit/?id=96f65d85d43167e3e65738c2b93414dea071015a commit 96f65d85d43167e3e65738c2b93414dea071015a Author: Rick Macklem AuthorDate: 2021-08-12 23:48:28 +0000 Commit: Rick Macklem CommitDate: 2021-08-27 01:05:28 +0000 nfsd: Fix sanity check for NFSv4.2 Allocate operations The NFSv4.2 Allocate operation sanity checks the aa_offset and aa_length arguments. Since they are assigned to variables of type off_t (signed) it was possible for them to be negative. It was also possible for aa_offset+aa_length to exceed OFF_MAX when stored in lo_end, which is uint64_t. This patch adds checks for these cases to the sanity check. (cherry picked from commit 06afb53bcd7b6a928bc90acb820383302ea8be9e) --- sys/fs/nfsserver/nfs_nfsdserv.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/sys/fs/nfsserver/nfs_nfsdserv.c b/sys/fs/nfsserver/nfs_nfsdserv.c index 0ba3472b4ff9..12181d04f1fa 100644 --- a/sys/fs/nfsserver/nfs_nfsdserv.c +++ b/sys/fs/nfsserver/nfs_nfsdserv.c @@ -5347,12 +5347,18 @@ nfsrvd_allocate(struct nfsrv_descript *nd, __unused int isdgram, off = fxdr_hyper(tl); tl += 2; lop->lo_first = off; len = fxdr_hyper(tl); - lop->lo_end = off + len; + lop->lo_end = lop->lo_first + len; /* - * Paranoia, just in case it wraps around, which shouldn't - * ever happen anyhow. + * Sanity check the offset and length. + * off and len are off_t (signed int64_t) whereas + * lo_first and lo_end are uint64_t and, as such, + * if off >= 0 && len > 0, lo_end cannot overflow + * unless off_t is changed to something other than + * int64_t. Check lo_end < lo_first in case that + * is someday the case. */ - if (nd->nd_repstat == 0 && (lop->lo_end < lop->lo_first || len <= 0)) + if (nd->nd_repstat == 0 && (len <= 0 || off < 0 || lop->lo_end > + OFF_MAX || lop->lo_end < lop->lo_first)) nd->nd_repstat = NFSERR_INVAL; if (nd->nd_repstat == 0 && vnode_vtype(vp) != VREG)