From patchwork Mon Feb 24 09:22:34 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Seiderer X-Patchwork-Id: 13987670 Received: from mout.gmx.net (mout.gmx.net [212.227.15.15]) (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 25DA42512FD; Mon, 24 Feb 2025 09:23:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=212.227.15.15 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740388993; cv=none; b=C+Fjk2xuyyZ3FTicq0BVIfzTqbzz+YgjWY9DSc9729Q/oMwurkAdVYLGUo2c9bdpq+w/SPdMAqwrJSfNBM1DW27AVO0aT0bEGwWrlhYkkWrNQ0viuv0ixaNn7ACCcKLI9dy8eQjeaPqi3JNyiLjlXDjsgPvoS3tu4pRkeDJhwgE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740388993; c=relaxed/simple; bh=GasDPFQCK9Vo+y9Jthkc9rqHin1OvrAixg/Q3HSc+bw=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=dCpn4sj3+uiHkm/miBqkJLpQT36SISQ5Mldc2kmTJSq0I02wwICnqpCKUF3voLdA9NXxe8K5TeS+zWrckhbiL54rTvStj58Ku9FLsdA0LwvzJH8nZALBX/nA8pl6ciQgGGtlvDWRXfM+E4NOE70T/TChe6K96vkIMFLL40Jce/k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=gmx.net; spf=pass smtp.mailfrom=gmx.net; dkim=pass (2048-bit key) header.d=gmx.net header.i=ps.report@gmx.net header.b=QwkbY93Z; arc=none smtp.client-ip=212.227.15.15 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=gmx.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmx.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmx.net header.i=ps.report@gmx.net header.b="QwkbY93Z" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmx.net; s=s31663417; t=1740388970; x=1740993770; i=ps.report@gmx.net; bh=GasDPFQCK9Vo+y9Jthkc9rqHin1OvrAixg/Q3HSc+bw=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:Message-ID: MIME-Version:Content-Transfer-Encoding:cc: content-transfer-encoding:content-type:date:from:message-id: mime-version:reply-to:subject:to; b=QwkbY93ZdqtM4kafaYMxtDOlnBMIk8TRWrkGg4QUXFjls4p72Ip3jhEiDk8WCaLL /95DG39lLjAKSvkHOGAuJLbOw+JmdmnTovvBiKfcCZHaV/UiLMV2M7d0c+bYHa8PI gGS6eYkSgJq1gdPFE3qC5IXCFh48WVconZPMNMGf1wEpZhs0K7SuRez0T8p6O+TFk 0z4FqMi4hRo58TSw4eI6tkv+0rw9Q0WshepqrLW932nBwbybjL8vk36pG8YnBmQpz n326MLr7UITUswj3dfbSGMEUzoSbu3NGEYAfi1k65CnDAk5jN0yzHxuJrdXPW+Vge Pt/3XIsClkXTBeIcgw== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from localhost.fritz.box ([82.135.81.227]) by mail.gmx.net (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1N8XPn-1tI7ul2cYj-012rqN; Mon, 24 Feb 2025 10:22:50 +0100 From: Peter Seiderer To: netdev@vger.kernel.org Cc: linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Shuah Khan , Peter Seiderer , Thomas Gleixner , Artem Chernyshev , Frederic Weisbecker , Nam Cao Subject: [PATCH net-next v7 0/8] Some pktgen fixes/improvments (part II) Date: Mon, 24 Feb 2025 10:22:34 +0100 Message-ID: <20250224092242.13192-1-ps.report@gmx.net> X-Mailer: git-send-email 2.48.1 Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Provags-ID: V03:K1:nCvJSsPYjUdIChk28cLUErz5A9U0Km0CQkvCP8bwA1vPBnDhema bj1OIGmwf4qIpuWwxffqC4TtRdWfGx8BAX5LAJi06xnWMl24gNU6M/8BWL8FHqZJ05czOhx vKYQ3ke5Jw8nBCSKIK8kXQeS/xa2pQhSPZNgUJ7Bo98IoDniV9/15xO19kJuj8M+P6bp0lr UnKpqHoIaAlJiUG8UtlIg== X-Spam-Flag: NO UI-OutboundReport: notjunk:1;M01:P0:ovGPJV05NyA=;iP4pVOQjk4IBLm4V5S4PCFOAIPb 6jx4wWk3JEy6hE5NlWBLt5fMsvrdesfLULUOGDso/3GmrZZ0rpDycYwYL8GfSl2FOjTPZSBx7 tZkPFDtPk3BPlO2rbmOR9cTnqJAdVbumXqBgP2hrTjrua+e9bkKuoluD5j/tFwOp9FBaWq38I 3hTFxO+dDf/s0e4D63U5ESfBCw0+pgauy3OS5s3wfLjfrfMndurPj+3S7ufDg1auGCXsiQqYg BYVoUaAGpj4STkUVdmoBa1LNRBWzLj8vDak2zWSgC34OfhYPoSFGY5U3vX5KK1Ps1NAuHh0HQ 2KAWKNFwIkeXuCRqFHPW+cUfCkd5bGCVRN80x6apMukg57t5XqkXstLaE3d36jqNUT19cqeWK 1F8KWEnbZLyBYDfOBPBN7BT1DqUoEBZgePHwGIHHm1R0x9/u4IcM85gOn4QGXK2AHE5h/6Y78 URgjPTSleKy+6si7mt9OIjwPu4XJ/vLRkbZG8LjB442KL3+F7LNa87jeZjEtyb0mN4d9qr/DX amaP2X74uHrI9ebpWZAUkZcqLU42Q9QIxyJWImEtjqRotrfAmbzTUrM/LqHTRREqBJPGdgKIc TiksjKdjFTfLycn6FrrRdRVPcdni5g1bBRHsv66nutkFfegbAxJsvCpRNJ6c73YU5QNjTn3qK WdgQC737EivH1BzxUxsU0t5jrYSFpAiHidHR57o8r80/3EAnSMlFnuI8n1QaVxeVbGX3rA7XR i5FrzG32dEIWj2kQf6oNddKJ9FivD5vZSeVK2xfsmoCM+hgeRxAseBiBtkPKfQkECDJRP1T3s sTE0nCPCbp+AS+a/IXmPodD9Ru4JktcjJR3gv8EmGw6qR6WClkPu6Eq4hRo0hnbzy/c1Z5U5q cADtnwgOfIWrsEeoiO29KHbDT9/2YI51CQ6HTPu89G6dsEjQxF2d0TRTw1N78mx5Cv91ZrlWS e/66pRSjiNnoANM9mbH683OtXlAXXT5tZYWZOhbv8SPQGFuPCO8KOg8D07C050pVT5cx8DvXm SimojbwqzkTZf+YCM6ZWopzJZTGAyGrs6HM2+yFeLK2bahs9Gni++pnUZAhhUk8FG8R5DY9UM UVcgH5jLUkhbdcedA8WztjHbW5CxC1SBCs06XlMa5F4rpxKtV23DT8ggjKnRQbuCDIPrmPMdQ QzbF+0hx6ZtTB3etD+bpzyZPch825j9qFXR0Fhp13rVFXqw7KUs6D4fc39Fl3RMrCBQOAoVSo v2X1ZQ6YtJ0VJ2pry6RUMy6OVEYG9eQlZVGFtZCJRzrDqEe6hg60Roy7Es8zFnbzw6vlvT9T0 gep/38XAXbL3nqlynTpPEO3YcQBlMGcrVu/S85G+5pmJZjJKQAtaimVN++LxftQ8V2yvFhTiq n+JwH5QkZ4aMe/teigDThoGSBka2STFgNpOrnTtk8nJLs7bCCgrMYvSsaK X-Patchwork-Delegate: kuba@kernel.org While taking a look at '[PATCH net] pktgen: Avoid out-of-range in get_imix_entries' ([1]) and '[PATCH net v2] pktgen: Avoid out-of-bounds access in get_imix_entries' ([2], [3]) and doing some tests and code review I detected that the /proc/net/pktgen/... parsing logic does not honour the user given buffer bounds (resulting in out-of-bounds access). This can be observed e.g. by the following simple test (sometimes the old/'longer' previous value is re-read from the buffer): $ echo add_device lo@0 > /proc/net/pktgen/kpktgend_0 $ echo "min_pkt_size 12345" > /proc/net/pktgen/lo\@0 && grep min_pkt_size /proc/net/pktgen/lo\@0 Params: count 1000 min_pkt_size: 12345 max_pkt_size: 0 Result: OK: min_pkt_size=12345 $ echo -n "min_pkt_size 123" > /proc/net/pktgen/lo\@0 && grep min_pkt_size /proc/net/pktgen/lo\@0 Params: count 1000 min_pkt_size: 12345 max_pkt_size: 0 Result: OK: min_pkt_size=12345 $ echo "min_pkt_size 123" > /proc/net/pktgen/lo\@0 && grep min_pkt_size /proc/net/pktgen/lo\@0 Params: count 1000 min_pkt_size: 123 max_pkt_size: 0 Result: OK: min_pkt_size=123 So fix the out-of-bounds access (and some minor findings) and add a simple proc_net_pktgen selftest... Patch set splited into part I (now already applied to net-next) - net: pktgen: replace ENOTSUPP with EOPNOTSUPP - net: pktgen: enable 'param=value' parsing - net: pktgen: fix hex32_arg parsing for short reads - net: pktgen: fix 'rate 0' error handling (return -EINVAL) - net: pktgen: fix 'ratep 0' error handling (return -EINVAL) - net: pktgen: fix ctrl interface command parsing - net: pktgen: fix access outside of user given buffer in pktgen_thread_write() And part II (this one): - net: pktgen: use defines for the various dec/hex number parsing digits lengths - net: pktgen: fix mix of int/long - net: pktgen: remove extra tmp variable (re-use len instead) - net: pktgen: remove some superfluous variable initializing - net: pktgen: fix mpls maximum labels list parsing - net: pktgen: fix access outside of user given buffer in pktgen_if_write() - net: pktgen: fix mpls reset parsing - net: pktgen: remove all superfluous index assignements - selftest: net: add proc_net_pktgen Regards, Peter Changes v6 -> v7: - rebased on actual net-next/main - selftest: net: add proc_net_pktgen - fixed conflict in tools/testing/selftests/net/config Changes v5 -> v6: - add rev-by Simon Horman - drop patch 'net: pktgen: use defines for the various dec/hex number parsing digits lengths' - adjust to dropped patch ''net: pktgen: use defines for the various dec/hex number parsing digits lengths' - net: pktgen: fix mix of int/long - fix line break (suggested by Simon Horman) Changes v4 -> v5: - split up patchset into part i/ii (suggested by Simon Horman) - add rev-by Simon Horman - net: pktgen: align some variable declarations to the most common pattern -> net: pktgen: fix mix of int/long - instead of align to most common pattern (int) adjust all usages to size_t for i and max and ssize_t for len and adjust function signatures of hex32_arg(), count_trail_chars(), num_arg() and strn_len() accordingly - respect reverse xmas tree order for local variable declarations (where possible without too much code churn) - update subject line and patch description - dropped net: pktgen: hex32_arg/num_arg error out in case no characters are available - keep empty hex/num arg is implicit assumed as zero value - dropped net: pktgen: num_arg error out in case no valid character is parsed - keep empty hex/num arg is implicit assumed as zero value - Change patch description ('Fixes:' -> 'Addresses the following:', suggested by Simon Horman) - net: pktgen: remove all superfluous index assignements - new patch (suggested by Simon Horman) - selftest: net: add proc_net_pktgen - addapt to dropped patch 'net: pktgen: hex32_arg/num_arg error out in case no characters are available', empty hex/num arg is now implicit assumed as zero value (instead of failure) Changes v3 -> v4: - add rev-by Simon Horman - new patch 'net: pktgen: use defines for the various dec/hex number parsing digits lengths' (suggested by Simon Horman) - replace C99 comment (suggested by Paolo Abeni) - drop available characters check in strn_len() (suggested by Paolo Abeni) - factored out patch 'net: pktgen: align some variable declarations to the most common pattern' (suggested by Paolo Abeni) - factored out patch 'net: pktgen: remove extra tmp variable (re-use len instead)' (suggested by Paolo Abeni) - factored out patch 'net: pktgen: remove some superfluous variable initializing' (suggested by Paolo Abeni) - factored out patch 'net: pktgen: fix mpls maximum labels list parsing' (suggested by Paolo Abeni) - factored out 'net: pktgen: hex32_arg/num_arg error out in case no characters are available' (suggested by Paolo Abeni) - factored out 'net: pktgen: num_arg error out in case no valid character is parsed' (suggested by Paolo Abeni) Changes v2 -> v3: - new patch: 'net: pktgen: fix ctrl interface command parsing' - new patch: 'net: pktgen: fix mpls reset parsing' - tools/testing/selftests/net/proc_net_pktgen.c: - fix typo in change description ('v1 -> v1' and tyop) - rename some vars to better match usage add_loopback_0 -> thr_cmd_add_loopback_0 rm_loopback_0 -> thr_cmd_rm_loopback_0 wrong_ctrl_cmd -> wrong_thr_cmd legacy_ctrl_cmd -> legacy_thr_cmd ctrl_fd -> thr_fd - add ctrl interface tests Changes v1 -> v2: - new patch: 'net: pktgen: fix hex32_arg parsing for short reads' - new patch: 'net: pktgen: fix 'rate 0' error handling (return -EINVAL)' - new patch: 'net: pktgen: fix 'ratep 0' error handling (return -EINVAL)' - net/core/pktgen.c: additional fix get_imix_entries() and get_labels() - tools/testing/selftests/net/proc_net_pktgen.c: - fix tyop not vs. nod (suggested by Jakub Kicinski) - fix misaligned line (suggested by Jakub Kicinski) - enable fomerly commented out CONFIG_XFRM dependent test (command spi), as CONFIG_XFRM is enabled via tools/testing/selftests/net/config CONFIG_XFRM_INTERFACE/CONFIG_XFRM_USER (suggestex by Jakub Kicinski) - add CONFIG_NET_PKTGEN=m to tools/testing/selftests/net/config (suggested by Jakub Kicinski) - add modprobe pktgen to FIXTURE_SETUP() (suggested by Jakub Kicinski) - fix some checkpatch warnings (Missing a blank line after declarations) - shrink line length by re-naming some variables (command -> cmd, device -> dev) - add 'rate 0' testcase - add 'ratep 0' testcase [1] https://lore.kernel.org/netdev/20241006221221.3744995-1-artem.chernyshev@red-soft.ru/ [2] https://lore.kernel.org/netdev/20250109083039.14004-1-pchelkin@ispras.ru/ [3] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=76201b5979768500bca362871db66d77cb4c225e Peter Seiderer (8): net: pktgen: fix mix of int/long net: pktgen: remove extra tmp variable (re-use len instead) net: pktgen: remove some superfluous variable initializing net: pktgen: fix mpls maximum labels list parsing net: pktgen: fix access outside of user given buffer in pktgen_if_write() net: pktgen: fix mpls reset parsing net: pktgen: remove all superfluous index assignements selftest: net: add proc_net_pktgen net/core/pktgen.c | 288 ++++---- tools/testing/selftests/net/Makefile | 1 + tools/testing/selftests/net/config | 1 + tools/testing/selftests/net/proc_net_pktgen.c | 646 ++++++++++++++++++ 4 files changed, 805 insertions(+), 131 deletions(-) create mode 100644 tools/testing/selftests/net/proc_net_pktgen.c