Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp934782pxb; Fri, 22 Apr 2022 14:45:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwhMtd8/gr112N+twv4FKfnUHfc+hOk4faovvEWyD3flqpj4LagPy03UANPxbtnJ5CFib9o X-Received: by 2002:a17:902:8a95:b0:156:a40a:71e5 with SMTP id p21-20020a1709028a9500b00156a40a71e5mr6613773plo.144.1650663900703; Fri, 22 Apr 2022 14:45:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650663900; cv=none; d=google.com; s=arc-20160816; b=KYX7WdSQCaFHlVxSObMg/A2+Dcgzrucj1rYPpC80g7warEpg+1t8f8BU+Tvo32PA+8 MXT2cwEnxS8ozbJLQIGFAg5E3j1RMi3/htKGmpit3jURZyVtj5PqA16c3eD9GQv9Xd7v tr+m6HBYyFe0fePMjE9L/xbgtc1op+JX+G30FVlNkLQ6u/yu1FUF+Zh3LOx8okq+TsGN /0DORDCU7RK8qL6Hd7O8OJMF4782AfNKAAPiX8WwuatTFWgQIYgNK5ww8+0GWojF4WWb gJIWNxbXPMsgbvCXfSWFlFbmcmlIMpq4QpECq/iQcGuRxsdjHsxeh7zH05XtTnNjfJSh OBqA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=M6cSf3rWybJaak8I5ckt3kVwPSyC+Ht3yWyW9Q792IM=; b=XiZe9lCN+dO7N3rjdoe4VLzRtUTd8IA5YMDtD3e2J5zZ/gBlDR1fIHkrsr9ChGmPLV I6yzbrp6LgnzzhrlSQA85MZw/8wbHQI8lBn7CcFoe4c2RRwInEY3y/Cj64skAJRmCyq8 oZczqAQNFkoihfVnauCc0LHoAwGe8J5aKKpkifEMyHlxUX5bjD4fu7VaM/SPYRy4k1cT kUnx5NxbA+8EAx+qFTlq7yClEC3zOAEEMDJGGTQIU0lp0BkVMOIxNap1uOdEeSIvmO6G WYFUE8Dg2j/qtsy8/7Atk66b/IZO0NIdQ0moEMvfsAeAoS0mWutZ7XWAAF8byzDfBXyP KZhQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=Sm8c4eAf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id lw14-20020a17090b180e00b001c66f2284b7si10422806pjb.49.2022.04.22.14.45.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Apr 2022 14:45:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=Sm8c4eAf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id C2EE5329F0A; Fri, 22 Apr 2022 12:52:58 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234101AbiDVQin (ORCPT + 99 others); Fri, 22 Apr 2022 12:38:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39616 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1392046AbiDVQik (ORCPT ); Fri, 22 Apr 2022 12:38:40 -0400 Received: from mail-lj1-x233.google.com (mail-lj1-x233.google.com [IPv6:2a00:1450:4864:20::233]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CEB535EBC9; Fri, 22 Apr 2022 09:35:46 -0700 (PDT) Received: by mail-lj1-x233.google.com with SMTP id c15so10284306ljr.9; Fri, 22 Apr 2022 09:35:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=M6cSf3rWybJaak8I5ckt3kVwPSyC+Ht3yWyW9Q792IM=; b=Sm8c4eAfIv0o+xf2IQZ0xOiTa9eR8RMQ6Y0jLcIPkfwWor0+zgK1lo6zGL5+1zmOjN u2WZSv0zsvOBABGm+SUxMcV7GiPA9e3WokAhnPL5oT97HV1sQwZWd/WLMu+cVYMTyO2r 8E6SPzLiXvxZQ4N18DxT6ZKVrnvowato2uy+3oXOMPXdgmIXkfQF61ji72EJLRb+5oX0 FTBwJBsbksmwTfF6Uk1sM98K6ehfdc3yC0672vZgSbHhRrl5+LopOZgZSEq2R+uv4BQp 67ntIlf0zy8UJYpjIbJqXEp6VyxkMN/H6j8Ig1KpBHevTNCX8gNpZF5LAo7WV3hUhTNv yz8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=M6cSf3rWybJaak8I5ckt3kVwPSyC+Ht3yWyW9Q792IM=; b=bWa2f6YL7BNMd+NntnTJzAuaJP9+fUUfvaAhI8VT9CbjJ369/fC/RhIbwRz5Dgossc Kl2L0InAxS+b7l55d8N1d7BvTwzM/VrOA17yjcqP9lp/F0TxYuXfnsFxc0GBc8NDJwnn GHX0QWkt5mZZRXnt0Dl7Au6KA5H8zJhwq0SwyLhoNAmf9AX1JUcIlzaF6n1SPVVmiTrn tHHhvoZ1H7ZWReZGVljeDlE/S6rOyY3tkvSFqcoDsJ/LaCL/2rvJCC74KvWmr3HYfhib SjjAc11I1LzehpUsy4K7W3QAykVRWK+H3jLgN68PsoQsiauQCRxUloUZpqvht78rZC9p I58g== X-Gm-Message-State: AOAM531tV3rysBlbj72iov6IImB6YoomHVEWxlpOdQ5VgnD6+XILT6pw sGaQXPfIBraqX8GDJK3swaoxCLCcNPaqHTE1nPXVae7sKr8= X-Received: by 2002:a2e:894e:0:b0:24d:bc0f:2238 with SMTP id b14-20020a2e894e000000b0024dbc0f2238mr3247631ljk.509.1650645344918; Fri, 22 Apr 2022 09:35:44 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: William Tu Date: Fri, 22 Apr 2022 09:35:08 -0700 Message-ID: Subject: Re: [PATCH net 3/3] ip_gre, ip6_gre: Fix race condition on o_seqno in collect_md mode To: Peilin Ye Cc: "David S. Miller" , Jakub Kicinski , Hideaki YOSHIFUJI , David Ahern , Paolo Abeni , Peilin Ye , "xeb@mail.ru" , Daniel Borkmann , Cong Wang , Eric Dumazet , Alexei Starovoitov , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Linux Kernel Network Developers , bpf , LKML Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Apr 21, 2022 at 3:09 PM Peilin Ye wrote: > > From: Peilin Ye > > As pointed out by Jakub Kicinski, currently using TUNNEL_SEQ in > collect_md mode is racy for [IP6]GRE[TAP] devices. Consider the > following sequence of events: > > 1. An [IP6]GRE[TAP] device is created in collect_md mode using "ip link > add ... external". "ip" ignores "[o]seq" if "external" is specified, > so TUNNEL_SEQ is off, and the device is marked as NETIF_F_LLTX (i.e. > it uses lockless TX); > 2. Someone sets TUNNEL_SEQ on outgoing skb's, using e.g. > bpf_skb_set_tunnel_key() in an eBPF program attached to this device; > 3. gre_fb_xmit() or __gre6_xmit() processes these skb's: > > gre_build_header(skb, tun_hlen, > flags, protocol, > tunnel_id_to_key32(tun_info->key.tun_id), > (flags & TUNNEL_SEQ) ? htonl(tunnel->o_seqno++) > : 0); ^^^^^^^^^^^^^^^^^ > > Since we are not using the TX lock (&txq->_xmit_lock), multiple CPUs may > try to do this tunnel->o_seqno++ in parallel, which is racy. Fix it by > making o_seqno atomic_t. > > As mentioned by Eric Dumazet in commit b790e01aee74 ("ip_gre: lockless > xmit"), making o_seqno atomic_t increases "chance for packets being out > of order at receiver" when NETIF_F_LLTX is on. > > Maybe a better fix would be: > > 1. Do not ignore "oseq" in external mode. Users MUST specify "oseq" if > they want the kernel to allow sequencing of outgoing packets; > 2. Reject all outgoing TUNNEL_SEQ packets if the device was not created > with "oseq". > > Unfortunately, that would break userspace. > > We could now make [IP6]GRE[TAP] devices always NETIF_F_LLTX, but let us > do it in separate patches to keep this fix minimal. > > Suggested-by: Jakub Kicinski > Fixes: 77a5196a804e ("gre: add sequence number for collect md mode.") > Signed-off-by: Peilin Ye > --- LGTM Acked-by: William Tu