From nobody Sat Aug 9 21:20:10 2025 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4bzv1k2syqz64QjL; Sat, 09 Aug 2025 21:20:10 +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 "R10" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4bzv1k25xdz3RGW; Sat, 09 Aug 2025 21:20:10 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1754774410; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=6m3wvFjXEp+ko6Ty7f1VjQhP0WPQplH8DSntthv6AiE=; b=Su+vZvdL0xKVFWPs+pErSfGeXr5BM2HpNDSAtbv9SEAcKxA1gikH5NceRTSF5AVKMEzS1H 0WQCm7jjXGw8IVSNoExLreDncrpCj5WrUmLEvZxwZ1SLh5UIIHbt+ZHG+B77nZ/S/59nxd erdmORuKPfsS2HOkSAoUyZ0j9vUpUf1Wde7ikb28sIjvs8u8p2aeiAlbcOiED3um7+WPEc yU0RGo8/QL9+0m+/0l/khzm42SB55Uiy7V18obJXBKVZIP5LmnxepE3s9XvppKjyqb40Cr S1Ih3eVh+IKvJWVGY3k1m959OxXN6KsmeWTF2EtAkveoWBF2JU4GVRLVW8Lkyw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1754774410; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=6m3wvFjXEp+ko6Ty7f1VjQhP0WPQplH8DSntthv6AiE=; b=Opm7XqKa4BI759BLg8HaU9/3GYatmte5vK+texwarlLuVBOw9D0t3bW+Ty98UqBNrPYBxc c7YxsRypVz/lF/AQZ/nxYG9iEXmfkvACvcGtDGnXVYQF8FNzYEElq1LpBijIMsulzEy7/i ovDhXIChiUYQ5Cii82BXIu61Af+XNT7i8c9L42xeZbHTwD4ZgdY2acV3p995hDzavYo+IZ TL+IijvjXYrUcIMwVHIhsaHF1kB3jOLsfrSGPJ4XJIW/9BYE7wtUG88Ou5ne+fQN3s4tNp 2Rxc7MQsDeFImZttDhbzywww8avzls3vNe2HVU6BU4At5l4iC/s8BH5nNztfRw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1754774410; a=rsa-sha256; cv=none; b=OftPwF6QqkoEO3JQtzyAxQOaBpWHNnpcz2ZUGEOMffuEy21z7hz/jZ8OBwDGUU/Xnmgj5i K//sL12CTU5syAvJ652Kh9oVo9Wwp4sJP9cX8QSXpUNxFGUSlVUfu/wTrGf4iq7COc57GD I4S4BBCCVpwVS6jNGFGCxFbcbYtg5Omx9ddzNBCV62bDdbL01mFumt5wecmiT6mbIvqn7Y BYtCsckaOrUz5z2vI/syacFHbPBoy9CElAhTPtRlboM6w5qjPYUGoNPtMBwzPaxnE1rEWK QlUWniT4n13Eo4CfNXWawqWI/oHLn6cgryrI8UV2+wEA1XCGFSplDclRvxFjow== 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 4bzv1k1KNqzdZp; Sat, 09 Aug 2025 21:20:10 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 579LKAXn005342; Sat, 9 Aug 2025 21:20:10 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 579LKALK005334; Sat, 9 Aug 2025 21:20:10 GMT (envelope-from git) Date: Sat, 9 Aug 2025 21:20:10 GMT Message-Id: <202508092120.579LKALK005334@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Rick Macklem Subject: git: 4046ad6bb0ee - main - vfs_syscalls.c: Fix handling of offset args for copy_file_range List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org 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/main X-Git-Reftype: branch X-Git-Commit: 4046ad6bb0ee542a42d89a48a7d6a56564ed7f33 Auto-Submitted: auto-generated The branch main has been updated by rmacklem: URL: https://cgit.FreeBSD.org/src/commit/?id=4046ad6bb0ee542a42d89a48a7d6a56564ed7f33 commit 4046ad6bb0ee542a42d89a48a7d6a56564ed7f33 Author: Rick Macklem AuthorDate: 2025-08-09 21:15:07 +0000 Commit: Rick Macklem CommitDate: 2025-08-09 21:16:18 +0000 vfs_syscalls.c: Fix handling of offset args for copy_file_range Commit 197997a broke handling of the offset arguments to copy_file_range() when specified non-NULL. The code fails to update the offsets and, as such, a loop like: do { len = copy_file_range(infd, &inpos, outfd, &outpos, SSIZE_MAX, 0); } while (len > 0); becomes an infinite loop, just doing the same copy over and over again. This patch fixes it. The clause "(foffsets_locked || foffsets_set)" in the if is not actually needed for correctness, but I thought it made the code a little more readable and might avoid some static analyzer from throwing a "used before being set" for the savinoff and savoutoff variables. Reviewed by: markj Differential Revision: https://reviews.freebsd.org/D51845 MFC after: 2 weeks Fixes: 197997a4c36d ("file: Fix offset handling in kern_copy_file_range()") --- sys/kern/vfs_syscalls.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/sys/kern/vfs_syscalls.c b/sys/kern/vfs_syscalls.c index c64618036733..b805e147bd62 100644 --- a/sys/kern/vfs_syscalls.c +++ b/sys/kern/vfs_syscalls.c @@ -5050,11 +5050,12 @@ kern_copy_file_range(struct thread *td, int infd, off_t *inoffp, int outfd, size_t retlen; void *rl_rcookie, *rl_wcookie; off_t inoff, outoff, savinoff, savoutoff; - bool foffsets_locked; + bool foffsets_locked, foffsets_set; infp = outfp = NULL; rl_rcookie = rl_wcookie = NULL; foffsets_locked = false; + foffsets_set = false; error = 0; retlen = 0; @@ -5122,6 +5123,8 @@ kern_copy_file_range(struct thread *td, int infd, off_t *inoffp, int outfd, } foffset_lock_pair(infp1, &inoff, outfp1, &outoff, 0); foffsets_locked = true; + } else { + foffsets_set = true; } savinoff = inoff; savoutoff = outoff; @@ -5180,11 +5183,12 @@ out: vn_rangelock_unlock(invp, rl_rcookie); if (rl_wcookie != NULL) vn_rangelock_unlock(outvp, rl_wcookie); + if ((foffsets_locked || foffsets_set) && + (error == EINTR || error == ERESTART)) { + inoff = savinoff; + outoff = savoutoff; + } if (foffsets_locked) { - if (error == EINTR || error == ERESTART) { - inoff = savinoff; - outoff = savoutoff; - } if (inoffp == NULL) foffset_unlock(infp, inoff, 0); else @@ -5193,6 +5197,9 @@ out: foffset_unlock(outfp, outoff, 0); else *outoffp = outoff; + } else if (foffsets_set) { + *inoffp = inoff; + *outoffp = outoff; } if (outfp != NULL) fdrop(outfp, td);