Message ID | 20230316174432.1592087-1-zyytlz.wz@163.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:604a:0:0:0:0:0 with SMTP id j10csp618956wrt; Thu, 16 Mar 2023 10:53:39 -0700 (PDT) X-Google-Smtp-Source: AK7set/GZOYzAU+k7UGtw6INUVXiGyWASIbNsvmlzzlkoI3oOJChZje0boZIO7CPZD8X0DgqdFSG X-Received: by 2002:a17:903:310a:b0:1a1:78e6:d600 with SMTP id w10-20020a170903310a00b001a178e6d600mr3162635plc.10.1678989219269; Thu, 16 Mar 2023 10:53:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1678989219; cv=none; d=google.com; s=arc-20160816; b=PDwdEPzVJR74CTgQNcs9azFMHECnVWJhPWAKwiD/VwCxXiZ4w098EXBsSZCVw23JdX f2lwH0GdrZMZuxpkDzPMk914nA0eDvK9S4ul/LJAUIyy1amxKs7QpCWRvKGguk33OCfu 40M1G0nrx5rCZxDSw1p6qgksrdjw2xCEHbDIEjhyHctHXqxhXH71nIi11k9W+qtX9D3W KL1t5hcljJJY/7hBQOx5pKkiLZ1Roixf99lsm6X0X3+2A+Crj5uHjh+UCtxsAth18jn9 Cz400TMZ/Drq208555U1OQO91j/cSS8JSm1DF5nyOY5jb0T03XqcWAQu7I/UeeQ7d1bE 2T+A== 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:dkim-signature; bh=nEAMnAlTlhmBc3GQSHDUq/SQ1R/Wav9t7BfHo/zL+ZI=; b=H3E+KQvpp4VB/2J0rmmaRWEorB0Cu9qG7ZYwofGgPV/tzpPaXueLVC5fppeSFlHOkT rmeTx0ULpV2DaES4WilA6cN/icUjY19oug9ZR7DtDgDHQ88OoY2OFPYKui8OAHyfM7TB FgFVA4KScl0k8L7L2iMCf49ad5Tx1nFNMYBuv/8DOazGLCHKf6Pg+8EjP8DUIJ/zCiqO QC9yRufb3jk9k9ft0ZcGkjV20OWK0qgJHxK5od4OzVg+4IwTz1W7rez6BJ+Sl30EDiRC vYGHE5dMIJUlYeIANN33wj1WH0iAIl4x3hSkYdobw9kv3VE9nAUIC/GtU6Eid5lBXlrG JMpg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b=eFIIFAUw; 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=163.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d19-20020a170902729300b0019adf06a9f0si12301pll.129.2023.03.16.10.53.26; Thu, 16 Mar 2023 10:53:39 -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=@163.com header.s=s110527 header.b=eFIIFAUw; 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=163.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230131AbjCPRpL (ORCPT <rfc822;pwkd43@gmail.com> + 99 others); Thu, 16 Mar 2023 13:45:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43948 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229895AbjCPRot (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Thu, 16 Mar 2023 13:44:49 -0400 Received: from m12.mail.163.com (m12.mail.163.com [220.181.12.216]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 5AA3749F3; Thu, 16 Mar 2023 10:44:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id:MIME-Version; bh=nEAMn AlTlhmBc3GQSHDUq/SQ1R/Wav9t7BfHo/zL+ZI=; b=eFIIFAUwP5fDPLIp7KfFk 55oJJ5VNga9gWULLyFnBxMJEwVyYIPd0/yM18xNy31DuP0Fmx1oUfVw91R8YHcUQ RFbXqF1bzzDhS3t4jiqB1GQrRgxgmVzToi2m0Vrsc3EFd+B0hcJlbXCOxQ0kYPdW 12oS+GZipHGfykDngcnBCA= Received: from leanderwang-LC2.localdomain (unknown [111.206.145.21]) by zwqz-smtp-mta-g4-0 (Coremail) with SMTP id _____wD3_8eBVRNkg0sdAQ--.31373S2; Fri, 17 Mar 2023 01:44:33 +0800 (CST) From: Zheng Wang <zyytlz.wz@163.com> To: valentina.manea.m@gmail.com Cc: shuah@kernel.org, gregkh@linuxfoundation.org, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, hackerzheng666@gmail.com, 1395428693sheep@gmail.com, alex000young@gmail.com, Zheng Wang <zyytlz.wz@163.com> Subject: [PATCH v3] usbip: vudc: Fix use after free bug in vudc_remove due to race condition Date: Fri, 17 Mar 2023 01:44:32 +0800 Message-Id: <20230316174432.1592087-1-zyytlz.wz@163.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: _____wD3_8eBVRNkg0sdAQ--.31373S2 X-Coremail-Antispam: 1Uf129KBjvdXoWrtF1UGFy5Jw45ZF18GrWkXrb_yoWkXwc_ua 4ruF4xGF4rCanxKF17XwnxZrWUKFyDXrn3XFs29F4fWa4xGr15Zw17Ars7uF47uF98GFyD Cws8t395Zw47ujkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUvcSsGvfC2KfnxnUUI43ZEXa7xRK9NVJUUUUU== X-Originating-IP: [111.206.145.21] X-CM-SenderInfo: h2113zf2oz6qqrwthudrp/1tbiXQU0U1WBo8O2kQAAss X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,RCVD_IN_MSPIKE_H2, 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1760547714473855025?= X-GMAIL-MSGID: =?utf-8?q?1760547799265226207?= |
Series |
[v3] usbip: vudc: Fix use after free bug in vudc_remove due to race condition
|
|
Commit Message
Zheng Wang
March 16, 2023, 5:44 p.m. UTC
In vudc_probe, it calls init_vudc_hw, which bound &udc->timer with v_timer.
When it calls usbip_sockfd_store, it will call v_start_timer to start the
timer work.
When we call vudc_remove to remove the driver, theremay be a sequence as
follows:
Fix it by shutdown the timer work before cleanup in vudc_remove.
Note that removing a driver is a root-only operation, and should never
happen.
CPU0 CPU1
|v_timer
vudc_remove |
kfree(udc); |
//free shost |
|udc->gadget
|//use
Fixes: b6a0ca111867 ("usbip: vudc: Add UDC specific ops")
Signed-off-by: Zheng Wang <zyytlz.wz@163.com>
---
drivers/usb/usbip/vudc_dev.c | 1 +
1 file changed, 1 insertion(+)
Comments
Sorry this is not v3 but v1, I will resubmit v1 again. Sorry again for my mistake. Thanks, Zheng Zheng Wang <zyytlz.wz@163.com> 于2023年3月17日周五 01:44写道: > > In vudc_probe, it calls init_vudc_hw, which bound &udc->timer with v_timer. > > When it calls usbip_sockfd_store, it will call v_start_timer to start the > timer work. > > When we call vudc_remove to remove the driver, theremay be a sequence as > follows: > > Fix it by shutdown the timer work before cleanup in vudc_remove. > > Note that removing a driver is a root-only operation, and should never > happen. > > CPU0 CPU1 > > |v_timer > vudc_remove | > kfree(udc); | > //free shost | > |udc->gadget > |//use > > Fixes: b6a0ca111867 ("usbip: vudc: Add UDC specific ops") > Signed-off-by: Zheng Wang <zyytlz.wz@163.com> > --- > drivers/usb/usbip/vudc_dev.c | 1 + > 1 file changed, 1 insertion(+) > > diff --git a/drivers/usb/usbip/vudc_dev.c b/drivers/usb/usbip/vudc_dev.c > index 2bc428f2e261..33d0991755bb 100644 > --- a/drivers/usb/usbip/vudc_dev.c > +++ b/drivers/usb/usbip/vudc_dev.c > @@ -633,6 +633,7 @@ int vudc_remove(struct platform_device *pdev) > { > struct vudc *udc = platform_get_drvdata(pdev); > > + timer_shutdown_sync(&udc->timer); > usb_del_gadget_udc(&udc->gadget); > cleanup_vudc_hw(udc); > kfree(udc); > -- > 2.25.1 >
On 3/16/23 11:44, Zheng Wang wrote: > In vudc_probe, it calls init_vudc_hw, which bound &udc->timer with v_timer. > > When it calls usbip_sockfd_store, it will call v_start_timer to start the > timer work. > > When we call vudc_remove to remove the driver, theremay be a sequence as > follows: > When you resend the patch as you indicated would, please add details on how you found this proble,m. > Fix it by shutdown the timer work before cleanup in vudc_remove. > thanks, -- Shuah
Shuah Khan <skhan@linuxfoundation.org> 于2023年3月17日周五 01:57写道: > > On 3/16/23 11:44, Zheng Wang wrote: > > In vudc_probe, it calls init_vudc_hw, which bound &udc->timer with v_timer. > > > > When it calls usbip_sockfd_store, it will call v_start_timer to start the > > timer work. > > > > When we call vudc_remove to remove the driver, theremay be a sequence as > > follows: > > > > When you resend the patch as you indicated would, please add details > on how you found this proble,m. > Get it, I found it by static analysis. So this might be false postive. Best regards, Zheng > > Fix it by shutdown the timer work before cleanup in vudc_remove. > > > > thanks, > -- Shuah >
diff --git a/drivers/usb/usbip/vudc_dev.c b/drivers/usb/usbip/vudc_dev.c index 2bc428f2e261..33d0991755bb 100644 --- a/drivers/usb/usbip/vudc_dev.c +++ b/drivers/usb/usbip/vudc_dev.c @@ -633,6 +633,7 @@ int vudc_remove(struct platform_device *pdev) { struct vudc *udc = platform_get_drvdata(pdev); + timer_shutdown_sync(&udc->timer); usb_del_gadget_udc(&udc->gadget); cleanup_vudc_hw(udc); kfree(udc);