From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2BF9AC43331 for ; Mon, 11 Nov 2019 18:42:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id ECD082067B for ; Mon, 11 Nov 2019 18:42:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1573497726; bh=PCHv+hTaj3m1wUuArJIxDlgvcAW8NtTUAcScLjKtTZI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=lMiElvAfSVyIosSSNSINix/SSyADtl+PX9QA7llHnAjxxkq8vl5zULl7bfsO9u2Z4 wMn8J2N3n0q731Oj1Brzp5qI/E+u58KRqCuuITmjwPaeInOmpn1/VxACcdPmT/pC3r kRELcoDKcvu1H+iZtcTf3xPkhkhAao63WebEsvHk= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729463AbfKKSmF (ORCPT ); Mon, 11 Nov 2019 13:42:05 -0500 Received: from mail.kernel.org ([198.145.29.99]:33208 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729468AbfKKSmE (ORCPT ); Mon, 11 Nov 2019 13:42:04 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 074BA20674; Mon, 11 Nov 2019 18:42:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1573497723; bh=PCHv+hTaj3m1wUuArJIxDlgvcAW8NtTUAcScLjKtTZI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LVc8kxlJvH9bK9wTVDRw2CO/XypRNv3zpIu07uA1YBJZknkBBVdbwgl1uV4QSNSdK h3qyI2V2VX4ZmpjSqdMuGlMA5kQlxp+BEWSIGegAZw+FrIf8AD9fAwhtbWVz/uy2g4 MEh8OZeb7ana4b3qb+Ur2NpfxD1fAdPsZf3kzsvo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Sean Tranchetti , "David S. Miller" Subject: [PATCH 4.19 006/125] net: qualcomm: rmnet: Fix potential UAF when unregistering Date: Mon, 11 Nov 2019 19:27:25 +0100 Message-Id: <20191111181440.205329891@linuxfoundation.org> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191111181438.945353076@linuxfoundation.org> References: <20191111181438.945353076@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Sean Tranchetti [ Upstream commit e7a86c687e64ab24f88330ad24ecc9442ce40c5a ] During the exit/unregistration process of the RmNet driver, the function rmnet_unregister_real_device() is called to handle freeing the driver's internal state and removing the RX handler on the underlying physical device. However, the order of operations this function performs is wrong and can lead to a use after free of the rmnet_port structure. Before calling netdev_rx_handler_unregister(), this port structure is freed with kfree(). If packets are received on any RmNet devices before synchronize_net() completes, they will attempt to use this already-freed port structure when processing the packet. As such, before cleaning up any other internal state, the RX handler must be unregistered in order to guarantee that no further packets will arrive on the device. Fixes: ceed73a2cf4a ("drivers: net: ethernet: qualcomm: rmnet: Initial implementation") Signed-off-by: Sean Tranchetti Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- drivers/net/ethernet/qualcomm/rmnet/rmnet_config.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) --- a/drivers/net/ethernet/qualcomm/rmnet/rmnet_config.c +++ b/drivers/net/ethernet/qualcomm/rmnet/rmnet_config.c @@ -66,10 +66,10 @@ static int rmnet_unregister_real_device( if (port->nr_rmnet_devs) return -EINVAL; - kfree(port); - netdev_rx_handler_unregister(real_dev); + kfree(port); + /* release reference on real_dev */ dev_put(real_dev);