Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp3113383rwb; Mon, 15 Aug 2022 18:25:53 -0700 (PDT) X-Google-Smtp-Source: AA6agR53yDsj7rsrQwPmUOoS5RuhbU7dqZXd8dQgXjpiW6X3DeNzP0apSZ08FHAjjul4QxBf1aq5 X-Received: by 2002:a17:906:93f0:b0:730:6d4e:970c with SMTP id yl16-20020a17090693f000b007306d4e970cmr12334136ejb.188.1660613153231; Mon, 15 Aug 2022 18:25:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660613153; cv=none; d=google.com; s=arc-20160816; b=ZmUdDMFsenQquJsGPfX2RYgytMPtu0Q6ZfEjslIx6F+cuY6gx005wwtPXxyibcHht0 LhyUSEvXh/5ZMKtdKKrhim25UnNlMJaTYYtB7AwI6NJK8tFI7DhUVsQnE46tzLDmEDTu RmkUiJaX7OQuA6GpjWbHt/iRfZBLVS7ul8rSwEEt4nsTXek8RyCv7EZ4mNptgpHm4grs nNLYuUGmwADqkKN7YmoTdiD593fGCl7WCrxTy/KmCqjoejEPA0eY9Tedtwtt9H7qpBsG e5mg+9nBgitYHr9yuT5h2NO8dfn4Cb5KegsxIlgQNU2UqX+wxhZZml48QA9E+THdtfNx cjUA== 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=wpovj454F5hY8CggUCN96TlqJLEz14jLT+6V66mWdXs=; b=H8km14JCfQ+089FyJxbYMKmdOqkDrJpRC1BNwhER7YYIi++4A/ro877hqIhYcWm2X0 i8XAlILi4N/QSU5EsmHLY+3G7zjejb6yeTd8h9te/JGCDX+PRFUoU3OEbRtu6UY1E2PN LvOQSx+kUqLM+dUmACqtlW39A+58gVGXmUrwmwmLlzqrZQuXnRB0LpecX22p49x6TWFB iH5ano0BRoKX7YstBbZh2Eyu7VR0Ynmhm7mMD+3sx3jcHH9Gej0fcNeTJlXM9VLNJnt4 RCgbTlqomcY0oswF9VBi8XW46Oo//k0vc6ttm/m3x9MuPA9o0YEWeniB0Ch9QBjBZfeK 4lDg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="ZL2cjTB/"; 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 qf8-20020a1709077f0800b00730412fe4d5si10996312ejc.740.2022.08.15.18.25.27; Mon, 15 Aug 2022 18:25:53 -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="ZL2cjTB/"; 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 S1344007AbiHPBIh (ORCPT + 99 others); Mon, 15 Aug 2022 21:08:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33074 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344075AbiHPBEC (ORCPT ); Mon, 15 Aug 2022 21:04:02 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 77726B9594; Mon, 15 Aug 2022 13:50:51 -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 dfw.source.kernel.org (Postfix) with ESMTPS id A4CB761291; Mon, 15 Aug 2022 20:50:23 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 961D7C433D6; Mon, 15 Aug 2022 20:50:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660596623; bh=ScgBIY3HQMCcOzB+zPgCsLe9LaGbzeQNrwHYt+biqjc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZL2cjTB/4Kel1pII9n3yPetvyLQ5UpyYZjxMgbhEm0kbOmcalyXLHoZbknUIrURSH uJeeLgmHuYiPz4J184621CAAnE8DC8ZrddyCILlDKAr/m7Z7IksslqNDDv5Br0amkS 3CulBEehXgsFlg7Pj1brHDyvJIL7OBl/KP2zPWgI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Zhenpeng Lin , Thadeu Lima de Souza Cascardo , Kamal Mostafa , Jamal Hadi Salim , Jakub Kicinski Subject: [PATCH 5.19 1138/1157] net_sched: cls_route: remove from list when handle is 0 Date: Mon, 15 Aug 2022 20:08:14 +0200 Message-Id: <20220815180525.971372875@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180439.416659447@linuxfoundation.org> References: <20220815180439.416659447@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 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: Thadeu Lima de Souza Cascardo commit 9ad36309e2719a884f946678e0296be10f0bb4c1 upstream. When a route filter is replaced and the old filter has a 0 handle, the old one won't be removed from the hashtable, while it will still be freed. The test was there since before commit 1109c00547fc ("net: sched: RCU cls_route"), when a new filter was not allocated when there was an old one. The old filter was reused and the reinserting would only be necessary if an old filter was replaced. That was still wrong for the same case where the old handle was 0. Remove the old filter from the list independently from its handle value. This fixes CVE-2022-2588, also reported as ZDI-CAN-17440. Reported-by: Zhenpeng Lin Signed-off-by: Thadeu Lima de Souza Cascardo Reviewed-by: Kamal Mostafa Cc: Acked-by: Jamal Hadi Salim Link: https://lore.kernel.org/r/20220809170518.164662-1-cascardo@canonical.com Signed-off-by: Jakub Kicinski Signed-off-by: Greg Kroah-Hartman --- net/sched/cls_route.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/net/sched/cls_route.c +++ b/net/sched/cls_route.c @@ -526,7 +526,7 @@ static int route4_change(struct net *net rcu_assign_pointer(f->next, f1); rcu_assign_pointer(*fp, f); - if (fold && fold->handle && f->handle != fold->handle) { + if (fold) { th = to_hash(fold->handle); h = from_hash(fold->handle >> 16); b = rtnl_dereference(head->table[th]);