Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3935972pxf; Mon, 22 Mar 2021 20:49:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyIQW4QhaCo59+B92Nd9/2//ZXMXmWV9iCOXrug/ravltNwpHostw2rKmpgIMm6Nc/qrGL/ X-Received: by 2002:a05:6402:c11:: with SMTP id co17mr2659067edb.246.1616471391234; Mon, 22 Mar 2021 20:49:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616471391; cv=none; d=google.com; s=arc-20160816; b=x8y3HhTLRop6GFR39Z9UXqIwLI/U9pLjFNvtGtJVujo5SUL45RusxX/EDKoKFwXExH ZUnYwhwNQZxJOx1MUhBnCTgaBcRMTR2mrdcVgV2viCma6/txrvOVHRrPt0Gccl7qdhGg psiaRM+1qtUfDiZ7kYKyAmdvs+SiLSfVb/0/1DQ/axsq4akKm0X1N93l0xpl7ZFzlxO7 aZP7GUrL0G7MkxytmCyze7Ml8V2aTfNm/zFzG0H6utuOXYV7GAZAwXS1umiiuVi+8o/e Z8HhGizbYmBAC0M3sgBr5Xu2N2gzJuzcDqG9DAkBfoDZfI10942q6s7zn7K6kQve22Ct 85pQ== 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=1GoWh5eS4Ly3A4l/bsaEFyKFS7162BJKVfkr1mQVN2s=; b=ahs0wbTOQ5nAkiY7pqNw6izYxDN1E3Tke6qi1Gnhmdycv2vkD8EyfrDR+kK3FQivnn aSl4Vcmw3adyuTn5GDwdfECTSFUnerBEsjVW4lGSK96HMG3JuWwbUaJj3xkNNoNT1CQl BuXeV5sT8Lg0SaXmcG3BieEZ1J2qwGJk5u26eqo4AP4eVGJszkftIiTRIXhYGLFdOlsY kV2rGERhwCSyGIofGgq5FrQweWSFtixlcdPqBkbFvgbK6Wt6XuAaziu90Vthnck52OqP v8HRN8cTgtlHhTM/AuJvKKz7F2KeAQzQq5y6bOorm9ynSXpc64I399VWhIpERRebDZ2R WB7g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mail.ustc.edu.cn header.s=dkim header.b=FIsQNV9h; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mail.ustc.edu.cn Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f6si12353698edq.600.2021.03.22.20.49.28; Mon, 22 Mar 2021 20:49:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@mail.ustc.edu.cn header.s=dkim header.b=FIsQNV9h; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mail.ustc.edu.cn Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229632AbhCWDsa (ORCPT + 99 others); Mon, 22 Mar 2021 23:48:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51936 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229537AbhCWDsD (ORCPT ); Mon, 22 Mar 2021 23:48:03 -0400 Received: from ustc.edu.cn (email6.ustc.edu.cn [IPv6:2001:da8:d800::8]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 2FBDBC061574; Mon, 22 Mar 2021 20:47:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mail.ustc.edu.cn; s=dkim; h=Received:From:To:Cc:Subject:Date: Message-Id:MIME-Version:Content-Transfer-Encoding; bh=1GoWh5eS4L y3A4l/bsaEFyKFS7162BJKVfkr1mQVN2s=; b=FIsQNV9hksoXuqYWMxy0FqR3Em tFJj9b469QfN5LEuURJC5mqJCbdp6nQ5/+vCtU9btDnRDilyf7od5Nb2WnJC5sCp 9JC6wqD5NHhi7IAVZFrBGW0HsjFqUtInzbXcFD9J1G2eFa+YR6YhZcUbNSHeiR63 SYXIs+gMYONIHHYkM= Received: from ubuntu.localdomain (unknown [202.38.69.14]) by newmailweb.ustc.edu.cn (Coremail) with SMTP id LkAmygCHj0PJZFlgc6waAA--.144S4; Tue, 23 Mar 2021 11:47:21 +0800 (CST) From: Lv Yunlong To: gregkh@linuxfoundation.org, linux-usb@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Lv Yunlong Subject: [PATCH] usb: Add data checks in usbtmc_disconnect Date: Mon, 22 Mar 2021 20:47:17 -0700 Message-Id: <20210323034717.12818-1-lyl2019@mail.ustc.edu.cn> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: LkAmygCHj0PJZFlgc6waAA--.144S4 X-Coremail-Antispam: 1UD129KBjvdXoW7Wr48Zr15ur1fZr4UGr4fGrg_yoWkJrX_ua 1UWF1xtrW5CF9xC3W7tr1rZw1xt3W0qw48XFs0y343Za4jqw4kAr1Iqrs5J397WF4UtryD Zrn2qryruayxujkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUIcSsGvfJTRUUUbV8FF20E14v26r1j6r4UM7CY07I20VC2zVCF04k26cxKx2IYs7xG 6rWj6s0DM7CIcVAFz4kK6r1j6r18M28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8w A2z4x0Y4vE2Ix0cI8IcVAFwI0_Ar0_tr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Cr0_ Gr1UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E14v26rxl6s 0DM2vYz4IE04k24VAvwVAKI4IrM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI 64kE6c02F40Ex7xfMcIj6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWUJVW8Jw Am72CE4IkC6x0Yz7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41lF7I21c0EjII2zVCS5cI20VAG YxC7MxkIecxEwVAFwVW8GwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8Jw C20s026c02F40E14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAF wI0_JF0_Jw1lIxkGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVWUJVWUCwCI42IY6xIIjx v20xvEc7CjxVAFwI0_Jr0_Gr1lIxAIcVCF04k26cxKx2IYs7xG6rWUJVWrZr1UMIIF0xvE x4A2jsIE14v26r1j6r4UMIIF0xvEx4A2jsIEc7CjxVAFwI0_Gr0_Gr1UYxBIdaVFxhVjvj DU0xZFpf9x0JUza0QUUUUU= X-CM-SenderInfo: ho1ojiyrz6zt1loo32lwfovvfxof0/ Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In usbtmc_disconnect, data is got from intf with the initial reference. There is no refcount inc operation before usbmc_free_int(data). In usbmc_free_int(data), the data may be freed. But later in usbtmc_disconnect, there is another put function of data. I think it is better to add necessary checks to avoid the data being put twice. It could cause errors in race. Signed-off-by: Lv Yunlong --- drivers/usb/class/usbtmc.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/usb/class/usbtmc.c b/drivers/usb/class/usbtmc.c index 74d5a9c5238a..e0438cb46386 100644 --- a/drivers/usb/class/usbtmc.c +++ b/drivers/usb/class/usbtmc.c @@ -2494,7 +2494,9 @@ static void usbtmc_disconnect(struct usb_interface *intf) } mutex_unlock(&data->io_mutex); usbtmc_free_int(data); - kref_put(&data->kref, usbtmc_delete); + + if (data->iin_ep_present && data->iin_urb) + kref_put(&data->kref, usbtmc_delete); } static void usbtmc_draw_down(struct usbtmc_file_data *file_data) -- 2.25.1