Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp3390494pxb; Tue, 19 Apr 2022 01:06:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwDve53pA+jM/e8I1xFqyF1EVdX8rXBXsFip/6YK1xafKSsltTOTe2nRrsYRb3LFeRIIXaU X-Received: by 2002:a17:90a:380f:b0:1bd:4aa6:651 with SMTP id w15-20020a17090a380f00b001bd4aa60651mr17159535pjb.83.1650355584787; Tue, 19 Apr 2022 01:06:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650355584; cv=none; d=google.com; s=arc-20160816; b=lMkTTh9tLGbpsIOBKbhNs7jkoKIdAXFGnCGA8nqU+82WLuaUIiDh8OGBzo8cxJzwMv DJmNXrxeP3pXiMBZzeJ65wpy6ajoYdIKGBdQK3q7kFRII5CoUks+VvPW5WNzzzlYa0PV xn2d+7cZGOJYZ9hUq2vQhzVyt4FnG5cLvo0ox2AXPN34SGZknDAcXxhoSzDPB6FqLCoI TPvdv8hmNit1pmhEuBL/d81r5BENB3gTHuKp1ujPysNfzZxUD7+ESSj3uRCfvGDqGmNf d+vdykoJd53bvsWjNeBYOn9L5inD1nv8wdixVy7gHHGiYrX3w1CyZmHc05vnR48zM2t3 n+aw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=2/WeKi8Zizym6/MMABvVjHGkG6GTSqZ07Up3P18p7F4=; b=NWmw2XtRJkZNYWtr4DD6RFOAtOnRtLabCSNF+sS1GDw2JUBoACUad8rmrq6Yy36Fkz k0Go8/GqO3kMGWIwMwQ4aNfvEFFIZk3pXGEFx5VCTQ6ynPYSDo07YmVe1nKWCsmIjUsB bWgiY94C4Wwz4Uo8mIKvyRrY5DKuGQXAsUf5NxjncVXBRatNwJi3RYCzTIGcB1NAFs4N 6tpgABP+wQy0F3yRBIAtCce6JWj9xG8sYLZ+dybH/y57ktPEHzmwRJI5rd2VID4VsQl+ Z+so4Ufhp2UeMr/nUW13EJpnQUJm/Q+oX3bXBSkTYOp4/q4Yht+85KfUL5tZ/Wg3T8xE U+FQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=O0ctSg5T; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z22-20020a63c056000000b003aa0077f0e7si4631284pgi.83.2022.04.19.01.06.09; Tue, 19 Apr 2022 01:06:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=O0ctSg5T; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238628AbiDRMZY (ORCPT + 99 others); Mon, 18 Apr 2022 08:25:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49302 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238398AbiDRMXV (ORCPT ); Mon, 18 Apr 2022 08:23:21 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D659A1B797; Mon, 18 Apr 2022 05:18:53 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 7C47CB80EDA; Mon, 18 Apr 2022 12:18:52 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C85AFC385AB; Mon, 18 Apr 2022 12:18:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1650284331; bh=qChVbIlFtuidMZRuxLHN8CXCO/NsypRaqy9iBBV8y0w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=O0ctSg5TEwWBS1hw/465mEUH7r9KRlwM74CzYaTHTXvttGYs5spkOuPsHIF3yKGSc CxH2IRTnhWWO00ZhT6/ZuJw234dxGdvAg+2Wn80QDiPiH6tyaMuoEMK2RpqpQuEJ0H 97HJ3095JbVj5VAkk7+80LivKBiW1ZkSS8AJUoGI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Marcelo Ricardo Leitner , Vlad Buslov , Davide Caratti , Jakub Kicinski , Sasha Levin Subject: [PATCH 5.17 077/219] net/sched: fix initialization order when updating chain 0 head Date: Mon, 18 Apr 2022 14:10:46 +0200 Message-Id: <20220418121208.242608101@linuxfoundation.org> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220418121203.462784814@linuxfoundation.org> References: <20220418121203.462784814@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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 From: Marcelo Ricardo Leitner [ Upstream commit e65812fd22eba32f11abe28cb377cbd64cfb1ba0 ] Currently, when inserting a new filter that needs to sit at the head of chain 0, it will first update the heads pointer on all devices using the (shared) block, and only then complete the initialization of the new element so that it has a "next" element. This can lead to a situation that the chain 0 head is propagated to another CPU before the "next" initialization is done. When this race condition is triggered, packets being matched on that CPU will simply miss all other filters, and will flow through the stack as if there were no other filters installed. If the system is using OVS + TC, such packets will get handled by vswitchd via upcall, which results in much higher latency and reordering. For other applications it may result in packet drops. This is reproducible with a tc only setup, but it varies from system to system. It could be reproduced with a shared block amongst 10 veth tunnels, and an ingress filter mirroring packets to another veth. That's because using the last added veth tunnel to the shared block to do the actual traffic, it makes the race window bigger and easier to trigger. The fix is rather simple, to just initialize the next pointer of the new filter instance (tp) before propagating the head change. The fixes tag is pointing to the original code though this issue should only be observed when using it unlocked. Fixes: 2190d1d0944f ("net: sched: introduce helpers to work with filter chains") Signed-off-by: Marcelo Ricardo Leitner Signed-off-by: Vlad Buslov Reviewed-by: Davide Caratti Link: https://lore.kernel.org/r/b97d5f4eaffeeb9d058155bcab63347527261abf.1649341369.git.marcelo.leitner@gmail.com Signed-off-by: Jakub Kicinski Signed-off-by: Sasha Levin --- net/sched/cls_api.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/sched/cls_api.c b/net/sched/cls_api.c index 5ce1208a6ea3..130b5fda9c51 100644 --- a/net/sched/cls_api.c +++ b/net/sched/cls_api.c @@ -1653,10 +1653,10 @@ static int tcf_chain_tp_insert(struct tcf_chain *chain, if (chain->flushing) return -EAGAIN; + RCU_INIT_POINTER(tp->next, tcf_chain_tp_prev(chain, chain_info)); if (*chain_info->pprev == chain->filter_chain) tcf_chain0_head_change(chain, tp); tcf_proto_get(tp); - RCU_INIT_POINTER(tp->next, tcf_chain_tp_prev(chain, chain_info)); rcu_assign_pointer(*chain_info->pprev, tp); return 0; -- 2.35.1