From patchwork Sat Oct 22 07:25:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 7490 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4242:0:0:0:0:0 with SMTP id s2csp1104794wrr; Sat, 22 Oct 2022 01:33:24 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4xBJgn0wFq7C9i9N1d1FsLlPOqxGn8idlVYyZvv4B9K0NjBcOb850f/R7d8V+LDF2cc7bM X-Received: by 2002:a17:902:ce09:b0:178:bb78:49a5 with SMTP id k9-20020a170902ce0900b00178bb7849a5mr23566023plg.100.1666427604370; Sat, 22 Oct 2022 01:33:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666427604; cv=none; d=google.com; s=arc-20160816; b=aR5Cl49+b50zcLQfS+ZCUUiKqTAN4WvxkvwAyJGGzWW6vGHYYfQcP73Y8G01puiRqD Q5l7o9dtF5y7n0hrJibZfRjsPcjM7tFUG6S5jlvTul+mjWrc2KBtYUz11e3QwRi/k5AE tACBQobfxmHVYiCZOlHMpC22JOHh2F0jzpeuh6DKGythNbDYgFlhNXOKW1P8GGAabJky I4H3qEcZ+NJN93fE9LHyhEgcY5xj3470Rwh2ZHjilFA1RGpFzfdqpBWowOAFrBi5KoeH QfcH3H1QiISlww8KbiJvhX70xsf/wa6KDy7v+jP6tZ7sBt8KV+Ru9OQMZmd1v3I1b7uW FaAA== 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 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.08; Sat, 22 Oct 2022 01:33:24 -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 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747375991685899341?= X-GMAIL-MSGID: =?utf-8?q?1747375991685899341?= 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; }