From patchwork Fri Jan 17 14:16:08 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Seiderer X-Patchwork-Id: 13943394 Received: from mout.gmx.net (mout.gmx.net [212.227.17.22]) (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 65DEA10E4; Fri, 17 Jan 2025 14:16:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=212.227.17.22 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737123395; cv=none; b=kuu+b4/KVrcWDHedgLuV3rz+VhMY4Q/HiYiIf6B7f4rpmPhBNWhwnctfmYfNlW7QQALsW8H9pl6tILaNdMxYXUFrxzzq+d8RKDc9EDR++lwPnhlno0s4s5fA5Bsmvtsy36wx5C0njGfgKAots2k+gEQMwKLIYmAk36r6MEpkOgk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737123395; c=relaxed/simple; bh=zePMm7z1lmEuzvXHCgfD9fFBz0psY1GxnVYPHbjAYo8=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=neZuZnekQtyKnTGO/MYSWxDN/Z3EkakYCjn9dKgsxLy15+lcIZPC1F3golAGuR9WtGVYFvpCMRqmwEt4L2cx5WERaj9HN+Wtfc03DjQjTeU12Lv3qRh/7FsKPeUELM1th1zmlAEMGBTnI6lz8VWbmu44uoniOLOVHAgqtlGmqQs= 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=tX2rjs78; arc=none smtp.client-ip=212.227.17.22 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="tX2rjs78" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmx.net; s=s31663417; t=1737123377; x=1737728177; i=ps.report@gmx.net; bh=zePMm7z1lmEuzvXHCgfD9fFBz0psY1GxnVYPHbjAYo8=; 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=tX2rjs788J5ST9BIu1bYLbM4QYBvbijyYK4f6phhTixUUvv+1HO1Sv4Wz9Hjcy1R 6IMx35OEMo6QDJqyu2+Ud06D4PEwPxdqXsqbeu68xCD5Hx8gULaunzpJTdLQOBd7u rB4uw2k9W+YoiWU/Hifo1u+MMObZjjcjX8OyclubB50ZMrH7dXI14ydCgDaLrJZfr GhCCetlepr5tFe9jyJqgoJ8k0FITmhTyYALQBGDZ3vb2lx9s2xMtAkipoJl2OF+86 NHZWtQW4CGsVL3Trp4i3bQ8DOBpxI4gn7+KSABk8vMtJFFDNDJfHwAqJtNYqAqPxH wxSR3sGiBvAdF0bUog== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from localhost.fritz.box ([82.135.81.138]) by mail.gmx.net (mrgmx104 [212.227.17.168]) with ESMTPSA (Nemesis) id 1Mnaof-1t9rue0KcX-00f2ha; Fri, 17 Jan 2025 15:16:17 +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 , =?utf-8?q?T?= =?utf-8?q?oke_H=C3=B8iland-J=C3=B8rgensen?= , Frederic Weisbecker , Artem Chernyshev , Nam Cao , Peter Seiderer Subject: [PATCH net-next v1 0/5] Some pktgen fixes/improvments Date: Fri, 17 Jan 2025 15:16:08 +0100 Message-ID: <20250117141613.691452-1-ps.report@gmx.net> X-Mailer: git-send-email 2.48.0 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:WrbwOVpR+6srgF4a+mdZUp/Kmr+/fv1oFHixgooVcVeTymeO5gx SXtB7hTeeuUoExSe2rwKql3bxd3jrQVrTy737oEU7Z0gvgMRDx+aTwlLolYuoODClMLPuqs VLPefQ/96Bd0dTgZx99FZQ8h6RvokjCVNSXUx6oARIHr4Db0ldH+AbcwI+fiuEJNq3IQImd k/l74HmANCuysR2CDqA1Q== X-Spam-Flag: NO UI-OutboundReport: notjunk:1;M01:P0:mzsRtgXD9zI=;2fx2afTQAlSrvIxfYkmAPMCnzZf M7DyNKi/eGlclH4vfr1dtNXk0r6PBFoZdb3CiHv86I5hSUujw+kMISzO+oTHgQnKHPCeCP1PJ i8SjVLv8a6nkngnaPLnDsqOG1XODH0Bmgajefr2Td9gNLSU/vamGMFDG64c5Kx/McmTzFAzKO kUCyrd+jb2iIlx6AinK32WMTuhNHJrOX6UrQWdrbfi2BEh87WKXVcbas3FjGOg1snLqrRALXP Jumj/38VNnn9qtA7vwJzhStFK3b+y7kwsYQ+1gKYWHQt9AP0QYbSda7qYtTQjxHZTM47pP02u P2Xpdwhyz+gQlWzZiTWWFmdYrLp1UPoLW2Fbxb+sYJ3Es6tjqZ8jYm7WVMvct0kdanfF+rreZ cag990eJgPQKWvtPGnzcpnAOg/nD6sEdkCwyCYUaz4UR4sD2GgsWU4Vu0Km9BaTCbXdBHu5wO X/YRgpR+clqmrrEsBA6AhsLtuR4bZq5dJJ3xFGEzUVhjFMhqGCBSpSg7RzW+fd9xZb0Sdjdi4 x3IU5FnRVdoRNOVPdwwtHl3oxMAbPwb6t40O3Hl0Wdqy6FgPhUs2ZnhC3Hr5rT9LJIOIOuwbw Cxms7zdH7he5DmAgKFLbK4tPuKUCSqOQbOEJI4vJ7CiHpqWT3758z94hcVgaKgGTIKL3beSp9 2f7V9v11PDKriHsFfAjTY/daX+/BARNulQTEJcDtq9NJg9QxtdTeHyhfmTbS34h5LgM0OsrO3 cn0cgsCcBvfgzXRKeREd+Gl/lYksBH7Di91rN5WOOAa1OId/en4B7gXvatjr5rNy8bebMfmne w6M+bo08+CMlxr0Tx+qNzbsUXp/mN0rsToK75I6OsJIZxla8JX79WkRkzKOBLKuoatbhzvHki GZeXrYqwVOhWSoj1WFwaxRNEeym/WiYWUOGvtP+X2HdUqnJjcHofs+QWhIxPQ80Es7WqhGaNX jvSwUe8vEoc56DEoso/mF17avStrTezan5cl80dvJFelKgV7w0jM6/NcQNitqs69C4h1lXafP Z0QGXSCPadK2ty1ohjZScm9cMmYlMqAJCoz1mdDo1T3d/lI1xgcyoGNB3iVJrnnuTBXjb0+bR Hylhrp7W+4VoHciO5Uk40PzHdsiyUk38Kh4ysiveBu61nU055lXX7vx/xuXtX/3CZIvggb8x5 SUb2qJQVomXwHKT4cWM+8Nhft79XgRhgs4IQInoeflsN+E9QIiY+R+Ygh+6DinBs= 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 [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 (5): net: pktgen: replace ENOTSUPP with EOPNOTSUPP net: pktgen: enable 'param=value' parsing 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 | 210 ++++--- tools/testing/selftests/net/Makefile | 1 + tools/testing/selftests/net/proc_net_pktgen.c | 575 ++++++++++++++++++ 3 files changed, 712 insertions(+), 74 deletions(-) create mode 100644 tools/testing/selftests/net/proc_net_pktgen.c