mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jason Yan <yanaijie@huawei.com>
To: Duoming Zhou <duoming@zju.edu.cn>, <linux-kernel@vger.kernel.org>
Cc: <linux-scsi@vger.kernel.org>, <jejb@linux.ibm.com>,
	<martin.petersen@oracle.com>, <kuba@kernel.org>,
	<john.garry@huawei.com>, <gregkh@linuxfoundation.org>,
	<davem@davemloft.net>
Subject: Re: [PATCH] scsi: libsas: fix use-after-free bug in smp_execute_task_sg
Date: Thu, 22 Sep 2022 22:06:30 +0800	[thread overview]
Message-ID: <9cd0b0ae-c6c7-a5bc-a834-a84010702bbc@huawei.com> (raw)
In-Reply-To: <20220920144213.10536-1-duoming@zju.edu.cn>


On 2022/9/20 22:42, Duoming Zhou wrote:
> When executing SMP task failed, the smp_execute_task_sg()
> calls del_timer() to delete the "slow_task->timer". However,
> if the timer handler sas_task_internal_timedout() is running,
> the del_timer() in smp_execute_task_sg() will not stop it
> and the UAF bug will happen. The process is shown below:
> 
>        (thread 1)               |        (thread 2)
> smp_execute_task_sg()          | sas_task_internal_timedout()
>   ...                           |
>   del_timer()                   |
>   ...                           |  ...
>   sas_free_task(task)           |
>    kfree(task->slow_task) //FREE|
>                                 |  task->slow_task->... //USE
> 
> Fix by calling del_timer_sync() in smp_execute_task_sg(),
> which makes sure the timer handler have finished before
> the "task->slow_task" is deallocated.
> 
> Fixes: 2908d778ab3e ("[SCSI] aic94xx: new driver")
> Signed-off-by: Duoming Zhou <duoming@zju.edu.cn>
> ---
>   drivers/scsi/libsas/sas_expander.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/scsi/libsas/sas_expander.c b/drivers/scsi/libsas/sas_expander.c
> index fa2209080cc..5ce25183010 100644
> --- a/drivers/scsi/libsas/sas_expander.c
> +++ b/drivers/scsi/libsas/sas_expander.c
> @@ -67,7 +67,7 @@ static int smp_execute_task_sg(struct domain_device *dev,
>   		res = i->dft->lldd_execute_task(task, GFP_KERNEL);
>   
>   		if (res) {
> -			del_timer(&task->slow_task->timer);
> +			del_timer_sync(&task->slow_task->timer);
>   			pr_notice("executing SMP task failed:%d\n", res);
>   			break;
>   		}
> 

The timer should be triggered 10 seconds later. I am curious why we stay
this long before del_timer().

However this change looks good to me.
Reviewed-by: Jason Yan <yanaijie@huawei.com>

  reply	other threads:[~2022-09-22 14:06 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-20 14:42 Duoming Zhou
2022-09-22 14:06 ` Jason Yan [this message]
2022-09-24  2:46   ` duoming
2022-09-25 16:56 ` Martin K. Petersen

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=9cd0b0ae-c6c7-a5bc-a834-a84010702bbc@huawei.com \
    --to=yanaijie@huawei.com \
    --cc=davem@davemloft.net \
    --cc=duoming@zju.edu.cn \
    --cc=gregkh@linuxfoundation.org \
    --cc=jejb@linux.ibm.com \
    --cc=john.garry@huawei.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=martin.petersen@oracle.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

all inboxes | Powered by JetHome®