public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
From: Simon Horman <horms@kernel.org>
To: tom@herbertland.com
Cc: Simon Horman <horms@kernel.org>,
	netdev@vger.kernel.org, justin.iurman@uliege.be,
	willemdebruijn.kernel@gmail.com, pabeni@redhat.com,
	willemb@google.com, davem@davemloft.net, kuba@kernel.org,
	justin.iurman@gmail.com
Subject: Re: [net-next,v9,09/10] test: Add ext_hdr.py in networking selftests
Date: Tue, 17 Mar 2026 15:24:58 +0000	[thread overview]
Message-ID: <20260317152456.1742468-3-horms@kernel.org> (raw)
In-Reply-To: <20260314175124.47010-10-tom@herbertland.com>

This is an AI-generated review of your patch. The human sending this
email has considered the AI review valid, or at least plausible.

For local reproduction steps see https://netdev-ai.bots.linux.dev/ai-local.html

Simon says: pylint also has quite a lot to say about this patch. I'm
assuming it is all minor stuff. But could you look into addressing the
issues it flags?

---
test: Add ext_hdr.py in networking selftests

This commit adds a new Python helper file that contains Extension Header
format definitions and related functions for building IPv6 extension
header chains in networking selftests.

> diff --git a/tools/testing/selftests/net/ext_hdr.py b/tools/testing/selftests/net/ext_hdr.py
> new file mode 100755
> index 000000000000..bfb7da4a7c88
> --- /dev/null
> +++ b/tools/testing/selftests/net/ext_hdr.py
> @@ -0,0 +1,385 @@
> +#!/usr/bin/env python3
> +# SPDX-License-Identifier: GPL-2.0
> +
> +# Helper functions for creating extension headers using scapy
> +
> +import ctypes
> +import shlex
> +import socket
> +import sys
> +import subprocess
> +import scapy
> +import proto_nums
> +
> +
> +# Read a sysctl
> +def sysctl_read(name):
> +    try:
> +        # shlex.split helps handle arguments correctly
> +        command = shlex.split(f"sysctl -n {name}")
> +        # Use check=True to raise an exception if the command fails
> +        result = subprocess.run(command, check=True,
> +                    capture_output=True, text=True)
> +        value = result.stdout.strip()
> +    except subprocess.CalledProcessError as ex:
> +        print(f"Error reading sysctl: {ex.stderr}")
> +    except FileNotFoundError:
> +        print("The 'sysctl' command was not found. "
> +              "Check your system's PATH.")
> +
> +    return int(value)

What happens when an exception is caught here? When either
subprocess.CalledProcessError or FileNotFoundError occurs, the exception
handlers print an error message but don't set 'value'. The function then
reaches the 'return int(value)' statement, which will raise
UnboundLocalError.

This will crash the test in several places:

tools/testing/selftests/net/ext_hdr.py:check_eh_order() uses the return:
    do_check = sysctl_read("net.ipv6.enforce_ext_hdr_order")

tools/testing/selftests/net/ext_hdr.py:make_eh_chain() uses the return:
    pair = make_full_hbh_dst_options_list(nnext_hdr, args,
        sysctl_read("net.ipv6.max_hbh_opts_number"),
        sysctl_read("net.ipv6.max_hbh_length"))

and:
    pair = make_full_hbh_dst_options_list(nnext_hdr, args,
        sysctl_read("net.ipv6.max_dst_opts_number"),
        sysctl_read("net.ipv6.max_dst_opts_length"))

Should the exception handlers return a default value or re-raise to let
callers handle it?

> +
> +# Common definitions for Destination and Hop-by-Hop options

[ ... ]

Should ext_hdr.py be added to TEST_FILES in the Makefile? The selftests
build system documentation requires that any file imported by test scripts
must be added to TEST_FILES. Without this, tests will work in the source
tree but fail after 'make install' with ModuleNotFoundError.

The file is imported at line 12 ('import proto_nums'), and appears to be
a library meant for import rather than direct execution. Both ext_hdr.py
and proto_nums.py need to be added to TEST_FILES in
tools/testing/selftests/net/Makefile.

  reply	other threads:[~2026-03-17 15:26 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-14 17:51 [PATCH net-next v9 00/10] ipv6: Address ext hdr DoS vulnerabilities Tom Herbert
2026-03-14 17:51 ` [PATCH net-next v9 01/10] ipv6: Check of max HBH or DestOp sysctl is zero and drop if it is Tom Herbert
2026-03-14 17:51 ` [PATCH net-next v9 02/10] ipv6: Cleanup IPv6 TLV definitions Tom Herbert
2026-03-14 17:51 ` [PATCH net-next v9 03/10] ipv6: Add case for IPV6_TLV_TNL_ENCAP_LIMIT in EH TLV switch Tom Herbert
2026-03-14 17:51 ` [PATCH net-next v9 04/10] ipv6: Set HBH and DestOpt limits to 2 Tom Herbert
2026-03-14 17:51 ` [PATCH net-next v9 05/10] ipv6: Document defaults for max_{dst|hbh}_opts_number sysctls Tom Herbert
2026-03-14 17:51 ` [PATCH net-next v9 06/10] ipv6: Enforce Extension Header ordering Tom Herbert
2026-03-14 17:51 ` [PATCH net-next v9 07/10] ipv6: Document enforce_ext_hdr_order sysctl Tom Herbert
2026-03-14 17:51 ` [PATCH net-next v9 08/10] test: Add proto_nums.py in networking selftests Tom Herbert
2026-03-17 15:22   ` Simon Horman
2026-03-14 17:51 ` [PATCH net-next v9 09/10] test: Add ext_hdr.py " Tom Herbert
2026-03-17 15:24   ` Simon Horman [this message]
2026-03-14 17:51 ` [PATCH net-next v9 10/10] test: Add networking selftest for eh limits Tom Herbert
2026-03-17 15:32   ` Simon Horman
2026-03-14 17:58 ` [PATCH net-next v9 00/10] ipv6: Address ext hdr DoS vulnerabilities Jakub Kicinski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260317152456.1742468-3-horms@kernel.org \
    --to=horms@kernel.org \
    --cc=davem@davemloft.net \
    --cc=justin.iurman@gmail.com \
    --cc=justin.iurman@uliege.be \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=tom@herbertland.com \
    --cc=willemb@google.com \
    --cc=willemdebruijn.kernel@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox