From owner-svn-src-projects@freebsd.org Wed Oct 16 00:13:28 2019 Return-Path: Delivered-To: svn-src-projects@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 12CAF157A97 for ; Wed, 16 Oct 2019 00:13:28 +0000 (UTC) (envelope-from rmacklem@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) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 46tCSR6YpLz41jq; Wed, 16 Oct 2019 00:13:27 +0000 (UTC) (envelope-from rmacklem@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id C4A6226988; Wed, 16 Oct 2019 00:13:27 +0000 (UTC) (envelope-from rmacklem@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x9G0DRGi060335; Wed, 16 Oct 2019 00:13:27 GMT (envelope-from rmacklem@FreeBSD.org) Received: (from rmacklem@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x9G0DRXV060334; Wed, 16 Oct 2019 00:13:27 GMT (envelope-from rmacklem@FreeBSD.org) Message-Id: <201910160013.x9G0DRXV060334@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: rmacklem set sender to rmacklem@FreeBSD.org using -f From: Rick Macklem Date: Wed, 16 Oct 2019 00:13:27 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org Subject: svn commit: r353602 - projects/nfsv42/sys/fs/nfsserver X-SVN-Group: projects X-SVN-Commit-Author: rmacklem X-SVN-Commit-Paths: projects/nfsv42/sys/fs/nfsserver X-SVN-Commit-Revision: 353602 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 16 Oct 2019 00:13:28 -0000 Author: rmacklem Date: Wed Oct 16 00:13:27 2019 New Revision: 353602 URL: https://svnweb.freebsd.org/changeset/base/353602 Log: Make the NFSv4.2 server fail Copy when from and to files are the same. The Linux copy_file_range() now allows the in_fd and out_fd to refer to the same file. The Linux client implements this case using read/write instead of the Copy operation, which is correct, since RFC-7862 does not allow Copy to be done with both file handles referring to the same file. When I looked, the server did not check for this case, so this patch adds code to fail the Copy when both in and out file handles refer to the same file. Modified: projects/nfsv42/sys/fs/nfsserver/nfs_nfsdserv.c Modified: projects/nfsv42/sys/fs/nfsserver/nfs_nfsdserv.c ============================================================================== --- projects/nfsv42/sys/fs/nfsserver/nfs_nfsdserv.c Tue Oct 15 23:54:51 2019 (r353601) +++ projects/nfsv42/sys/fs/nfsserver/nfs_nfsdserv.c Wed Oct 16 00:13:27 2019 (r353602) @@ -5217,6 +5217,11 @@ nfsrvd_copy_file_range(struct nfsrv_descript *nd, __un nd->nd_repstat = NFSERR_NOTSUPP; goto nfsmout; } + if (vp == tovp) { + /* Copying a byte range within the same file is not allowed. */ + nd->nd_repstat = NFSERR_INVAL; + goto nfsmout; + } NFSM_DISSECT(tl, uint32_t *, 2 * NFSX_STATEID + 3 * NFSX_HYPER + 3 * NFSX_UNSIGNED); instp->ls_flags = (NFSLCK_CHECK | NFSLCK_READACCESS); From owner-svn-src-projects@freebsd.org Thu Oct 17 05:50:58 2019 Return-Path: Delivered-To: svn-src-projects@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 657E616F056 for ; Thu, 17 Oct 2019 05:50:58 +0000 (UTC) (envelope-from rmacklem@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) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 46tyvQ1HZHz3LFV; Thu, 17 Oct 2019 05:50:58 +0000 (UTC) (envelope-from rmacklem@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 0F97F1C052; Thu, 17 Oct 2019 05:50:58 +0000 (UTC) (envelope-from rmacklem@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x9H5ovql010473; Thu, 17 Oct 2019 05:50:57 GMT (envelope-from rmacklem@FreeBSD.org) Received: (from rmacklem@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x9H5ovHS010472; Thu, 17 Oct 2019 05:50:57 GMT (envelope-from rmacklem@FreeBSD.org) Message-Id: <201910170550.x9H5ovHS010472@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: rmacklem set sender to rmacklem@FreeBSD.org using -f From: Rick Macklem Date: Thu, 17 Oct 2019 05:50:57 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org Subject: svn commit: r353676 - projects/nfsv42/sys/fs/nfsclient X-SVN-Group: projects X-SVN-Commit-Author: rmacklem X-SVN-Commit-Paths: projects/nfsv42/sys/fs/nfsclient X-SVN-Commit-Revision: 353676 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 17 Oct 2019 05:50:58 -0000 Author: rmacklem Date: Thu Oct 17 05:50:57 2019 New Revision: 353676 URL: https://svnweb.freebsd.org/changeset/base/353676 Log: Patch the NFSv4.2 client side Copy for the Linux server. RFC-7862 states that a Copy request with offset or offset + len greater than file size should fail with NFSERR_INVAL. However the Linux NFSv4.2 server replies with a length of 0. This patch translates this case into NFSERR_INVAL. Modified: projects/nfsv42/sys/fs/nfsclient/nfs_clvnops.c Modified: projects/nfsv42/sys/fs/nfsclient/nfs_clvnops.c ============================================================================== --- projects/nfsv42/sys/fs/nfsclient/nfs_clvnops.c Thu Oct 17 01:30:37 2019 (r353675) +++ projects/nfsv42/sys/fs/nfsclient/nfs_clvnops.c Thu Oct 17 05:50:57 2019 (r353676) @@ -3542,8 +3542,9 @@ nfs_copy_file_range(struct vop_copy_file_range_args *a nmp = VFSTONFS(invp->v_mount); mtx_lock(&nmp->nm_mtx); + /* NFSv4.2 Copy is not permitted for infile == outfile. */ if (!NFSHASNFSV4(nmp) || nmp->nm_minorvers < NFSV42_MINORVERSION || - (nmp->nm_privflag & NFSMNTP_NOCOPY) != 0) { + (nmp->nm_privflag & NFSMNTP_NOCOPY) != 0 || invp == outvp) { mtx_unlock(&nmp->nm_mtx); error = vn_generic_copy_file_range(ap->a_invp, ap->a_inoffp, ap->a_outvp, ap->a_outoffp, ap->a_lenp, ap->a_flags, @@ -3633,6 +3634,15 @@ nfs_copy_file_range(struct vop_copy_file_range_args *a 1, 1); if (error == 0 && ret != 0) error = ret; + } + if (error == 0 && len2 == 0) { + /* + * Some Linux NFSv4.2 servers can reply NFS_OK, but + * with a copied length (wr_count) == 0 when the + * offset + len is past EOF. (RFC-7862 requires a + * reply of NFS4ERR_INVAL for this case.) + */ + error = NFSERR_INVAL; } if (error == 0) { if (consecutive == false) { From owner-svn-src-projects@freebsd.org Fri Oct 18 00:19:45 2019 Return-Path: Delivered-To: svn-src-projects@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 CB2051625CF for ; Fri, 18 Oct 2019 00:19:45 +0000 (UTC) (envelope-from rmacklem@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) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 46vRVn4jLvz3RJx; Fri, 18 Oct 2019 00:19:45 +0000 (UTC) (envelope-from rmacklem@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 84C1D931; Fri, 18 Oct 2019 00:19:45 +0000 (UTC) (envelope-from rmacklem@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x9I0Jjj5065544; Fri, 18 Oct 2019 00:19:45 GMT (envelope-from rmacklem@FreeBSD.org) Received: (from rmacklem@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x9I0Jj92065543; Fri, 18 Oct 2019 00:19:45 GMT (envelope-from rmacklem@FreeBSD.org) Message-Id: <201910180019.x9I0Jj92065543@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: rmacklem set sender to rmacklem@FreeBSD.org using -f From: Rick Macklem Date: Fri, 18 Oct 2019 00:19:45 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org Subject: svn commit: r353710 - projects/nfsv42/sys/fs/nfsserver X-SVN-Group: projects X-SVN-Commit-Author: rmacklem X-SVN-Commit-Paths: projects/nfsv42/sys/fs/nfsserver X-SVN-Commit-Revision: 353710 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 18 Oct 2019 00:19:45 -0000 Author: rmacklem Date: Fri Oct 18 00:19:45 2019 New Revision: 353710 URL: https://svnweb.freebsd.org/changeset/base/353710 Log: Add vfs.nfsd.checkcopysize to enable a check for Copy past input file EOF. RFC-7862 requires that a NFSv4.2 server reply NFSERR_INVAL when the offset of the input file plus length exceeds the file's size. However, the Linux NFSv4.2 client likes to do this and will break when this check is done. As such, this patch adds the check, but it only enabled when vfs.nfsd.checkcopysize is set non-zero. The patch also adds a needed check for nd->nd_repstat == 0 before calling vn_copy_file_range(). Found during interoperability testing with Linux. Modified: projects/nfsv42/sys/fs/nfsserver/nfs_nfsdserv.c Modified: projects/nfsv42/sys/fs/nfsserver/nfs_nfsdserv.c ============================================================================== --- projects/nfsv42/sys/fs/nfsserver/nfs_nfsdserv.c Fri Oct 18 00:00:17 2019 (r353709) +++ projects/nfsv42/sys/fs/nfsserver/nfs_nfsdserv.c Fri Oct 18 00:19:45 2019 (r353710) @@ -80,6 +80,10 @@ SYSCTL_INT(_vfs_nfsd, OID_AUTO, default_flexfile, CTLF static int nfsrv_linuxseekdata = 1; SYSCTL_INT(_vfs_nfsd, OID_AUTO, linuxseekdata, CTLFLAG_RW, &nfsrv_linuxseekdata, 0, "Return EINVAL for SEEK_DATA at EOF"); +static int nfsrv_checkcopysize = 0; +SYSCTL_INT(_vfs_nfsd, OID_AUTO, checkcopysize, CTLFLAG_RW, + &nfsrv_checkcopysize, 0, + "Enable check for Copy inoff + len > file_size"); /* * This list defines the GSS mechanisms supported. @@ -5340,24 +5344,39 @@ nfsrvd_copy_file_range(struct nfsrv_descript *nd, __un vn_rangelock_unlock(vp, rl_rcookie); } - /* - * If len == 0, set it based on invp's size. Since it is range - * locked, it should not change in size. - */ - if (len == 0) { - error = NFSVOPLOCK(vp, LK_SHARED); - if (error == 0) { - ret = nfsvno_getattr(vp, &at, nd, curthread, 1, - NULL); - /* If offset past EOF, just leave len == 0. */ - if (ret == 0 && at.na_size > inoff) + error = NFSVOPLOCK(vp, LK_SHARED); + if (error == 0) { + ret = nfsvno_getattr(vp, &at, nd, curthread, 1, NULL); + if (ret == 0) { + /* + * Since invp is range locked, na_size should + * not change. + */ + if (len == 0 && at.na_size > inoff) { + /* + * If len == 0, set it based on invp's + * size. If offset is past EOF, just + * leave len == 0. + */ len = at.na_size - inoff; - NFSVOPUNLOCK(vp, 0); - if (ret != 0 && nd->nd_repstat == 0) - nd->nd_repstat = ret; - } else if (nd->nd_repstat == 0) - nd->nd_repstat = error; - } + } else if (nfsrv_checkcopysize != 0 && + inoff + len > at.na_size) { + /* + * RFC-7862 says that NFSERR_INVAL must + * be returned when inoff + len exceeds + * the file size, however the NFSv4.2 + * Linux client likes to do this, so + * only check if nfsrv_checkcopysize + * is set. + */ + nd->nd_repstat = NFSERR_INVAL; + } + } + NFSVOPUNLOCK(vp, 0); + if (ret != 0 && nd->nd_repstat == 0) + nd->nd_repstat = ret; + } else if (nd->nd_repstat == 0) + nd->nd_repstat = error; } /* @@ -5369,10 +5388,12 @@ nfsrvd_copy_file_range(struct nfsrv_descript *nd, __un xfer = nfs_maxcopyrange; else xfer = len; - nd->nd_repstat = vn_copy_file_range(vp, &inoff, tovp, &outoff, &xfer, 0, - nd->nd_cred, nd->nd_cred, NULL); - if (nd->nd_repstat == 0) - len = xfer; + if (nd->nd_repstat == 0) { + nd->nd_repstat = vn_copy_file_range(vp, &inoff, tovp, &outoff, + &xfer, 0, nd->nd_cred, nd->nd_cred, NULL); + if (nd->nd_repstat == 0) + len = xfer; + } /* Unlock the ranges. */ if (rl_rcookie != NULL)