2021-04-01 17:53:50

by Lv Yunlong

[permalink] [raw]
Subject: [PATCH] drbd: Fix a use after free in get_initial_state

In get_initial_state, it calls notify_initial_state_done(skb,..) if
cb->args[5]==1. I see that if genlmsg_put() failed in
notify_initial_state_done(), the skb will be freed by nlmsg_free(skb).
Then get_initial_state will goto out and the freed skb will be used by
return value skb->len.

My patch lets skb_len = skb->len and return the skb_len to avoid the uaf.

Fixes: a29728463b254 ("drbd: Backport the "events2" command")
Signed-off-by: Lv Yunlong <[email protected]>
---
drivers/block/drbd/drbd_nl.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
index bf7de4c7b96c..474f84675d0a 100644
--- a/drivers/block/drbd/drbd_nl.c
+++ b/drivers/block/drbd/drbd_nl.c
@@ -4905,6 +4905,7 @@ static int get_initial_state(struct sk_buff *skb, struct netlink_callback *cb)
struct drbd_state_change *state_change = (struct drbd_state_change *)cb->args[0];
unsigned int seq = cb->args[2];
unsigned int n;
+ unsigned int skb_len = skb->len;
enum drbd_notification_type flags = 0;

/* There is no need for taking notification_mutex here: it doesn't
@@ -4915,7 +4916,7 @@ static int get_initial_state(struct sk_buff *skb, struct netlink_callback *cb)
cb->args[5]--;
if (cb->args[5] == 1) {
notify_initial_state_done(skb, seq);
- goto out;
+ return skb_len;
}
n = cb->args[4]++;
if (cb->args[4] < cb->args[3])
--
2.25.1



2021-04-01 18:33:25

by Christoph Böhmwalder

[permalink] [raw]
Subject: Re: [Drbd-dev] [PATCH] drbd: Fix a use after free in get_initial_state

On 4/1/21 1:57 PM, Lv Yunlong wrote:
> In get_initial_state, it calls notify_initial_state_done(skb,..) if
> cb->args[5]==1. I see that if genlmsg_put() failed in
> notify_initial_state_done(), the skb will be freed by nlmsg_free(skb).
> Then get_initial_state will goto out and the freed skb will be used by
> return value skb->len.
>
> My patch lets skb_len = skb->len and return the skb_len to avoid the uaf.
>
> Fixes: a29728463b254 ("drbd: Backport the "events2" command")
> Signed-off-by: Lv Yunlong <[email protected]>
> ---
> drivers/block/drbd/drbd_nl.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
> index bf7de4c7b96c..474f84675d0a 100644
> --- a/drivers/block/drbd/drbd_nl.c
> +++ b/drivers/block/drbd/drbd_nl.c
> @@ -4905,6 +4905,7 @@ static int get_initial_state(struct sk_buff *skb, struct netlink_callback *cb)
> struct drbd_state_change *state_change = (struct drbd_state_change *)cb->args[0];
> unsigned int seq = cb->args[2];
> unsigned int n;
> + unsigned int skb_len = skb->len;
> enum drbd_notification_type flags = 0;
>
> /* There is no need for taking notification_mutex here: it doesn't
> @@ -4915,7 +4916,7 @@ static int get_initial_state(struct sk_buff *skb, struct netlink_callback *cb)
> cb->args[5]--;
> if (cb->args[5] == 1) {
> notify_initial_state_done(skb, seq);
> - goto out;
> + return skb_len;
> }
> n = cb->args[4]++;
> if (cb->args[4] < cb->args[3])
>

Thanks for the patch!

I think the problem goes even further: skb can also be freed in the
notify_*_state_change -> notify_*_state calls below.

Also, at the point where we save skb->len into skb_len, skb is not
initialized yet. Maybe it makes more sense to not return a length in the
first place here, but an error code instead.

--
Christoph Böhmwalder
LINBIT | Keeping the Digital World Running
DRBD HA — Disaster Recovery — Software defined Storage

2021-04-02 05:11:57

by Chen, Rong A

[permalink] [raw]
Subject: Re: [PATCH] drbd: Fix a use after free in get_initial_state

_______________________________________________
kbuild mailing list -- [email protected]
To unsubscribe send an email to [email protected]


Attachments:
(No filename) (15.33 kB)
.config.gz (40.73 kB)
(No filename) (152.00 B)
Download all attachments