From patchwork Wed Apr 25 14:15:03 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Nikita V. Shirokov" X-Patchwork-Id: 904247 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=tehnerd.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=tehnerd-com.20150623.gappssmtp.com header.i=@tehnerd-com.20150623.gappssmtp.com header.b="iuqB+1OY"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 40WMfp2c01z9rxx for ; Thu, 26 Apr 2018 00:15:30 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754602AbeDYOP1 (ORCPT ); Wed, 25 Apr 2018 10:15:27 -0400 Received: from mail-pf0-f196.google.com ([209.85.192.196]:40194 "EHLO mail-pf0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754594AbeDYOPZ (ORCPT ); Wed, 25 Apr 2018 10:15:25 -0400 Received: by mail-pf0-f196.google.com with SMTP id f189so6237977pfa.7 for ; Wed, 25 Apr 2018 07:15:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tehnerd-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id; bh=nRA2EAE7MVDrBxxLMiedgNhzHPrNncYRvparoLM1DKU=; b=iuqB+1OYP+DIL8q6YlsRZvUaFooaQCClhT5ScomSSjGY/h2yrdW8VHtLJisChjA0p5 imSb1UQDeLFT39VhYzgktRF/Ps/IIHmQFPLLAMS1JC2oIUtbtVVb2+SzaRQaqxis4dbL +UPNBx8ZFVFbM28eC7Wgf8Sof1fyoi8Xx8ScL10JBElj/m8AMS/xpEqAWPnMQnJIIIq4 p9QXnA9jAVZ2y8/EUCP+FM5t6zUV1eoOExLHKvPLCm/mwokwaWUTmXXrCiUGAJr8qUSo hjljHm3UDKMUytQzoWOBAg/4RWlt4HohwP4nBi411f1yxEjXRvOk06S47qiQFRITy9Kd hd0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=nRA2EAE7MVDrBxxLMiedgNhzHPrNncYRvparoLM1DKU=; b=L89QVsDbTv4ilJ8wiu/9jawxMggBokkKSux+l6Aw5uq5213bn0jPjnqi2C5c4JkYo3 BZSF4ZWPPxMfYSUbQjiPSRLkyz74G8DxllMSbwjYFCT0HgTaWZJywnsco/Dk1qcDL/ef W22hu7FEqyY9puwdicBBDiAlU0d9fp8VgZ5ATmtfjjoBdrPt2ZCI2mRfVJR7r31h0Gbk FbEhk3fhkX/GExH7G7Lyz/fE66Lqm4lGB+EuujdMcqv+p+KcUIg6K8IBRl4Pn/LLtubu FqBY+NGcb9t2eaNZhM3RGTTdH3v7/TaMTKCBhh3b3Q4tuxwR8sPj/mKXUyNH940aDgQ5 PFjg== X-Gm-Message-State: ALQs6tBftBfV3473nO0XDEFvbt4hxMicQbHbD/Qs1WjZs9oZJsINHKEO AAjH4lZZ2TDVOmxJ0CUqKexYZ3dbqic= X-Google-Smtp-Source: AIpwx4+a/jD98jNjdPr5mCXTOUD92bLefVvkym6w5xH5OSZzHwODUaxxfcvVV3ps3qtpRukQVZHkLQ== X-Received: by 10.99.4.69 with SMTP id 66mr24405110pge.323.1524665724453; Wed, 25 Apr 2018 07:15:24 -0700 (PDT) Received: from maindev.thefacebook.com ([199.201.64.2]) by smtp.gmail.com with ESMTPSA id v1sm32928639pfg.144.2018.04.25.07.15.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 25 Apr 2018 07:15:23 -0700 (PDT) From: "Nikita V. Shirokov" To: Alexei Starovoitov , Daniel Borkmann , "David S . Miller" Cc: netdev@vger.kernel.org, "Nikita V. Shirokov" Subject: [PATCH bpf-next] bpf: fix xdp_generic for bpf_adjust_tail usecase Date: Wed, 25 Apr 2018 07:15:03 -0700 Message-Id: <20180425141503.25772-1-tehnerd@tehnerd.com> X-Mailer: git-send-email 2.15.1 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org when bpf_adjust_tail was introduced for generic xdp, it changed skb's tail pointer, so it was pointing to the new "end of the packet". however skb's len field wasn't properly modified, so on the wire ethernet frame had original (or even bigger, if adjust_head was used) size. this diff is fixing this. Fixes: 198d83bb3 (" bpf: make generic xdp compatible w/ bpf_xdp_adjust_tail") Signed-off-by: Nikita V. Shirokov --- Notes: original tests missed this because it looks like tap interface ignores incorrect ethernet FCS (all tests were done in VM) and even w/ missaligned l3 and l2 lengths, kernel still were accepting this ICMP packet output was generated w/ bpf_adjust_tail prog from samples before this fix (see lengths field of the ethernet layer): tehnerd@maindev:~$ sudo tcpdump -ni tap0 icmp -vvv -eee tcpdump: listening on tap0, link-type EN10MB (Ethernet), capture size 262144 bytes 06:38:15.546782 52:54:00:12:34:57 > 12:0e:a3:cc:78:b8, ethertype IPv4 (0x0800), length 1454: (tos 0x0, ttl 64, id 0, offset 0, flags [none], proto ICMP (1), length 112) 172.16.0.2 > 172.16.0.1: ICMP 172.16.0.2 unreachable - need to frag (mtu 586), length 92 (tos 0x0, ttl 64, id 48021, offset 0, flags [DF], proto TCP (6), length 1412) 172.16.0.1.50916 > 172.16.0.2.22: Flags [P.], seq 427401155:427402515, ack 3567613893, win 229, options [nop,nop,TS val 1287434011 ecr 2176566223], length 1360 after: tehnerd@maindev:~$ sudo tcpdump -ni tap0 icmp -vvv -eee tcpdump: listening on tap0, link-type EN10MB (Ethernet), capture size 262144 bytes 06:47:37.226843 52:54:00:12:34:57 > 32:45:9f:69:35:ba, ethertype IPv4 (0x0800), length 126: (tos 0x0, ttl 64, id 0, offset 0, flags [none], proto ICMP (1), length 112) 172.16.0.2 > 172.16.0.1: ICMP 172.16.0.2 unreachable - need to frag (mtu 586), length 92 (tos 0x0, ttl 64, id 29964, offset 0, flags [DF], proto TCP (6), length 1412) 172.16.0.1.50918 > 172.16.0.2.22: Flags [P.], seq 14171614:14172974, ack 1433043471, win 229, options [nop,nop,TS val 1287995744 ecr 3312743811], length 1360 net/core/dev.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/net/core/dev.c b/net/core/dev.c index c624a04dad1f..8f8931b93140 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -4057,8 +4057,10 @@ static u32 netif_receive_generic_xdp(struct sk_buff *skb, * pckt. */ off = orig_data_end - xdp.data_end; - if (off != 0) + if (off != 0) { skb_set_tail_pointer(skb, xdp.data_end - xdp.data); + skb->len -= off; + } switch (act) { case XDP_REDIRECT: