Skip to content

Commit b8f6b05

Browse files
Liu Shixindavem330
authored andcommitted
netlabel: Fix memory leak in netlbl_mgmt_add_common
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: 63c4168 ("netlabel: Add network address selectors to the NetLabel/LSM domain mapping") Reported-by: Hulk Robot <[email protected]> Signed-off-by: Liu Shixin <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent f0c227c commit b8f6b05

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

net/netlabel/netlabel_mgmt.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ static const struct nla_policy netlbl_mgmt_genl_policy[NLBL_MGMT_A_MAX + 1] = {
7676
static int netlbl_mgmt_add_common(struct genl_info *info,
7777
struct netlbl_audit *audit_info)
7878
{
79+
void *pmap = NULL;
7980
int ret_val = -EINVAL;
8081
struct netlbl_domaddr_map *addrmap = NULL;
8182
struct cipso_v4_doi *cipsov4 = NULL;
@@ -175,6 +176,7 @@ static int netlbl_mgmt_add_common(struct genl_info *info,
175176
ret_val = -ENOMEM;
176177
goto add_free_addrmap;
177178
}
179+
pmap = map;
178180
map->list.addr = addr->s_addr & mask->s_addr;
179181
map->list.mask = mask->s_addr;
180182
map->list.valid = 1;
@@ -183,10 +185,8 @@ static int netlbl_mgmt_add_common(struct genl_info *info,
183185
map->def.cipso = cipsov4;
184186

185187
ret_val = netlbl_af4list_add(&map->list, &addrmap->list4);
186-
if (ret_val != 0) {
187-
kfree(map);
188-
goto add_free_addrmap;
189-
}
188+
if (ret_val != 0)
189+
goto add_free_map;
190190

191191
entry->family = AF_INET;
192192
entry->def.type = NETLBL_NLTYPE_ADDRSELECT;
@@ -223,6 +223,7 @@ static int netlbl_mgmt_add_common(struct genl_info *info,
223223
ret_val = -ENOMEM;
224224
goto add_free_addrmap;
225225
}
226+
pmap = map;
226227
map->list.addr = *addr;
227228
map->list.addr.s6_addr32[0] &= mask->s6_addr32[0];
228229
map->list.addr.s6_addr32[1] &= mask->s6_addr32[1];
@@ -235,10 +236,8 @@ static int netlbl_mgmt_add_common(struct genl_info *info,
235236
map->def.calipso = calipso;
236237

237238
ret_val = netlbl_af6list_add(&map->list, &addrmap->list6);
238-
if (ret_val != 0) {
239-
kfree(map);
240-
goto add_free_addrmap;
241-
}
239+
if (ret_val != 0)
240+
goto add_free_map;
242241

243242
entry->family = AF_INET6;
244243
entry->def.type = NETLBL_NLTYPE_ADDRSELECT;
@@ -248,10 +247,12 @@ static int netlbl_mgmt_add_common(struct genl_info *info,
248247

249248
ret_val = netlbl_domhsh_add(entry, audit_info);
250249
if (ret_val != 0)
251-
goto add_free_addrmap;
250+
goto add_free_map;
252251

253252
return 0;
254253

254+
add_free_map:
255+
kfree(pmap);
255256
add_free_addrmap:
256257
kfree(addrmap);
257258
add_doi_put_def:

0 commit comments

Comments
 (0)