Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F157864499
D49440.id152498.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
D49440.id152498.diff
View Options
diff --git a/sys/kern/vfs_syscalls.c b/sys/kern/vfs_syscalls.c
--- a/sys/kern/vfs_syscalls.c
+++ b/sys/kern/vfs_syscalls.c
@@ -4945,11 +4945,11 @@
int error;
size_t retlen;
void *rl_rcookie, *rl_wcookie;
- off_t savinoff, savoutoff;
+ off_t inoff, outoff, savinoff, savoutoff;
infp = outfp = NULL;
rl_rcookie = rl_wcookie = NULL;
- savinoff = -1;
+ savinoff = -1; /* sentinel value for error handling */
error = 0;
retlen = 0;
@@ -4993,11 +4993,25 @@
/* Set the offset pointers to the correct place. */
if (inoffp == NULL)
- inoffp = &infp->f_offset;
- if (outoffp == NULL)
- outoffp = &outfp->f_offset;
- savinoff = *inoffp;
- savoutoff = *outoffp;
+ inoff = foffset_lock(infp, 0);
+ else
+ inoff = *inoffp;
+ if (outoffp == NULL) {
+ if (infp == outfp && inoffp == NULL) {
+ /*
+ * Overlapping ranges are not allowed. A more thorough
+ * check is below, but we must not lock the same offset
+ * twice.
+ */
+ foffset_unlock(infp, inoff, FOF_NOUPDATE);
+ error = EINVAL;
+ goto out;
+ }
+ outoff = foffset_lock(outfp, 0);
+ } else
+ outoff = *outoffp;
+ savinoff = inoff;
+ savoutoff = outoff;
invp = infp->f_vnode;
outvp = outfp->f_vnode;
@@ -5017,8 +5031,8 @@
* overlap.
*/
if (invp == outvp) {
- if ((savinoff <= savoutoff && savinoff + len > savoutoff) ||
- (savinoff > savoutoff && savoutoff + len > savinoff)) {
+ if ((inoff <= outoff && inoff + len > outoff) ||
+ (inoff > outoff && outoff + len > inoff)) {
error = EINVAL;
goto out;
}
@@ -5027,28 +5041,36 @@
/* Range lock the byte ranges for both invp and outvp. */
for (;;) {
- rl_wcookie = vn_rangelock_wlock(outvp, *outoffp, *outoffp +
- len);
- rl_rcookie = vn_rangelock_tryrlock(invp, *inoffp, *inoffp +
- len);
+ rl_wcookie = vn_rangelock_wlock(outvp, outoff, outoff + len);
+ rl_rcookie = vn_rangelock_tryrlock(invp, inoff, inoff + len);
if (rl_rcookie != NULL)
break;
vn_rangelock_unlock(outvp, rl_wcookie);
- rl_rcookie = vn_rangelock_rlock(invp, *inoffp, *inoffp + len);
+ rl_rcookie = vn_rangelock_rlock(invp, inoff, inoff + len);
vn_rangelock_unlock(invp, rl_rcookie);
}
retlen = len;
- error = vn_copy_file_range(invp, inoffp, outvp, outoffp, &retlen,
+ error = vn_copy_file_range(invp, &inoff, outvp, &outoff, &retlen,
flags, infp->f_cred, outfp->f_cred, td);
out:
if (rl_rcookie != NULL)
vn_rangelock_unlock(invp, rl_rcookie);
if (rl_wcookie != NULL)
vn_rangelock_unlock(outvp, rl_wcookie);
- if (savinoff != -1 && (error == EINTR || error == ERESTART)) {
- *inoffp = savinoff;
- *outoffp = savoutoff;
+ if (savinoff != -1) {
+ if (error == EINTR || error == ERESTART) {
+ inoff = savinoff;
+ outoff = savoutoff;
+ }
+ if (inoffp == NULL)
+ foffset_unlock(infp, inoff, 0);
+ else
+ *inoffp = inoff;
+ if (outoffp == NULL)
+ foffset_unlock(outfp, outoff, 0);
+ else
+ *outoffp = outoff;
}
if (outfp != NULL)
fdrop(outfp, td);
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Tue, May 26, 11:08 PM (18 h, 30 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
33540666
Default Alt Text
D49440.id152498.diff (2 KB)
Attached To
Mode
D49440: copy_file_range: Fix file offset handling
Attached
Detach File
Event Timeline
Log In to Comment