Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp4801622yba; Tue, 30 Apr 2019 04:44:17 -0700 (PDT) X-Google-Smtp-Source: APXvYqyESIHLHk/R4P7yzioiEss/Suki57B1ePEKhQ8NtJCxhRAkiUjIgbp5foxR9z5to+eXQQW/ X-Received: by 2002:a63:d343:: with SMTP id u3mr15907523pgi.285.1556624656989; Tue, 30 Apr 2019 04:44:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556624656; cv=none; d=google.com; s=arc-20160816; b=Oyi5KjuRNg8yIuLLRUt48XesGi1imSeev6zJ1QEx0cs3tqN2coLJfQQn7j29R+mFpQ HVC2V5CcomMLvL7u5zi9MmZclwF3fWh8FMykBbcOKya+s+Wyh/qVrMFrGmC2s4+QmDXD U8Zfvt3e98vNmyUjBfQniZ+cu/sbPig+7QSrP4mmzQgElH1eqE5+MwiQ7cy3NFJNuCTY DxUDH9O2zJ80riE4nlDA8vGMzM6oe4Qw4D5B+M/Jy7vN3gogu9qp1QoXEZBxAfhjCVEc bAC5JRYZ6ywzOYAJRLuwJRTI94GqpUwyMM5sWIivuy6CRWeza/ROUW0Hec8T6SHt4F42 Sbqw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=6S09fCU4rZmsudtwUK048gMYK3GCyKxMZYHvmkXt4gQ=; b=MkAiScxZAgZCJn6dgZDSci1bAVnVaGMiUIjY9Ss0GPecUm/iDJnI7+qisD8VVw1ifU wO5stlkr8il8FjZmSJ8RZNdVymYyKlSEV8SkHBmv/3SlKlf1jJs01xD0KZrb252YFqa0 oNnNAr5iBP1p9wIdEQIo1G7nI3QheyCJpBjBOreYdEkBe49fPA6LUioxmgncIWprFYom f0XiTWCbQ0z4Ajx+WlKyHFZ4sISJ7qXwAzoCdFaJsooW5N65x9wti4RzE/CE49mnZyqH ltYGTu9rE8iiu6tsW+NheXKKGC8O32183wlhS+a7sxYnV89T5jptoIQBuirZzdz5lIqf /BGw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=LZVXc4ov; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r70si23485261pfa.183.2019.04.30.04.44.01; Tue, 30 Apr 2019 04:44:16 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=LZVXc4ov; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727873AbfD3LlG (ORCPT + 99 others); Tue, 30 Apr 2019 07:41:06 -0400 Received: from mail.kernel.org ([198.145.29.99]:48010 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727730AbfD3LlB (ORCPT ); Tue, 30 Apr 2019 07:41:01 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 23D6B21734; Tue, 30 Apr 2019 11:40:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1556624460; bh=J0ShUQzD1srjF3bzW26x95MrxhY7MvI01lJ6PQT1qB4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LZVXc4ov0lAHZXocFF4vnuyo+6CyRweBmg8ALnuTNJGybeFnibZLLjlSIRQfefKLQ 8CSAtZyJU7f0Bz6Iu/6K66oJtbd5IdDRfMUT1j7o/KPopDtCWo3ySm6ShEeHWXm0Wt C0r57OpaUIQPUTkvnDr4corWAgOi5c+OdNdVpNH8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot+8b707430713eb46e1e45@syzkaller.appspotmail.com, Xin Long , "David S. Miller" Subject: [PATCH 4.9 27/41] tipc: check bearer name with right length in tipc_nl_compat_bearer_enable Date: Tue, 30 Apr 2019 13:38:38 +0200 Message-Id: <20190430113531.206287981@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190430113524.451237916@linuxfoundation.org> References: <20190430113524.451237916@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Xin Long commit 6f07e5f06c8712acc423485f657799fc8e11e56c upstream. Syzbot reported the following crash: BUG: KMSAN: uninit-value in memchr+0xce/0x110 lib/string.c:961 memchr+0xce/0x110 lib/string.c:961 string_is_valid net/tipc/netlink_compat.c:176 [inline] tipc_nl_compat_bearer_enable+0x2c4/0x910 net/tipc/netlink_compat.c:401 __tipc_nl_compat_doit net/tipc/netlink_compat.c:321 [inline] tipc_nl_compat_doit+0x3aa/0xaf0 net/tipc/netlink_compat.c:354 tipc_nl_compat_handle net/tipc/netlink_compat.c:1162 [inline] tipc_nl_compat_recv+0x1ae7/0x2750 net/tipc/netlink_compat.c:1265 genl_family_rcv_msg net/netlink/genetlink.c:601 [inline] genl_rcv_msg+0x185f/0x1a60 net/netlink/genetlink.c:626 netlink_rcv_skb+0x431/0x620 net/netlink/af_netlink.c:2477 genl_rcv+0x63/0x80 net/netlink/genetlink.c:637 netlink_unicast_kernel net/netlink/af_netlink.c:1310 [inline] netlink_unicast+0xf3e/0x1020 net/netlink/af_netlink.c:1336 netlink_sendmsg+0x127f/0x1300 net/netlink/af_netlink.c:1917 sock_sendmsg_nosec net/socket.c:622 [inline] sock_sendmsg net/socket.c:632 [inline] Uninit was created at: __alloc_skb+0x309/0xa20 net/core/skbuff.c:208 alloc_skb include/linux/skbuff.h:1012 [inline] netlink_alloc_large_skb net/netlink/af_netlink.c:1182 [inline] netlink_sendmsg+0xb82/0x1300 net/netlink/af_netlink.c:1892 sock_sendmsg_nosec net/socket.c:622 [inline] sock_sendmsg net/socket.c:632 [inline] It was triggered when the bearer name size < TIPC_MAX_BEARER_NAME, it would check with a wrong len/TLV_GET_DATA_LEN(msg->req), which also includes priority and disc_domain length. This patch is to fix it by checking it with a right length: 'TLV_GET_DATA_LEN(msg->req) - offsetof(struct tipc_bearer_config, name)'. Reported-by: syzbot+8b707430713eb46e1e45@syzkaller.appspotmail.com Signed-off-by: Xin Long Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- net/tipc/netlink_compat.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) --- a/net/tipc/netlink_compat.c +++ b/net/tipc/netlink_compat.c @@ -394,7 +394,12 @@ static int tipc_nl_compat_bearer_enable( if (!bearer) return -EMSGSIZE; - len = min_t(int, TLV_GET_DATA_LEN(msg->req), TIPC_MAX_BEARER_NAME); + len = TLV_GET_DATA_LEN(msg->req); + len -= offsetof(struct tipc_bearer_config, name); + if (len <= 0) + return -EINVAL; + + len = min_t(int, len, TIPC_MAX_BEARER_NAME); if (!string_is_valid(b->name, len)) return -EINVAL;