From patchwork Tue Nov 29 15:25:36 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 700583 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3tSnSd3gcmz9vG3 for ; Wed, 30 Nov 2016 02:26:09 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.b="HKSYLKSF"; dkim-atps=neutral Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758064AbcK2PZ4 (ORCPT ); Tue, 29 Nov 2016 10:25:56 -0500 Received: from mail-wj0-f170.google.com ([209.85.210.170]:36403 "EHLO mail-wj0-f170.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757777AbcK2PZx (ORCPT ); Tue, 29 Nov 2016 10:25:53 -0500 Received: by mail-wj0-f170.google.com with SMTP id qp4so148344648wjc.3 for ; Tue, 29 Nov 2016 07:25:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=12SyTUlXDSbQEBm4A5pp59r8uZrc9XbJL3TzVHMGXLI=; b=HKSYLKSFR1QJFXXxPjiKj9YgyE827ReXdNtKg+55CT9zbiKwNBt+UyW+BrF5sdPOff Qa0sgg7nsfCbb+l7NtJpjAXH+rjTgVx0E1iQxghG5nlNP0AUhvZwR+NSEl3MiiyquOpF JKW1CuAVXxgBNS5mm1utqYmaDpQuSWrgxk86b7Wga0RbaRgVxUoUunX0GVmeEsJpg+Se CQ7bIC0YEn92/O1+GiMZ89MSsUSLMO69hH6n7ABblKSGN3R1j616N4LL/xywCtApxIaB xcL0unhjQ9gqB4eNkZrFENHaG9wuMLt0zj1oBGMrOS0bY7PrEi7F8OO0cGuCTkZI9DTe PtTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=12SyTUlXDSbQEBm4A5pp59r8uZrc9XbJL3TzVHMGXLI=; b=m0sREe0GzeT8KLEf825DiqSdSkVIkvC5nhJDAKPu8PueikJApmYuAP4cGBILjDZj1d v3aRar/67PMtGfsHlu4L9VTMvbVcwp4dKZLenKXF/92Vz9mdhfvYuq/NNOg7BVLulPXr 8k41kIac8DpR9U443fHw80Jrlb3D6zqDaGnpnT3NQ2LHbttaG3J6ww1y3iO0htOZ63KZ k+JtI1QNPcJvLbr+BQ3JArvG7UmW0DTvySEP3ZFeyQGaSv2BCpDBu502gBbd76x903bu v+7NMk4+QHmOwXyI5oEXLqvJhIxLEYZ/QeEm7NkDVjZ1TjYfigUGwM4do2n4YhcQTNWK N+1g== X-Gm-Message-State: AKaTC02dBl2tSNE5Bj4qmIjg1zzqaPz/GwV/av2mUkvk+NLKOUQKw6VyUdHff0TIqBo9AK8E X-Received: by 10.194.158.100 with SMTP id wt4mr28978806wjb.148.1480433151535; Tue, 29 Nov 2016 07:25:51 -0800 (PST) Received: from andreyknvl0.muc.corp.google.com ([100.105.12.17]) by smtp.gmail.com with ESMTPSA id jm6sm68363516wjb.27.2016.11.29.07.25.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 29 Nov 2016 07:25:50 -0800 (PST) Received: by andreyknvl0.muc.corp.google.com (Postfix, from userid 206546) id 3CFB2180140; Tue, 29 Nov 2016 16:25:49 +0100 (CET) From: Andrey Konovalov To: Herbert Xu , "David S . Miller" , Jason Wang , Eric Dumazet , Paolo Abeni , "Michael S . Tsirkin" , Soheil Hassas Yeganeh , Markus Elfring , Mike Rapoport , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Dmitry Vyukov , Kostya Serebryany , syzkaller@googlegroups.com, Andrey Konovalov Subject: [PATCH] tun: Use netif_receive_skb instead of netif_rx Date: Tue, 29 Nov 2016 16:25:36 +0100 Message-Id: <1480433136-7922-1-git-send-email-andreyknvl@google.com> X-Mailer: git-send-email 2.8.0.rc3.226.g39d4020 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org This patch changes tun.c to call netif_receive_skb instead of netif_rx when a packet is received. The difference between the two is that netif_rx queues the packet into the backlog, and netif_receive_skb proccesses the packet in the current context. This patch is required for syzkaller [1] to collect coverage from packet receive paths, when a packet being received through tun (syzkaller collects coverage per process in the process context). A similar patch was introduced back in 2010 [2, 3], but the author found out that the patch doesn't help with the task he had in mind (for cgroups to shape network traffic based on the original process) and decided not to go further with it. The main concern back then was about possible stack exhaustion with 4K stacks, but CONFIG_4KSTACKS was removed and stacks are 8K now. [1] https://github.com/google/syzkaller [2] https://www.spinics.net/lists/netdev/thrd440.html#130570 [3] https://www.spinics.net/lists/netdev/msg130570.html Signed-off-by: Andrey Konovalov Acked-by: Eric Dumazet --- drivers/net/tun.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/net/tun.c b/drivers/net/tun.c index 8093e39..4b56e91 100644 --- a/drivers/net/tun.c +++ b/drivers/net/tun.c @@ -1304,7 +1304,9 @@ static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile, skb_probe_transport_header(skb, 0); rxhash = skb_get_hash(skb); - netif_rx_ni(skb); + local_bh_disable(); + netif_receive_skb(skb); + local_bh_enable(); stats = get_cpu_ptr(tun->pcpu_stats); u64_stats_update_begin(&stats->syncp);