Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp1861886rwb; Fri, 19 Aug 2022 10:36:43 -0700 (PDT) X-Google-Smtp-Source: AA6agR7OEQ8adea0bDlJaK4e6cvd3bl06cESQ6bSQy95BLdEhkoOiFLrQLfx8vUUtE7DVnMAiG8F X-Received: by 2002:a63:6a84:0:b0:42a:3375:8fea with SMTP id f126-20020a636a84000000b0042a33758feamr4731552pgc.298.1660930602973; Fri, 19 Aug 2022 10:36:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660930602; cv=none; d=google.com; s=arc-20160816; b=1HwWACuygh61AJqAVtMjuX8OMRXLhQwczHNQl/Gy9kqVSWQ1ttryJbeFPx7hIYyAZm AuF/2+2E0LvGhSlWE6ZSHyTyKtmSzA/RiK4eJNIgm4+AWa5D47MvKwui6vEO9g7mmTY0 nqoVm5iZQBcwVy662LSSbyDPAsYeqpN5ckivDQsXUL8B2MaBebL7On9Gr1lLGYAfLG2E g8NlYHKz7lgdKJMLwe4nBUsk0fELBpOnDB2HbT2fCeq4asW1B774pQq7vLHQQIAbM3C8 Na0hq9nFUS1UgvSwWMno9+j8QYHIGpUIorHdVvjMngM8qN/y3s/MEcmL+/l/eDrRrhS7 SZlQ== 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=SXu/70/3r62LopkQzTV6hcPtXbypHPKT9nRA8O2+GjI=; b=IJPPxavihJ0YRrb8AWBpzVq2nUUJVodWo0Wb74/em4sX+xrzWFcfQmckNB0NBE7TOV FE3FHxdSloOodXk3zowmV2BX/yKRuaRZpH4tB6HFiMnN0fRDWt9PdMbrEzrTZP0Ogmkm JEvTPeneZ0bjWD3kty7FrdVIoOWJmEvUS6Mar3+dtUUkpEG27me+BDQ7IyHPWlci+2Kh vqQoK8rxO9eNB/hb3UZuP7XqMTj4XaXG3hDOGfcLYZS0vOfQmmeJxnBT1jcFQBfJEZ06 7sKSJh53IGnE2DWlFPSuohCsk/MSc5KMaKei9gC5j5eq9WkbtLzGWFcbDMu9qbYdcLNf cRsg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=MZJjOq9G; 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 dw24-20020a056a00369800b0053606bf05d0si2646262pfb.0.2022.08.19.10.36.32; Fri, 19 Aug 2022 10:36:42 -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=MZJjOq9G; 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 S1349582AbiHSPkz (ORCPT + 99 others); Fri, 19 Aug 2022 11:40:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37762 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349993AbiHSPki (ORCPT ); Fri, 19 Aug 2022 11:40:38 -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 5C781E869C; Fri, 19 Aug 2022 08:40:33 -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 C87D9B8277D; Fri, 19 Aug 2022 15:40:30 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 349B4C433D6; Fri, 19 Aug 2022 15:40:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660923629; bh=QXKbbD2rBMM2SVJ7jtAh4BSriiVTIwVcRFRHymGJ04g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MZJjOq9Gd1Gkw7aemgJQczCtnNGV7QWMTgDc9pOkyH97SCEJ+3uOEupmJjtWnKptB vPGJHevncZ9HHVnR4BAbBonnLkt44ksUuCeOgum5MF0YbxI6awRkIBxCwIxAClIpiE Sl5hMSJ4M6hOda4vV0eolJRNBbtZJm7jiA9S7AC8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jamal Hadi Salim , Stephen Hemminger , "David S. Miller" Subject: [PATCH 5.18 2/6] net_sched: cls_route: disallow handle of 0 Date: Fri, 19 Aug 2022 17:40:14 +0200 Message-Id: <20220819153710.530694228@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220819153710.430046927@linuxfoundation.org> References: <20220819153710.430046927@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: Jamal Hadi Salim commit 02799571714dc5dd6948824b9d080b44a295f695 upstream. Follows up on: https://lore.kernel.org/all/20220809170518.164662-1-cascardo@canonical.com/ handle of 0 implies from/to of universe realm which is not very sensible. Lets see what this patch will do: $sudo tc qdisc add dev $DEV root handle 1:0 prio //lets manufacture a way to insert handle of 0 $sudo tc filter add dev $DEV parent 1:0 protocol ip prio 100 \ route to 0 from 0 classid 1:10 action ok //gets rejected... Error: handle of 0 is not valid. We have an error talking to the kernel, -1 //lets create a legit entry.. sudo tc filter add dev $DEV parent 1:0 protocol ip prio 100 route from 10 \ classid 1:10 action ok //what did the kernel insert? $sudo tc filter ls dev $DEV parent 1:0 filter protocol ip pref 100 route chain 0 filter protocol ip pref 100 route chain 0 fh 0x000a8000 flowid 1:10 from 10 action order 1: gact action pass random type none pass val 0 index 1 ref 1 bind 1 //Lets try to replace that legit entry with a handle of 0 $ sudo tc filter replace dev $DEV parent 1:0 protocol ip prio 100 \ handle 0x000a8000 route to 0 from 0 classid 1:10 action drop Error: Replacing with handle of 0 is invalid. We have an error talking to the kernel, -1 And last, lets run Cascardo's POC: $ ./poc 0 0 -22 -22 -22 Signed-off-by: Jamal Hadi Salim Acked-by: Stephen Hemminger Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- net/sched/cls_route.c | 10 ++++++++++ 1 file changed, 10 insertions(+) --- a/net/sched/cls_route.c +++ b/net/sched/cls_route.c @@ -424,6 +424,11 @@ static int route4_set_parms(struct net * return -EINVAL; } + if (!nhandle) { + NL_SET_ERR_MSG(extack, "Replacing with handle of 0 is invalid"); + return -EINVAL; + } + h1 = to_hash(nhandle); b = rtnl_dereference(head->table[h1]); if (!b) { @@ -477,6 +482,11 @@ static int route4_change(struct net *net int err; bool new = true; + if (!handle) { + NL_SET_ERR_MSG(extack, "Creating with handle of 0 is invalid"); + return -EINVAL; + } + if (opt == NULL) return handle ? -EINVAL : 0;