Received: by 2002:ab2:2997:0:b0:1ec:cbc4:63fb with SMTP id n23csp533715lqb; Thu, 29 Feb 2024 07:54:58 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUlfIe33MSQoap2lk0MEIvNXcZk07hH0OvhVEMVO/Oz2ZxvB4JgeuXObA+H5zZgTKieUZ8BsI2plWQncSebitmT8S46m6uD5PFq6WYhMA== X-Google-Smtp-Source: AGHT+IG7jjMx1ZAA+Aj88RNpTzuRWPEvP0UTbci6zBePD/m8ORv/Rn/85vpF45rADAilpUXhP/6r X-Received: by 2002:aa7:8603:0:b0:6e5:3684:807f with SMTP id p3-20020aa78603000000b006e53684807fmr2803065pfn.6.1709222098425; Thu, 29 Feb 2024 07:54:58 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709222098; cv=pass; d=google.com; s=arc-20160816; b=cNvcMtvlxbvYqep1wU1uXN4U1h48ziSbLVTlFcj0O8rZ/Q4jjRLchxU75M1E55J87t aZEiS2MY9YBgiy5Yd1h6Udkh3qD0iEEiUqfH70saUKyysdBAbKfMlWHTowXgG6GeS07T LrvrshwmOxYoi5OalxAP78qW4g2pWGyd43b7bPxnt6nrlRaq5HLAyxRPjg33SWcFXBmc mcGTdFB0W/eZTqA4zb6n/ZYCS8LE2QTjG7nD9T4qzNXL2c/RKuFz2Xaop3IlA8h6EZb5 zjKCcLKL67h7ganX3k5iPzwKcEPYRcoRwvbDEDnurP80ViRQYC9v56Ck6LcnNjTDSBPK K4Mw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=Wd6uJA2nreEDAdhQbcBPZjgs+K4Ysic3ttqDAiTFzpg=; fh=w39zcnz1h5Vxd3h2fv1lsMiixYQqdc0wHuSKerdhac8=; b=VTw6WMcfX53q3ic3k5sc41XZ2uE3aTi2kRJMZH0iUo+IQjGQ29klKh/J3iWHAZkGdB KnAQ+gOKau09InXEL1uP2pgYlt7mJGhIXUAI6WKRoQ0pKJCMk4WkwEHyWbrJpglqm20+ xgvzApk6Z+obdBYrJdC0rLiJH84MDjyyW4P9t/c88i8JR5/CQjJ4pPLOrpyLhNmEr8EQ rvDe5CmwQtiJezvElzI2WXpRF1eGCeTEkzWXcWLeYuAjsGKRm1ENUZ3ifu6LinM49q5Z eDzWQfdO1xqzjlNSJEII5/wp7j+OhEJ3JBMb1K2rTukSfVuMGp/jbR2SgKtuf18+LwM8 /nzQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=a7iFWRAi; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-86958-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-86958-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id y19-20020a056a00191300b006e559bc3247si1531554pfi.36.2024.02.29.07.54.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Feb 2024 07:54:58 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-86958-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=a7iFWRAi; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-86958-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-86958-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id EC3CFB21AB3 for ; Thu, 29 Feb 2024 15:51:43 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0CAE6155A35; Thu, 29 Feb 2024 15:49:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="a7iFWRAi" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EC859154C08; Thu, 29 Feb 2024 15:49:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709221752; cv=none; b=MgdOQvqwhrkKJCgb+f44wBG7S4XCYGUqm93Vpk5pmEoY4/ekFDNgUgxqliB+DNTJITqBTFkoVIZToMTSXHIMl2XvF+Imkccob9Zaa14upSYGPvBvVZ8B4jPVVHJ8Pn0DJcGHhunUnP+Js6uM13NB6vaz8TOaKo4HVOYQcLCusIY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709221752; c=relaxed/simple; bh=fAometgkYT+8afRTn5I8qtc/WQf0RndWwBfG1rn1ejA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FY1zN+OSRLWg990Z4YszO2cMv74jiAtRvWwnjFLbrQoBqKS+xT3Zu9KVuFcbedCXd5tIU7FKUrlFOAPF6CoGfBywnw2Y2jGTRJd3g5QjZYNwE5uMQk0/pj2muUrgKuNl8pRvhye1oLUyFZeQ631L/skx/iFyFu1HYUZvXYkyCNA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=a7iFWRAi; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 92710C43399; Thu, 29 Feb 2024 15:49:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1709221751; bh=fAometgkYT+8afRTn5I8qtc/WQf0RndWwBfG1rn1ejA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=a7iFWRAimzL3PztuPKn2woouIj3US35MiqL8QLYkKAYunfg/kXTxhSgcArIrJQVLA x2GvLnByVxrRcFISqIT5MkXAXptzkbVgFRSAFWdAkhhgzsIWbwpXAhtjZ459vpGqQF 1Z0JTfSjZ3rw2Fc2QGie5EdQuV9jHSY8oFQO+WLWLMgdDpLgK3XZ0n3N7R6e6qGinE jalL0kr7IM6txlyiA/Jj2iHm8Xmrt2yJYTGWLWRhu5PIhx9vhvyWoVA4iwswujMnWW MNXqu7a2uAAXph8JGwVV6jvRq9KoenH19SH97DGZd4Bu9zfE8ka8pZWMgLfEBpQPt1 rRGTxhQHuxs+g== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Aaron Conole , Simon Horman , Jakub Kicinski , Sasha Levin , pshelar@ovn.org, davem@davemloft.net, edumazet@google.com, pabeni@redhat.com, shuah@kernel.org, netdev@vger.kernel.org, dev@openvswitch.org, linux-kselftest@vger.kernel.org Subject: [PATCH AUTOSEL 6.7 10/26] selftests: openvswitch: Add validation for the recursion test Date: Thu, 29 Feb 2024 10:48:29 -0500 Message-ID: <20240229154851.2849367-10-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240229154851.2849367-1-sashal@kernel.org> References: <20240229154851.2849367-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 6.7.6 Content-Transfer-Encoding: 8bit From: Aaron Conole [ Upstream commit bd128f62c365504e1268dc09fcccdfb1f091e93a ] Add a test case into the netlink checks that will show the number of nested action recursions won't exceed 16. Going to 17 on a small clone call isn't enough to exhaust the stack on (most) systems, so it should be safe to run even on systems that don't have the fix applied. Signed-off-by: Aaron Conole Reviewed-by: Simon Horman Link: https://lore.kernel.org/r/20240207132416.1488485-3-aconole@redhat.com Signed-off-by: Jakub Kicinski Signed-off-by: Sasha Levin --- .../selftests/net/openvswitch/openvswitch.sh | 13 ++++ .../selftests/net/openvswitch/ovs-dpctl.py | 71 +++++++++++++++---- 2 files changed, 69 insertions(+), 15 deletions(-) diff --git a/tools/testing/selftests/net/openvswitch/openvswitch.sh b/tools/testing/selftests/net/openvswitch/openvswitch.sh index f8499d4c87f3f..36e40256ab92a 100755 --- a/tools/testing/selftests/net/openvswitch/openvswitch.sh +++ b/tools/testing/selftests/net/openvswitch/openvswitch.sh @@ -502,7 +502,20 @@ test_netlink_checks () { wc -l) == 2 ] || \ return 1 + info "Checking clone depth" ERR_MSG="Flow actions may not be safe on all matching packets" + PRE_TEST=$(dmesg | grep -c "${ERR_MSG}") + ovs_add_flow "test_netlink_checks" nv0 \ + 'in_port(1),eth(),eth_type(0x800),ipv4()' \ + 'clone(clone(clone(clone(clone(clone(clone(clone(clone(clone(clone(clone(clone(clone(clone(clone(clone(drop)))))))))))))))))' \ + >/dev/null 2>&1 && return 1 + POST_TEST=$(dmesg | grep -c "${ERR_MSG}") + + if [ "$PRE_TEST" == "$POST_TEST" ]; then + info "failed - clone depth too large" + return 1 + fi + PRE_TEST=$(dmesg | grep -c "${ERR_MSG}") ovs_add_flow "test_netlink_checks" nv0 \ 'in_port(1),eth(),eth_type(0x0806),arp()' 'drop(0),2' \ diff --git a/tools/testing/selftests/net/openvswitch/ovs-dpctl.py b/tools/testing/selftests/net/openvswitch/ovs-dpctl.py index b97e621face95..5e0e539a323d5 100644 --- a/tools/testing/selftests/net/openvswitch/ovs-dpctl.py +++ b/tools/testing/selftests/net/openvswitch/ovs-dpctl.py @@ -299,7 +299,7 @@ class ovsactions(nla): ("OVS_ACTION_ATTR_PUSH_NSH", "none"), ("OVS_ACTION_ATTR_POP_NSH", "flag"), ("OVS_ACTION_ATTR_METER", "none"), - ("OVS_ACTION_ATTR_CLONE", "none"), + ("OVS_ACTION_ATTR_CLONE", "recursive"), ("OVS_ACTION_ATTR_CHECK_PKT_LEN", "none"), ("OVS_ACTION_ATTR_ADD_MPLS", "none"), ("OVS_ACTION_ATTR_DEC_TTL", "none"), @@ -465,29 +465,42 @@ class ovsactions(nla): print_str += "pop_mpls" else: datum = self.get_attr(field[0]) - print_str += datum.dpstr(more) + if field[0] == "OVS_ACTION_ATTR_CLONE": + print_str += "clone(" + print_str += datum.dpstr(more) + print_str += ")" + else: + print_str += datum.dpstr(more) return print_str def parse(self, actstr): + totallen = len(actstr) while len(actstr) != 0: parsed = False + parencount = 0 if actstr.startswith("drop"): # If no reason is provided, the implicit drop is used (i.e no # action). If some reason is given, an explicit action is used. - actstr, reason = parse_extract_field( - actstr, - "drop(", - "([0-9]+)", - lambda x: int(x, 0), - False, - None, - ) + reason = None + if actstr.startswith("drop("): + parencount += 1 + + actstr, reason = parse_extract_field( + actstr, + "drop(", + "([0-9]+)", + lambda x: int(x, 0), + False, + None, + ) + if reason is not None: self["attrs"].append(["OVS_ACTION_ATTR_DROP", reason]) parsed = True else: - return + actstr = actstr[len("drop"): ] + return (totallen - len(actstr)) elif parse_starts_block(actstr, "^(\d+)", False, True): actstr, output = parse_extract_field( @@ -504,6 +517,7 @@ class ovsactions(nla): False, 0, ) + parencount += 1 self["attrs"].append(["OVS_ACTION_ATTR_RECIRC", recircid]) parsed = True @@ -516,12 +530,22 @@ class ovsactions(nla): for flat_act in parse_flat_map: if parse_starts_block(actstr, flat_act[0], False): - actstr += len(flat_act[0]) + actstr = actstr[len(flat_act[0]):] self["attrs"].append([flat_act[1]]) actstr = actstr[strspn(actstr, ", ") :] parsed = True - if parse_starts_block(actstr, "ct(", False): + if parse_starts_block(actstr, "clone(", False): + parencount += 1 + subacts = ovsactions() + actstr = actstr[len("clone("):] + parsedLen = subacts.parse(actstr) + lst = [] + self["attrs"].append(("OVS_ACTION_ATTR_CLONE", subacts)) + actstr = actstr[parsedLen:] + parsed = True + elif parse_starts_block(actstr, "ct(", False): + parencount += 1 actstr = actstr[len("ct(") :] ctact = ovsactions.ctact() @@ -553,6 +577,7 @@ class ovsactions(nla): natact = ovsactions.ctact.natattr() if actstr.startswith("("): + parencount += 1 t = None actstr = actstr[1:] if actstr.startswith("src"): @@ -607,15 +632,29 @@ class ovsactions(nla): actstr = actstr[strspn(actstr, ", ") :] ctact["attrs"].append(["OVS_CT_ATTR_NAT", natact]) - actstr = actstr[strspn(actstr, ",) ") :] + actstr = actstr[strspn(actstr, ", ") :] self["attrs"].append(["OVS_ACTION_ATTR_CT", ctact]) parsed = True - actstr = actstr[strspn(actstr, "), ") :] + actstr = actstr[strspn(actstr, ", ") :] + while parencount > 0: + parencount -= 1 + actstr = actstr[strspn(actstr, " "):] + if len(actstr) and actstr[0] != ")": + raise ValueError("Action str: '%s' unbalanced" % actstr) + actstr = actstr[1:] + + if len(actstr) and actstr[0] == ")": + return (totallen - len(actstr)) + + actstr = actstr[strspn(actstr, ", ") :] + if not parsed: raise ValueError("Action str: '%s' not supported" % actstr) + return (totallen - len(actstr)) + class ovskey(nla): nla_flags = NLA_F_NESTED @@ -2111,6 +2150,8 @@ def main(argv): ovsflow = OvsFlow() ndb = NDB() + sys.setrecursionlimit(100000) + if hasattr(args, "showdp"): found = False for iface in ndb.interfaces: -- 2.43.0