netconsole: selftest for userdata overflow
Subsystems (4)
Breno Leitao
maintainerv2 cover netconsole: selftest for userdata overflow
Implement comprehensive testing for netconsole userdata entry handling, demonstrating correct behavior when creating maximum entries and preventing unauthorized overflow.
Refactor existing test infrastructure to support modular, reusable helper functions that validate strict entry limit enforcement.
Also, add a warning if update_userdata() sees more than MAX_USERDATA_ITEMS entries. This shouldn't happen and it is a bug that shouldn't be silently ignored.
---
Changes in v2:
- Add the new script (netcons_overflow.sh) in tools/testing/selftests/drivers/net/Makefile as suggested by Simon
Horman
- Link to v1: https://lore.kernel.org/r/[email protected]
---
Breno Leitao (4):
netconsole: Warn if MAX_USERDATA_ITEMS limit is exceeded
netconsole: selftest: Split the helpers from the selftest
netconsole: selftest: Delete all userdata keys
netconsole: selftest: verify userdata entry limit
MAINTAINERS | 3 +- drivers/net/netconsole.c | 2 +- tools/testing/selftests/drivers/net/Makefile | 1 + .../selftests/drivers/net/lib/sh/lib_netcons.sh | 225 +++++++++++++++++++++ .../testing/selftests/drivers/net/netcons_basic.sh | 218 +------------------- .../selftests/drivers/net/netcons_overflow.sh | 67 ++++++ 6 files changed, 297 insertions(+), 219 deletions(-)
---
base-commit: 94c16fd4df9089931f674fb9aaec41ea20b0fd7a
change-id: 20241204-netcons_overflow_test-eaf735d1f743
Best regards,
Signature · 1 line
Breno Leitao <[email protected]>
Breno Leitao
maintainerPATCH v2 1/4 netconsole: Warn if MAX_USERDATA_ITEMS limit is exceeded
netconsole configfs helpers doesn't allow the creation of more than MAX_USERDATA_ITEMS items.
Add a warning when netconsole userdata update function attempts sees more than MAX_USERDATA_ITEMS entries.
Replace silent ignore mechanism with WARN_ON_ONCE() to highlight potential misuse during development and debugging.
--- drivers/net/netconsole.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/netconsole.c +1 -1
@@ -730,7 +730,7 @@ static void update_userdata(struct netconsole_target *nt)struct userdatum *udm_item;struct config_item *item; -if (child_count >=MAX_USERDATA_ITEMS ) +if (WARN_ON_ONCE (child_count >=MAX_USERDATA_ITEMS ))break ; child_count++;
Signature · 1 line
2.43.5
Breno Leitao
maintainerPATCH v2 2/4 netconsole: selftest: Split the helpers from the selftest
In reply to Breno LeitaoSplit helper functions from the netconsole basic test into a separate library file to enable reuse across different netconsole tests. This change only moves the existing helper functions to lib/sh/lib_netcons.sh while preserving the same test functionality.
The helpers provide common functions for:
- Setting up network namespaces and interfaces
- Managing netconsole dynamic targets
- Setting user data
- Handling test dependencies
- Cleanup operations
Do not make any change in the code, other than the mechanical separation.
--- MAINTAINERS | 1 + .../selftests/drivers/net/lib/sh/lib_netcons.sh | 225 +++++++++++++++++++++ .../testing/selftests/drivers/net/netcons_basic.sh | 218 +------------------- 3 files changed, 227 insertions(+), 217 deletions(-)
MAINTAINERS +1 -0
@@ -16174,6 +16174,7 @@ M: Breno Leitao <[email protected]> S: Maintained F: Documentation/networking/netconsole.rst F: drivers/net/netconsole.c +F: tools/testing/selftests/drivers/net/lib/sh/lib_netcons.sh F: tools/testing/selftests/drivers/net/netcons_basic.sh NETDEVSIM
tools/testing/selftests/drivers/net/lib/sh/lib_netcons.sh new file +225 -0
225 lines not on this page · raw message
tools/testing/selftests/drivers/net/netcons_basic.sh +1 -217
225 lines not on this page · raw message
Signature · 1 line
2.43.5
Jakub Kicinski
maintainerRe: [PATCH net-next v2 2/4] netconsole: selftest: Split the helpers from the selftest
Quoted 12 lines · On Fri, 03 Jan 2025 04:57:50 -0800 Breno Leitao wrote:
Split helper functions from the netconsole basic test into a separate library file to enable reuse across different netconsole tests. This change only moves the existing helper functions to
lib/sh/lib_netcons.shwhile preserving the same test functionality.The helpers provide common functions for:
- Setting up network namespaces and interfaces
- Managing netconsole dynamic targets
- Setting user data
- Handling test dependencies
- Cleanup operations
Quoted 2 lines
Do not make any change in the code, other than the mechanical separation.
You have to update the Makefile, we don't wildcard all files under drivers/net/lib, the lib support in ksft is not great :(
$ make -C tools/testing/selftests/ \ TARGETS="drivers/net drivers/net/hw" \ install INSTALL_PATH=/tmp/ksft-net-drv [... noise ...] $ find /tmp/ksft-net-drv/ -iname '*netcons*' /tmp/ksft-net-drv/drivers/net/netcons_basic.sh /tmp/ksft-net-drv/drivers/net/netcons_overflow.sh
.. your new lib file won't get installed.
Signature · 1 line
pw-bot: cr
Breno Leitao
maintainerRe: [PATCH net-next v2 2/4] netconsole: selftest: Split the helpers from the selftest
Quoted 27 lines · Jakub Kicinski
Quoted 12 lines · On Fri, 03 Jan 2025 04:57:50 -0800 Breno Leitao wrote:
Split helper functions from the netconsole basic test into a separate library file to enable reuse across different netconsole tests. This change only moves the existing helper functions to
lib/sh/lib_netcons.shwhile preserving the same test functionality.The helpers provide common functions for:
- Setting up network namespaces and interfaces
- Managing netconsole dynamic targets
- Setting user data
- Handling test dependencies
- Cleanup operationsQuoted 2 lines
Do not make any change in the code, other than the mechanical separation.
You have to update the
Makefile, we don't wildcard all files underdrivers/net/lib, the lib support in ksft is not great :($ make -C tools/testing/selftests/ \ TARGETS="drivers/net drivers/net/hw" \ install INSTALL_PATH=/tmp/ksft-net-drv [... noise ...] $ find /tmp/ksft-net-drv/ -iname '*netcons*' /tmp/ksft-net-drv/drivers/net/netcons_basic.sh /tmp/ksft-net-drv/drivers/net/netcons_overflow.sh
Quoted 1 line
.. your new lib file won't get installed.
Thanks for the detailed explanation. I found that the new lib was not installed.
I will be adding the following to the upcoming revision.
/tools/testing/selftests/drivers/net/Makefile
@@ -1,6 +1,7 @@
# SPDX-License-Identifier: GPL-2.0
TEST_INCLUDES := $(wildcard lib/py/*.py) \
+ $(wildcard lib/sh/*.sh) \ ../../net/net_helper.sh \ ../../net/lib.sh \
Breno Leitao
maintainerPATCH v2 3/4 netconsole: selftest: Delete all userdata keys
In reply to Breno LeitaoModify the cleanup function to remove all userdata keys created during the test, instead of just deleting a single predefined key. This ensures a more thorough cleanup of temporary resources.
Move the KEY_PATH variable definition inside the set_user_data function to reduce global variables and improve encapsulation. The KEY_PATH variable is now dynamically created when setting user data.
This change has no effect on the current test, while improving an upcoming test that would create several userdata entries.
--- tools/testing/selftests/drivers/net/lib/sh/lib_netcons.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
tools/testing/selftests/drivers/net/lib/sh/lib_netcons.sh +3 -3
@@ -23,7 +23,6 @@ TARGET=$(mktemp -u netcons_XXXXX) DEFAULT_PRINTK_VALUES=$(cat /proc/sys/kernel/printk) NETCONS_CONFIGFS="/sys/kernel/config/netconsole" NETCONS_PATH="${NETCONS_CONFIGFS}"/"${TARGET}" -KEY_PATH="${NETCONS_PATH}/userdata/${USERDATA_KEY}" # NAMESPACE will be populated by setup_ns with a random value NAMESPACE=""
@@ -116,8 +115,8 @@ function cleanup() { # delete netconsole dynamic reconfiguration echo 0 > "${NETCONS_PATH}"/enabled - # Remove key - rmdir "${KEY_PATH}" + # Remove all the keys that got created during the selftest + find "${NETCONS_PATH}/userdata/" -mindepth 1 -type d -delete # Remove the configfs entry rmdir "${NETCONS_PATH}"
@@ -139,6 +138,7 @@ function set_user_data() { exit "${ksft_skip}" fi + KEY_PATH="${NETCONS_PATH}/userdata/${USERDATA_KEY}" mkdir -p "${KEY_PATH}" VALUE_PATH="${KEY_PATH}""/value" echo "${USERDATA_VALUE}" > "${VALUE_PATH}"
Signature · 1 line
2.43.5
Breno Leitao
maintainerPATCH v2 4/4 netconsole: selftest: verify userdata entry limit
In reply to Breno LeitaoAdd a new selftest for netconsole that tests the userdata entry limit functionality. The test performs two key verifications:
1. Create MAX_USERDATA_ITEMS (16) userdata entries successfully
2. Confirm that attempting to create an additional userdata entry fails
The selftest script uses the netcons library and checks the behavior by attempting to create entries beyond the maximum allowed limit.
--- MAINTAINERS | 2 +- tools/testing/selftests/drivers/net/Makefile | 1 + .../selftests/drivers/net/netcons_overflow.sh | 67 ++++++++++++++++++++++ 3 files changed, 69 insertions(+), 1 deletion(-)
MAINTAINERS +1 -1
@@ -16175,7 +16175,7 @@ S: Maintained F: Documentation/networking/netconsole.rst F: drivers/net/netconsole.c F: tools/testing/selftests/drivers/net/lib/sh/lib_netcons.sh -F: tools/testing/selftests/drivers/net/netcons_basic.sh +F: tools/testing/selftests/drivers/net/netcons\* NETDEVSIM M: Jakub Kicinski <[email protected]>
tools/testing/selftests/drivers/net/Makefile +1 -0
@@ -6,6 +6,7 @@ TEST_INCLUDES := $(wildcard lib/py/*.py) \ TEST_PROGS := \ netcons_basic.sh \ + netcons_overflow.sh \ ping.py \ queues.py \ stats.py \
tools/testing/selftests/drivers/net/netcons_overflow.sh new file +67 -0
67 lines not on this page · raw message
Signature · 1 line
2.43.5