From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: Chunyan Zhang <zhang.lyra@gmail.com>
Cc: Chunyan Zhang <chunyan.zhang@unisoc.com>,
Jiri Slaby <jirislaby@kernel.org>,
linux-serial@vger.kernel.org,
Baolin Wang <baolin.wang@linux.alibaba.com>,
Orson Zhai <orsonzhai@gmail.com>,
LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH V3 1/2] serial: sprd: Assign sprd_port after initialized to avoid wrong access
Date: Tue, 25 Jul 2023 19:33:36 +0200 [thread overview]
Message-ID: <2023072551-surrogate-reproach-3634@gregkh> (raw)
In-Reply-To: <CAAfSe-ugFQZqNzuukghJHot71v=GoueamooFGzAdEUoPvEgh8g@mail.gmail.com>
On Tue, Jul 25, 2023 at 03:49:15PM +0800, Chunyan Zhang wrote:
> On Tue, 25 Jul 2023 at 14:50, Greg Kroah-Hartman
> <gregkh@linuxfoundation.org> wrote:
> >
> > On Tue, Jul 25, 2023 at 02:40:52PM +0800, Chunyan Zhang wrote:
> > > The global pointer 'sprd_port' may not zero when sprd_probe returns
> > > failure, that is a risk for sprd_port to be accessed afterward, and
> > > may lead to unexpected errors.
> > >
> > > For example:
> > >
> > > There are two UART ports, UART1 is used for console and configured in
> > > kernel command line, i.e. "console=";
> > >
> > > The UART1 probe failed and the memory allocated to sprd_port[1] was
> > > released, but sprd_port[1] was not set to NULL;
> > >
> > > In UART2 probe, the same virtual address was allocated to sprd_port[2],
> > > and UART2 probe process finally will go into sprd_console_setup() to
> > > register UART1 as console since it is configured as preferred console
> > > (filled to console_cmdline[]), but the console parameters (sprd_port[1])
> > > belong to UART2.
> > >
> > > So move the sprd_port[] assignment to where the port already initialized
> > > can avoid the above issue.
> > >
> > > Fixes: b7396a38fb28 ("tty/serial: Add Spreadtrum sc9836-uart driver support")
> > > Signed-off-by: Chunyan Zhang <chunyan.zhang@unisoc.com>
> > > ---
> > > V3:
> > > - Call uart_unregister_driver() only when the 'sprd_ports_num' decreases to 0;
> > > - Add calling sprd_rx_free_buf() instread of sprd_remove() under clean_up lable.
> > >
> > > V2:
> > > - Leave sprd_remove() to keep the unrelated code logic the same.
> > > ---
> > > drivers/tty/serial/sprd_serial.c | 25 +++++++++++++++++--------
> > > 1 file changed, 17 insertions(+), 8 deletions(-)
> > >
> > > diff --git a/drivers/tty/serial/sprd_serial.c b/drivers/tty/serial/sprd_serial.c
> > > index b58f51296ace..fc1377029021 100644
> > > --- a/drivers/tty/serial/sprd_serial.c
> > > +++ b/drivers/tty/serial/sprd_serial.c
> > > @@ -1106,7 +1106,7 @@ static bool sprd_uart_is_console(struct uart_port *uport)
> > > static int sprd_clk_init(struct uart_port *uport)
> > > {
> > > struct clk *clk_uart, *clk_parent;
> > > - struct sprd_uart_port *u = sprd_port[uport->line];
> > > + struct sprd_uart_port *u = container_of(uport, struct sprd_uart_port, port);
> >
> > Now that you are not allocaing the sprd_port[] pointers, shouldn't you
> > also remove that variable entirely?
>
> sprd_console_write() and sprd_console_setup() [1] also need sprd_port[].
Why? Can't they also use the structure passed to them instead?
> So, this driver still needs to allocate the buffer for sprd_port[],
> the change is using a local variable instead of allocating directly to
> the global pointer.
Ah, I missed that you were saving the pointer off.
I think it would be better if you could just remove the static array
entirely, that's a sign of a very old driver that should be fixed up.
thanks,
greg k-h
next prev parent reply other threads:[~2023-07-25 17:33 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-25 6:40 [PATCH V3 1/2] serial: sprd: Assign sprd_port after initialized to avoid wrong access Chunyan Zhang
2023-07-25 6:40 ` [PATCH V3 2/2] serial: sprd: Fix DMA buffer leak issue Chunyan Zhang
2023-07-25 6:50 ` [PATCH V3 1/2] serial: sprd: Assign sprd_port after initialized to avoid wrong access Greg Kroah-Hartman
2023-07-25 7:49 ` Chunyan Zhang
2023-07-25 17:33 ` Greg Kroah-Hartman [this message]
2023-07-31 3:55 ` Baolin Wang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=2023072551-surrogate-reproach-3634@gregkh \
--to=gregkh@linuxfoundation.org \
--cc=baolin.wang@linux.alibaba.com \
--cc=chunyan.zhang@unisoc.com \
--cc=jirislaby@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-serial@vger.kernel.org \
--cc=orsonzhai@gmail.com \
--cc=zhang.lyra@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox