From nobody Tue Sep 16 16:31:07 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 4cR6pg6t1qz67Z4n; Tue, 16 Sep 2025 16:31:07 +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 "R12" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4cR6pg4kDGz41Tl; Tue, 16 Sep 2025 16:31:07 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1758040267; 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=ChfOeV1LNxjrrpbf4e6kCOgoFv3Z2AWq8LLY1GOf9LE=; b=BQYRggBSiLp8aP5y0caAUxOURM61qoNUMVPo+vFJePo0UtZDY0rXVS69VneYlTfqDhIEL2 +BkzLe43h8tgHniBXNIii3slm36gaeB7cv2uU298EmJQfwcoy2P24pTXYrpVSLmjkNRF08 YJuzu32esgajvu0iN1LIDWoNp157Riif6tg8oAPTvziWUcZKdKNhjT/FPSvVXDoNAkHqx/ ah/a2O7C32MPlDUhELdZNfB0xxVTjuyy7kMlkkDuEp9DpjaXfWk3OP8cjWGrdjl5Il7Kua F6xuxT3x7j0ir903q9OrqFUe5C3mbfGw7KIWEeZVsQoBI6B4MIK9JVo6Lwz5Tg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1758040267; 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=ChfOeV1LNxjrrpbf4e6kCOgoFv3Z2AWq8LLY1GOf9LE=; b=cUNzfL0oVupfe4+tsgeu6t2qMzMWfy8QcIzVbeY/VSHU5pWIjniQgh2btaxzKEZ1aOaSmq /Vq+3MU3Lr7aw6UyW1T//rjSQy098w7So8LrOyIemJprBU7Bo+9cMNXKBFskfIny4J22vR xIXsnlxMYkyJqQIPO4as/sXuPbGF9hF9iCvW3vmxm3Y1PPe5zOSMEtc19TQnryuzQJm+gI bu+plBWVVVCxKvKVmeE2jZLPdl0QFQqyZoEMHORYddhYI81Cmf3khnOlzsFa4PcEauIf18 5sWAX2QOr7eF3uDwDWaw2l8ZwG0Ask+xTjTK8F6+FQvUHTSlFUOiGWQG+cBQaQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1758040267; a=rsa-sha256; cv=none; b=wnu6QYp0Lt5GsbaAyioSR6lC95J9M/He0Ls4B4sP4sHMwdi0uvE+I1gVkItiWSxvpo9Tci 7SEKVAlUSi8OKxTMn7aK1QlR8Ni8Pnwbr8nq+n8i8o//7vIJbf7E3vD9mTwzVfA8hHygA7 t+ryV5ITgbhCtYbNq4+hdB10A0h3IlndnzEV63SmMEp5ILSvUmMC03ZQ/8IlVj485A/DbS 40ViCEh5+oXEYYkELibRfruj27IpA2+oEftBEJIiXhivSjmlcBlj1DMnP1+EuKC/EGMq14 Tu+xI3EtOumHO1hcuuCexdBL9C486Kh14EIFpfIosOYQYx7mnnDyd933LvF1Ag== ARC-Authentication-Results: i=1; mx1.freebsd.org; none 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 4cR6pg3qC5znWF; Tue, 16 Sep 2025 16:31:07 +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 58GGV7vB058650; Tue, 16 Sep 2025 16:31:07 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 58GGV7R4058647; Tue, 16 Sep 2025 16:31:07 GMT (envelope-from git) Date: Tue, 16 Sep 2025 16:31:07 GMT Message-Id: <202509161631.58GGV7R4058647@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Gordon Tetlow Subject: git: d1e981cbf3bd - releng/14.3 - 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: gordon X-Git-Repository: src X-Git-Refname: refs/heads/releng/14.3 X-Git-Reftype: branch X-Git-Commit: d1e981cbf3bdfff5a3fb7a2d21d80c0ed747524d Auto-Submitted: auto-generated The branch releng/14.3 has been updated by gordon: URL: https://cgit.FreeBSD.org/src/commit/?id=d1e981cbf3bdfff5a3fb7a2d21d80c0ed747524d commit d1e981cbf3bdfff5a3fb7a2d21d80c0ed747524d Author: Rick Macklem AuthorDate: 2025-08-09 21:15:07 +0000 Commit: Gordon Tetlow CommitDate: 2025-09-14 00:23:36 +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. Approved by: so Security: FreeBSD-EN-25:16.vfs (cherry picked from commit 4046ad6bb0ee542a42d89a48a7d6a56564ed7f33) (cherry picked from commit 2fd0083fcc23f4c25860b8890292448720a5961c) --- 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 02908f76ef85..6756925416a3 100644 --- a/sys/kern/vfs_syscalls.c +++ b/sys/kern/vfs_syscalls.c @@ -4908,11 +4908,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; @@ -4980,6 +4981,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; @@ -5035,11 +5038,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 @@ -5048,6 +5052,9 @@ out: foffset_unlock(outfp, outoff, 0); else *outoffp = outoff; + } else if (foffsets_set) { + *inoffp = inoff; + *outoffp = outoff; } if (outfp != NULL) fdrop(outfp, td);