Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp1826558pxj; Sun, 9 May 2021 06:14:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyy+FBxlKRJwe0mmQ4NBCu2FK70p5Q6AnYnHIGnQw8VPsLSdvsCvvA3bBrupaamyGTHIBGg X-Received: by 2002:aa7:cd8b:: with SMTP id x11mr24089654edv.87.1620566064558; Sun, 09 May 2021 06:14:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620566064; cv=none; d=google.com; s=arc-20160816; b=kG2lNo1JEF9dD3AOIQ6PRoj3j2LD/q4Cue7+kf+Ie2Cm2gi7ZonC+BYytU07XAJHyD GgYYM0yHr16mK54kKI9kCpF7Ed/QBBbPD8X7QvQhPVNYUc58l+62LxLmQzdR2OgrZ+4d 2Bhy5oa6SgYNAJicsqP1UkAc63nN7a44HPvoMXpaTkeWNap6dmjEnwJlTpFVk5v+DO0U SA7rO9wqKiQV0tC5M5+cL2u3KgRLpaUVRv+njoNVUzDpZC5FJ7Nqu/kW7u1EI6EH0lQs 3f7gxMVrBCUOg323aURlBmniLWn3//eXVaqvgC2cBbqu2I9d5OHi1F+1STZj3XY9JxLT ZQAA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=9DlvneKe0ecmLfDaeKd38H1zb7Aa+qJlSHhVPoE4AJc=; b=COnsYfoyxp6TlOjh95wJWgHjfYeVxDIIYCH5a8ZF//eoMEUwCOVSFUaq+N/+kj+Hbz 08bsp4BFfKHa4xtn9DM+0SsEKevmeLtXRwcZhZlWtCTrnG3Zf7lcBYRwoa5SxNNynB/C vSzjiVpYw9b1H7egCmJTAtmNPmQg5766HDsHlIP00cor7rl4i0dD7kWVgvodPlV9pYer a2AliSzfU1gE/kLvoZNjEYsJ9wMpgbjLIXm8tmRLZqGLraa4YctfDRL8urIWvQjXig+A ti3m4zUhGhy+UNfeFtjGigpKlYTej0RbmhtUVawXTglEpzk34Y/gEjJkpOa3iF7QWvUG zbNQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z62si11766362ede.508.2021.05.09.06.14.00; Sun, 09 May 2021 06:14:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229650AbhEINMO (ORCPT + 99 others); Sun, 9 May 2021 09:12:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41884 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229563AbhEINMN (ORCPT ); Sun, 9 May 2021 09:12:13 -0400 Received: from Chamillionaire.breakpoint.cc (Chamillionaire.breakpoint.cc [IPv6:2a0a:51c0:0:12e:520::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E3B11C061573; Sun, 9 May 2021 06:11:10 -0700 (PDT) Received: from fw by Chamillionaire.breakpoint.cc with local (Exim 4.92) (envelope-from ) id 1lfjCt-0001y1-2w; Sun, 09 May 2021 15:10:51 +0200 Date: Sun, 9 May 2021 15:10:51 +0200 From: Florian Westphal To: Phillip Potter Cc: davem@davemloft.net, kuba@kernel.org, yhs@fb.com, ast@kernel.org, johannes.berg@intel.com, rdunlap@infradead.org, 0x7f454c46@gmail.com, yangyingliang@huawei.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] netlink: netlink_sendmsg: memset unused tail bytes in skb Message-ID: <20210509131051.GD4038@breakpoint.cc> References: <20210509121858.1232583-1-phil@philpotter.co.uk> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210509121858.1232583-1-phil@philpotter.co.uk> User-Agent: Mutt/1.10.1 (2018-07-13) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Phillip Potter wrote: > When allocating the skb within netlink_sendmsg, with certain supplied > len arguments, extra bytes are allocated at the end of the data buffer, > due to SKB_DATA_ALIGN giving a larger size within __alloc_skb for > alignment reasons. This means that after using skb_put with the same > len value and then copying data into the skb, the skb tail area is > non-zero in size and contains uninitialised bytes. Wiping this area > (if it exists) fixes a KMSAN-found uninit-value bug reported by syzbot at: > https://syzkaller.appspot.com/bug?id=3e63bcec536b7136b54c72e06adeb87dc6519f69 This patch papers over the real bug. Please fix TIPC instead. Incomplete patch as a starting point: diff --git a/net/tipc/node.c b/net/tipc/node.c --- a/net/tipc/node.c +++ b/net/tipc/node.c @@ -2481,7 +2481,6 @@ int tipc_nl_node_get_link(struct sk_buff *skb, struct genl_info *info) struct net *net = genl_info_net(info); struct nlattr *attrs[TIPC_NLA_LINK_MAX + 1]; struct tipc_nl_msg msg; - char *name; int err; msg.portid = info->snd_portid; @@ -2499,13 +2498,11 @@ int tipc_nl_node_get_link(struct sk_buff *skb, struct genl_info *info) if (!attrs[TIPC_NLA_LINK_NAME]) return -EINVAL; - name = nla_data(attrs[TIPC_NLA_LINK_NAME]); - msg.skb = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); if (!msg.skb) return -ENOMEM; - if (strcmp(name, tipc_bclink_name) == 0) { + if (nla_strcmp(attrs[TIPC_NLA_LINK_NAME], tipc_bclink_name) == 0) { err = tipc_nl_add_bc_link(net, &msg, tipc_net(net)->bcl); if (err) goto err_free; You will also need to change tipc_node_find_by_name() to pass the nla attr. Alternatively TIPC_NLA_LINK_NAME policy can be changed: diff --git a/net/tipc/netlink.c b/net/tipc/netlink.c --- 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, ... which makes it safe to treat the raw attribute payload as a c-string, but this might break existing userspace applications. Its probably a good idea to audit all NLA_STRING attributes in tipc for similar problems.