netconsole: selftest for userdata overflow
Subsystems (4)
Breno Leitao
maintainerv3 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 v3:
- Added the new shell helpers files in the TEST_INCLUDES (Jakub)
- Link to v2: https://lore.kernel.org/r/[email protected]
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 | 2 + .../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, 298 insertions(+), 219 deletions(-)
---
base-commit: 7bf1659bad4e9413cdba132ef9cbd0caa9cabcc4
change-id: 20241204-netcons_overflow_test-eaf735d1f743
Best regards,
Signature · 1 line
Breno Leitao <[email protected]>
Breno Leitao
maintainerPATCH v3 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 v3 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 + tools/testing/selftests/drivers/net/Makefile | 1 + .../selftests/drivers/net/lib/sh/lib_netcons.sh | 225 +++++++++++++++++++++ .../testing/selftests/drivers/net/netcons_basic.sh | 218 +------------------- 4 files changed, 228 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/Makefile +1 -0
@@ -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 \
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
Breno Leitao
maintainerPATCH v3 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 v3 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
@@ -7,6 +7,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
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Quoted 8 lines · On Wed, 08 Jan 2025 03:50:24 -0800 you wrote:
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.
[...]
Here is the summary with links:
- [net-next,v3,1/4] netconsole: Warn if MAX_USERDATA_ITEMS limit is exceeded
https://git.kernel.org/netdev/net-next/c/e51c7478d23b - [net-next,v3,2/4] netconsole: selftest: Split the helpers from the selftest https://git.kernel.org/netdev/net-next/c/61f51cc6defe - [net-next,v3,3/4] netconsole: selftest: Delete all userdata keys https://git.kernel.org/netdev/net-next/c/7dcb65351b30 - [net-next,v3,4/4] netconsole: selftest: verify userdata entry limit https://git.kernel.org/netdev/net-next/c/daea6d23cd2f
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html