The branch main has been updated by kib:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=1364d8fd9b25d6d3e9618e7be073a1a1b41aa19c

commit 1364d8fd9b25d6d3e9618e7be073a1a1b41aa19c
Author:     Konstantin Belousov <[email protected]>
AuthorDate: 2026-07-08 19:21:00 +0000
Commit:     Konstantin Belousov <[email protected]>
CommitDate: 2026-07-09 04:53:23 +0000

    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
---
 sys/kern/kern_sendfile.c | 8 ++------
 sys/kern/sys_generic.c   | 6 +++---
 sys/sys/syscallsubr.h    | 2 +-
 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);

Reply via email to