Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 24 Apr 2026 17:56:27 +0000
From:      John Baldwin <jhb@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
Subject:   git: 8fae13b0d261 - stable/15 - LinuxKPI: Fix simple_read_from_buffer for zero-size and off-the-end reads
Message-ID:  <69ebaecb.1e135.48f5f076@gitrepo.freebsd.org>

index | next in thread | raw e-mail

The branch stable/15 has been updated by jhb:

URL: https://cgit.FreeBSD.org/src/commit/?id=8fae13b0d26198b6ac7ac41e025811e4ee9efdf9

commit 8fae13b0d26198b6ac7ac41e025811e4ee9efdf9
Author:     John Baldwin <jhb@FreeBSD.org>
AuthorDate: 2026-03-17 19:49:01 +0000
Commit:     John Baldwin <jhb@FreeBSD.org>
CommitDate: 2026-04-24 17:49:14 +0000

    LinuxKPI: Fix simple_read_from_buffer for zero-size and off-the-end reads
    
    I noticed that the buf_size < 0 check can never be true (it's a
    size_t) and decided to check for this condition by an alternate
    expression, and I also noticed that a read_size of 0 would incorrectly
    return -EFAULT.  Instead, return success for both of these cases as
    reading beyond the EOF of a normal file also returns EOF, not EINVAL.
    
    Reviewed by:    bz
    Sponsored by:   AFRL, DARPA
    Differential Revision:  https://reviews.freebsd.org/D55845
    
    (cherry picked from commit 2353fa1aca553883141a7b5d0aa54312a4610412)
---
 sys/compat/linuxkpi/common/include/linux/fs.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/sys/compat/linuxkpi/common/include/linux/fs.h b/sys/compat/linuxkpi/common/include/linux/fs.h
index 40e1b396fe86..7e28be070850 100644
--- a/sys/compat/linuxkpi/common/include/linux/fs.h
+++ b/sys/compat/linuxkpi/common/include/linux/fs.h
@@ -368,8 +368,8 @@ simple_read_from_buffer(void __user *dest, size_t read_size, loff_t *ppos,
 	size_t buf_remain = buf_size - *ppos;
 	ssize_t num_read;
 
-	if (buf_remain < 0 || buf_remain > buf_size)
-		return -EINVAL;
+	if (*ppos >= buf_size || read_size == 0)
+		return (0);
 
 	if (read_size > buf_remain)
 		read_size = buf_remain;


home | help

Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?69ebaecb.1e135.48f5f076>