Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp99439pxb; Fri, 15 Oct 2021 01:18:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz7DxS+C3ebihI0aYO/A59dF7xF1ul5hZ4jE66wWihweP25E6/E0QC+yy/Qai6eP7E8Lg9+ X-Received: by 2002:a17:902:f683:b0:13f:2fbe:498f with SMTP id l3-20020a170902f68300b0013f2fbe498fmr9789826plg.17.1634285905463; Fri, 15 Oct 2021 01:18:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634285905; cv=none; d=google.com; s=arc-20160816; b=kdCnT9s+90UHExaOshrSNYKR91YRhJOKI76dKS1EDPI1pBbs/nv+tCqqpWe+0BaVd2 U+142+KMz/vKanSgiNfZqbv5Niuv71c7F72K0+h4SAhZpQ8a4opJXty+fDcZnVQPY5NV 6QZQIOdixyVcaRk53mXoHp+tMWSaIebmelz2lHwAZGYauvIbBye5wsFoXtcH4oOPsdD5 b1i4yoCMcwmcUY5I84OUENOPayNikSN64449t8IDKjNznbNCUcc/NDB2sxj/cj+AoGQc QVdRqbHYT/9/9y0Jlo97zmsSrSW2QA5pcI6YqP2f+u6/fue3c3MroG3wqa5/lHJCvabn /Iww== 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 :message-id:date:subject:cc:to:from; bh=lajo9gT7DF3vwxFnwf3oy3BTs5t9ua+UvBgO9b/317M=; b=WWa0ohKSdrO1h6f+qSjbX8YrYw0BOlopJF3nAFDrVHq6oer3z+sTrvSRjlROSFr/Bb Lqp4tJaatqL4WwWVcyb85EKx3Th+IfomtVVgRw6wenpQ9P2JoItEgr8j8ZMcndjc2pXg fbv/tERr05EvDdOe8JMCTWqbDNkd9kbNIwW/7am01FJmlO3DYq7KezxwSHbMZmndMnyS gl1QAxUu9V/5HndLCF2SLZ//ZAx0/pDfw5Ioga7yxKJ1nkC73+hVSgqZgM6T+ZsWGvlx RcJ0nK0usFdWhIRJAWdHVWUbq11I03nU2MWxhwwbpGse6zBUVDGs/uV8gTfTWurL9F6b oGUg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x8si9101068pfh.219.2021.10.15.01.18.17; Fri, 15 Oct 2021 01:18:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232597AbhJOEGj (ORCPT + 63 others); Fri, 15 Oct 2021 00:06:39 -0400 Received: from szxga02-in.huawei.com ([45.249.212.188]:24319 "EHLO szxga02-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229445AbhJOEGi (ORCPT ); Fri, 15 Oct 2021 00:06:38 -0400 Received: from dggeml757-chm.china.huawei.com (unknown [172.30.72.57]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4HVswx4tqrzbcyb; Fri, 15 Oct 2021 12:00:01 +0800 (CST) Received: from localhost.localdomain (10.175.104.82) by dggeml757-chm.china.huawei.com (10.1.199.137) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2308.8; Fri, 15 Oct 2021 12:04:30 +0800 From: Ziyang Xuan To: , CC: , , , , , Subject: [PATCH net] rsi: stop thread firstly in rsi_91x_init() error handling Date: Fri, 15 Oct 2021 12:03:35 +0800 Message-ID: <20211015040335.1021546-1-william.xuanziyang@huawei.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.175.104.82] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To dggeml757-chm.china.huawei.com (10.1.199.137) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org When fail to init coex module, free 'common' and 'adapter' directly, but common->tx_thread which will access 'common' and 'adapter' is running at the same time. That will trigger the UAF bug. ================================================================== BUG: KASAN: use-after-free in rsi_tx_scheduler_thread+0x50f/0x520 [rsi_91x] Read of size 8 at addr ffff8880076dc000 by task Tx-Thread/124777 CPU: 0 PID: 124777 Comm: Tx-Thread Not tainted 5.15.0-rc5+ #19 Call Trace: dump_stack_lvl+0xe2/0x152 print_address_description.constprop.0+0x21/0x140 ? rsi_tx_scheduler_thread+0x50f/0x520 kasan_report.cold+0x7f/0x11b ? rsi_tx_scheduler_thread+0x50f/0x520 rsi_tx_scheduler_thread+0x50f/0x520 ... Freed by task 111873: kasan_save_stack+0x1b/0x40 kasan_set_track+0x1c/0x30 kasan_set_free_info+0x20/0x30 __kasan_slab_free+0x109/0x140 kfree+0x117/0x4c0 rsi_91x_init+0x741/0x8a0 [rsi_91x] rsi_probe+0x9f/0x1750 [rsi_usb] Stop thread before free 'common' and 'adapter' to fix it. Fixes: 2108df3c4b18 ("rsi: add coex support") Signed-off-by: Ziyang Xuan --- drivers/net/wireless/rsi/rsi_91x_main.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/net/wireless/rsi/rsi_91x_main.c b/drivers/net/wireless/rsi/rsi_91x_main.c index d98483298555..87f83def6c25 100644 --- a/drivers/net/wireless/rsi/rsi_91x_main.c +++ b/drivers/net/wireless/rsi/rsi_91x_main.c @@ -359,6 +359,7 @@ struct rsi_hw *rsi_91x_init(u16 oper_mode) if (common->coex_mode > 1) { if (rsi_coex_attach(common)) { rsi_dbg(ERR_ZONE, "Failed to init coex module\n"); + rsi_kill_thread(&common->tx_thread); goto err; } } -- 2.25.1