Received: by 2002:a05:6a10:c604:0:0:0:0 with SMTP id y4csp3763794pxt; Tue, 10 Aug 2021 10:45:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxzRqIXC0GRWefyiCkEwqR09ST00Xjj1eJlQN6gaXE+C3G9b+4GttHM9tuCF/1WiZbnIK6A X-Received: by 2002:a05:6e02:1041:: with SMTP id p1mr268415ilj.125.1628617555526; Tue, 10 Aug 2021 10:45:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628617555; cv=none; d=google.com; s=arc-20160816; b=T8ELVPJYbGJupm3cJSXvD8nK/KO3CoY+Ntz6nuPxjaqWfVO2BN819gWyRIm5uhOk8a eiqbdrL2bjKUhCptqCiZONIlW2GzvguaLcXSbBqEvOmHvCC72EFU25hXFnxxEd+w/gOb N+YNaVSYDadleuQD1iI784ESN0Vj7PQOW5SyH2rfHV4d2WN2fvYXWlr4jbF5F9+pK17E lM8VLKk8TZMgBOHVz5q/kPW2AzCOETMVHwlkL3vKd7vvAk3yjqikk3YH3XeOs8PE6+tB USivDOdUe84r9Lx9vWlcIdQxUGOHMnm2DROzZ5ishy7vG89pYmI6CnQRRmG7qfQFdXPX RTBA== 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=+iNJfLRL2b5u30YWd6Np98VqfRp/UboIrFGJwMQVGlo=; b=POQdA/xUnAdAtX+W5fejvSfzUPwdKieI2fMvG4SPQEOv0TkqYvHGvaz7UWdfBt9gGS qeJj1mK0tO0jjkQdwCeiLWE7A8ltUir2SWGIvZcbmzlXA49iL660pmcVrVypyqiMRLrD namAPsEHemt2Ijp7k1ze2GCrCXznmjRvrPQBtmzQsVtVoH+e5EfLL0mWvC7S3/iCu8ak Ek04yIXl91rq3dyBrobJW9L9/Xs1njfuNR2HTOnf/q5jAvQah1aTSKJEjLi5oGBdZrKJ Z/5X45ifVusmF/SVXYnXmabFBuLKzzbk0U5UbsCwoxSWUgvc2V0PqRXHnbrB/Mk5ATj+ euog== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=haagob9z; 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 o15si21618045ilf.79.2021.08.10.10.45.41; Tue, 10 Aug 2021 10:45:55 -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=haagob9z; 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 S235397AbhHJRpR (ORCPT + 99 others); Tue, 10 Aug 2021 13:45:17 -0400 Received: from mail.kernel.org ([198.145.29.99]:41108 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234913AbhHJRlm (ORCPT ); Tue, 10 Aug 2021 13:41:42 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id DD37061212; Tue, 10 Aug 2021 17:38:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1628617108; bh=mtHvomnz+GOQ0h9ygikC2fB+8jfm/bjDlMaEj3vsUxQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=haagob9z+kTqrstREMyM1KAOfQ+tcw7yCBSN6GS/FRa3tSp+bQ3RkfraOA3BoLrDQ TJfMpjXLK8yJlUIBkzPRAu+GUZ7i6nfgC14Nj07M/Y+iMMxBdbSv41gaOAsJWVX6Y0 qtckmbptYYVqNBD93jAkxkfZu2EJoUA5m3SckRvk= 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.10 049/135] net: vxge: fix use-after-free in vxge_device_unregister Date: Tue, 10 Aug 2021 19:29:43 +0200 Message-Id: <20210810172957.355515739@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210810172955.660225700@linuxfoundation.org> References: <20210810172955.660225700@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 87892bd992b1..56556373548c 100644 --- a/drivers/net/ethernet/neterion/vxge/vxge-main.c +++ b/drivers/net/ethernet/neterion/vxge/vxge-main.c @@ -3527,13 +3527,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