From owner-svn-src-head@freebsd.org Sun Nov 10 01:08:15 2019 Return-Path: Delivered-To: svn-src-head@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 065361A3632; Sun, 10 Nov 2019 01:08:15 +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 479bV66PwTz4LyS; Sun, 10 Nov 2019 01:08:14 +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 BB2AE1F38F; Sun, 10 Nov 2019 01:08:14 +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 xAA18E1D065465; Sun, 10 Nov 2019 01:08:14 GMT (envelope-from rmacklem@FreeBSD.org) Received: (from rmacklem@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id xAA18EMa065464; Sun, 10 Nov 2019 01:08:14 GMT (envelope-from rmacklem@FreeBSD.org) Message-Id: <201911100108.xAA18EMa065464@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: rmacklem set sender to rmacklem@FreeBSD.org using -f From: Rick Macklem Date: Sun, 10 Nov 2019 01:08:14 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r354574 - head/sys/kern X-SVN-Group: head X-SVN-Commit-Author: rmacklem X-SVN-Commit-Paths: head/sys/kern X-SVN-Commit-Revision: 354574 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 10 Nov 2019 01:08:15 -0000 Author: rmacklem Date: Sun Nov 10 01:08:14 2019 New Revision: 354574 URL: https://svnweb.freebsd.org/changeset/base/354574 Log: Update copy_file_range(2) to be Linux5 compatible. The current linux man page and testing done on a fairly recent linux5.n kernel have identified two changes to the semantics of the linux copy_file_range system call. Since the copy_file_range(2) system call is intended to be linux compatible and is only currently in head/current and not used by any commands, it seems appropriate to update the system call to be compatible with the current linux one. The first of these semantic changes was changed to be compatible with linux5.n by r354564. For the second semantic change, the old linux man page stated that, if infd and outfd referred to the same file, EBADF should be returned. Now, the semantics is to allow infd and outfd to refer to the same file so long as the byte ranges defined by the input file offset, output file offset and len does not overlap. If the byte ranges do overlap, EINVAL should be returned. This patch modifies copy_file_range(2) to be linux5.n compatible for this semantic change. Modified: head/sys/kern/vfs_syscalls.c head/sys/kern/vfs_vnops.c Modified: head/sys/kern/vfs_syscalls.c ============================================================================== --- head/sys/kern/vfs_syscalls.c Sat Nov 9 22:25:45 2019 (r354573) +++ head/sys/kern/vfs_syscalls.c Sun Nov 10 01:08:14 2019 (r354574) @@ -4838,7 +4838,7 @@ kern_copy_file_range(struct thread *td, int infd, off_ outvp = outfp->f_vnode; /* Sanity check the f_flag bits. */ if ((outfp->f_flag & (FWRITE | FAPPEND)) != FWRITE || - (infp->f_flag & FREAD) == 0 || invp == outvp) { + (infp->f_flag & FREAD) == 0) { error = EBADF; goto out; } @@ -4846,6 +4846,17 @@ kern_copy_file_range(struct thread *td, int infd, off_ /* If len == 0, just return 0. */ if (len == 0) goto out; + + /* + * If infp and outfp refer to the same file, the byte ranges cannot + * overlap. + */ + if (invp == outvp && ((savinoff <= savoutoff && savinoff + len > + savoutoff) || (savinoff > savoutoff && savoutoff + len > + savinoff))) { + error = EINVAL; + goto out; + } /* Range lock the byte ranges for both invp and outvp. */ for (;;) { Modified: head/sys/kern/vfs_vnops.c ============================================================================== --- head/sys/kern/vfs_vnops.c Sat Nov 9 22:25:45 2019 (r354573) +++ head/sys/kern/vfs_vnops.c Sun Nov 10 01:08:14 2019 (r354574) @@ -2699,8 +2699,6 @@ vn_copy_file_range(struct vnode *invp, off_t *inoffp, uvalout < (uint64_t)*outoffp || invp->v_type != VREG || outvp->v_type != VREG) error = EINVAL; - else if (invp == outvp) - error = EBADF; if (error != 0) goto out;