From nobody Fri Dec 19 06:57:08 2025 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 31813763FE; Sun, 24 Mar 2024 22:47:32 +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=1711320452; cv=none; b=AeMQXWK0q1ZM/zhZ2n9ZURMGVPrgMC/2rCgYiALQ/VaxdXlq/akOpXsK59HTlTxp5tNpf6KBWYafB+MtreqeJNT9qdzknttQ/5fCqAFHEHXEf53Jwo6Q2/h37KaP2OXdEZKhl9Bq0h1iZ8njkII4/QW15TPqjy/1Ls31SOmbGh0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711320452; c=relaxed/simple; bh=fAometgkYT+8afRTn5I8qtc/WQf0RndWwBfG1rn1ejA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=TgXRUT7hfcCsnbtefU2N0TNHGCrsx5QniS5n4YtpSZRCXwh9G9OvUaVwTZmTc/RRg9Gio3K0O+sPxo9Ls/yilXKtcjAr8H1AWEF+Bs2A+9frliJsK5nCgKWT0MCQb6NhZn0P55soPJxIHQcSX10Sw0eAzP7ol7Y0jJTrDTuIuaw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=r4Tq0mDV; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="r4Tq0mDV" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4E07CC43390; Sun, 24 Mar 2024 22:47:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711320452; bh=fAometgkYT+8afRTn5I8qtc/WQf0RndWwBfG1rn1ejA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=r4Tq0mDVX/zRiC4qigd7YnjjTjOlMcS9yOgVyhwaLjpEFFlIvtRo3Y/woIxsJ5N3S SiRBdFzEs3/8o7EHmVYT4obYxQ6vMuynqNxua0shtml/8WZHydokKAsEzj8MTy2uwW L7gl8NmfOiW+clZgzmaS/Pi4VTFdrda76YBT3f+nut8DhjykAiHCkwrs5Saxmouzal qCYd4a8suZ+xxrrTNpPUUL3qNkfyWzzrc2xdnXuoyymKaQfXlGyfuMdkfNl0bb+7p5 phpNi+oa3jk51McERZ8T7zYyLdE0Cltc/0qzpD08eAVmn5mI62rZLMN6HhN1RgNc3C VtlS3+fu7dIpg== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Aaron Conole , Simon Horman , Jakub Kicinski , Sasha Levin Subject: [PATCH 6.7 010/713] selftests: openvswitch: Add validation for the recursion test Date: Sun, 24 Mar 2024 18:35:36 -0400 Message-ID: <20240324224720.1345309-11-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240324224720.1345309-1-sashal@kernel.org> References: <20240324224720.1345309-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 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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) =3D=3D 2 ] || \ return 1 =20 + info "Checking clone depth" ERR_MSG=3D"Flow actions may not be safe on all matching packets" + PRE_TEST=3D$(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=3D$(dmesg | grep -c "${ERR_MSG}") + + if [ "$PRE_TEST" =3D=3D "$POST_TEST" ]; then + info "failed - clone depth too large" + return 1 + fi + PRE_TEST=3D$(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/t= esting/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 +=3D "pop_mpls" else: datum =3D self.get_attr(field[0]) - print_str +=3D datum.dpstr(more) + if field[0] =3D=3D "OVS_ACTION_ATTR_CLONE": + print_str +=3D "clone(" + print_str +=3D datum.dpstr(more) + print_str +=3D ")" + else: + print_str +=3D datum.dpstr(more) =20 return print_str =20 def parse(self, actstr): + totallen =3D len(actstr) while len(actstr) !=3D 0: parsed =3D False + parencount =3D 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 =3D parse_extract_field( - actstr, - "drop(", - "([0-9]+)", - lambda x: int(x, 0), - False, - None, - ) + reason =3D None + if actstr.startswith("drop("): + parencount +=3D 1 + + actstr, reason =3D 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 =3D True else: - return + actstr =3D actstr[len("drop"): ] + return (totallen - len(actstr)) =20 elif parse_starts_block(actstr, "^(\d+)", False, True): actstr, output =3D parse_extract_field( @@ -504,6 +517,7 @@ class ovsactions(nla): False, 0, ) + parencount +=3D 1 self["attrs"].append(["OVS_ACTION_ATTR_RECIRC", recircid]) parsed =3D True =20 @@ -516,12 +530,22 @@ class ovsactions(nla): =20 for flat_act in parse_flat_map: if parse_starts_block(actstr, flat_act[0], False): - actstr +=3D len(flat_act[0]) + actstr =3D actstr[len(flat_act[0]):] self["attrs"].append([flat_act[1]]) actstr =3D actstr[strspn(actstr, ", ") :] parsed =3D True =20 - if parse_starts_block(actstr, "ct(", False): + if parse_starts_block(actstr, "clone(", False): + parencount +=3D 1 + subacts =3D ovsactions() + actstr =3D actstr[len("clone("):] + parsedLen =3D subacts.parse(actstr) + lst =3D [] + self["attrs"].append(("OVS_ACTION_ATTR_CLONE", subacts)) + actstr =3D actstr[parsedLen:] + parsed =3D True + elif parse_starts_block(actstr, "ct(", False): + parencount +=3D 1 actstr =3D actstr[len("ct(") :] ctact =3D ovsactions.ctact() =20 @@ -553,6 +577,7 @@ class ovsactions(nla): natact =3D ovsactions.ctact.natattr() =20 if actstr.startswith("("): + parencount +=3D 1 t =3D None actstr =3D actstr[1:] if actstr.startswith("src"): @@ -607,15 +632,29 @@ class ovsactions(nla): actstr =3D actstr[strspn(actstr, ", ")= :] =20 ctact["attrs"].append(["OVS_CT_ATTR_NAT", natact]) - actstr =3D actstr[strspn(actstr, ",) ") :] + actstr =3D actstr[strspn(actstr, ", ") :] =20 self["attrs"].append(["OVS_ACTION_ATTR_CT", ctact]) parsed =3D True =20 - actstr =3D actstr[strspn(actstr, "), ") :] + actstr =3D actstr[strspn(actstr, ", ") :] + while parencount > 0: + parencount -=3D 1 + actstr =3D actstr[strspn(actstr, " "):] + if len(actstr) and actstr[0] !=3D ")": + raise ValueError("Action str: '%s' unbalanced" % actst= r) + actstr =3D actstr[1:] + + if len(actstr) and actstr[0] =3D=3D ")": + return (totallen - len(actstr)) + + actstr =3D actstr[strspn(actstr, ", ") :] + if not parsed: raise ValueError("Action str: '%s' not supported" % actstr) =20 + return (totallen - len(actstr)) + =20 class ovskey(nla): nla_flags =3D NLA_F_NESTED @@ -2111,6 +2150,8 @@ def main(argv): ovsflow =3D OvsFlow() ndb =3D NDB() =20 + sys.setrecursionlimit(100000) + if hasattr(args, "showdp"): found =3D False for iface in ndb.interfaces: --=20 2.43.0