All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] drbd: Fix a use after free in get_initial_state
@ 2021-04-01 11:57 Lv Yunlong
  2021-04-01 13:01 ` [Drbd-dev] " Christoph Böhmwalder
  2021-04-02  5:09   ` kernel test robot
  0 siblings, 2 replies; 6+ messages in thread
From: Lv Yunlong @ 2021-04-01 11:57 UTC (permalink / raw)
  To: philipp.reisner, lars.ellenberg, axboe
  Cc: drbd-dev, linux-block, linux-kernel, Lv Yunlong

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 <lyl2019@mail.ustc.edu.cn>
---
 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



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

end of thread, other threads:[~2021-04-02  5:10 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-01 11:57 [PATCH] drbd: Fix a use after free in get_initial_state Lv Yunlong
2021-04-01 13:01 ` [Drbd-dev] " Christoph Böhmwalder
2021-04-01 15:13   ` lyl2019
2021-04-01 15:17     ` lyl2019
2021-04-02  5:09 ` kernel test robot
2021-04-02  5:09   ` kernel test robot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.