Received: by 2002:a05:6358:5282:b0:b5:90e7:25cb with SMTP id g2csp3412854rwa; Tue, 23 Aug 2022 04:29:06 -0700 (PDT) X-Google-Smtp-Source: AA6agR5KArfvX4HfmC3IRXKaKgQjNFXwQ7je9sBXMkJX53+ztsGm3/GSp0Y51P/VeJZg4kizXBgj X-Received: by 2002:a17:902:ce81:b0:172:9ac1:6ee with SMTP id f1-20020a170902ce8100b001729ac106eemr23433850plg.93.1661254146427; Tue, 23 Aug 2022 04:29:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661254146; cv=none; d=google.com; s=arc-20160816; b=rDQ0xyMach4ZdblLBeCddEbDQYWnpV5w+Y4ahoVInxaOUFwEVQ4i/qnnVJplAO502b i6b8a+OEe7Sw16b2bnEoLBaNu+wHy7C4fycZscYbi8nIyDMXszkA5GnOGbMCclPFRi+4 jeIQ2g2ZQ6lco9vc4Itob7wIglbPqR+tJWnwf8+uIM+Hn2yHMq1L/g+f4LFNCnksx/rq ZP/EtcYeDkAAFIDgeOKaQ6mE/7SXsBWT05LJ7xK2tCaBdVRukrFHuaZ+TSX84awQbi3g sNaH2mKqMOLF6XduZyNcJ3dyCiNjOzjhzecHtu70M7lgviinFfMNyTVV8jxNH47XGW7v v67A== 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=0qrkgKbo5bN2gtsoGzxdI8st6lVc5PbYgjaZV9wFPLI=; b=QSyywws+GluLaJG/oOU+VTyukqCtcalFJVmNzybzapvNMsH9th1R/n9gC1+/hd9BRO bZbGE5iUBej4fxbtYj5jGeO9SujJdkuzmlDIuI1FYUNoPcP2MrUa/Vmxhxh96PLuqZI6 8k+cW/yCZrhlLIRqUaT9bTq7mCiamqe28Nta+iUHzMGEFyakLC+wOD41nj+Sl74+xqt1 xLhggF9at7QzzdLCwiBbwniSHgE6/q29oftmO53spstIG1dg4ZUDLg7GV7EKpSdgvb3s TTwkoOKzDuvLpWu13K89e70a7l5e6ris7m0nqW4gARTwUuu4orJYIDbYiJ4+xK3NuXvh GQGw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=b+wVhStm; 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 y20-20020a62b514000000b00535efd4c2e0si13228920pfe.61.2022.08.23.04.28.53; Tue, 23 Aug 2022 04:29:06 -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=b+wVhStm; 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 S1356913AbiHWKz7 (ORCPT + 99 others); Tue, 23 Aug 2022 06:55:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39906 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1355718AbiHWKuE (ORCPT ); Tue, 23 Aug 2022 06:50:04 -0400 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9BC2CAB1B7; Tue, 23 Aug 2022 02:12:37 -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 sin.source.kernel.org (Postfix) with ESMTPS id C7D34CE1B55; Tue, 23 Aug 2022 09:12:35 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C5587C433C1; Tue, 23 Aug 2022 09:12:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1661245954; bh=OGw3oPz10IqjYMxRUxCHGCBX+uIvqJJ1DbIfwwhwO/A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=b+wVhStmQs2VNjHr5jisZ9OTj6wB/ATG6qVTdyRib8d7bZ0BjD7WsRgXpBnam8xuW zYQegmOcxzTWdefjmzy/oSkf0DC/d4igdAuBWK2kfQqf8mqNb6UpgJ8NbTD0PJAPNm 2105++qccEhffNR3UGm+L+rvEIwI6uVJ/5btC1IU= 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 4.19 211/287] net_sched: cls_route: disallow handle of 0 Date: Tue, 23 Aug 2022 10:26:20 +0200 Message-Id: <20220823080108.037249281@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220823080100.268827165@linuxfoundation.org> References: <20220823080100.268827165@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 @@ -427,6 +427,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) { @@ -480,6 +485,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;