Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp3886425rwi; Sat, 22 Oct 2022 01:33:54 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6D3eBn0iSwg8BCGbWa7N245FaKHqMnupwiPkRWx7vhuXvixaVqqztpRt864ohMj/0dehOl X-Received: by 2002:aa7:9152:0:b0:565:895b:e524 with SMTP id 18-20020aa79152000000b00565895be524mr23371443pfi.85.1666427634497; Sat, 22 Oct 2022 01:33:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666427634; cv=none; d=google.com; s=arc-20160816; b=phCqjFpKqJr5oNOMmFnfnRo9DnvEzhdaZUgIcckjdXgRw9hnVvVXJF5ow3rx/JH0R5 ywo/xDAz2X7V3yGx+YWh7Dq62OK4VEGeLF1PcAudDZO/ttp15RDZHAfcmeOtkctm3LJ1 YmQpWJ5lS2IyWzmUYqIJtIf6VUO/CxeJ8ozrEg7qvGPPJ4YIMKGGYQ8tV5VDnD4puZli zzrYViNZB8g87qW6PsLu4Pq561E+F7s64o989Ht6TeUaNvthNAY6wG1YKKcTjfqV+kkt nN91L2gM9HNFPUP3teOscgJzSVKxYE6eFtXrkOYHKnrrJxAErfrxirsIGCeHwPIbLjfm gcsw== 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=X2gydzhDT82LpqIkq2gSSn5Qmhd99GxcWsuwm2CchbU=; b=d3YwGaGSzBz6XftqtGuzWjBirlbaKMElshfAbk+IHhduMspW3SzMvvRDENIVotCUcf PRXrIj8W6a43esQmFXEr9G/Zcy+TtPW3hHqhRhU/ug/nL8GnQd14A+yykylPHWFZGIgq EurDcPdOtQzGBBMpmWjkD+KUlGeCr5B5mEBoIYRTmV4YzGijbBy2QQber6sUGXV1hhmC edy56g/RNXz5gA0A3ExFNVhu6geqyInla7QMlqmgReKONsYKQfCPb12dgBZZUcfWoh+E p3kxz1cvbHdFdcgKSyIarn6/74hiPTX47Bs4LpNPOXmi80jZ33MAsV5q71WLuAT4bhCp nMMA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=0RAxthJ3; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a11-20020a170902eccb00b00176db576dc0si33535273plh.147.2022.10.22.01.33.39; Sat, 22 Oct 2022 01:33:54 -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=0RAxthJ3; 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 S233544AbiJVIRT (ORCPT + 99 others); Sat, 22 Oct 2022 04:17:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49164 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233872AbiJVIP1 (ORCPT ); Sat, 22 Oct 2022 04:15:27 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D4ED12D7D27; Sat, 22 Oct 2022 00:56:22 -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 432A360B83; Sat, 22 Oct 2022 07:55:24 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 44EAEC433D7; Sat, 22 Oct 2022 07:55:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666425323; bh=SolJk47Z+/TaZ6Q3OGuH3kP9ZyqpnIFIdMh1bXPf0PM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=0RAxthJ3EdCtMMh9GWRnFUHlv/d6UwwnxYeINZkR/28rjepE/ghrJA9z6qa4KStW2 yRMj+iRKdVCXheysRcuc5gkPTB/QB/sOxS8dJYto6wo6yDpgH4r1Yi+k+IPaoyZUVN yctRG41zHs5ygM8fuDEGmVSnpOAUtE0qwSs77jic= 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.19 456/717] scsi: libsas: Fix use-after-free bug in smp_execute_task_sg() Date: Sat, 22 Oct 2022 09:25:35 +0200 Message-Id: <20221022072518.465490802@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221022072415.034382448@linuxfoundation.org> References: <20221022072415.034382448@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.3 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 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 260e735d06fa..1ec5f4c8e430 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; } -- 2.35.1