Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp6554288ybx; Mon, 11 Nov 2019 10:52:00 -0800 (PST) X-Google-Smtp-Source: APXvYqyTNEjvpfQXLRG/H0VBntdu+zQhmuQnqiRf9I1kow/rCLF1BQIQXyUJyMX//2QXagJ/rbOv X-Received: by 2002:a17:906:4c93:: with SMTP id q19mr18240888eju.91.1573498320740; Mon, 11 Nov 2019 10:52:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573498320; cv=none; d=google.com; s=arc-20160816; b=Ztk1OjY9bbw43rxDjkX1YzsGq56Bu6GCOQREB4LKqfeOfF0OujVQq2trhB6SIU+Fx6 eNqzGstfRmT0zUuuMQfRSHvOObuoQtuIYrC/sdar/ttOD8iSBmUr+wQlmw3dsfL1gbG4 wbnaZTHkcIYwsiiQ/slMPiv7qJDjQAU5AYl9Pbru7AEstzvoQJzOYgtFa/8WxOhwgYnK rbAqac6gF6FDNjlm1Few7NV4wDPFK73XBbJr08PoW+0W+tc7TyfhLqMxDGMRJYNclPBj yio3jeP4l6EhP7q/gTiQ9U7ITVHXJ4jIBPRaERIDovynNwcBuWbkb+zAL9hGBQ6tobSF xk7g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=SqfLmgIo8be+yeMxLbjrUMUaYZvJDW6r/+L4h7YhYEA=; b=tB8LGQXHN91pPM7arrrPKzreTNxJpKpC5vjStEALpOIgnml1GWdtleP1TWUbRCbjSh ihmfmXM8AsDxUytdvG/QYVyGoFGF11Tj939+zPRz+l0YJlC7GA8mGdr/MAOa8yDN0kT7 ds75VD9XyvxyJWaDEU2zCKnx+EpY5R3hGNhej6lfqLyXLeibfUKz7UCsLnbZQRbrwgmF nl1OAhBDKACojQO6ydfpmiye2nYiCfsAxTp6Jc94fvKxZ7q4f5SLvpa9MpxWkKWcvYFt q4Ar0HPI5GkpiDm+w0LS/aadTlPteLmtKTbk2Z6O+zW+pQuKOZGAwWzErKePXQCJ6j2V HOEA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=THdsZqC9; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d6si13764606edj.28.2019.11.11.10.51.37; Mon, 11 Nov 2019 10:52:00 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=THdsZqC9; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730262AbfKKSsd (ORCPT + 99 others); Mon, 11 Nov 2019 13:48:33 -0500 Received: from mail.kernel.org ([198.145.29.99]:41614 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729865AbfKKSsb (ORCPT ); Mon, 11 Nov 2019 13:48:31 -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 0BB0E20674; Mon, 11 Nov 2019 18:48:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1573498110; bh=xFBlIuhONq+naCWyfL6jszbnWwxREMT+IEYwbtlTFTM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=THdsZqC93Agg3FmpAO9lwe3GkUHuVi/dBVRoXK/T5VfpYauLtn4s0jKyayMbAzHU5 eB1xqob5sPEp9xKChccAdVWfQ5F0XnkdVfTOhysmZyVzMz1h8GPNTezdC3OBoxVkDf VlENLJ098pgC9KaV7n/hae5NWMXMDamdZypLTfBM= 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 5.3 006/193] net: qualcomm: rmnet: Fix potential UAF when unregistering Date: Mon, 11 Nov 2019 19:26:28 +0100 Message-Id: <20191111181500.307705719@linuxfoundation.org> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191111181459.850623879@linuxfoundation.org> References: <20191111181459.850623879@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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 @@ -57,10 +57,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);