From patchwork Wed Jan 22 14:41:02 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Seiderer X-Patchwork-Id: 13947378 Received: from mout.gmx.net (mout.gmx.net [212.227.15.19]) (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 00183214235; Wed, 22 Jan 2025 14:41:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=212.227.15.19 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737556908; cv=none; b=d5NQ5s23aRZUJKt9MYdGMg16b5b5s+6XVn3hBj6TCNH6QSXCHuAMdmWpTJe3nQKNwl6Fb8YAbY2Yv8tVM9dVNQb8nRiIS9f56YUPEhwnmkOARNA0QcMmXphBxr0GtWqvmlCag1N8NCQUDsDqqt9OSJ68KfVBJ4xYBBw1yxs+xuw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737556908; c=relaxed/simple; bh=SrAuI6Xzqo4U/BtMFWcAR5rKSTPYSN+fVoaIp7b0wfg=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=PZQX9VXVRbcyl6rdpn5MYq5Oc3olAHDPifsNibBUtVAjvO293SScTWRMYXEJwFKsUfx2kjWDVrcbuQEtbSIFh6qe+BzNHfXIQxDOtg9EDYMsFWm0y1g6PVUMpuTpyFkzBoPP9ybl0+O8B1xT9kjxbP30H3W67e06EuQ5iFIcaOo= 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=dIrGOq/i; arc=none smtp.client-ip=212.227.15.19 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="dIrGOq/i" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmx.net; s=s31663417; t=1737556885; x=1738161685; i=ps.report@gmx.net; bh=SrAuI6Xzqo4U/BtMFWcAR5rKSTPYSN+fVoaIp7b0wfg=; 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=dIrGOq/iqQg3GFU8YoqtJMTbRVkzYwB1vpnEYBvwQp1G6a+HhAXCkA+TgWmpZWfm fU6x383ZH+OTpbzP0+Bu81ndSFXNTeZ0b6UPcpeEkayz8Td4lAGhFShY/P3dlpSm2 goHhYKwBfEZ1HZlmzdSY1AIsDHks/7eHikWxDCky+RAnZgKgJ9YBkRRLImZzjZn56 DaUxueOuKYAuR4CxrG63FTjsoZWA5AcNhApUchZR5dkwLhSiifd2I/Ut8fRKGt8mB myiR3jwa/YHZV4rr1x9V20CCYKfY5gtLgxY8qOdRRd4/GZDEmxY5QA4nhQgHNSUx4 47lkC7dlHOcNuXJ2ig== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from localhost.fritz.box ([82.135.81.9]) by mail.gmx.net (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MpUZ4-1t9JWK3ZPw-00d6bk; Wed, 22 Jan 2025 15:41:24 +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 , Frederic Weisbecker , Artem Chernyshev , Nam Cao , Peter Seiderer Subject: [PATCH net-next v2 0/8] Some pktgen fixes/improvments Date: Wed, 22 Jan 2025 15:41:02 +0100 Message-ID: <20250122144110.619989-1-ps.report@gmx.net> X-Mailer: git-send-email 2.48.1 Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Provags-ID: V03:K1:/wcjGWJRmCXVeylaUlnbgM9rsQe2c+r8+W0QjoAQbKYuk7+nulL X/SJ9eYf9u4V6rHwXV/FYgQuQzTh1NKpbOgtmPWVaBQTXenl0Z/ADl+tT2BQig7FRWiiyg7 iGsjcfoxz9UrAzHAR2i+YbqjkCTrvrbvlk2encsgyonHSaI9ynvHle6V2YNF1+YgYk//zmE DKePfyjbu5RJf2beZDnfQ== X-Spam-Flag: NO UI-OutboundReport: notjunk:1;M01:P0:DUOCOqGNfLY=;fIWlLC+Jn/p58bj0MZGFt+NemuW th4e17QvqECE64/kXSnzRE4FyRIGW90b7EepWipN0ogGemzaYvo1g2nZN2SCvuaAf79UzrjVG 6Ic693+4XXq9MKlymctdw15kIPQQ3rcfBj0S1zcCAJxocMovMG09oYMBkORPcgYD2XqQAjAaO sp2LDkdMsDtpfBp5y035JkLiGDFAHtlJVubUIoeDelGEGby4NS3RjvsA3VeilhUUjRoNwfx+W 56WIzpM7zk8QLwNC3zymLQvKT8hXAA3J09ygEIYi/eKtbCSoIk2WzBpH6s21+rcy6KRHiW15l mvSpp0DLZ7Z/VO7oebtQxj4/kprHNMC1RYBBCxQ25e3cx/NLAESFit5cMgVEcn5BQyW1iTZ8u tHY1IQkKBaFZzrs1Sj1gdgxZGYfqZeUlMb0Kp32PUrOqPusNLdmTi1Zeg5cQxSH70f1JKhgMB nQ1B8AXtr9/mnQqDOMgcW11zuoC+tiDlrpmdkO5/dXio7yWXRY8+K1/gf/83KvnxC63quMi56 G0n6kpMW6yMyrrYZ5gX9HpSkIH75EARKVvF/Cv6BeRQoJxWnPMXH2W63/7vzvxrT6CrxwRWyl 4F3Oc3Ac9ph6nLWKy88yAOUDeIiqs665y2JZ0eRdq8uUgOpy4DG1ZkhUnQ2BqdxJTAeQ/EAaZ 4HYR0JZih6vYG9FIS2f6yXczGQb1ydOtY4iLcfxNdG7tagCGeu+S+9toEFX4FMx30vjOCUg5d Dz1qncnaIJ1bgDS8EUlm2lLoNYhOPzIsViqBwrJSSyAcAOok35IHA5qnG3XBdRKndeW6/gATJ 2Aq2zpxqxo7lxYwca/xNAFQzbmg5Y2NlspjSmY+5JSqrMN8Cu6GC0+2zz0K+wiQDk89AIoKhx 6XNMLOdgBLDoW6N+apdINcCH8H4uDO0axDEISbtEAFABqdLshKvRaZNaEnq/q5R2E4GD9UYNM hrhhvyMl/Gq+7wlYPj+RGlSuMIBch4f4boFxsva/sSFCdyu7+ojGsdOdR2/BsmRrScXDh1533 X5kYGNrbDC63wO7dh0w/x8Y/7ZI6E2DOpekaPhPO9q4Evl8f0Rvvz9yGfDxc+NQQThQZy70jT c2wBn3u0A+NJAUexqT5RF0FftL+ncnn966DKPC2WabJEP2gfZbFw11yRqCrBVz3DouCVBY7bO JzOSWh3ageP2GERfnfk8QSPm7FBXVl429GHmTHr5qrg== 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 two minor findings) and add a simple proc_net_pktgen selftest... Regards, Peter 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: 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 access outside of user given buffer in pktgen_thread_write() net: pktgen: fix access outside of user given buffer in pktgen_if_write() selftest: net: add proc_net_pktgen net/core/pktgen.c | 238 ++++--- tools/testing/selftests/net/Makefile | 1 + tools/testing/selftests/net/config | 1 + tools/testing/selftests/net/proc_net_pktgen.c | 605 ++++++++++++++++++ 4 files changed, 761 insertions(+), 84 deletions(-) create mode 100644 tools/testing/selftests/net/proc_net_pktgen.c