aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKonstantin Belousov <kib@FreeBSD.org>2026-07-08 19:21:00 +0000
committerKonstantin Belousov <kib@FreeBSD.org>2026-07-09 04:53:23 +0000
commit1364d8fd9b25d6d3e9618e7be073a1a1b41aa19c (patch)
tree95a2410e0e37b37a38a7f4c7c5d316d044c375a8
parentcd7b65080f2f2e038ddba42048f24f8e98b011f2 (diff)
kern_writefile(): fix several regressions
sendfile(): for trailers uio, set uio_rw to UIO_WRITE instead of checking it kern_filewrite(): remove unused argument offset kern_writev(): the check should compare cnt against zero, not uio_resid Reported by: markj Fixes: dfad790c8cca ("sendfile: stop abusing kern_writev()") Sponsored by: The FreeBSD Foundation MFC after: 1 week
-rw-r--r--sys/kern/kern_sendfile.c8
-rw-r--r--sys/kern/sys_generic.c6
-rw-r--r--sys/sys/syscallsubr.h2
3 files changed, 6 insertions, 10 deletions
diff --git a/sys/kern/kern_sendfile.c b/sys/kern/kern_sendfile.c
index 1a534210ca0c..f975470e6dcf 100644
--- a/sys/kern/kern_sendfile.c
+++ b/sys/kern/kern_sendfile.c
@@ -1175,8 +1175,7 @@ prepend_header:
SOCK_IO_SEND_UNLOCK(so);
CURVNET_RESTORE();
- error = kern_filewrite(td, sockfd, sock_fp, trl_uio,
- (off_t)-1, 0, &cnt);
+ error = kern_filewrite(td, sockfd, sock_fp, trl_uio, 0, &cnt);
if (error == 0)
sbytes += cnt;
goto out;
@@ -1256,10 +1255,7 @@ sendfile(struct thread *td, struct sendfile_args *uap, int compat)
&trl_uio);
if (error != 0)
goto out;
- if (trl_uio->uio_rw != UIO_WRITE) {
- error = EINVAL;
- goto out;
- }
+ trl_uio->uio_rw = UIO_WRITE;
trl_uio->uio_td = td;
}
}
diff --git a/sys/kern/sys_generic.c b/sys/kern/sys_generic.c
index d5145d6cf322..bbfeebbe2f2e 100644
--- a/sys/kern/sys_generic.c
+++ b/sys/kern/sys_generic.c
@@ -555,7 +555,7 @@ dofilewrite(struct thread *td, int fd, struct file *fp, struct uio *auio,
auio->uio_rw = UIO_WRITE;
auio->uio_td = td;
auio->uio_offset = offset;
- error = kern_filewrite(td, fd, fp, auio, offset, flags, &cnt);
+ error = kern_filewrite(td, fd, fp, auio, flags, &cnt);
/*
* Handle short writes and generate SIGPIPE if needed.
@@ -563,7 +563,7 @@ dofilewrite(struct thread *td, int fd, struct file *fp, struct uio *auio,
* see sousrsend().
*/
if (error != 0 && fp->f_type != DTYPE_SOCKET) {
- if (auio->uio_resid != cnt && (error == ERESTART ||
+ if (cnt != 0 && (error == ERESTART ||
error == EINTR || error == EWOULDBLOCK))
error = 0;
if (error == EPIPE) {
@@ -584,7 +584,7 @@ dofilewrite(struct thread *td, int fd, struct file *fp, struct uio *auio,
*/
int
kern_filewrite(struct thread *td, int fd, struct file *fp, struct uio *auio,
- off_t offset, int flags, ssize_t *cntp)
+ int flags, ssize_t *cntp)
{
ssize_t cnt;
int error;
diff --git a/sys/sys/syscallsubr.h b/sys/sys/syscallsubr.h
index 131a8925a2d4..f0652806b999 100644
--- a/sys/sys/syscallsubr.h
+++ b/sys/sys/syscallsubr.h
@@ -177,7 +177,7 @@ int kern_fhopen(struct thread *td, const struct fhandle *u_fhp, int flags);
int kern_fhstat(struct thread *td, fhandle_t fh, struct stat *buf);
int kern_fhstatfs(struct thread *td, fhandle_t fh, struct statfs *buf);
int kern_filewrite(struct thread *td, int fd, struct file *fp,
- struct uio *auio, off_t offset, int flags, ssize_t *cntp);
+ struct uio *auio, int flags, ssize_t *cntp);
int kern_fpathconf(struct thread *td, int fd, int name, long *valuep);
int kern_freebsd11_getfsstat(struct thread *td,
struct freebsd11_statfs *ubuf, long bufsize, int mode);