From patchwork Mon Oct 24 11:30:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 9725 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp547596wru; Mon, 24 Oct 2022 09:39:27 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4FaLBBU7tJCxnjpqYH1q5+sEHUX5JIhmD/Ykto/DGXGauvO7jHMIkMsz4DWB1GGAnvxdcr X-Received: by 2002:a17:907:7fa5:b0:791:9a5f:101a with SMTP id qk37-20020a1709077fa500b007919a5f101amr28363939ejc.453.1666629566947; Mon, 24 Oct 2022 09:39:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666629566; cv=none; d=google.com; s=arc-20160816; b=JjctrQ0nY6rHbFUHedprUcBMYxZ2XiMbM01Ka50D/JopGhPpSELirbLyMyIx1SpngN +HLt/UimPmQW2vyyhNCRcngl8iCIwfTvIVMXGkVO6wULZr+fF+ij2KfWxdxYpiGg+2jb ZduvhI9xc4gZgXR6IMpwLBYWmilXclAlYekh4deev4+1Yjt0R2zgzOmYyYFACD080QpE SsydGdmREcXDBJw+7Wtmn1kToSMyrisnJT7KnuybMfl0ykKXGol0nlvjk9a/iHHjEkMA DZZKVt/1iZOxKrf5Nyi0YM4TPO446jW5Tiib+fk41Fhb9MF9QcnbrUFd2j9SeeQrhvjP Mh7w== 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=BTw78aSuMHTEk5X02qx0Iix9Q/NY70LVODq4YAUft64=; b=oJr43ojan7byYBoZLFG1oH8lKZ7KaXu5KT8+IyTHeI1DiFQtX2p2ZtLKqEkPNbifrq yalggKxyTDNoNm7GdWxJYAVcr5iujkCuUgleMSDKV5b5f8+lHH3seVX0QANHvaQNnRtd 0CoIn0Bk/hajGMUyFBGYypoQNpCjmSsYtOMgBvQau6mCr8EdMhYbUlDE594wBD2rMV9L TqKPmvByVNYNlW++bHh3BTsP0DBOJXCEFUOi8k6oQSLpHF2WMQUqEHEkNcJKzC+JNkJJ 2MJC/SLExj7pelRdg9FxJOhe84OnxK+oNGtBvxXP1+Cd7L1bJofSKzNSP9CHDar9nFwW mStA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=P4uOr85J; 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 j26-20020a170906255a00b0078de8494d15si84238ejb.996.2022.10.24.09.39.03; Mon, 24 Oct 2022 09:39:26 -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=P4uOr85J; 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 S233924AbiJXQ2n (ORCPT + 99 others); Mon, 24 Oct 2022 12:28:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51148 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231357AbiJXQ1m (ORCPT ); Mon, 24 Oct 2022 12:27:42 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4B8AE474D4; Mon, 24 Oct 2022 08:14:44 -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 dfw.source.kernel.org (Postfix) with ESMTPS id CB3446127C; Mon, 24 Oct 2022 12:26:32 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DC45DC433C1; Mon, 24 Oct 2022 12:26:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666614392; bh=qGhiw56H1/lUFsIpPvRlT9JAzi56ogDfYrZcj4vISEU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=P4uOr85JkjwQlZafeVdQWz+3SvClCu+1WTQ2FumKl0BOWEtMWZkU1PF2bno/8wnI5 eT9QBaHTa6nxS6R72fsYuMk8YyEy1/APntZz/eXMqNmIlSaW5eHzcihmMdQKSTAsOC dEqL17IGsgNr1uu4Kq83f+gqm/qY0es+3+yrfid8= 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.10 243/390] scsi: libsas: Fix use-after-free bug in smp_execute_task_sg() Date: Mon, 24 Oct 2022 13:30:40 +0200 Message-Id: <20221024113033.180284498@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024113022.510008560@linuxfoundation.org> References: <20221024113022.510008560@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?1747587764295829065?= X-GMAIL-MSGID: =?utf-8?q?1747587764295829065?= 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 8d6bcc19359f..51485d0251f2 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; }