Skip to content

Commit b04c461

Browse files
wangxiaoming321davem330
authored andcommitted
net: ipv4: current group_info should be put after using.
Plug a group_info refcount leak in ping_init. group_info is only needed during initialization and the code failed to release the reference on exit. While here move grabbing the reference to a place where it is actually needed. Signed-off-by: Chuansheng Liu <[email protected]> Signed-off-by: Zhang Dongxing <[email protected]> Signed-off-by: xiaoming wang <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 321d03c commit b04c461

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

net/ipv4/ping.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -252,26 +252,33 @@ int ping_init_sock(struct sock *sk)
252252
{
253253
struct net *net = sock_net(sk);
254254
kgid_t group = current_egid();
255-
struct group_info *group_info = get_current_groups();
256-
int i, j, count = group_info->ngroups;
255+
struct group_info *group_info;
256+
int i, j, count;
257257
kgid_t low, high;
258+
int ret = 0;
258259

259260
inet_get_ping_group_range_net(net, &low, &high);
260261
if (gid_lte(low, group) && gid_lte(group, high))
261262
return 0;
262263

264+
group_info = get_current_groups();
265+
count = group_info->ngroups;
263266
for (i = 0; i < group_info->nblocks; i++) {
264267
int cp_count = min_t(int, NGROUPS_PER_BLOCK, count);
265268
for (j = 0; j < cp_count; j++) {
266269
kgid_t gid = group_info->blocks[i][j];
267270
if (gid_lte(low, gid) && gid_lte(gid, high))
268-
return 0;
271+
goto out_release_group;
269272
}
270273

271274
count -= cp_count;
272275
}
273276

274-
return -EACCES;
277+
ret = -EACCES;
278+
279+
out_release_group:
280+
put_group_info(group_info);
281+
return ret;
275282
}
276283
EXPORT_SYMBOL_GPL(ping_init_sock);
277284

0 commit comments

Comments
 (0)