Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 16 Jan 2024 02:56:24 GMT
From:      Kyle Evans <kevans@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: 09a43b8790bd - main - kern: tty: fix ttyinq_read_uio assertion
Message-ID:  <202401160256.40G2uOIk071436@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by kevans:

URL: https://cgit.FreeBSD.org/src/commit/?id=09a43b8790bdeb97fbecd3ea767c2f599eb4a4d3

commit 09a43b8790bdeb97fbecd3ea767c2f599eb4a4d3
Author:     Kyle Evans <kevans@FreeBSD.org>
AuthorDate: 2024-01-16 02:55:58 +0000
Commit:     Kyle Evans <kevans@FreeBSD.org>
CommitDate: 2024-01-16 02:55:58 +0000

    kern: tty: fix ttyinq_read_uio assertion
    
    It's clear from later context that `rlen` was always expected to include
    `flen`, as we'll trim `flen` bytes from the end of the read.  Relax our
    initial assertion to only require the total size less trimmed bytes to
    lie within the out buffer size.
    
    While we're here, I note that if we have to read more than one block and
    we're trimming from the end then we'll do the wrong thing and omit
    `flen` bytes from every block, rather than just the end.  Add an
    assertion to make sure we're not doing that, but the only caller that
    specifies a non-zero `flen` today will only really be doing so if rlen
    is entirely within a single buffer.
    
    Reviewed by:    cy, imp
    Differential Revision:  https://reviews.freebsd.org/D43377
---
 sys/kern/tty_inq.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/sys/kern/tty_inq.c b/sys/kern/tty_inq.c
index 1a31d8b7fa2b..2eed9802a7b7 100644
--- a/sys/kern/tty_inq.c
+++ b/sys/kern/tty_inq.c
@@ -164,7 +164,8 @@ ttyinq_read_uio(struct ttyinq *ti, struct tty *tp, struct uio *uio,
     size_t rlen, size_t flen)
 {
 
-	MPASS(rlen <= uio->uio_resid);
+	/* rlen includes flen, flen bytes will be trimmed from the end. */
+	MPASS(rlen - flen <= uio->uio_resid);
 
 	while (rlen > 0) {
 		int error;
@@ -191,6 +192,14 @@ ttyinq_read_uio(struct ttyinq *ti, struct tty *tp, struct uio *uio,
 		MPASS(clen >= flen);
 		rlen -= clen;
 
+		/*
+		 * Caller shouldn't request that we trim anything if we might be
+		 * reading across blocks.  We could handle it, but today we do
+		 * not.
+		 */
+		if (flen > 0)
+			MPASS(rlen == 0);
+
 		/*
 		 * We can prevent buffering in some cases:
 		 * - We need to read the block until the end.



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202401160256.40G2uOIk071436>