Received: by 2002:a05:6358:5282:b0:b5:90e7:25cb with SMTP id g2csp3470460rwa; Tue, 23 Aug 2022 05:25:02 -0700 (PDT) X-Google-Smtp-Source: AA6agR7tvI4sPnweofskK8Z9ltux89iE3m7GYqawjPUab6BIW1LgX9BnZKaf+HcyND7xp0C0I6Q4 X-Received: by 2002:a05:6402:4389:b0:446:f7f0:adfb with SMTP id o9-20020a056402438900b00446f7f0adfbmr3514468edc.245.1661257501807; Tue, 23 Aug 2022 05:25:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661257501; cv=none; d=google.com; s=arc-20160816; b=edpQd3gusD9z2lRCYIh2fiosDXt5d6j1nOMGQdDjlpMw6RRAQ/HN/Zy53nHIxd/cVe 0D6bqJzdjDBF5bmv3F78d+ww0qQQpH6paGPkgd2BBnqo0xivQDQSs9B0GpIoYvfrbe/4 JSBqUpGTnVbK/4UFtD05gswLaXN1Y6U/a+MC7gx+LO2GsRfzWtPgsV3D1LINduMCzj0b TLw4IVL6o+mzVGircGwx04AsVMze/wlPKzfg12Ug8b7deLHhEwur1ZEk4RGcyocuWuvP y2WGXGLoGmLOl17Q55njl3ClkLm8r74z0m/Zi3ZATyYVhh6uLaCmi84/W18XDs+8vfw1 tBmg== 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=mjcfrFuhdZacezLISyLiBCvVirSYEbW7blA5tADbaY4=; b=lduGksFaJ+5/A+YP1w7YlRw2/7OHJ07/GKUpuTGXxXTKtp5vp/z9n+BR7wvfxIqabb Dii+WPwqN46PJqQPa+KY3FEpsj2QzMZgXZdOQ81aqQp2fj1lNGSc55CVOC4lq1LiCrLw hTRrPqRyPaw3Jd5IxCN5STCUVbDr2amqV76HZ66IvS2+spHThGynUOFSg+pgvvS3cQql ANkfJUZY4OVsHBHE1fzVgmK4gXuWUG5W9ubJS96Z2ClRHg7k9ZxpXJRH7tPNQhDH9BJX lMQ0mawLUZk28VsLq42579BuHH8YIUeEx77O+MS05Faq8GsOJusLFw+qqeiRPeLITyqJ FWbQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=pSuosgHa; 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 y25-20020aa7ce99000000b0043ba23f56a6si1743337edv.200.2022.08.23.05.24.36; Tue, 23 Aug 2022 05:25:01 -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=pSuosgHa; 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 S1352793AbiHWKIz (ORCPT + 99 others); Tue, 23 Aug 2022 06:08:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45054 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352608AbiHWKCM (ORCPT ); Tue, 23 Aug 2022 06:02:12 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DD3A8481E5; Tue, 23 Aug 2022 01:50:12 -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 3892DB81BF8; Tue, 23 Aug 2022 08:50:11 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6E49CC433C1; Tue, 23 Aug 2022 08:50:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1661244609; bh=aBpW8P6JAzg18R0ex/FMrFPmZRwmlbCx0SvikDrfELc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pSuosgHa4tngWMaHWBjNnp/QMZ92ygjD/r8O+PSB25eWEjDZK75lxthvd0ibOF1VM MTSmFQSao6MJyoVY23ZEew4wDZHNWMXGWLcmLJVhHlQbagf5PrIlVqi6YqKZtQamD8 etq5DxsS+EXU77ElmbIgH/ZnPVRJu+7bN+2OnKmM= 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 4.14 164/229] net_sched: cls_route: remove from list when handle is 0 Date: Tue, 23 Aug 2022 10:25:25 +0200 Message-Id: <20220823080059.527782547@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220823080053.202747790@linuxfoundation.org> References: <20220823080053.202747790@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 @@ -531,7 +531,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]);