Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp3813062pxv; Mon, 28 Jun 2021 13:34:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy1mCZrEA5Dcs4mAlcBXI6C58zIgSPCV3x63moqp4bxMsR5B+8LadD4MaRmPC8+tKAQUsZQ X-Received: by 2002:a6b:b7c3:: with SMTP id h186mr116087iof.82.1624912489002; Mon, 28 Jun 2021 13:34:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624912488; cv=none; d=google.com; s=arc-20160816; b=hFVsGm1YendkeH63DSnYXkl0n+djNQoHyjrvb6f0oOY10OiOYDqgsxJTwar7lhjLbU JohvHB51bcWZVtQpNQM3/jemKE9jAhNCFUkYwKvPRyjjqi5t4jznXDY6mIY8sSWtrgW9 zPbEQ1UL2A7i/VV7sSjaYyYJ3JhMkOYdyppiZE5YhMjNEkggJ1UZLPeO6JEKnsX47+p/ h1BY0OVKrG7u5r4cFeoRfe4MqDzirmrWoVYQKahxNt4gbkQC5v+5Eb3KMFMRzn873ql6 tGNd146zWDnMZgJlpy7JGlAne0YdoM7HzGwnJB4OEqm7YkJzQOKhc/IKvTRMgx8BbfwD 0AvA== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=cr7UQW1iGqnO3Pp5cAbFSNVitXjQK/RpEbG9g7tC85s=; b=J+G3BnEzikplI7scZXvd0rq1puynOEezCMUgLPxZ+k70wkLrSMu2HvHx+8Pe1InN+G JFhdnR6eZgII/0uicYHHUdt4NBYnZx1x9j/T3aK9f7iq1Fp09dX60HBrNA9paFfl7uej uHD7i83oBvwhYEwTgN2WdZh4QR2qnQbraR6MF/rAZRmsv5JbxVBhC2ygZV1iri1r44Gs /OOQnPpN0kRn/+7QuqzGyPZ5SgSLdcspu1A4ioIfUIhuwdrw9es9wFtqdvStKLeAv1bB vhuD1Gpe7S/HBkM0OBpsf8AKlfM2BYEx9fsDlJQvu+fyzctSrfBOQ5MeP+Eo0gMpj0ha ydJg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=JmBTLDgK; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w3si19398573ilh.113.2021.06.28.13.34.33; Mon, 28 Jun 2021 13:34:48 -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=@kernel.org header.s=k20201202 header.b=JmBTLDgK; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236688AbhF1PLw (ORCPT + 99 others); Mon, 28 Jun 2021 11:11:52 -0400 Received: from mail.kernel.org ([198.145.29.99]:55612 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235026AbhF1OuY (ORCPT ); Mon, 28 Jun 2021 10:50:24 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 0117761D27; Mon, 28 Jun 2021 14:36:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1624891019; bh=tw3njbl5kYSuuAEPN4CkEILmi76E+5XQNw5vC1dpNVk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JmBTLDgKySI6OAE6DFmlSW/T0ZQqp1UeNQM1+H/VZ+QgAOb/5V6/Aq6lgfYstKfhg MPFsfW1R8mSi6vS5Z9pcjzENnzuz0GMG4XQDGI31x4rXHZETnuIXVrDjCPRtVqVktj C70zGPHcl7ZaaLnvxO53DAON4UdIYMKoFXSdolQq4ZaBVEedxJV2ARQsDPK4nrFk6Q jFKMYLixbsd8Ma5AhMaRP0MGE8AWc7Vh+hsXhxq5PiLI83ogMSys8inuqm5gHgcPAI FufsMSDHLtvJcQTTfUAD/m72KVBt0V3tUWyla9pAkJaEYrMjMZSNo8pc1NskUX88qC 4p78j8cXsdEjA== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Dongliang Mu , "David S . Miller" , Sasha Levin Subject: [PATCH 4.14 33/88] net: usb: fix possible use-after-free in smsc75xx_bind Date: Mon, 28 Jun 2021 10:35:33 -0400 Message-Id: <20210628143628.33342-34-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210628143628.33342-1-sashal@kernel.org> References: <20210628143628.33342-1-sashal@kernel.org> MIME-Version: 1.0 X-KernelTest-Patch: http://kernel.org/pub/linux/kernel/v4.x/stable-review/patch-4.14.238-rc1.gz X-KernelTest-Tree: git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.git X-KernelTest-Branch: linux-4.14.y X-KernelTest-Patches: git://git.kernel.org/pub/scm/linux/kernel/git/stable/stable-queue.git X-KernelTest-Version: 4.14.238-rc1 X-KernelTest-Deadline: 2021-06-30T14:36+00:00 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Dongliang Mu [ Upstream commit 56b786d86694e079d8aad9b314e015cd4ac02a3d ] The commit 46a8b29c6306 ("net: usb: fix memory leak in smsc75xx_bind") fails to clean up the work scheduled in smsc75xx_reset-> smsc75xx_set_multicast, which leads to use-after-free if the work is scheduled to start after the deallocation. In addition, this patch also removes a dangling pointer - dev->data[0]. This patch calls cancel_work_sync to cancel the scheduled work and set the dangling pointer to NULL. Fixes: 46a8b29c6306 ("net: usb: fix memory leak in smsc75xx_bind") Signed-off-by: Dongliang Mu Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- drivers/net/usb/smsc75xx.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/drivers/net/usb/smsc75xx.c b/drivers/net/usb/smsc75xx.c index 62f2862c9775..8b9fd4e071f3 100644 --- a/drivers/net/usb/smsc75xx.c +++ b/drivers/net/usb/smsc75xx.c @@ -1495,7 +1495,7 @@ static int smsc75xx_bind(struct usbnet *dev, struct usb_interface *intf) ret = smsc75xx_wait_ready(dev, 0); if (ret < 0) { netdev_warn(dev->net, "device not ready in smsc75xx_bind\n"); - goto err; + goto free_pdata; } smsc75xx_init_mac_address(dev); @@ -1504,7 +1504,7 @@ static int smsc75xx_bind(struct usbnet *dev, struct usb_interface *intf) ret = smsc75xx_reset(dev); if (ret < 0) { netdev_warn(dev->net, "smsc75xx_reset error %d\n", ret); - goto err; + goto cancel_work; } dev->net->netdev_ops = &smsc75xx_netdev_ops; @@ -1515,8 +1515,11 @@ static int smsc75xx_bind(struct usbnet *dev, struct usb_interface *intf) dev->net->max_mtu = MAX_SINGLE_PACKET_SIZE; return 0; -err: +cancel_work: + cancel_work_sync(&pdata->set_multicast); +free_pdata: kfree(pdata); + dev->data[0] = 0; return ret; } @@ -1527,7 +1530,6 @@ static void smsc75xx_unbind(struct usbnet *dev, struct usb_interface *intf) cancel_work_sync(&pdata->set_multicast); netif_dbg(dev, ifdown, dev->net, "free pdata\n"); kfree(pdata); - pdata = NULL; dev->data[0] = 0; } } -- 2.30.2