From patchwork Mon Oct 24 11:31:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 10189 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp641572wru; Mon, 24 Oct 2022 13:35:49 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6wuLpo11PhB+37vGnw+HbXmueWG6hl71WyxePM+WvzDubExKxK3RXr77S3Ke9fXe+Y49I1 X-Received: by 2002:aa7:dc06:0:b0:461:b683:5fba with SMTP id b6-20020aa7dc06000000b00461b6835fbamr7649671edu.72.1666643738862; Mon, 24 Oct 2022 13:35:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666643738; cv=none; d=google.com; s=arc-20160816; b=lAAFP8x1/7g0FUN54TWe8mTgxbfjqBVFeGh/1sRkOQugzxGeNJGf5uGkTi8Tfvlr+/ DRV/r4L2yHULdFNGL8JQBgLBx0spThARYAb9isdYLjqfQ7iriqIRa3guZM7iql/wsVny dlOHRj34QtikDTLUZh4EOr1RrDk1faVhv2PoDaAem25aFF/zbn7iXGzorWDNKx4pkJuH xfoz6hgrulkU2jHXzekijXlivF+xb1WF2vyq9u+qvF/0P/FYCdXzWGbYwmO5watoq7Of gnPYI3K/Kfzb5fROgtk/+L8/GhYjrgt5E7t7YNu0w7JEv+DDLH4J2b0+4YAwqy11bMiq gHWQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=OH9AgJ5YCu5niQF4ZqKJ8t8k3xgEO5t6goiDptO/IOU=; b=p+I7VKV7ninLSYSoTCj/wrH/ZPKfBefdFvhvjCeyFj5R3Yjdvw1tZUi9K3V+IJ5qqV 58on9/bg2+gl6kQXvHUTy1c9J+Jq5ucbzLsyXZwKr0Fy27mfL6kXJbUaX5iZV3G+QkfV KUp4cosHdjunBY2Y1+rYD7k9nWu6ML1LIPY3Ohvv3J54L3iSoiULKdUJKxjtpCh6a843 99zq32fwv3vYXqPcmQmYDyfkliysRyRMKV0tOoFPizsbN5nEH1yJFOwX3F5KiDannkRr ipWjvyar0zdm4u0/mihgBfSdHokrRLEvI7L6K8XGqW7l/q27F5X3SeyX/a66MBkzTws0 e6iQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ciSoZHLS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hb38-20020a170907162600b0078dcdb1c9dfsi734074ejc.553.2022.10.24.13.35.13; Mon, 24 Oct 2022 13:35:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ciSoZHLS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233054AbiJXUZP (ORCPT + 99 others); Mon, 24 Oct 2022 16:25:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38002 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233437AbiJXUXR (ORCPT ); Mon, 24 Oct 2022 16:23:17 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C7F61349A3; Mon, 24 Oct 2022 11:38:42 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 0D291B815DA; Mon, 24 Oct 2022 12:12:13 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6317DC433D6; Mon, 24 Oct 2022 12:12:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666613531; bh=Eq053hQgh5hot3gFniUkU0XCEGYQXU6z0x6OdiZi4KQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ciSoZHLSmjYelPs7J4blb48JzNkjfZS5yekCOzQqBtYr1yGWIMNB16s3znGxuPldz 3LdP/qmZZwRM8EEeL+06ssTdpfnl2nUjiRE43DHcBXL968RawoOggiDAc15U7ENwco ESCyKaLtZvvT5UE3tbLK5x+h9EGVvcCE3rFgXJS8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jason Yan , Duoming Zhou , "Martin K. Petersen" , Sasha Levin Subject: [PATCH 5.4 155/255] scsi: libsas: Fix use-after-free bug in smp_execute_task_sg() Date: Mon, 24 Oct 2022 13:31:05 +0200 Message-Id: <20221024113007.799761629@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024113002.471093005@linuxfoundation.org> References: <20221024113002.471093005@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-7.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747602625268419679?= X-GMAIL-MSGID: =?utf-8?q?1747602625268419679?= From: Duoming Zhou [ Upstream commit 46ba53c30666717cb06c2b3c5d896301cd00d0c0 ] When executing SMP task failed, the smp_execute_task_sg() calls del_timer() to delete "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 a UAF 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. Link: https://lore.kernel.org/r/20220920144213.10536-1-duoming@zju.edu.cn Fixes: 2908d778ab3e ("[SCSI] aic94xx: new driver") Reviewed-by: Jason Yan Signed-off-by: Duoming Zhou Signed-off-by: Martin K. Petersen Signed-off-by: Sasha Levin --- 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 9fdb9c9fbda4..173f91ae38f0 100644 --- a/drivers/scsi/libsas/sas_expander.c +++ b/drivers/scsi/libsas/sas_expander.c @@ -85,7 +85,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; }