From nobody Wed Jan 24 19:48:40 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 4TKvf02tqGz58cPn; Wed, 24 Jan 2024 19:48:40 +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 4TKvf02Krmz4Gt7; Wed, 24 Jan 2024 19:48:40 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1706125720; 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=Gj9wbsUswnDuSUggRKe8MaL8uLetPdQvV5U9SVywkmM=; b=SurTIHRuiQqDa/eqTV9ZzrPzhGh+AYqLxuV5JMiSpDkzTYVVjFGlZvupBY5xmxNdcL5go7 Hh0JulivFZWXC4nbWtheWgF8CayqkaszRR+VCozazFe9hMi2H2fqQMArOgLyC7lnhlax1M zoQM+Zq4mnoN2ADpYI6falyhNzBAF7Lot8YZ4kqBcI6TtV37ZywbN5CW7BceD/QKSo2yFg x3V18WHFlIMKQvFzl0Vlj9Jgm5JEBp3osUnqDaUsKaV/aXfiuO+HMxehI7HS9TNO7AFP6G c8Am6Z90K9yLAVignOCluJSPaI8QlU6kL+D+e+NJNspDmSfDK6edqgope7VIJQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1706125720; 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=Gj9wbsUswnDuSUggRKe8MaL8uLetPdQvV5U9SVywkmM=; b=HBFeiPUKgRR90jPydK2r/D4odVYZKL9Bc7inhqrRSk8OdYb6VfYZQx25LCpo+8g69rNL2C xGEYSAOTu5m20PEHiOZhlBvyDClE1LNWjRuZLSjWQAakbtAcHm/ggPS2zESr0rsXcK2JRQ 3pFXeEbwTL0/6jqcY8nogLsV4Nx0M9Lh20AtjR1sI4uKgiSdmTZcqeUARIBaYPyqed3Wdw olz3GxWI53n4Agq2ORV0OINDu0u7TSB/QRABtMS8IEx35tQs0GvXzDpB4ZADT6lPjVUO1s c+7kwft9Y6BFMCFiIszH8HYipRwd7yzBh81WLx6Mqy8gfJ2vkS/wttQea1i5Uw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1706125720; a=rsa-sha256; cv=none; b=plZ42NcNci0jFCk+ic8LIBVnI4P0Nvv6AFUV7W0ehWxpFNGuK4KYZ/5MjoYYFAYtC5saJK oxNG3vhxr9p7VZxrwopheOXE07rp+3BQKB88wIZMI1qTpRMHekeGJ4kujs7Ymw4+pB+q3h K0GzfPxp3+bwZJvgDUWM+wCqZX59ECjQ64WeZuEFcv3ANYcri4h+616rSaAGp2S6BZ39zo FBoag2qFviGBb58in7VQpHB6s2LeC4eQv7Vp622efNhGMAn0rCkwtY4iUU4nfNg/dxlkfw 4J5SNTVjkxxjx6j68M5H/uAWLoN4MI9D9LvWSRssUgDbrs5723ztrqvd/c1dww== 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 4TKvf01N9RzRyP; Wed, 24 Jan 2024 19:48:40 +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 40OJmekF007134; Wed, 24 Jan 2024 19:48:40 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 40OJmeWQ007131; Wed, 24 Jan 2024 19:48:40 GMT (envelope-from git) Date: Wed, 24 Jan 2024 19:48:40 GMT Message-Id: <202401241948.40OJmeWQ007131@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: 5738d741fb79 - main - kern: tty: fix recanonicalization 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: 5738d741fb796c1f0a6b5c2157af7de58104ac97 Auto-Submitted: auto-generated The branch main has been updated by kevans: URL: https://cgit.FreeBSD.org/src/commit/?id=5738d741fb796c1f0a6b5c2157af7de58104ac97 commit 5738d741fb796c1f0a6b5c2157af7de58104ac97 Author: Kyle Evans AuthorDate: 2024-01-24 19:36:26 +0000 Commit: Kyle Evans CommitDate: 2024-01-24 19:48:31 +0000 kern: tty: fix recanonicalization `ti->ti_begin` is actually the offset within the first block that is unread, so we must use that for our lower bound. Moving to the previous block has to be done at the end of the loop in order to correctly handle the case of ti_begin == TTYINQ_DATASIZE. At that point, lastblock is still the last one with data written and the next write into the queue would advance lastblock. If we move to the previous block at the beginning, then we're essentially off by one block for the entire scan and run the risk of running off the end of the block queue. The ti_begin == 0 case is still handled correctly, as we skip the loop entirely and the linestart gets recorded as the first byte available for writing. The bit after the loop about moving to the next block is also still correct, even with both previous fixes in mind: we skipped moving to the previous block if we hit ti_begin, and `off + 1` would in-fact be a member of the next block from where we're reading if it falls on a block boundary. Reported by: dim Fixes: 522083ffbd1ab ("kern: tty: recanonicalize the buffer on [...]") --- sys/kern/tty_inq.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/sys/kern/tty_inq.c b/sys/kern/tty_inq.c index 533fdfd30ce9..589d958e59fa 100644 --- a/sys/kern/tty_inq.c +++ b/sys/kern/tty_inq.c @@ -371,12 +371,9 @@ ttyinq_canonicalize_break(struct ttyinq *ti, const char *breakc) /* Start just past the end... */ off = ti->ti_end; - canon = 0; - - while (off > 0) { - if ((off % TTYINQ_DATASIZE) == 0) - tib = tib->tib_prev; + canon = ti->ti_begin; + while (off > ti->ti_begin) { off--; boff = off % TTYINQ_DATASIZE; @@ -384,20 +381,23 @@ ttyinq_canonicalize_break(struct ttyinq *ti, const char *breakc) canon = off + 1; break; } + + if (off != ti->ti_begin && boff == 0) + tib = tib->tib_prev; } - MPASS(canon > 0 || off == 0); + MPASS(canon > ti->ti_begin || off == ti->ti_begin); /* - * We should only be able to hit bcanon == 0 if we walked everything we - * have and didn't find any of the break characters, so if bcanon == 0 - * then tib is already the correct block and we should avoid touching - * it. + * We should only be able to hit canon == ti_begin if we walked + * everything we have and didn't find any of the break characters, so + * if canon == ti_begin then tib is already the correct block and we + * should avoid touching it. * * For all other scenarios, if canon lies on a block boundary then tib * has already advanced to the previous block. */ - if (canon != 0 && (canon % TTYINQ_DATASIZE) == 0) + if (canon != ti->ti_begin && (canon % TTYINQ_DATASIZE) == 0) tib = tib->tib_next; ti->ti_linestart = ti->ti_reprint = canon; ti->ti_startblock = ti->ti_reprintblock = tib;