Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp1127818rwi; Wed, 19 Oct 2022 07:04:42 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4CwbJP5M6YUcR/8J4Mg0usoc0hFE3QMmdGJIispdktWlASF/C5Fs+pc7uubL7bcwiRWdAi X-Received: by 2002:a63:cf48:0:b0:439:7d1c:fedc with SMTP id b8-20020a63cf48000000b004397d1cfedcmr7477504pgj.281.1666188281811; Wed, 19 Oct 2022 07:04:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666188281; cv=none; d=google.com; s=arc-20160816; b=txR3SypDcD2bqD0DUDC0jpLGQ//9EXm8wDb/fH7ymzUQgqhiaj57vnrXU1zLeh54Zm E8re9po0D9nB5fAOHiW3MUrppn/YuE0aHaq7S44pcm9lQxTCX11JghMG0EIK+bnZxJgo zX2tAzXR6l7qGc5KWcKoCoiYVlmxKG6+jAdKKX19qcKzSeq2pBD9V8ft/2J0a3l+a3FE 0S7r13FFXUA/ZZYRQ3oR0cd+hryebpuDqfWWUBRvBZR9T8lhtTmUCexEQkqllVmLqlsW bMfzk0rxs+pDWwCPjz4CwpZjH/EtsOEaiLRxv8Oe+3OGCFY+H9IR096tGRtc+49qzGeW N7gg== 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=ArSNUb49BbA1Njga8bz0Cnw5SuyWZ+TUc6uI9wHKT6c=; b=ov2efl4msZDMdTSzxcZx/mcfd3r9kwuQYbw02cJmQb9ADcwce9UWGrlHGDMGoG+1EK sb0wix1UOCsNZzqAebqcOIj0irUb4z6ruGnGlIRJTAsJr2PxXOAJf+x74cNMjQTe+i1C fmuSrKndwKLc6m3Xlmg3WJk/KAp17v6BuhlTWcinVeS2OeliSvQvuhmtXyzkEWE523nt 4uw0VnttYiOB446i5YFwm6MHls0jmihlgOmZ803jsJAFd9TASyB/nkTy9S4SwThpe8Z/ 93fJ6fv+Ude9HpYS0dvvp7P+MryKc5y1qFs8YFoRu6v8LS9lVXmprAESD1jtY5ZMHkCa 1x9g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=2L8q+z+L; 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 y187-20020a638ac4000000b004630aa449c2si18449386pgd.242.2022.10.19.07.04.18; Wed, 19 Oct 2022 07:04:41 -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=2L8q+z+L; 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 S231856AbiJSNfD (ORCPT + 99 others); Wed, 19 Oct 2022 09:35:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42912 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232817AbiJSNe0 (ORCPT ); Wed, 19 Oct 2022 09:34:26 -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 EED2310EA2D; Wed, 19 Oct 2022 06:23: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 ams.source.kernel.org (Postfix) with ESMTPS id 54961B82477; Wed, 19 Oct 2022 09:05:00 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A3E00C433C1; Wed, 19 Oct 2022 09:04:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666170299; bh=G9GOzQgt9GJresKgsdu7VVr7HoVOvDNE9KXB4pbcRpE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=2L8q+z+L5sL2C57Rsis7qqxprbkd8P6Av/8iDpIcHZ+5d8gX9jjuhVelwfESxZdIG xKxaEKH0Y+289O3LEwZzlnOlU3vNwypmxOoHKoXjkRZvt5s8o2MWsYW6BsijnYz0V+ xfsQ/6Pv4tW+tDv8apEuTGtHMmEFg00N7ZXdJTWA= 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 6.0 565/862] scsi: libsas: Fix use-after-free bug in smp_execute_task_sg() Date: Wed, 19 Oct 2022 10:30:52 +0200 Message-Id: <20221019083314.963185967@linuxfoundation.org> X-Mailer: git-send-email 2.38.0 In-Reply-To: <20221019083249.951566199@linuxfoundation.org> References: <20221019083249.951566199@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.4 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 fa2209080cc2..5ce251830104 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