netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] team: Fix use-after-free when an option instance allocation fails
@ 2023-12-06 12:37 Florent Revest
  2023-12-06 13:21 ` Jiri Pirko
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Florent Revest @ 2023-12-06 12:37 UTC (permalink / raw)
  To: netdev, linux-kernel; +Cc: jiri, davem, edumazet, kuba, pabeni, 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")
Signed-off-by: Florent Revest <revest@chromium.org>
---
 drivers/net/team/team.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c
index 508d9a392ab18..f575f225d4178 100644
--- a/drivers/net/team/team.c
+++ b/drivers/net/team/team.c
@@ -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:
-- 
2.43.0.rc2.451.g8631bc7472-goog


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] team: Fix use-after-free when an option instance allocation fails
  2023-12-06 12:37 [PATCH] team: Fix use-after-free when an option instance allocation fails Florent Revest
@ 2023-12-06 13:21 ` Jiri Pirko
  2023-12-06 15:05 ` Hangbin Liu
  2023-12-08 18:50 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 6+ messages in thread
From: Jiri Pirko @ 2023-12-06 13:21 UTC (permalink / raw)
  To: Florent Revest; +Cc: netdev, linux-kernel, davem, edumazet, kuba, pabeni

Wed, Dec 06, 2023 at 01:37:18PM CET, revest@chromium.org 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.
>
>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")
>Signed-off-by: Florent Revest <revest@chromium.org>

Reviewed-by: Jiri Pirko <jiri@nvidia.com>

Thanks!

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] team: Fix use-after-free when an option instance allocation fails
  2023-12-06 12:37 [PATCH] team: Fix use-after-free when an option instance allocation fails Florent Revest
  2023-12-06 13:21 ` Jiri Pirko
@ 2023-12-06 15:05 ` Hangbin Liu
  2023-12-06 16:31   ` Florent Revest
  2023-12-08 18:50 ` patchwork-bot+netdevbpf
  2 siblings, 1 reply; 6+ messages in thread
From: Hangbin Liu @ 2023-12-06 15:05 UTC (permalink / raw)
  To: Florent Revest; +Cc: netdev, linux-kernel, jiri, davem, edumazet, kuba, pabeni

On Wed, Dec 06, 2023 at 01:37:18PM +0100, Florent Revest 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.
> 
> 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")
> Signed-off-by: Florent Revest <revest@chromium.org>
> ---
>  drivers/net/team/team.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c
> index 508d9a392ab18..f575f225d4178 100644
> --- a/drivers/net/team/team.c
> +++ b/drivers/net/team/team.c
> @@ -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:
> -- 
> 2.43.0.rc2.451.g8631bc7472-goog
> 

Reviewed-by: Hangbin Liu <liuhangbin@gmail.com>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] team: Fix use-after-free when an option instance allocation fails
  2023-12-06 15:05 ` Hangbin Liu
@ 2023-12-06 16:31   ` Florent Revest
  2023-12-07  1:02     ` Hangbin Liu
  0 siblings, 1 reply; 6+ messages in thread
From: Florent Revest @ 2023-12-06 16:31 UTC (permalink / raw)
  To: Hangbin Liu
  Cc: netdev, linux-kernel, jiri, davem, edumazet, kuba, pabeni, stable

On Wed, Dec 6, 2023 at 4:05 PM Hangbin Liu <liuhangbin@gmail.com> wrote:
>
> On Wed, Dec 06, 2023 at 01:37:18PM +0100, Florent Revest 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.
> >
> > 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")
> > Signed-off-by: Florent Revest <revest@chromium.org>
>
> Reviewed-by: Hangbin Liu <liuhangbin@gmail.com>

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:

Cc: stable@vger.kernel.org

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] team: Fix use-after-free when an option instance allocation fails
  2023-12-06 16:31   ` Florent Revest
@ 2023-12-07  1:02     ` Hangbin Liu
  0 siblings, 0 replies; 6+ messages in thread
From: Hangbin Liu @ 2023-12-07  1:02 UTC (permalink / raw)
  To: Florent Revest
  Cc: netdev, linux-kernel, jiri, davem, edumazet, kuba, pabeni, stable

On Wed, Dec 06, 2023 at 05:31:58PM +0100, Florent Revest wrote:
> 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:
> 
> Cc: stable@vger.kernel.org

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

Thanks
Hangbin

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] team: Fix use-after-free when an option instance allocation fails
  2023-12-06 12:37 [PATCH] team: Fix use-after-free when an option instance allocation fails Florent Revest
  2023-12-06 13:21 ` Jiri Pirko
  2023-12-06 15:05 ` Hangbin Liu
@ 2023-12-08 18:50 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 6+ messages in thread
From: patchwork-bot+netdevbpf @ 2023-12-08 18:50 UTC (permalink / raw)
  To: Florent Revest; +Cc: netdev, linux-kernel, jiri, davem, edumazet, kuba, pabeni

Hello:

This patch was applied to netdev/net.git (main)
by Jakub Kicinski <kuba@kernel.org>:

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!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2023-12-08 18:50 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-12-06 12:37 [PATCH] team: Fix use-after-free when an option instance allocation fails Florent Revest
2023-12-06 13:21 ` Jiri Pirko
2023-12-06 15:05 ` Hangbin Liu
2023-12-06 16:31   ` Florent Revest
2023-12-07  1:02     ` Hangbin Liu
2023-12-08 18:50 ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).