Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3926389pxj; Tue, 11 May 2021 15:19:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxLNZ/nwzjyXzSiQkY9mf7HGk2q6YG/BxizajoSK7+BF2FUP/AlvHIw0JIej0ZDClUvH0Kr X-Received: by 2002:a17:906:4889:: with SMTP id v9mr34070800ejq.21.1620771585987; Tue, 11 May 2021 15:19:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620771585; cv=none; d=google.com; s=arc-20160816; b=mPg/ujJqIwHDZsWDKn5z/tW500qSJr+yCqRlN9sw+gqK+U35PvUvE+PMmRtmt8AVj7 DF5Gf/zM/1CJebEnniadbJ5K2bJefyUQGIvqFRE/G40r16tJenUFAI9hSYGu+excuHOl AfD+iDfWCq/XJuyYbmiT/HwHzmPYIxhauqHiCaXJDyLx9muH3V3FYjMqd7n80Jd9tvJN rAKla+SN07blhnzR2qG+0o9IQbegETwwUvqm5Ty+/FM+DvyLR0vRVY3fw2068iM4SEjC cwRD4Nm5juVqmqt6x3YGEdIYW1t6VsPu07Ig/Vf5O2tGYYbahFALjBUs7EKoixcFeWZk rCvA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=rIMnU3pEMyzESxwl/9HGpb60VQFyauRdmgB1fZ2i0PQ=; b=lcjnQKFJ3a6o+jdonjJ+9I+ZY58JVJFgAVF3ihk+ORF+wxgyz8azuhMfxdc4j0TFmr pjMZAifqBdvDF6FjuXG0NiFnaeLWG/5HNVT3QoREaFRhkHRl1yp/2+xxWg0V8zlHXPaq RwBgMxU8cw8fsHh3Q+obe8tMmME714np8VnEHLRvlLw/LNtqpKMXltrZgRiEM2TtNYIr PG82QmdyK+vsVXdtD2DfwlxLyXUKDs9GCqILLgtajAMCcQfL0ff/+GLSRwOKoHDGXtda qSm4i9Z/yVnsdo150ae/ysAfU3/a4KpQ75Q5r+Gu9S9OEq3fgcaHrspMzUs4FqDQ9sEm Ytkw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@philpotter-co-uk.20150623.gappssmtp.com header.s=20150623 header.b="lbQ/0T7C"; 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 h15si18574646ejq.124.2021.05.11.15.18.52; Tue, 11 May 2021 15:19:45 -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; dkim=pass header.i=@philpotter-co-uk.20150623.gappssmtp.com header.s=20150623 header.b="lbQ/0T7C"; 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 S230023AbhEKWSq (ORCPT + 99 others); Tue, 11 May 2021 18:18:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42372 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229637AbhEKWSq (ORCPT ); Tue, 11 May 2021 18:18:46 -0400 Received: from mail-wr1-x441.google.com (mail-wr1-x441.google.com [IPv6:2a00:1450:4864:20::441]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7AB8FC06174A for ; Tue, 11 May 2021 15:17:39 -0700 (PDT) Received: by mail-wr1-x441.google.com with SMTP id x5so21611951wrv.13 for ; Tue, 11 May 2021 15:17:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=philpotter-co-uk.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=rIMnU3pEMyzESxwl/9HGpb60VQFyauRdmgB1fZ2i0PQ=; b=lbQ/0T7CfsdayyPHbn5j4LU/IELNGNpn0EpNuxTYaaWR39f9MgG9/y4+g0Cm2GjRQV QQRZGDOKRn+tYKQc9u7XzQtJPqzXCuFixHfaFoMsgRqaBYAoGdPCNgRUX9yS1PO1QkLU Vtj96GjtmCI+Z1hZ5/bCnNBjuGeRAXQ0uoAf2E738XJ0O4KJh9JBzsyJnm5cZxQqQBcj cNYzAulxov0Vl5Vy6WIA8qON2WvpFmHCxcx8mYKYeetbMunHQxoysUbXjxM24/QraVCt QbUfnodLLtx9SATocntwK/2mWPtMFNYAAEuNlroBdkfm5vBBm69LIW9yUNv6l2ng4zbl usBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=rIMnU3pEMyzESxwl/9HGpb60VQFyauRdmgB1fZ2i0PQ=; b=czgnI+lXH4LWuul+Xg9/5tjpt+o9LnNaYGixtmWAgGNWHCFrnIgMPHwTXlbSvQPVVW 1BRosvNimK+EnkiLkeTf2GSxygxCR1f9yccVZ2JAuRUEQk3CeUOJVIKyQg/vi9Xe5Ji1 H7OFVNBKFQaN9Z99//VGdnv8U1zwU1CAanJH2nGCxKuiWC14FX3Y9gFdVM/2bGvlhWm1 ihHI3hNt/nn8b3GJcVq7NEHccmsTkfDTOtG7k44ZhLYdtPrKMLb7Rp5QrCkZo9IwXPCF /zoMhdwdjrJYoV2OPN/PJEtyVtTSANu8Nu3sxLNbdNwcAMmkZCW9z7oqsTeQDtb8oZ8P Ah6A== X-Gm-Message-State: AOAM531BMOq5Ou3SiV5adHR9SDcBCmVwNcYVdO5liq9G0k2OjMbWBH25 OiGp0E3xUDUxlDC6LXC8H4qw5g== X-Received: by 2002:a05:6000:180a:: with SMTP id m10mr40452470wrh.215.1620771458027; Tue, 11 May 2021 15:17:38 -0700 (PDT) Received: from equinox (2.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.a.1.e.e.d.f.d.0.b.8.0.1.0.0.2.ip6.arpa. [2001:8b0:dfde:e1a0::2]) by smtp.gmail.com with ESMTPSA id r7sm4207518wmq.3.2021.05.11.15.17.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 May 2021 15:17:37 -0700 (PDT) Date: Tue, 11 May 2021 23:17:35 +0100 From: Phillip Potter To: Florian Westphal 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: References: <20210509121858.1232583-1-phil@philpotter.co.uk> <20210509131051.GD4038@breakpoint.cc> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210509131051.GD4038@breakpoint.cc> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, May 09, 2021 at 03:10:51PM +0200, Florian Westphal wrote: > 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. Dear Florian, Thank you for your feedback and code + suggestions, I will take a look at this over the next few days and then resubmit. Regards, Phil