Skip to contentSkip to conversation

netconsole: selftest for userdata overflow

PATCH Applied Breno Leitao 2 participants 6 messages Jan 8, 2025 – Jan 10, 2025

Subsystems (4)
lore
Share & tools
lore

Breno Leitao

author maintainer
#0 lore raw

v3 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]>
author maintainer
#1 lore raw

PATCH 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
index f422a2f666ef2276cf5b10e1dbc6badbc8ef0038..86ab4a42769a49eebe5dd6f01dafafc6c86ec54f 100644
@@ -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
author maintainer
#2 lore raw

PATCH v3 2/4 netconsole: selftest: Split the helpers from the selftest

In reply to Breno Leitao

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.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
index a685c551faf089f862b5b8e96e3aeab05be97a40..d3cd4b7e48652b7a56873b840fd2ed6e12791008 100644
@@ -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
index 0fec8f9801ad4d94d99ab6d0acaea6e2e7b2894d..dafff5d7fe88c82a1d27aa49faca728b52435ebc 100644
@@ -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
author maintainer
#3 lore raw

PATCH v3 3/4 netconsole: selftest: Delete all userdata keys

In reply to Breno Leitao

Modify 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
index fdd45a3468f17449eeb66d9a808b7a3b2107e47c..3acaba41ac7b21aa2fd8457ed640a5ac8a41bc12 100644
@@ -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
author maintainer
#4 lore raw

PATCH v3 4/4 netconsole: selftest: verify userdata entry limit

In reply to Breno Leitao

Add 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
index d3cd4b7e48652b7a56873b840fd2ed6e12791008..44b560e3470ad612b60c7bf002152311bb419c72 100644
@@ -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
index dafff5d7fe88c82a1d27aa49faca728b52435ebc..469179c18935ffcc12b979ccdc9f84e9d4082b90 100644
@@ -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
#5 lore raw
In reply to Breno Leitao
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