Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp7366040rwi; Mon, 24 Oct 2022 13:36:30 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5lzwXE2RA8nwp8BCyKAqe944nW8vXTOLhFGaSphD8OHl32iKCp2d5Icd2GYFi+T4hibQ1E X-Received: by 2002:aa7:cb09:0:b0:461:e6b6:4bad with SMTP id s9-20020aa7cb09000000b00461e6b64badmr3826023edt.27.1666643789814; Mon, 24 Oct 2022 13:36:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666643789; cv=none; d=google.com; s=arc-20160816; b=BOUfNqOVICo8wMvrtKEF/dwVT/Kgqnwsf4WHRMEPMN/TKRh/iBtY1q7C0AHJfAQS7Z ZLuDdIjIIdRpKZ0syLw6rDOEmfQfDJAMToOrAHKhNRaPmBAIONjdP06X5M41KE2DT7Tj gD3nI7P/Htoz81X313W1q+K8VkyTu30gNzGEwtoJ1VOl3SzWwrwGNaX08Wxkj9xeeqQw 9pFMonJy+MWasDeUya7YTHpCWwGBOQZdibbRidYKn4B6SksYCvvREC5MUuqPBIur2TJg G/2KjEkingQcmboZuY3i4MaWeOVGguEFvL3NIRsE9xLCsNjfh5ufdOtgf9MUt7wtvutF 78Kg== 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 Return-Path: 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.36.04; Mon, 24 Oct 2022 13:36:29 -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 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 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; } -- 2.35.1