Skip to contentSkip to conversation

team: Fix use-after-free when an option instance allocation fails

PATCH Applied Florent Revest 4 participants 6 messages Dec 6, 2023 – Dec 8, 2023

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 team: Fix use-after-free when an option instance allocation fails

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.

Fixes 80f7c6683fe0 ("team: add support for per-port options")
---
 drivers/net/team/team.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/net/team/team.c +3 -1
index 508d9a392ab18..f575f225d4178 100644
@@ -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:
Signature · 1 line
2.43.0.rc2.451.g8631bc7472-goog
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 11 lines · Wed, Dec 06, 2023 at 01:37:18PM CET, [email protected] wrote:

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.

Quoted 7 lines

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.

Fixes 80f7c6683fe0 ("team: add support for per-port options")

Thanks!

Reviewed-by on v1 1/1
#2 lore raw
In reply to Florent Revest
Quoted 41 lines · Florent Revest

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.

Fixes 80f7c6683fe0 ("team: add support for per-port options")
---
 drivers/net/team/team.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/net/team/team.c +3 -1
index 508d9a392ab18..f575f225d4178 100644
@@ -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:
Signature · 1 line
2.43.0.rc2.451.g8631bc7472-goog
#3 lore raw
Quoted 18 lines · Hangbin Liu
Quoted 16 lines · Florent Revest

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.

Quoted 4 lines
Quoted 2 lines
Fixes 80f7c6683fe0 ("team: add support for per-port options")

Thank you for the quick reviews Hangbin & Jiri, I appreciate! :)

I just realized I forgot to CC stable (like I always do... :) maybe I should tattoo it on my arm) Let me know if you'd like a v2 adding:

#4 lore raw
Quoted 6 lines · Florent Revest

Thank you for the quick reviews Hangbin & Jiri, I appreciate! :)

I just realized I forgot to CC stable (like I always do... :) maybe I should tattoo it on my arm) Let me know if you'd like a v2 adding:

I think Greg will take care of it. No need to send v2 when there is nothing to change.

Thanks
Hangbin

#5 lore raw
In reply to Florent Revest
This patch was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This patch was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:

Quoted 9 lines · On Wed, 6 Dec 2023 13:37:18 +0100 you wrote:

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.

[...]

Here is the summary with links:
- team: Fix use-after-free when an option instance allocation fails

    https://git.kernel.org/netdev/net/c/c12296bbecc4

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html