From nobody Tue Jan 16 02:56:24 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 4TDYYj0gZnz56SXQ; Tue, 16 Jan 2024 02:56:25 +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 4TDYYj0BsCz4fRq; Tue, 16 Jan 2024 02:56:25 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1705373785; 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=JvHmBBe2eIjYhBZu7Yma79FJ+ec6KlpocIcUErCrTLU=; b=N6vFlPT61CGOfzlmHAOq9VnUXpsoOjL9gj9W8AukQoFATajqMipWo/gxZBtO3CNZZS1MPb B+H4N7+7rfXoIsdVKXfhyk6Tp7raHBvfRRgonEtOyANKBu/aYjm+2rPVSR4hL9CxKr7OTf oJ4uRDQYef6rKVpD63OkTJ3n3tSXRW/+ywD0aSpicUHNflrAm6m6F5h/iJUhWFyBkMVf0N cQhFTItEbDqhbmRkbypVcunULbvXBzZ2FiGJwj6Eo6KwLm/6zXrQFxGUatfqME1dMjbmUZ prev1x9XlwMTcUtqu5hn3D96al90v2mtA4z8aiGkcQcJGDJ94gN5SgvdAtMozw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1705373785; 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=JvHmBBe2eIjYhBZu7Yma79FJ+ec6KlpocIcUErCrTLU=; b=Px1c1hGFvtn5sw3a5es5zdDu4llqGTYsYxyZhzVv0u/B/z4/mx0BFesGVgTFQ9XP29VQgb Cvgjju0LakJUk73d/F7m7hf9fKRks5kA8NCY0y83IgSJePkiuI0mEnLmTqEWkhIkDETeWA 8r3MFUbuR4JStFOoFmNyHr+bWfa16sNA3qtksqjqNtrCZUhWGRdInd6LqyKjAZAtt3qLXd ceheMdt3ZIbuxRgLToWvus/kICPgysRcT1g0Y42eeciJwKFYDt6QKpMcEscwEtoOoJuEF1 q6PB1dzXXZ0LbHJ2lG490BF+/aOtyQ+PDdgOy0FqIUzw8WlqODOn0YT+342mog== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1705373785; a=rsa-sha256; cv=none; b=ZJ6h2raQzbW9kzI5uz6F51Fv4kExjk2R+dQJUDXW0dxD5It8fJOg3nhfy3WL9mAX/6+h7U tZ1jYbH0mkZMd2uIO32nx05oPL56PXCatfAeBeHYbKv4dtPpUVZNE35sRICIBIWESPinU5 /xG2gOxpFc1VZvi8ZD9Lv9AMdSO/TdA4optpAkdwPu2nu44L0dB4u2tRr6zhZHo2vU4/CL RBo4h/qtLJSLCCz99uIm7xwU3myU1iXrqLwybMv+5IV8BSreqC8Nv83n6IPUAJhbdUPSB9 +4D/zINJ8HSJXOW2GYjP2OhdjzygssQb9KdddPvEx4lXWXENu+up6d288GkEoQ== 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 4TDYYh6MCNzNLB; Tue, 16 Jan 2024 02:56:24 +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 40G2uOLV071443; Tue, 16 Jan 2024 02:56:24 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 40G2uOIk071436; Tue, 16 Jan 2024 02:56:24 GMT (envelope-from git) Date: Tue, 16 Jan 2024 02:56:24 GMT Message-Id: <202401160256.40G2uOIk071436@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Kyle Evans Subject: git: 09a43b8790bd - main - 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/main X-Git-Reftype: branch X-Git-Commit: 09a43b8790bdeb97fbecd3ea767c2f599eb4a4d3 Auto-Submitted: auto-generated The branch main has been updated by kevans: URL: https://cgit.FreeBSD.org/src/commit/?id=09a43b8790bdeb97fbecd3ea767c2f599eb4a4d3 commit 09a43b8790bdeb97fbecd3ea767c2f599eb4a4d3 Author: Kyle Evans AuthorDate: 2024-01-16 02:55:58 +0000 Commit: Kyle Evans 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.