Received: by 2002:a05:6a10:c604:0:0:0:0 with SMTP id y4csp3756008pxt; Tue, 10 Aug 2021 10:34:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzZpvrNmpquTrTV/0w+2UDEYv7Ix+LPreo5/kdsHVw8IGMTwS9p4bDo8chv/xaknnwE32PZ X-Received: by 2002:a17:906:a298:: with SMTP id i24mr28815900ejz.151.1628616863983; Tue, 10 Aug 2021 10:34:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628616863; cv=none; d=google.com; s=arc-20160816; b=SRe6w0t+AS6YWmfRXx1kbeZtOAuib1zwWHirDeYqJ6PkiEmfa3UcwcB6/nWAe5yDC3 bdjWYxNX4IvGqY9ubIgv3g9bFa2NVbzq4Jidt1bqICZ/Nyz7xUEHISGkWwUOweZAE/Oe kS/X7i5iFvN2/KUgMw7XuoHXYEvOB3+1ZeaRO/kZ7nlEbhki3dH1Y1vlPH2kkPtqYo/m 2L6IFHFVyyvFRp81CJgCxSzgWuHgPqyDUVhuteNN6rLZAxGn5KNSSn31CtGvS55rA3Ta W8FtR0PlFwTtm2CT1r6aFvhn0QPRvWxBmgVi4ig8nIDp2YCcM0zsuZ3JY7tmCTTAm6WK 9D+A== 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=n3GzRchOPohC5Z1z+fxa6zCelKwfT4sGBSFH6jjk5Ck=; b=OqCLTiMYjlpoi4JbYJ8A9LCeh0RjIO4bL7hFZXNuoyfIvMlLehD/te4u522Z4KGOUD FZp3aSWvy/Dmp2/iVEOFK8OxB0qWHVffNyADGQ/2xImDhDP6Mq3YAo36VG1l/1WU6xBa ZbcuhHlycLJvqXLfr2pdDEGrGsP3f4fzeBSoNFW0hoexqh0+QUzsOX0KqbpPGXHLBEXN c77tcYNdvYeBpxIQpWt2LbIl+EiYYh9zjYQgWyeQTZGnjjqbmJLCKRgk+GOQsweiQEw0 F8oAd0EGrH9cd3CX6Msc7xZQ919yUvM7Rskin5aQPRWqBMcbp3Sk+RLidmCK0UmUHV9v VThw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=j2NTd7KS; 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 ar26si1623544ejc.725.2021.08.10.10.33.58; Tue, 10 Aug 2021 10:34:23 -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=j2NTd7KS; 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 S231382AbhHJRc3 (ORCPT + 99 others); Tue, 10 Aug 2021 13:32:29 -0400 Received: from mail.kernel.org ([198.145.29.99]:60302 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231268AbhHJRcX (ORCPT ); Tue, 10 Aug 2021 13:32:23 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 8F3E160F94; Tue, 10 Aug 2021 17:32:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1628616721; bh=3DjrTyv5nsPqasdF4+blUb8lfkFTf1bfNJVxdLYiGAo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=j2NTd7KSI7y8tGSUhza437A+H/rrmrnscnmkNWz7fb9c1wV7nBeBBaGvzpIIPwuKW w8hHnkpegWicP2v5cbQqKiN3WmoHru99KO0RdlpCFcpw8uNUA39sJqNFPTsxO5PFND LCW880BQnO0VKeoLqAlZxBG+rjhPBCr6PJRKEmT0= 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.19 18/54] net: vxge: fix use-after-free in vxge_device_unregister Date: Tue, 10 Aug 2021 19:30:12 +0200 Message-Id: <20210810172944.779403736@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210810172944.179901509@linuxfoundation.org> References: <20210810172944.179901509@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 5ae3fa82909f..0766288e2f38 100644 --- a/drivers/net/ethernet/neterion/vxge/vxge-main.c +++ b/drivers/net/ethernet/neterion/vxge/vxge-main.c @@ -3529,13 +3529,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