Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp3754939pxv; Mon, 19 Jul 2021 08:02:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzIwPyuJ9W9O+6bQyXmUEmbk01WdTiLWgSBv7k/umD43NqUhxc0TlBaQQfR6qfmOY5Prmc0 X-Received: by 2002:a92:280a:: with SMTP id l10mr17660154ilf.125.1626706936017; Mon, 19 Jul 2021 08:02:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626706936; cv=none; d=google.com; s=arc-20160816; b=ds6fhSQbFKbAJXoBZH6IZBNPiaG7rynU6E6SB0XvzeA9q71jRuil/5fSV9uEKdaGVA 3VNncExNPM4GdxHsTZP0qFiNsdMXlIuIYwBJwSwkyt589/ROYiMD1gqv/LFYfa1CfD2n Y8PYdoVKhWXEu/H/Ux4Na6OXl6yCPPLk+byrOyEW3CM8MF/m91cKlmwJL/o7AgLD6rc8 pwGecjg0l+tuqaU4nobMzdg8i0/wZUlyp4Xc3eYXWXRvJWh5Yzg0mJkGdfEwU2tOgcJA sHBlC5XWl1ovuSStvTwZMgxzYQqR4eq7woPGna358KppBpbNtNPURfXZhhi8Vv74X/4b O2KA== 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=T/Q119rL6zgtR5kOhNyx33vFtVTrjypeenMYlPhr9Zo=; b=S/daLYZPiARBi8PoIkQedX1T5Eu8ZxlWXKcN1pIWI9G2B1Wp+T8v5lm1vxD0nDjtxm HqlZNGBUkkAIW8I1HigCjHrKyU8tYwjQkf9TEKRp9yxfpDeCed0qfqlvIvapCc0GQVz4 ekH8FckVxUaDjDJ9K468X4FI8ES5aKQBzKvFyVPhHXJ6VKg4P1aLR5bcNm1PCWLIXo/h T+23p5DYA87aip/rQIvh46I7PikuMByjTgGeipYO0RxmTBA3IcGBlaBLy1EIl6zcmtxr Tcb8s9weFLDRhhkxFPIoqZiTTT4icb2P7F/51/CvLrKXte5YllWmcrw++dj/Z1RVIoBw NDRA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=2ekpBsyH; 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=pass (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 z17si9316375jao.13.2021.07.19.08.02.03; Mon, 19 Jul 2021 08:02:16 -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=@linuxfoundation.org header.s=korg header.b=2ekpBsyH; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242542AbhGSOT3 (ORCPT + 99 others); Mon, 19 Jul 2021 10:19:29 -0400 Received: from mail.kernel.org ([198.145.29.99]:52828 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241588AbhGSOSC (ORCPT ); Mon, 19 Jul 2021 10:18:02 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id D1C6D6113B; Mon, 19 Jul 2021 14:58:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626706721; bh=7cf9s0WJLknvqbvhZ3mFo260NRJ5Qby36RhCgiPJq5Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=2ekpBsyH4e6QUKkfTZI5HZ6Vnr26VJWsLMZUyby+6e1ML96tHvdrmlifO5a8ktKHc 71A3I/v8bSC//88jp/tSYqY7NyNUkNEnkWudSLKshJYqBRwPiOqYjdtDvWjA5Tv9WY qDN8D7E8H7p9D95uoLFjc4m5NkGy3SzSY+qYye2E= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Hulk Robot , Liu Shixin , "David S. Miller" , Sasha Levin Subject: [PATCH 4.4 068/188] netlabel: Fix memory leak in netlbl_mgmt_add_common Date: Mon, 19 Jul 2021 16:50:52 +0200 Message-Id: <20210719144928.849804703@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210719144913.076563739@linuxfoundation.org> References: <20210719144913.076563739@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: Liu Shixin [ Upstream commit b8f6b0522c298ae9267bd6584e19b942a0636910 ] Hulk Robot reported memory leak in netlbl_mgmt_add_common. The problem is non-freed map in case of netlbl_domhsh_add() failed. BUG: memory leak unreferenced object 0xffff888100ab7080 (size 96): comm "syz-executor537", pid 360, jiffies 4294862456 (age 22.678s) hex dump (first 32 bytes): 05 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ fe 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 ................ backtrace: [<0000000008b40026>] netlbl_mgmt_add_common.isra.0+0xb2a/0x1b40 [<000000003be10950>] netlbl_mgmt_add+0x271/0x3c0 [<00000000c70487ed>] genl_family_rcv_msg_doit.isra.0+0x20e/0x320 [<000000001f2ff614>] genl_rcv_msg+0x2bf/0x4f0 [<0000000089045792>] netlink_rcv_skb+0x134/0x3d0 [<0000000020e96fdd>] genl_rcv+0x24/0x40 [<0000000042810c66>] netlink_unicast+0x4a0/0x6a0 [<000000002e1659f0>] netlink_sendmsg+0x789/0xc70 [<000000006e43415f>] sock_sendmsg+0x139/0x170 [<00000000680a73d7>] ____sys_sendmsg+0x658/0x7d0 [<0000000065cbb8af>] ___sys_sendmsg+0xf8/0x170 [<0000000019932b6c>] __sys_sendmsg+0xd3/0x190 [<00000000643ac172>] do_syscall_64+0x37/0x90 [<000000009b79d6dc>] entry_SYSCALL_64_after_hwframe+0x44/0xae Fixes: 63c416887437 ("netlabel: Add network address selectors to the NetLabel/LSM domain mapping") Reported-by: Hulk Robot Signed-off-by: Liu Shixin Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- net/netlabel/netlabel_mgmt.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/net/netlabel/netlabel_mgmt.c b/net/netlabel/netlabel_mgmt.c index 13f777f20995..5f1218dc9162 100644 --- a/net/netlabel/netlabel_mgmt.c +++ b/net/netlabel/netlabel_mgmt.c @@ -92,6 +92,7 @@ static const struct nla_policy netlbl_mgmt_genl_policy[NLBL_MGMT_A_MAX + 1] = { static int netlbl_mgmt_add_common(struct genl_info *info, struct netlbl_audit *audit_info) { + void *pmap = NULL; int ret_val = -EINVAL; struct netlbl_domaddr_map *addrmap = NULL; struct cipso_v4_doi *cipsov4 = NULL; @@ -165,6 +166,7 @@ static int netlbl_mgmt_add_common(struct genl_info *info, ret_val = -ENOMEM; goto add_free_addrmap; } + pmap = map; map->list.addr = addr->s_addr & mask->s_addr; map->list.mask = mask->s_addr; map->list.valid = 1; @@ -173,10 +175,8 @@ static int netlbl_mgmt_add_common(struct genl_info *info, map->def.cipso = cipsov4; ret_val = netlbl_af4list_add(&map->list, &addrmap->list4); - if (ret_val != 0) { - kfree(map); - goto add_free_addrmap; - } + if (ret_val != 0) + goto add_free_map; entry->def.type = NETLBL_NLTYPE_ADDRSELECT; entry->def.addrsel = addrmap; @@ -212,6 +212,7 @@ static int netlbl_mgmt_add_common(struct genl_info *info, ret_val = -ENOMEM; goto add_free_addrmap; } + pmap = map; map->list.addr = *addr; map->list.addr.s6_addr32[0] &= mask->s6_addr32[0]; map->list.addr.s6_addr32[1] &= mask->s6_addr32[1]; @@ -222,10 +223,8 @@ static int netlbl_mgmt_add_common(struct genl_info *info, map->def.type = entry->def.type; ret_val = netlbl_af6list_add(&map->list, &addrmap->list6); - if (ret_val != 0) { - kfree(map); - goto add_free_addrmap; - } + if (ret_val != 0) + goto add_free_map; entry->def.type = NETLBL_NLTYPE_ADDRSELECT; entry->def.addrsel = addrmap; @@ -234,10 +233,12 @@ static int netlbl_mgmt_add_common(struct genl_info *info, ret_val = netlbl_domhsh_add(entry, audit_info); if (ret_val != 0) - goto add_free_addrmap; + goto add_free_map; return 0; +add_free_map: + kfree(pmap); add_free_addrmap: kfree(addrmap); add_doi_put_def: -- 2.30.2