LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Xianting TIan <xianting.tian@linux.alibaba.com>
To: jassisinghbrar@gmail.com
Cc: linux-kernel@vger.kernel.org, guoren@kernel.org
Subject: Re: [PATCH] mailbox: fix a UAF bug in msg_submit()
Date: Tue, 10 Aug 2021 18:45:26 +0800	[thread overview]
Message-ID: <554d6b8d-0b09-f3cc-8124-b33131d1243f@linux.alibaba.com> (raw)
In-Reply-To: <20210806121521.124365-1-xianting.tian@linux.alibaba.com>

Could I get the comments for the patch, thanks.


在 2021/8/6 下午8:15, Xianting Tian 写道:
> We met a UAF issue during our mailbox testing.
>
> In synchronous mailbox, we use mbox_send_message() to send a message
> and wait for completion. mbox_send_message() calls msg_submit() to
> send the message for the first time, if timeout, it will send the
> message in tx_tick() for the second time.
>
> We assume message sending failed for both two times,  then the message
> will be still in the internal buffer of a chan(chan->msg_data[idx]).
> It will be send again in the same way when mbox_send_message() is
> called next time. But, at this time this message (chan->msg_data[idx])
> may be a UAF pointer, as the message is passed to mailbox core by user.
> User may free it after last calling of mbox_send_message() returned
> or not. Who knows!!!
>
> In this patch, if the first time sending timeout, we pass timeout
> info(-ETIME) to msg_submit() when do the second time sending by
> tx_tick(). If it still send failed (chan->mbox->ops->send_data()
> returned non-zero value) in the second time, we will give up this
> message(chan->msg_count--) sending. It doesn't matter, user can chose
> to send it again.
>
> Actually, the issue I described above doesn't exist if
> 'chan->mbox->ops->send_data()' always return 0. Because if it always
> returns 0, we will always do 'chan->msg_count—' regardless of message
> sending success or failure. We have such mailbox driver, for example,
> hi6220_mbox_send_data() always return 0. But we still have mailbox
> drivers, which don't always return 0, for example, flexrm_send_data()
> of drivers/mailbox/bcm-flexrm-mailbox.c.
>
> Signed-off-by: Xianting Tian <xianting.tian@linux.alibaba.com>
> ---
>   drivers/mailbox/mailbox.c | 8 ++++----
>   1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/mailbox/mailbox.c b/drivers/mailbox/mailbox.c
> index 3e7d4b20a..3e010aafa 100644
> --- a/drivers/mailbox/mailbox.c
> +++ b/drivers/mailbox/mailbox.c
> @@ -50,7 +50,7 @@ static int add_to_rbuf(struct mbox_chan *chan, void *mssg)
>   	return idx;
>   }
>   
> -static void msg_submit(struct mbox_chan *chan)
> +static void msg_submit(struct mbox_chan *chan, int last_submit)
>   {
>   	unsigned count, idx;
>   	unsigned long flags;
> @@ -75,7 +75,7 @@ static void msg_submit(struct mbox_chan *chan)
>   		chan->cl->tx_prepare(chan->cl, data);
>   	/* Try to submit a message to the MBOX controller */
>   	err = chan->mbox->ops->send_data(chan, data);
> -	if (!err) {
> +	if (!err || last_submit == -ETIME) {
>   		chan->active_req = data;
>   		chan->msg_count--;
>   	}
> @@ -101,7 +101,7 @@ static void tx_tick(struct mbox_chan *chan, int r)
>   	spin_unlock_irqrestore(&chan->lock, flags);
>   
>   	/* Submit next message */
> -	msg_submit(chan);
> +	msg_submit(chan, r);
>   
>   	if (!mssg)
>   		return;
> @@ -260,7 +260,7 @@ int mbox_send_message(struct mbox_chan *chan, void *mssg)
>   		return t;
>   	}
>   
> -	msg_submit(chan);
> +	msg_submit(chan, 0);
>   
>   	if (chan->cl->tx_block) {
>   		unsigned long wait;

  reply	other threads:[~2021-08-10 10:45 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-06 12:15 Xianting Tian
2021-08-10 10:45 ` Xianting TIan [this message]
2021-08-11  2:37 ` Guo Ren
2021-08-17  3:40   ` Xianting TIan
2021-08-17  4:29 ` Jassi Brar
2021-08-17  5:40   ` Xianting TIan
2021-08-17  5:58   ` Xianting TIan
2021-08-17  8:01     ` Xianting TIan
2021-08-17 23:33       ` Jassi Brar
2021-08-18  1:40         ` Xianting TIan

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=554d6b8d-0b09-f3cc-8124-b33131d1243f@linux.alibaba.com \
    --to=xianting.tian@linux.alibaba.com \
    --cc=guoren@kernel.org \
    --cc=jassisinghbrar@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --subject='Re: [PATCH] mailbox: fix a UAF bug in msg_submit()' \
    /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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).