Received: by 2002:a05:7412:a9a2:b0:e2:908c:2ebd with SMTP id o34csp2575195rdh; Mon, 30 Oct 2023 00:56:57 -0700 (PDT) X-Google-Smtp-Source: AGHT+IED/jmXssu/tiCpXz1/vFL3M1haRSqMj6bc/djgnlYZTu1fuhkEfwJAWugbv46RAB46+Fd8 X-Received: by 2002:a05:6830:150d:b0:6b8:807b:b50 with SMTP id k13-20020a056830150d00b006b8807b0b50mr9566680otp.22.1698652617398; Mon, 30 Oct 2023 00:56:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698652617; cv=none; d=google.com; s=arc-20160816; b=nsUjBWj/IJOJXgGf0vyMGeV8SsXZAg9HEvFULlC+9a/QMkckzab/PSKajbsljbxgdW eBts4ZPCQ/2Imr7wZc1NE6/a4wKfLbiBxjaEzC7VLsGPJGVFV22PZJZ9ZRqn9RBEwoGv dd5jc2h0MH/RKJZv5o//NALpWFuAhMiItMfUUAMoW2CVAo0GiAA72EYS4rYsJDhwAues 0bgJRCxEF+oJWMx//NJn1uouA1bqcwfocHWM15TZr9h8UjnHUxIaB/fU705nINFDyvIY UnNGP8P/0j731HK07dk6hNaMzl+VI7Prg6iIr73uVCD42B6/rZoUxAtCMgsLqiAn8eSo 6PAg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=5t9eU8J5yxO7BvU8JT+OpUytvz6S9LcChDCUUgV2Oz8=; fh=BVlexREXt/vxrSn73JvF7l2LJ9/X7PDR2qtL5amWQYg=; b=CZvd8cRYEjxl0Hh0n2kaXZfV1Ai3r4iNhNlN81or8Rn/HXK3+R4Jt44eIpsmya2SgE o9h3lh851eVXaKyMk4AA5H8IsxiiXFckJoOA2K8L5uUUKlczHpnkkVSEQ7XjuSlpTnFr RSD4K0l/ZSHZRq31wO41sLUkOuk2Jhr9Otx64zarECfsy/9UjTpCGMDDZZIhJEuYDQhj RWXrUgh70xW4yq0wU1AkmGXS3JpHujsI3vwaJO3MZ3u/p4XCeLfafKV9PCcmmkq8cSuY LM+9sh51Q+D1iIz14nVKUCSKE903522y0Nb2+HPjevVlOmr8pRQ9BWHBy8JjbMH0ewKt pikg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=i1EA9OjW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id 67-20020a630046000000b005b909e678dfsi4568060pga.450.2023.10.30.00.56.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Oct 2023 00:56:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=i1EA9OjW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id ED174806833A; Mon, 30 Oct 2023 00:56:53 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231944AbjJ3H4l (ORCPT + 99 others); Mon, 30 Oct 2023 03:56:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46324 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231419AbjJ3H4l (ORCPT ); Mon, 30 Oct 2023 03:56:41 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 67477A2 for ; Mon, 30 Oct 2023 00:55:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1698652550; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=5t9eU8J5yxO7BvU8JT+OpUytvz6S9LcChDCUUgV2Oz8=; b=i1EA9OjWDZaZ6+cqHg+1OB9Me4LLObP1Hj1/h2orK07jV9TtQsx8roCVJ2MloVkcUsYhUf QvSOXwPKgKPmSEHNzv1X25UO6C0jF42hwXO1ueOHK2KC1g+czzl8i7I8urR5IyyJeRfL2n g2t87LzU5801oTe+RNx7FQEqCphqe+o= Received: from mail-pf1-f200.google.com (mail-pf1-f200.google.com [209.85.210.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-650-c9dlPGKeMfWytpr2nQnoHQ-1; Mon, 30 Oct 2023 03:55:47 -0400 X-MC-Unique: c9dlPGKeMfWytpr2nQnoHQ-1 Received: by mail-pf1-f200.google.com with SMTP id d2e1a72fcca58-6bf2b098e43so2589349b3a.3 for ; Mon, 30 Oct 2023 00:55:47 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698652546; x=1699257346; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=5t9eU8J5yxO7BvU8JT+OpUytvz6S9LcChDCUUgV2Oz8=; b=HGwoNp+9iChPSfb4jCvXmxgvKPdVNVj4NLzunpXvtcJFYB6PXAFPSaGwrZYntyU4uk UBUul6vufMZCxToql6Ir3datjprMQJ+XcHK41v01aoZ+nUt49B0jyaZsU9nMivLQ6r6r 3rZuFQDAvWVL9l5WpNjwZDnyfg8jBnymtEJhEhk6mG1u+xn444CjreN4WwFz6dD4QGPZ 8TZRXH+v54muM2qE0rVH2aceb1u0gcjOPUYLlkf+UZklkL2JnB0Flippwb2PVPU/hiNl QvQ0u5zj986N8LPfIWTSPjjaRWe3lEdcQv0dh3y9iSnd/pleaDfLu7hRNHnI5ycQPXM1 /RZQ== X-Gm-Message-State: AOJu0YyxBptHo6icATHdaQiS/IlGoUA047S15bNptTL7cvatwVKaBYQv BH6un1K0+TlY72j1I9iWGRDBFcQOGJtDVwwP//9cUJ6H6WLT+7Qsk/SraxV/5AIGF0WMJVZxozF wi9lGyk5V6E+pJPMJWHMUeG26 X-Received: by 2002:a05:6a20:3d0b:b0:16b:79c2:7d6e with SMTP id y11-20020a056a203d0b00b0016b79c27d6emr8487044pzi.30.1698652546282; Mon, 30 Oct 2023 00:55:46 -0700 (PDT) X-Received: by 2002:a05:6a20:3d0b:b0:16b:79c2:7d6e with SMTP id y11-20020a056a203d0b00b0016b79c27d6emr8487037pzi.30.1698652545956; Mon, 30 Oct 2023 00:55:45 -0700 (PDT) Received: from kernel-devel.local ([240d:1a:c0d:9f00:245e:16ff:fe87:c960]) by smtp.gmail.com with ESMTPSA id be3-20020a170902aa0300b001c9e53b721csm3016067plb.261.2023.10.30.00.55.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Oct 2023 00:55:45 -0700 (PDT) From: Shigeru Yoshida To: jmaloy@redhat.com, ying.xue@windriver.com Cc: netdev@vger.kernel.org, tipc-discussion@lists.sourceforge.net, linux-kernel@vger.kernel.org, Shigeru Yoshida , syzbot+5138ca807af9d2b42574@syzkaller.appspotmail.com, syzbot+9425c47dccbcb4c17d51@syzkaller.appspotmail.com Subject: [PATCH net v3] tipc: Change nla_policy for bearer-related names to NLA_NUL_STRING Date: Mon, 30 Oct 2023 16:55:40 +0900 Message-ID: <20231030075540.3784537-1-syoshida@redhat.com> X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.3 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Mon, 30 Oct 2023 00:56:54 -0700 (PDT) syzbot reported the following uninit-value access issue [1]: ===================================================== BUG: KMSAN: uninit-value in strlen lib/string.c:418 [inline] BUG: KMSAN: uninit-value in strstr+0xb8/0x2f0 lib/string.c:756 strlen lib/string.c:418 [inline] strstr+0xb8/0x2f0 lib/string.c:756 tipc_nl_node_reset_link_stats+0x3ea/0xb50 net/tipc/node.c:2595 genl_family_rcv_msg_doit net/netlink/genetlink.c:971 [inline] genl_family_rcv_msg net/netlink/genetlink.c:1051 [inline] genl_rcv_msg+0x11ec/0x1290 net/netlink/genetlink.c:1066 netlink_rcv_skb+0x371/0x650 net/netlink/af_netlink.c:2545 genl_rcv+0x40/0x60 net/netlink/genetlink.c:1075 netlink_unicast_kernel net/netlink/af_netlink.c:1342 [inline] netlink_unicast+0xf47/0x1250 net/netlink/af_netlink.c:1368 netlink_sendmsg+0x1238/0x13d0 net/netlink/af_netlink.c:1910 sock_sendmsg_nosec net/socket.c:730 [inline] sock_sendmsg net/socket.c:753 [inline] ____sys_sendmsg+0x9c2/0xd60 net/socket.c:2541 ___sys_sendmsg+0x28d/0x3c0 net/socket.c:2595 __sys_sendmsg net/socket.c:2624 [inline] __do_sys_sendmsg net/socket.c:2633 [inline] __se_sys_sendmsg net/socket.c:2631 [inline] __x64_sys_sendmsg+0x307/0x490 net/socket.c:2631 do_syscall_x64 arch/x86/entry/common.c:50 [inline] do_syscall_64+0x41/0xc0 arch/x86/entry/common.c:80 entry_SYSCALL_64_after_hwframe+0x63/0xcd Uninit was created at: slab_post_alloc_hook+0x12f/0xb70 mm/slab.h:767 slab_alloc_node mm/slub.c:3478 [inline] kmem_cache_alloc_node+0x577/0xa80 mm/slub.c:3523 kmalloc_reserve+0x13d/0x4a0 net/core/skbuff.c:559 __alloc_skb+0x318/0x740 net/core/skbuff.c:650 alloc_skb include/linux/skbuff.h:1286 [inline] netlink_alloc_large_skb net/netlink/af_netlink.c:1214 [inline] netlink_sendmsg+0xb34/0x13d0 net/netlink/af_netlink.c:1885 sock_sendmsg_nosec net/socket.c:730 [inline] sock_sendmsg net/socket.c:753 [inline] ____sys_sendmsg+0x9c2/0xd60 net/socket.c:2541 ___sys_sendmsg+0x28d/0x3c0 net/socket.c:2595 __sys_sendmsg net/socket.c:2624 [inline] __do_sys_sendmsg net/socket.c:2633 [inline] __se_sys_sendmsg net/socket.c:2631 [inline] __x64_sys_sendmsg+0x307/0x490 net/socket.c:2631 do_syscall_x64 arch/x86/entry/common.c:50 [inline] do_syscall_64+0x41/0xc0 arch/x86/entry/common.c:80 entry_SYSCALL_64_after_hwframe+0x63/0xcd TIPC bearer-related names including link names must be null-terminated strings. If a link name which is not null-terminated is passed through netlink, strstr() and similar functions can cause buffer overrun. This causes the above issue. This patch changes the nla_policy for bearer-related names from NLA_STRING to NLA_NUL_STRING. This resolves the issue by ensuring that only null-terminated strings are accepted as bearer-related names. syzbot reported similar uninit-value issue related to bearer names [2]. The root cause of this issue is that a non-null-terminated bearer name was passed. This patch also resolved this issue. Fixes: 7be57fc69184 ("tipc: add link get/dump to new netlink api") Fixes: 0655f6a8635b ("tipc: add bearer disable/enable to new netlink api") Reported-and-tested-by: syzbot+5138ca807af9d2b42574@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=5138ca807af9d2b42574 [1] Reported-and-tested-by: syzbot+9425c47dccbcb4c17d51@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=9425c47dccbcb4c17d51 [2] Signed-off-by: Shigeru Yoshida --- v2->v3: - Change the title - Change the nla_policy for bearer-related names instead of using nla_strscpy() - Resolve bearer-name related issue too https://lore.kernel.org/all/20231020163415.2445440-1-syoshida@redhat.com/ v1->v2: - Use nla_strscpy() - Fix similar bugs in other functions other than syzbot reported https://lore.kernel.org/all/20230924060325.3779150-1-syoshida@redhat.com/ --- net/tipc/netlink.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/net/tipc/netlink.c b/net/tipc/netlink.c index e8fd257c0e68..1a9a5bdaccf4 100644 --- a/net/tipc/netlink.c +++ b/net/tipc/netlink.c @@ -88,7 +88,7 @@ const struct nla_policy tipc_nl_net_policy[TIPC_NLA_NET_MAX + 1] = { const struct nla_policy tipc_nl_link_policy[TIPC_NLA_LINK_MAX + 1] = { [TIPC_NLA_LINK_UNSPEC] = { .type = NLA_UNSPEC }, - [TIPC_NLA_LINK_NAME] = { .type = NLA_STRING, + [TIPC_NLA_LINK_NAME] = { .type = NLA_NUL_STRING, .len = TIPC_MAX_LINK_NAME }, [TIPC_NLA_LINK_MTU] = { .type = NLA_U32 }, [TIPC_NLA_LINK_BROADCAST] = { .type = NLA_FLAG }, @@ -125,7 +125,7 @@ const struct nla_policy tipc_nl_prop_policy[TIPC_NLA_PROP_MAX + 1] = { const struct nla_policy tipc_nl_bearer_policy[TIPC_NLA_BEARER_MAX + 1] = { [TIPC_NLA_BEARER_UNSPEC] = { .type = NLA_UNSPEC }, - [TIPC_NLA_BEARER_NAME] = { .type = NLA_STRING, + [TIPC_NLA_BEARER_NAME] = { .type = NLA_NUL_STRING, .len = TIPC_MAX_BEARER_NAME }, [TIPC_NLA_BEARER_PROP] = { .type = NLA_NESTED }, [TIPC_NLA_BEARER_DOMAIN] = { .type = NLA_U32 } -- 2.41.0