Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp4049243ybe; Mon, 9 Sep 2019 03:25:18 -0700 (PDT) X-Google-Smtp-Source: APXvYqx2aws97mf4rUhkH3i8kgCcVCKmvhqiBqbQlfZb6H4Jyju/6sRU27FU+yvcRUXy86KDNmOk X-Received: by 2002:a05:6402:286:: with SMTP id l6mr23459186edv.111.1568024718286; Mon, 09 Sep 2019 03:25:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568024718; cv=none; d=google.com; s=arc-20160816; b=r+NklrYtfs4UF1yhzJVZZyJG3UAPII2YF6FjtHqOTg672Gc9fC+XhNSWz99scwlJmZ mBQ92qZqBfc1pAj38EQPd0W3mJ2H38T5YOvSUzQ7IV+Lk/LsHyV3KqqtGzVybVgGh6zl mzKX6L0fSkoaKNtGYV1txbfq5IpngBssQF/zKRk39kJSeDDQPStLI01PrKiqQ4C64Gfg /gJSplMGyCbCpa52AhMkCSso42cP2CYDsDw0mXVYqJT3YS9lF2SVe+cE8sfD4roE5pdd J16AxpsmYUlZURsX8YWG/8GRv+7tGnSh4eYCXaiM0+4iC19+AdxieLpDg16hfqddRlWK tkHw== 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=NpOp4INhR47PwGXyX7YmCy6KFdcqUyZiVTj+DLKVVO4=; b=KJifRewZ6YKCtezA1axksp5DF9+KFEAqlQk74pJ6c0CXmTsmRoOdjRcjZnl37k0qv6 Vjf7zEUNXupEu+/iPv2vPCEfB1aI/NDUOrvk0x5d3w3VukMqYtduvnh59+eA4LD6eQpV xJBhW93FqZrttKmAqK/H9jQL2M2/5zLJtAA9kxfdi7CISFtW3pah3EfdQ+A90h43KIOn 2ECOIaQ5Pk+KFMEDcio9jhnP4h7mIEmavnS3gsV6MD+S8znlp7y/D7IxgfzQnoiCTh0c igMKyzkInoIEyT0gEp9Si2xMdZb01Bs9sDhtsmTNZPXPWuNyqDmHGCcr0qvtM9possV5 snuw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=J4q89psd; 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 x47si8302151eda.396.2019.09.09.03.24.54; Mon, 09 Sep 2019 03:25:18 -0700 (PDT) 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=J4q89psd; 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 S1731481AbfIHMt2 (ORCPT + 99 others); Sun, 8 Sep 2019 08:49:28 -0400 Received: from mail.kernel.org ([198.145.29.99]:39308 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731452AbfIHMtZ (ORCPT ); Sun, 8 Sep 2019 08:49:25 -0400 Received: from localhost (unknown [62.28.240.114]) (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 0F4FA218AF; Sun, 8 Sep 2019 12:49:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1567946964; bh=qUm4Hz3UlfFJcoxfNGwaaABMr5AHGadsYX+6XAWtEKk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=J4q89psdWXUXiRYmNuWomw1StBamUTsVWzHpEV3jOk55rtFAAIUm6wQ7bRM1gw3WG O1hiCm0NAMKsBECjKXW3gWrFiba8G31FW6Im8xwIhdaX3OxQY7LGGgo4h4/8SCpcr8 o1XUaqaVA+SBi6Ao+6JePKKfhIk0M/HiEk2kf27o= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Feng Sun , Xiaojun Zhao , "David S. Miller" Subject: [PATCH 5.2 02/94] net: fix skb use after free in netpoll Date: Sun, 8 Sep 2019 13:40:58 +0100 Message-Id: <20190908121150.500931264@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190908121150.420989666@linuxfoundation.org> References: <20190908121150.420989666@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: Feng Sun [ Upstream commit 2c1644cf6d46a8267d79ed95cb9b563839346562 ] After commit baeababb5b85d5c4e6c917efe2a1504179438d3b ("tun: return NET_XMIT_DROP for dropped packets"), when tun_net_xmit drop packets, it will free skb and return NET_XMIT_DROP, netpoll_send_skb_on_dev will run into following use after free cases: 1. retry netpoll_start_xmit with freed skb; 2. queue freed skb in npinfo->txq. queue_process will also run into use after free case. hit netpoll_send_skb_on_dev first case with following kernel log: [ 117.864773] kernel BUG at mm/slub.c:306! [ 117.864773] invalid opcode: 0000 [#1] SMP PTI [ 117.864774] CPU: 3 PID: 2627 Comm: loop_printmsg Kdump: loaded Tainted: P OE 5.3.0-050300rc5-generic #201908182231 [ 117.864775] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS Ubuntu-1.8.2-1ubuntu1 04/01/2014 [ 117.864775] RIP: 0010:kmem_cache_free+0x28d/0x2b0 [ 117.864781] Call Trace: [ 117.864781] ? tun_net_xmit+0x21c/0x460 [ 117.864781] kfree_skbmem+0x4e/0x60 [ 117.864782] kfree_skb+0x3a/0xa0 [ 117.864782] tun_net_xmit+0x21c/0x460 [ 117.864782] netpoll_start_xmit+0x11d/0x1b0 [ 117.864788] netpoll_send_skb_on_dev+0x1b8/0x200 [ 117.864789] __br_forward+0x1b9/0x1e0 [bridge] [ 117.864789] ? skb_clone+0x53/0xd0 [ 117.864790] ? __skb_clone+0x2e/0x120 [ 117.864790] deliver_clone+0x37/0x50 [bridge] [ 117.864790] maybe_deliver+0x89/0xc0 [bridge] [ 117.864791] br_flood+0x6c/0x130 [bridge] [ 117.864791] br_dev_xmit+0x315/0x3c0 [bridge] [ 117.864792] netpoll_start_xmit+0x11d/0x1b0 [ 117.864792] netpoll_send_skb_on_dev+0x1b8/0x200 [ 117.864792] netpoll_send_udp+0x2c6/0x3e8 [ 117.864793] write_msg+0xd9/0xf0 [netconsole] [ 117.864793] console_unlock+0x386/0x4e0 [ 117.864793] vprintk_emit+0x17e/0x280 [ 117.864794] vprintk_default+0x29/0x50 [ 117.864794] vprintk_func+0x4c/0xbc [ 117.864794] printk+0x58/0x6f [ 117.864795] loop_fun+0x24/0x41 [printmsg_loop] [ 117.864795] kthread+0x104/0x140 [ 117.864795] ? 0xffffffffc05b1000 [ 117.864796] ? kthread_park+0x80/0x80 [ 117.864796] ret_from_fork+0x35/0x40 Signed-off-by: Feng Sun Signed-off-by: Xiaojun Zhao Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- net/core/netpoll.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) --- a/net/core/netpoll.c +++ b/net/core/netpoll.c @@ -122,7 +122,7 @@ static void queue_process(struct work_st txq = netdev_get_tx_queue(dev, q_index); HARD_TX_LOCK(dev, txq, smp_processor_id()); if (netif_xmit_frozen_or_stopped(txq) || - netpoll_start_xmit(skb, dev, txq) != NETDEV_TX_OK) { + !dev_xmit_complete(netpoll_start_xmit(skb, dev, txq))) { skb_queue_head(&npinfo->txq, skb); HARD_TX_UNLOCK(dev, txq); local_irq_restore(flags); @@ -335,7 +335,7 @@ void netpoll_send_skb_on_dev(struct netp HARD_TX_UNLOCK(dev, txq); - if (status == NETDEV_TX_OK) + if (dev_xmit_complete(status)) break; } @@ -352,7 +352,7 @@ void netpoll_send_skb_on_dev(struct netp } - if (status != NETDEV_TX_OK) { + if (!dev_xmit_complete(status)) { skb_queue_tail(&npinfo->txq, skb); schedule_delayed_work(&npinfo->tx_work,0); }