diff mbox series

[net] team: better TEAM_OPTION_TYPE_STRING validation

Message ID 20250212134928.1541609-1-edumazet@google.com (mailing list archive)
State Accepted
Commit 5bef3ac184b5626ea62385d6b82a1992b89d7940
Delegated to: Netdev Maintainers
Headers show
Series [net] team: better TEAM_OPTION_TYPE_STRING validation | expand

Checks

Context Check Description
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for net
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag present in non-next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers warning 1 maintainers not CCed: andrew+netdev@lunn.ch
netdev/build_clang success Errors and warnings before: 2 this patch: 2
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 10 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/contest success net-next-2025-02-13--12-00 (tests: 889)

Commit Message

Eric Dumazet Feb. 12, 2025, 1:49 p.m. UTC
syzbot reported following splat [1]

Make sure user-provided data contains one nul byte.

[1]
 BUG: KMSAN: uninit-value in string_nocheck lib/vsprintf.c:633 [inline]
 BUG: KMSAN: uninit-value in string+0x3ec/0x5f0 lib/vsprintf.c:714
  string_nocheck lib/vsprintf.c:633 [inline]
  string+0x3ec/0x5f0 lib/vsprintf.c:714
  vsnprintf+0xa5d/0x1960 lib/vsprintf.c:2843
  __request_module+0x252/0x9f0 kernel/module/kmod.c:149
  team_mode_get drivers/net/team/team_core.c:480 [inline]
  team_change_mode drivers/net/team/team_core.c:607 [inline]
  team_mode_option_set+0x437/0x970 drivers/net/team/team_core.c:1401
  team_option_set drivers/net/team/team_core.c:375 [inline]
  team_nl_options_set_doit+0x1339/0x1f90 drivers/net/team/team_core.c:2662
  genl_family_rcv_msg_doit net/netlink/genetlink.c:1115 [inline]
  genl_family_rcv_msg net/netlink/genetlink.c:1195 [inline]
  genl_rcv_msg+0x1214/0x12c0 net/netlink/genetlink.c:1210
  netlink_rcv_skb+0x375/0x650 net/netlink/af_netlink.c:2543
  genl_rcv+0x40/0x60 net/netlink/genetlink.c:1219
  netlink_unicast_kernel net/netlink/af_netlink.c:1322 [inline]
  netlink_unicast+0xf52/0x1260 net/netlink/af_netlink.c:1348
  netlink_sendmsg+0x10da/0x11e0 net/netlink/af_netlink.c:1892
  sock_sendmsg_nosec net/socket.c:718 [inline]
  __sock_sendmsg+0x30f/0x380 net/socket.c:733
  ____sys_sendmsg+0x877/0xb60 net/socket.c:2573
  ___sys_sendmsg+0x28d/0x3c0 net/socket.c:2627
  __sys_sendmsg net/socket.c:2659 [inline]
  __do_sys_sendmsg net/socket.c:2664 [inline]
  __se_sys_sendmsg net/socket.c:2662 [inline]
  __x64_sys_sendmsg+0x212/0x3c0 net/socket.c:2662
  x64_sys_call+0x2ed6/0x3c30 arch/x86/include/generated/asm/syscalls_64.h:47
  do_syscall_x64 arch/x86/entry/common.c:52 [inline]
  do_syscall_64+0xcd/0x1e0 arch/x86/entry/common.c:83
 entry_SYSCALL_64_after_hwframe+0x77/0x7f

Fixes: 3d249d4ca7d0 ("net: introduce ethernet teaming device")
Reported-by: syzbot+1fcd957a82e3a1baa94d@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=1fcd957a82e3a1baa94d
Signed-off-by: Eric Dumazet <edumazet@google.com>
Cc: Jiri Pirko <jiri@nvidia.com>
---
 drivers/net/team/team_core.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

Jiri Pirko Feb. 12, 2025, 2:56 p.m. UTC | #1
Wed, Feb 12, 2025 at 02:49:28PM +0100, edumazet@google.com wrote:
>syzbot reported following splat [1]
>
>Make sure user-provided data contains one nul byte.
>
>[1]
> BUG: KMSAN: uninit-value in string_nocheck lib/vsprintf.c:633 [inline]
> BUG: KMSAN: uninit-value in string+0x3ec/0x5f0 lib/vsprintf.c:714
>  string_nocheck lib/vsprintf.c:633 [inline]
>  string+0x3ec/0x5f0 lib/vsprintf.c:714
>  vsnprintf+0xa5d/0x1960 lib/vsprintf.c:2843
>  __request_module+0x252/0x9f0 kernel/module/kmod.c:149
>  team_mode_get drivers/net/team/team_core.c:480 [inline]
>  team_change_mode drivers/net/team/team_core.c:607 [inline]
>  team_mode_option_set+0x437/0x970 drivers/net/team/team_core.c:1401
>  team_option_set drivers/net/team/team_core.c:375 [inline]
>  team_nl_options_set_doit+0x1339/0x1f90 drivers/net/team/team_core.c:2662
>  genl_family_rcv_msg_doit net/netlink/genetlink.c:1115 [inline]
>  genl_family_rcv_msg net/netlink/genetlink.c:1195 [inline]
>  genl_rcv_msg+0x1214/0x12c0 net/netlink/genetlink.c:1210
>  netlink_rcv_skb+0x375/0x650 net/netlink/af_netlink.c:2543
>  genl_rcv+0x40/0x60 net/netlink/genetlink.c:1219
>  netlink_unicast_kernel net/netlink/af_netlink.c:1322 [inline]
>  netlink_unicast+0xf52/0x1260 net/netlink/af_netlink.c:1348
>  netlink_sendmsg+0x10da/0x11e0 net/netlink/af_netlink.c:1892
>  sock_sendmsg_nosec net/socket.c:718 [inline]
>  __sock_sendmsg+0x30f/0x380 net/socket.c:733
>  ____sys_sendmsg+0x877/0xb60 net/socket.c:2573
>  ___sys_sendmsg+0x28d/0x3c0 net/socket.c:2627
>  __sys_sendmsg net/socket.c:2659 [inline]
>  __do_sys_sendmsg net/socket.c:2664 [inline]
>  __se_sys_sendmsg net/socket.c:2662 [inline]
>  __x64_sys_sendmsg+0x212/0x3c0 net/socket.c:2662
>  x64_sys_call+0x2ed6/0x3c30 arch/x86/include/generated/asm/syscalls_64.h:47
>  do_syscall_x64 arch/x86/entry/common.c:52 [inline]
>  do_syscall_64+0xcd/0x1e0 arch/x86/entry/common.c:83
> entry_SYSCALL_64_after_hwframe+0x77/0x7f
>
>Fixes: 3d249d4ca7d0 ("net: introduce ethernet teaming device")
>Reported-by: syzbot+1fcd957a82e3a1baa94d@syzkaller.appspotmail.com
>Closes: https://syzkaller.appspot.com/bug?extid=1fcd957a82e3a1baa94d
>Signed-off-by: Eric Dumazet <edumazet@google.com>
>Cc: Jiri Pirko <jiri@nvidia.com>

Reviewed-by: Jiri Pirko <jiri@nvidia.com>
patchwork-bot+netdevbpf@kernel.org Feb. 13, 2025, 4:50 p.m. UTC | #2
Hello:

This patch was applied to netdev/net.git (main)
by Jakub Kicinski <kuba@kernel.org>:

On Wed, 12 Feb 2025 13:49:28 +0000 you wrote:
> syzbot reported following splat [1]
> 
> Make sure user-provided data contains one nul byte.
> 
> [1]
>  BUG: KMSAN: uninit-value in string_nocheck lib/vsprintf.c:633 [inline]
>  BUG: KMSAN: uninit-value in string+0x3ec/0x5f0 lib/vsprintf.c:714
>   string_nocheck lib/vsprintf.c:633 [inline]
>   string+0x3ec/0x5f0 lib/vsprintf.c:714
>   vsnprintf+0xa5d/0x1960 lib/vsprintf.c:2843
>   __request_module+0x252/0x9f0 kernel/module/kmod.c:149
>   team_mode_get drivers/net/team/team_core.c:480 [inline]
>   team_change_mode drivers/net/team/team_core.c:607 [inline]
>   team_mode_option_set+0x437/0x970 drivers/net/team/team_core.c:1401
>   team_option_set drivers/net/team/team_core.c:375 [inline]
>   team_nl_options_set_doit+0x1339/0x1f90 drivers/net/team/team_core.c:2662
>   genl_family_rcv_msg_doit net/netlink/genetlink.c:1115 [inline]
>   genl_family_rcv_msg net/netlink/genetlink.c:1195 [inline]
>   genl_rcv_msg+0x1214/0x12c0 net/netlink/genetlink.c:1210
>   netlink_rcv_skb+0x375/0x650 net/netlink/af_netlink.c:2543
>   genl_rcv+0x40/0x60 net/netlink/genetlink.c:1219
>   netlink_unicast_kernel net/netlink/af_netlink.c:1322 [inline]
>   netlink_unicast+0xf52/0x1260 net/netlink/af_netlink.c:1348
>   netlink_sendmsg+0x10da/0x11e0 net/netlink/af_netlink.c:1892
>   sock_sendmsg_nosec net/socket.c:718 [inline]
>   __sock_sendmsg+0x30f/0x380 net/socket.c:733
>   ____sys_sendmsg+0x877/0xb60 net/socket.c:2573
>   ___sys_sendmsg+0x28d/0x3c0 net/socket.c:2627
>   __sys_sendmsg net/socket.c:2659 [inline]
>   __do_sys_sendmsg net/socket.c:2664 [inline]
>   __se_sys_sendmsg net/socket.c:2662 [inline]
>   __x64_sys_sendmsg+0x212/0x3c0 net/socket.c:2662
>   x64_sys_call+0x2ed6/0x3c30 arch/x86/include/generated/asm/syscalls_64.h:47
>   do_syscall_x64 arch/x86/entry/common.c:52 [inline]
>   do_syscall_64+0xcd/0x1e0 arch/x86/entry/common.c:83
>  entry_SYSCALL_64_after_hwframe+0x77/0x7f
> 
> [...]

Here is the summary with links:
  - [net] team: better TEAM_OPTION_TYPE_STRING validation
    https://git.kernel.org/netdev/net/c/5bef3ac184b5

You are awesome, thank you!
diff mbox series

Patch

diff --git a/drivers/net/team/team_core.c b/drivers/net/team/team_core.c
index dc7cbd6a9798a7b09422c0bb1bf38b74dc113b1e..f4019815f473617708b4e0662b355c7738c64731 100644
--- a/drivers/net/team/team_core.c
+++ b/drivers/net/team/team_core.c
@@ -2639,7 +2639,9 @@  int team_nl_options_set_doit(struct sk_buff *skb, struct genl_info *info)
 				ctx.data.u32_val = nla_get_u32(attr_data);
 				break;
 			case TEAM_OPTION_TYPE_STRING:
-				if (nla_len(attr_data) > TEAM_STRING_MAX_LEN) {
+				if (nla_len(attr_data) > TEAM_STRING_MAX_LEN ||
+				    !memchr(nla_data(attr_data), '\0',
+					    nla_len(attr_data))) {
 					err = -EINVAL;
 					goto team_put;
 				}