From nobody Tue Feb 6 18:11:04 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 4TTrsN4MWfz59jJJ; Tue, 6 Feb 2024 18:11:04 +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 4TTrsN3k9wz46FP; Tue, 6 Feb 2024 18:11:04 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1707243064; 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=y0W28LFwhW5ELOG6tU5CmE8U3B4zxsW2b+p5TmBEiaU=; b=KWOrL+iQjQ9Dwh9DUjBDDpkqUR9GlWBOcDIC3nsBFAjDyOlZKV0AIN6MJ+aL6NVTNjntU9 oJVl0NDhOcfnRW1aQdKvBqtJtImpgmFy5jHFF4XoGOzzoKr7GhTUTVBDLNGjRgYXejTuqO 6dyrKTWWbOLR8u9xMCt+gIcgYLxP15xoSpttd5m+8XhlJg9b21feq/1NKduhn+43den54l 0p+N7dFSZQ5j+bpijIr3XZQBqN5xiUYP6ZMqmL5Ao7WesS06XSaWp8OvQ4cPyHFgbBfgQg Cb63otLmBsQwKx/LuR+YUv1MVIm9jnOXZJNA5iNQlUtI3h6di/kD9IaL/A8p3g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1707243064; 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=y0W28LFwhW5ELOG6tU5CmE8U3B4zxsW2b+p5TmBEiaU=; b=tY2/isUCYizcSOjQ3AhTDGCBoqgQvC3rO5Z2zv4/jzrS8/0nOC4gnYbEGjkcN7zLeqzhGI zYDLxTiM/Qco8bswJbllW44w2/2aDJl1DK/Aee2a2DL/UXFwVog7xYjtYx4f9/Uj8ENf3n X+JyRRVao+Lqmht5+qIMeml17ZQGnNE/LXj7rdBc5l48gCuNR8zNHShBDwDne7a5SZ3xFU Uvxoie0eB++c32BEOH787IBBnWpTyMzFT/tjCQZYSEyVJFDghSWhu08zQcxfIT48OnYjeu yJkQv8HZcQLFzRKbXAJnNxPwnf/5CAsZYxsHr0+lrl4sdt68oSUNeAxnf1J8Ig== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1707243064; a=rsa-sha256; cv=none; b=T8Qy9RJKsGaLnJFbUQUlMKzD2cPqUYNeZVAcDZYIAgqtPjEkH5/ueLA9O9pJBgSXH6qI4O gXKb2/JfZKkdbYbgQGx9vM0jUevbso0okCONg/Fh5haRYS3a9ZRkkLhOvwkoEUoxsGrl/f GCrPEaTO9IXNm+aYEtDWn3E44/lyB1/5bgqytu+Ae3AAB0IzfHQbsfxMYvy7Qkuk/Ww6Ez UPZwjB6VSCe9wJtX37a2229KqaadSvSz/hc2LvdLAnXb0957285H2ktED6mKnbzqE7M1RM Kicf9vctscXD/csqgI6K8D167EnGOjgUN8s78U5r4JwCozJtyvQJzVU2S/jCYA== 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 4TTrsN2qTpzZMN; Tue, 6 Feb 2024 18:11:04 +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 416IB4pY044584; Tue, 6 Feb 2024 18:11:04 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 416IB40l044581; Tue, 6 Feb 2024 18:11:04 GMT (envelope-from git) Date: Tue, 6 Feb 2024 18:11:04 GMT Message-Id: <202402061811.416IB40l044581@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: 81ef0de636ff - stable/13 - 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/13 X-Git-Reftype: branch X-Git-Commit: 81ef0de636ff8ba0b8057ced593f2ab92597b1a6 Auto-Submitted: auto-generated The branch stable/13 has been updated by kevans: URL: https://cgit.FreeBSD.org/src/commit/?id=81ef0de636ff8ba0b8057ced593f2ab92597b1a6 commit 81ef0de636ff8ba0b8057ced593f2ab92597b1a6 Author: Kyle Evans AuthorDate: 2024-01-16 02:55:58 +0000 Commit: Kyle Evans CommitDate: 2024-02-06 15:31:24 +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.