Received: by 2002:a05:6a10:c604:0:0:0:0 with SMTP id y4csp3759304pxt; Tue, 10 Aug 2021 10:39:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwfHiUQxDaOGNkc8Kj6sg77wpZTK8m/5MynPePZVHBpohSuwiL9GpySpqeK2gQR5+3Kanet X-Received: by 2002:a17:906:4d94:: with SMTP id s20mr27833163eju.152.1628617161107; Tue, 10 Aug 2021 10:39:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628617161; cv=none; d=google.com; s=arc-20160816; b=TQZD73gM0WDym1AG9aSu3SQhuDCJ3Kwd3ojqZckO8KdO1zKyVq0SJ46ptOKB3lP1Yz u3RbcloR2CCOKblexZV3mdG+2d4p935QESP4wrWnMRjspWHqSBLxL26KtIc59vkP2bv3 HC5QgVPctQvt2ASZ7OA8Rn0kZ34gkMLQjQ37cKKJuO2teMLOlfb/RGCIcLYEXAm9QHPa GBI2eV+umQYdOZBElt+cvYQp95yQQ1o+TwlaHGr57P6/0p5BFP2wSeCdw39KDGGyFS9c 4Lj95gdWk5EvRlEGClrCb8z1JJ63z1bORZBSSjOL32NjcmYG+P0OWPSIxyNHO19zTmAT m78A== 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=CFXdzsHvIuULR2wfgJ/u698bQsC54IizJq+APVtG/qU=; b=PDskcwVWRXuP4vI9I3Un51Bm0vavCZFo4WXBlKYF0DSHBbqJ73nMphbt7cjccxoYoy RioTW/ejUecBAgPwtgsDQt0TswfGtIojp4k7LjpNaEYXzM8fNTr13FCzoU9N/y2LwOiM ng37Fps3AwKgBUPDPcxBxGbIZFhCnGKaip2BmPf8M4NqbNVWCES8JlbqV54+cxTWqT8U 2jR8Twpyh/4EeUEEpHCRmjG/OV+MIxp9WyZrjyIur+gh0p7lWSlLpiERizP8evF6rzNW rT3QxF0QHvsVPQtKpKcxR/l8QGU4zpVBfCYOb0nOMkk1t97CAvjQHAkkEiQWjiaXC+LO 19uA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="mW95Q/lo"; 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 x12si20314760eds.503.2021.08.10.10.38.57; Tue, 10 Aug 2021 10:39:21 -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="mW95Q/lo"; 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 S233438AbhHJRgj (ORCPT + 99 others); Tue, 10 Aug 2021 13:36:39 -0400 Received: from mail.kernel.org ([198.145.29.99]:43106 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233218AbhHJRfD (ORCPT ); Tue, 10 Aug 2021 13:35:03 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 1A76660FC4; Tue, 10 Aug 2021 17:34:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1628616881; bh=padmp1EfJk5gEo26tVeSIiRYdf6NZwwoY/vBdgBuUMs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mW95Q/lofdST/qLr1FeNB9owmzXjNH8huWB4Nf57PNWgqv7F/g8GJiyfDP2AJdQi5 kskAlphfCVfN0TtVFrYps2IyBPjfL8jXFuN49pFg+stMJrwqCXhiNEqW96TwlfoMNZ MjQNYT9ODY7EW6Foqqn8kRjr22nI5y5wW75Rqs40= 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 5.4 33/85] net: vxge: fix use-after-free in vxge_device_unregister Date: Tue, 10 Aug 2021 19:30:06 +0200 Message-Id: <20210810172949.315217211@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210810172948.192298392@linuxfoundation.org> References: <20210810172948.192298392@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 1d334f2e0a56..607e2ff272dc 100644 --- a/drivers/net/ethernet/neterion/vxge/vxge-main.c +++ b/drivers/net/ethernet/neterion/vxge/vxge-main.c @@ -3524,13 +3524,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