Received: by 2002:a05:6a10:8a4d:0:0:0:0 with SMTP id dn13csp872572pxb; Fri, 13 Aug 2021 08:10:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwjE/wbMMzhQM8IA1IywyuZfDSeOuLW2PuCid/i/7WdmhIyx5QpP+Lh9NEupBZlYe9nPmxl X-Received: by 2002:a92:b501:: with SMTP id f1mr2087077ile.59.1628867418156; Fri, 13 Aug 2021 08:10:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628867418; cv=none; d=google.com; s=arc-20160816; b=LoxVNqmTHmb4IjGqg3RX18dOZgkPl19tDImFBarjcaQjawoE880X8PG0j7Rjy5gnsd jBr+ErWHdP06935gmkr5116r9LpHFfHV+jZSxqLnpUbIap2eykocUrDNGaPCkC0Apbf+ gXnNP34Uvu/nsmBv42vL+2TdF33vgVEGTApRLbkgolhkIXdh0cn1YaUQ+IjKEUP6Emoc xLR2HX9AbkZiqzTJppNAY4a1zKAWxLKKMuCmmvV7H3i9c5G+G1ppESOlI3PY4YiRJiN8 /1MlBomN0n1/D513Z73xJ9btXQmZ4RmQAJ4xt8Ark3qpziANjeqmHBSQ+tkqYHPXmSQb WIIw== 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=H2aqsTvY041vuCdxex1pwNPd2waozk9wQ5ExR7HeQ3QT9Bx/JiOXPhfR30PgUphJwp HfHcFSAZxS4/44XnaOGIFMLp/uol/oej4xpb8WRZ5SQGQGnUx/cjM1zUq7BwEBHz2nM0 i/pTKt/u2assAOPNgrbHrlt650tw0guIUO9vgx3pfLz3RhmGus+4AT5RHbi2wkXQKLd3 QezSEamoBHvH6KEBPZwQLuQLtn4K8NARIfbz8JliBxcmdblYv+qstNk3B9MCqLcC7iPy /KdeY0JSNWkWZQlXw3doqDssVOvqK0CAsTJbNpyBgdg/eeE3W3zmLXHjDfMGG74GOBQa RlXA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=h7gT2Pjp; 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 z16si2062600jat.29.2021.08.13.08.10.06; Fri, 13 Aug 2021 08:10:18 -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=h7gT2Pjp; 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 S241386AbhHMPJW (ORCPT + 99 others); Fri, 13 Aug 2021 11:09:22 -0400 Received: from mail.kernel.org ([198.145.29.99]:51984 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241304AbhHMPJQ (ORCPT ); Fri, 13 Aug 2021 11:09:16 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 4BCCE610A5; Fri, 13 Aug 2021 15:08:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1628867329; bh=yyoemwsBvh19aiEslTcjG5vsMeyQtHkA1RfuZX4iPDE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=h7gT2PjpEPHMyPoq8+uOY0Ev21xwU7mPcVWXAVNaeK06nHnFkIa4i6Zt5OL++Hmsf r8AseWeN/yWY4HFzt2HaOfTM7eDSXIESQbgvjkeGF6BKCmtt9OV3y2byhcNaHS6fyi 1pksEY2XowK3GtjFROrUQvP8QtAx+eAV2nw7cirw= 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.4 08/25] net: vxge: fix use-after-free in vxge_device_unregister Date: Fri, 13 Aug 2021 17:06:32 +0200 Message-Id: <20210813150520.997995843@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210813150520.718161915@linuxfoundation.org> References: <20210813150520.718161915@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