Received: by 2002:a05:6a10:8a4d:0:0:0:0 with SMTP id dn13csp875762pxb; Fri, 13 Aug 2021 08:13:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw5+Op5LmUfvZ5ICMuqYVc0VYyqUpsOoU+nix+hEYytLPQy5yQuupgG3fsBQ6Dq6mFFc9qB X-Received: by 2002:aa7:d144:: with SMTP id r4mr3682288edo.111.1628867625128; Fri, 13 Aug 2021 08:13:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628867625; cv=none; d=google.com; s=arc-20160816; b=0F2qUDDMCKAWBGkSt1mnEoXyDgb5rhkGDWt2arzZaTix0EBUn9m+xYHm9jcMAosH7L Y3c6FCVCWFH4M4IBnCd4HEg7W6GWc8Brp4AfZxRLKlw0vorUp7Q4PqRlap76Qyh/3KrI kbZYM8wHdjGHQvjiNtwdOhzfY6IKThT9yGUe1wbhQiiajMDZhjNhdrJQpwWqEOQHhYcY Lx8hzYKQ0vevR+zQFIpGjNlpmanVydrOknTP8jUy00DvaLgJXrs57iS4vt5RHeCsp+tS wN1Zb+GGaf5nftYgvq2attOxBNmaGdf0g9IS2d80I12R/ZcFDq5DsgaxWwFSx0zteSyv D4aA== 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=E7sxauWu09iH0jUpKHLOcmrwCRY1RywooocteCr72zs=; b=twlcfQJnZ3XH4mS9DNPdb5KWjLhOAy4oPzEOD4HnBnTwyDPXNwgTx2MmLmdjdSGVAv Al2HWmAVBJN8H4kdZoyfCO9txSaqkdvoCWgmDrI/cYoE73X0skFtZC+rz3ceJuXl2NvH vCnJAJHOufrwZleo7qatWKNFeXByxB2FuSyr9B/Hagb+yK38O6vAKOPKD7Xnj5D/aBQ3 3XpwKzbxqp04y9LnHRwk3pNr16HGP+5VyuSA+IVbP6G9rc/Vtk8NZmVSiXmbb8s48Fsx JDq97a813hkXsnGCm1+MRD+HQ9l3NfRFIQUSRn3bNs7inVFn7bO0jJ2Aaw5fL0NLhOw9 0xGw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=srpEtT6Q; 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=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d22si2365494ejj.387.2021.08.13.08.12.58; Fri, 13 Aug 2021 08:13:45 -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=@linuxfoundation.org header.s=korg header.b=srpEtT6Q; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241392AbhHMPLH (ORCPT + 99 others); Fri, 13 Aug 2021 11:11:07 -0400 Received: from mail.kernel.org ([198.145.29.99]:53344 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241562AbhHMPKa (ORCPT ); Fri, 13 Aug 2021 11:10:30 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 95E3561106; Fri, 13 Aug 2021 15:10:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1628867404; bh=yyoemwsBvh19aiEslTcjG5vsMeyQtHkA1RfuZX4iPDE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=srpEtT6Qye/KJKJYEgBJKg5/CKcHN9EzjuFvrxiI3tgh9NZ5cVkrcqjHGVkk2QxRD Rtp9Qo1FsuYVcRN2seN2R4oXqS0glOVK5AxL/PnoNWTR+8JXG8JvWwMRTq9qNLz43n KK+eN5Fy6QCwHQnJAoH/ND/QieZJA9NBzwMuPoW8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dan Carpenter , Pavel Skripkin , Jesse Brandeburg , Jakub Kicinski , Sasha Levin Subject: [PATCH 4.9 09/30] net: vxge: fix use-after-free in vxge_device_unregister Date: Fri, 13 Aug 2021 17:06:37 +0200 Message-Id: <20210813150522.742804565@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210813150522.445553924@linuxfoundation.org> References: <20210813150522.445553924@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Pavel Skripkin [ Upstream commit 942e560a3d3862dd5dee1411dbdd7097d29b8416 ] Smatch says: drivers/net/ethernet/neterion/vxge/vxge-main.c:3518 vxge_device_unregister() error: Using vdev after free_{netdev,candev}(dev); drivers/net/ethernet/neterion/vxge/vxge-main.c:3518 vxge_device_unregister() error: Using vdev after free_{netdev,candev}(dev); drivers/net/ethernet/neterion/vxge/vxge-main.c:3520 vxge_device_unregister() error: Using vdev after free_{netdev,candev}(dev); drivers/net/ethernet/neterion/vxge/vxge-main.c:3520 vxge_device_unregister() error: Using vdev after free_{netdev,candev}(dev); Since vdev pointer is netdev private data accessing it after free_netdev() call can cause use-after-free bug. Fix it by moving free_netdev() call at the end of the function Fixes: 6cca200362b4 ("vxge: cleanup probe error paths") Reported-by: Dan Carpenter Signed-off-by: Pavel Skripkin Reviewed-by: Jesse Brandeburg Signed-off-by: Jakub Kicinski Signed-off-by: Sasha Levin --- drivers/net/ethernet/neterion/vxge/vxge-main.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/net/ethernet/neterion/vxge/vxge-main.c b/drivers/net/ethernet/neterion/vxge/vxge-main.c index e0993eba5df3..c6950e580883 100644 --- a/drivers/net/ethernet/neterion/vxge/vxge-main.c +++ b/drivers/net/ethernet/neterion/vxge/vxge-main.c @@ -3539,13 +3539,13 @@ static void vxge_device_unregister(struct __vxge_hw_device *hldev) kfree(vdev->vpaths); - /* we are safe to free it now */ - free_netdev(dev); - vxge_debug_init(vdev->level_trace, "%s: ethernet device unregistered", buf); vxge_debug_entryexit(vdev->level_trace, "%s: %s:%d Exiting...", buf, __func__, __LINE__); + + /* we are safe to free it now */ + free_netdev(dev); } /* -- 2.30.2