Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 27 Jul 2021 01:49:33 GMT
From:      Mark Johnston <markj@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
Subject:   git: 978804184224 - stable/13 - uart: Fix an out-of-bounds read in ns8250_bus_probe()
Message-ID:  <202107270149.16R1nXvb067307@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch stable/13 has been updated by markj:

URL: https://cgit.FreeBSD.org/src/commit/?id=97880418422475bc35c2485074ac77912f202305

commit 97880418422475bc35c2485074ac77912f202305
Author:     Mark Johnston <markj@FreeBSD.org>
AuthorDate: 2021-07-13 21:49:39 +0000
Commit:     Mark Johnston <markj@FreeBSD.org>
CommitDate: 2021-07-27 01:46:34 +0000

    uart: Fix an out-of-bounds read in ns8250_bus_probe()
    
    The problem is that ns8250_bus_probe() accesses a field from the
    ns8250_softc, which embeds the generic UART softc, but the ns8250_softc
    hasn't yet been allocated because we're still probing.
    
    This is a regression from commit 0aefb0a63c50.  This fixed a problem
    where one of the upper four IER bits, which are usually reserved, needs
    to be set in order to get RX interrupts before the RX FIFO is full.  At
    the same time, we avoid clearing those reserved bits (see commit
    58957d87173, though other UART drivers I looked at do not bother with
    this).
    
    So, copy what ns8250_init() does to disable interrupts, since we don't
    know what the "right" mask is at this point.
    
    Reported by:    syzbot+f256beefd0df9eb796e7@syzkaller.appspotmail.com
    Reviewed by:    imp
    Sponsored by:   The FreeBSD Foundation
    
    (cherry picked from commit 4a9a41650c909706bc0b9a3f29817c11b262b0a0)
---
 sys/dev/uart/uart_dev_ns8250.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/sys/dev/uart/uart_dev_ns8250.c b/sys/dev/uart/uart_dev_ns8250.c
index 45b4d315c3d5..2b2f75cf5336 100644
--- a/sys/dev/uart/uart_dev_ns8250.c
+++ b/sys/dev/uart/uart_dev_ns8250.c
@@ -791,13 +791,11 @@ ns8250_bus_param(struct uart_softc *sc, int baudrate, int databits,
 int
 ns8250_bus_probe(struct uart_softc *sc)
 {
-	struct ns8250_softc *ns8250;
 	struct uart_bas *bas;
 	int count, delay, error, limit;
 	uint8_t lsr, mcr, ier;
 	uint8_t val;
 
-	ns8250 = (struct ns8250_softc *)sc;
 	bas = &sc->sc_bas;
 
 	error = ns8250_probe(bas);
@@ -892,7 +890,8 @@ ns8250_bus_probe(struct uart_softc *sc)
 		    --limit)
 			DELAY(delay);
 		if (limit == 0) {
-			ier = uart_getreg(bas, REG_IER) & ns8250->ier_mask;
+			/* See the comment in ns8250_init(). */
+			ier = uart_getreg(bas, REG_IER) & 0xe0;
 			uart_setreg(bas, REG_IER, ier);
 			uart_setreg(bas, REG_MCR, mcr);
 			val = 0;



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