]> git.baikalelectronics.ru Git - kernel.git/commit
net: team: fix memory leak in __team_options_register
authorAnant Thazhemadam <anant.thazhemadam@gmail.com>
Sun, 4 Oct 2020 20:55:36 +0000 (02:25 +0530)
committerDavid S. Miller <davem@davemloft.net>
Sun, 4 Oct 2020 21:47:22 +0000 (14:47 -0700)
commit6b1ae9a46b7c6c32199d24c6410ccdae1053d097
tree0fecd22ecdabd0463f8ea05327df537b7dc6fc35
parentef62d8787cdeeaa9131dd3032bc5bc74e57fc9f4
net: team: fix memory leak in __team_options_register

The variable "i" isn't initialized back correctly after the first loop
under the label inst_rollback gets executed.

The value of "i" is assigned to be option_count - 1, and the ensuing
loop (under alloc_rollback) begins by initializing i--.
Thus, the value of i when the loop begins execution will now become
i = option_count - 2.

Thus, when kfree(dst_opts[i]) is called in the second loop in this
order, (i.e., inst_rollback followed by alloc_rollback),
dst_optsp[option_count - 2] is the first element freed, and
dst_opts[option_count - 1] does not get freed, and thus, a memory
leak is caused.

This memory leak can be fixed, by assigning i = option_count (instead of
option_count - 1).

Fixes: 7842ca2e3bf3 ("team: add support for per-port options")
Reported-by: syzbot+69b804437cfec30deac3@syzkaller.appspotmail.com
Tested-by: syzbot+69b804437cfec30deac3@syzkaller.appspotmail.com
Signed-off-by: Anant Thazhemadam <anant.thazhemadam@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/team/team.c