Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp1084726pxk; Fri, 25 Sep 2020 05:59:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzST+LNm8Ojt7c65lrVLLjJNdFFo+pnk5iQOjOQUlIPrfaadsJG6k5IA+kXGVxZ9JXhHt0j X-Received: by 2002:a17:906:e18:: with SMTP id l24mr2575533eji.334.1601038780025; Fri, 25 Sep 2020 05:59:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601038780; cv=none; d=google.com; s=arc-20160816; b=inPblDBVO65Plg7HJe6UD1mfe1HNtFDm+OBUrTgAYa5VLmCcyhq+PkfkTI+FF/1XIY 9FreHiigsEWZKLuml/zZQFsPcO+qJRLFcBQBQI039Qo16AeHkG11Jjxr76hZKUflvfIg i38iJREvJ8s1yBZ76783pSspXD9gNrpI0V9nbAmn9fENUTBk2MZxNEPqKHU6f9BgO0N/ YueaqjdGRjwbSD6n/1SypX/+EIT09YVwt29NyEY8ttmPK9dXN1KQyAuFrUA0jlCuOX77 WJvOz8Eh2KtHQUAoXula33HInKNf7QinPEzYxccekylWgh9TN0dI/0PG9+8SnY6xcui5 zrYQ== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=NxHPZIwpJX4viGmm4VDF+mt1BJdgn70Y+v9u0Dj3xHc=; b=WNuMn64zwsXj7HW7N53OhlKII9P0HxyiG0UD+DTRMmZiQ1yHynJP6pQH3HmgOsD6IB 0w5zotrf92qyEnffllTLt9EISLAPa1eHTK+j5zWrVOoj/MP4lSLOirregLLAc7moemHX hmczAi6ls00EBUP6bxKp3bk4xxIgEkJEDCOoKcznLxM6o9Sx0rC6KtjT7rPOjceTzvLt 8uqD5/evqeeqCidJtPfRy4byMCXE20vYaBtqnWCsJfDYGD/kczHdPRQGfjXw5zW1iQuc en1mkcZDL9WMVbdSkvL3iM6Ah91MtMbVcRXTyb7qM1R1iE3nIj1J4MPqF3xyuUs7AALh Vbzw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="zKoC/XAO"; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dr1si1793507ejc.187.2020.09.25.05.59.16; Fri, 25 Sep 2020 05:59:40 -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=@kernel.org header.s=default header.b="zKoC/XAO"; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729021AbgIYMzR (ORCPT + 99 others); Fri, 25 Sep 2020 08:55:17 -0400 Received: from mail.kernel.org ([198.145.29.99]:34492 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729635AbgIYMzK (ORCPT ); Fri, 25 Sep 2020 08:55:10 -0400 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (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 87220206DB; Fri, 25 Sep 2020 12:55:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1601038509; bh=b5Wpjm1up6q4L0/jfnwWLFD4gMn0/33WnX8MqxYW5Wc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=zKoC/XAOtJ+3WVHQIB2wisjiWN9KgHrKmUGVs1VPSwENLDtE9xjBz+Bgl+UIMxm9J HvEbJMJ/iyxQiJ5eBSWCyVAVg0k+trOkr9aB5MSy7SOLZ4SAJhf6ZSfF3RpFRo5kQ0 ExibfgKDtDjanFCEYvMJfT1uNsT7zcJCKgRJ/pi8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Hillf Danton , Peilin Ye , "David S. Miller" , syzbot+f95d90c454864b3b5bc9@syzkaller.appspotmail.com Subject: [PATCH 4.19 15/37] tipc: Fix memory leak in tipc_group_create_member() Date: Fri, 25 Sep 2020 14:48:43 +0200 Message-Id: <20200925124723.245390291@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200925124720.972208530@linuxfoundation.org> References: <20200925124720.972208530@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Peilin Ye [ Upstream commit bb3a420d47ab00d7e1e5083286cab15235a96680 ] tipc_group_add_to_tree() returns silently if `key` matches `nkey` of an existing node, causing tipc_group_create_member() to leak memory. Let tipc_group_add_to_tree() return an error in such a case, so that tipc_group_create_member() can handle it properly. Fixes: 75da2163dbb6 ("tipc: introduce communication groups") Reported-and-tested-by: syzbot+f95d90c454864b3b5bc9@syzkaller.appspotmail.com Cc: Hillf Danton Link: https://syzkaller.appspot.com/bug?id=048390604fe1b60df34150265479202f10e13aff Signed-off-by: Peilin Ye Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- net/tipc/group.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) --- a/net/tipc/group.c +++ b/net/tipc/group.c @@ -273,8 +273,8 @@ static struct tipc_member *tipc_group_fi return NULL; } -static void tipc_group_add_to_tree(struct tipc_group *grp, - struct tipc_member *m) +static int tipc_group_add_to_tree(struct tipc_group *grp, + struct tipc_member *m) { u64 nkey, key = (u64)m->node << 32 | m->port; struct rb_node **n, *parent = NULL; @@ -291,10 +291,11 @@ static void tipc_group_add_to_tree(struc else if (key > nkey) n = &(*n)->rb_right; else - return; + return -EEXIST; } rb_link_node(&m->tree_node, parent, n); rb_insert_color(&m->tree_node, &grp->members); + return 0; } static struct tipc_member *tipc_group_create_member(struct tipc_group *grp, @@ -302,6 +303,7 @@ static struct tipc_member *tipc_group_cr u32 instance, int state) { struct tipc_member *m; + int ret; m = kzalloc(sizeof(*m), GFP_ATOMIC); if (!m) @@ -314,8 +316,12 @@ static struct tipc_member *tipc_group_cr m->port = port; m->instance = instance; m->bc_acked = grp->bc_snd_nxt - 1; + ret = tipc_group_add_to_tree(grp, m); + if (ret < 0) { + kfree(m); + return NULL; + } grp->member_cnt++; - tipc_group_add_to_tree(grp, m); tipc_nlist_add(&grp->dests, m->node); m->state = state; return m;