From nobody Tue Feb 06 18:11:01 2024 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4TTrsK3dx1z59jJG; Tue, 6 Feb 2024 18:11:01 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4TTrsK390nz46BW; Tue, 6 Feb 2024 18:11:01 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1707243061; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=Aihf/wwWtOpk81PmkCbzXwuInJmZjlChxd9glfxzdFQ=; b=gY5pxKunk7wSFBCn+0LtTD92OZ/deiF2u3zFt6EydOn+3nuU9P0etDo2BA9H6whNtnmXgK SrumVtVuAeLx7r56aUdKrqdG0UY6ksWIMnSVbZrMUvO1fUeTIVH/kzWpU007GXzuHFSUzZ 4Xx69Tk8jqu8HhkXp5Sxv3QTvHurLd0atH94MomfCdqZObIu78ZvGL/wq/oWrWp8/qYhZF EKQN/3++hY6yHSfeCk9M5i61bxewETgoEBP5cYIAmgMO6JzSva/UhxAsn2e8Z1/6DE7kCS cgsvyk1ivnNvu/tOraEjwcwqqdXBU5kA1IPT1xOOb7jE7jYDrZyfGYt1T1BsFw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1707243061; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=Aihf/wwWtOpk81PmkCbzXwuInJmZjlChxd9glfxzdFQ=; b=l+iLuzj7Zz/KZPrG17cgj/QYzgEPj6EWFJ/RmX4j5aD1XUoClu2Fwp0o1wNdqswXaL9CiL MDimEDzHuPAYH77TWZ7h6vKyMYmMGlHGIQKbW1pp2xreF2a+/JEpVmYhcB5gGVhT12S09K 9RBP8bdKKL3qfyY7WhpQYSfUTjOSGfK8bryAQqJWQHC9JzVHbLNLU9cnLRu0ePDH/cu+hH U3yFBScwllIkCCyhcWMzZOKQCxXknMtYynlcr8k6TjfBFBYpWv8x0dbjcvJ07KqDedAG1+ bHK4UhDBC1Hj5jgrj/gR/wv0ergxw13LD1pjM17hneW0q+cgdFzEbWseg4+KXg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1707243061; a=rsa-sha256; cv=none; b=Shf/kuwlpJrxc26P02JdTJ/Z6olW6DJQ5EY4IoIGK7P6DFPnCkcGGUNDg9ZGG5mz+zxIS4 2IS0UaKTN7+6/jfljc/+PxbdQjkEmq+mqCiCHWglEMDKMshJd5kIr/Ujz4mEvNI06g0/Yl HzRTmrcH9dne7mXOaC9UEYEacVXTNuiootiy/PQq60QXP2XDxOFq7VZz8NoINI9TEwltDy 5IZ9hiazxLiOAQLEPU2aSegMglVAkLpGORRQn4Pcuj3jwktC2ifR/JbBS+mDBo+MMp0Rc1 7oJ+weXgaulnzK28JB7zaOJjPXgx0lSvZKgMLYNUmG9axIvR6rtWZnM/6aDj8A== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4TTrsK2CctzZ4b; Tue, 6 Feb 2024 18:11:01 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 416IB1Wv044441; Tue, 6 Feb 2024 18:11:01 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 416IB1jB044439; Tue, 6 Feb 2024 18:11:01 GMT (envelope-from git) Date: Tue, 6 Feb 2024 18:11:01 GMT Message-Id: <202402061811.416IB1jB044439@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Kyle Evans Subject: git: a8aa5ba3db69 - stable/14 - kern: tty: fix ttyinq_read_uio assertion List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kevans X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: a8aa5ba3db694f97d21e946d6392c527af31f05b Auto-Submitted: auto-generated The branch stable/14 has been updated by kevans: URL: https://cgit.FreeBSD.org/src/commit/?id=a8aa5ba3db694f97d21e946d6392c527af31f05b commit a8aa5ba3db694f97d21e946d6392c527af31f05b Author: Kyle Evans AuthorDate: 2024-01-16 02:55:58 +0000 Commit: Kyle Evans CommitDate: 2024-02-06 15:31:17 +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 (cherry picked from commit 09a43b8790bdeb97fbecd3ea767c2f599eb4a4d3) --- 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 daf3bde77712..0bf7c2fa5b5e 100644 --- a/sys/kern/tty_inq.c +++ b/sys/kern/tty_inq.c @@ -165,7 +165,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; @@ -192,6 +193,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.