Skip to content

Commit

Permalink
team: Fix use-after-free when an option instance allocation fails
Browse files Browse the repository at this point in the history
In __team_options_register, team_options are allocated and appended to
the team's option_list.
If one option instance allocation fails, the "inst_rollback" cleanup
path frees the previously allocated options but doesn't remove them from
the team's option_list.
This leaves dangling pointers that can be dereferenced later by other
parts of the team driver that iterate over options.

This patch fixes the cleanup path to remove the dangling pointers from
the list.

As far as I can tell, this uaf doesn't have much security implications
since it would be fairly hard to exploit (an attacker would need to make
the allocation of that specific small object fail) but it's still nice
to fix.

Cc: [email protected]
Fixes: 80f7c66 ("team: add support for per-port options")
Signed-off-by: Florent Revest <[email protected]>
Reviewed-by: Jiri Pirko <[email protected]>
Reviewed-by: Hangbin Liu <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Jakub Kicinski <[email protected]>
  • Loading branch information
FlorentRevest authored and kuba-moo committed Dec 8, 2023
1 parent bd4a816 commit c12296b
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion drivers/net/team/team.c
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,10 @@ static int __team_options_register(struct team *team,
return 0;

inst_rollback:
for (i--; i >= 0; i--)
for (i--; i >= 0; i--) {
__team_option_inst_del_option(team, dst_opts[i]);
list_del(&dst_opts[i]->list);
}

i = option_count;
alloc_rollback:
Expand Down

0 comments on commit c12296b

Please sign in to comment.