Re: [PATCH v4] uart: fix race between uart_put_char() and uart_shutdown()

From: Andy Shevchenko
Date: Thu Jul 12 2018 - 05:03:26 EST


On Wed, Jul 11, 2018 at 7:07 PM, Tycho Andersen <tycho@xxxxxxxx> wrote:

> Anyway, since the lock is not acquired, if uart_shutdown() is called, the
> last chunk of that function may release state->xmit.buf before its assigned
> to null, and cause the race above.
>
> To fix it, let's lock uport->lock when allocating/deallocating
> state->xmit.buf in addition to the per-port mutex.

> * use the result of uart_port_lock() in uart_shutdown() to avoid
> uninitialized warning
> * don't use the uart_port_lock/unlock macros in uart_port_startup,
> instead test against uport directly; the compiler can't seem to "see"
> through the macros/ref/unref calls to not warn about uninitialized
> flags. We don't need to do a ref here since we hold the per-port
> mutex anyway.

> + if (uport)
> + spin_lock_irqsave(&uport->lock, flags);

> + if (uport)
> + spin_unlock_irqrestore(&uport->lock, flags);

At some point it It was uart_port_lock()/uart_port_unlock(), and you
changed to simple spin lock. The macro also take reference to the
port. Do we aware about that here?

--
With Best Regards,
Andy Shevchenko