Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp6569061ybx; Mon, 11 Nov 2019 11:06:22 -0800 (PST) X-Google-Smtp-Source: APXvYqyYEcoiMtGYVjTl2qw/s3UBVi9Q00falLJgmFjbwhBIBixen8NF8NLt2taH4144sUdj8rFH X-Received: by 2002:a17:906:5502:: with SMTP id r2mr24789739ejp.3.1573499181947; Mon, 11 Nov 2019 11:06:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573499181; cv=none; d=google.com; s=arc-20160816; b=JnliCiXby0l3wtIonaFnxNt4axXcWl+eQ3tpb+83ExzUyviruCyd0cQ4X9QNa6zbG3 Qef/UjFEa0fZpz3SKhAimEm4v7TtsBrdhaz/Jq4SEVO5RjbXMm+/NIc2R9n6WSp3OQXh D2RsVZNO2t/Q9nOdsYegi1pN1TmEt7bj/umf1WzP8QNZ/bjTkjMWgWsSdU4/aywYhRnH eQ/hkIFpB1/sEKA5WOs+lst0TqPIUulJVptQbGpTiSqhotBvtbvSDbZ91lYfoYqMbjHp G9SXuCYFeKNlNysOgFJvEPAfLeCqhLu91NKxW2wSdaVZWf9yXf1fOehswowu9zHMmeIp vIbg== 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=Z/iEaUovm9wof5xys9GB1T9LwlMBUhvdZvbf35eBe8M=; b=h1lMn6SW/vq3oHVLUvhkspiGqpQXsfCC2CwogWFJnznefnffGz30IVN9vebFMzVmEr pVWis6FCwTJgmp61TyS8DN3CLHjJf6ZD/PfZNXTPjnuE3uA4cwQnfd/GCapxx3sfJo97 Ih4f2KkO7GwV4sOkQl+4VJEm0XmbKnbrvPittGo+lpLUk+TgY2kKvSoQqXWQ1eFKbQDO 3d4gNWpcHJFnMhZH2iBKYhj8CTJVvCOkYJcFGq3at0RtkoXq72wXCgjPEiseODDPSel5 TNm4z9CP7Acljp0dfNbR+3KtIw5R4LncSKcLKiCeL1own72SSmsRuuVBUcWcPBcbrAnI kKgA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=LVc8kxlJ; 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 o1si9484896eje.298.2019.11.11.11.05.57; Mon, 11 Nov 2019 11:06:21 -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=LVc8kxlJ; 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 S1729473AbfKKSmG (ORCPT + 99 others); Mon, 11 Nov 2019 13:42:06 -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: 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 @@ -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);