lkml.org 
[lkml]   [2020]   [Oct]   [12]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    From
    Subject[PATCH 4.14 51/70] net: team: fix memory leak in __team_options_register
    Date
    From: Anant Thazhemadam <anant.thazhemadam@gmail.com>

    commit 9a9e77495958c7382b2438bc19746dd3aaaabb8e upstream.

    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: 80f7c6683fe0 ("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>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

    ---
    drivers/net/team/team.c | 2 +-
    1 file changed, 1 insertion(+), 1 deletion(-)

    --- a/drivers/net/team/team.c
    +++ b/drivers/net/team/team.c
    @@ -299,7 +299,7 @@ inst_rollback:
    for (i--; i >= 0; i--)
    __team_option_inst_del_option(team, dst_opts[i]);

    - i = option_count - 1;
    + i = option_count;
    alloc_rollback:
    for (i--; i >= 0; i--)
    kfree(dst_opts[i]);

    \
     
     \ /
      Last update: 2020-10-12 16:10    [W:2.123 / U:0.128 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site