Skip to content

Commit 5101645

Browse files
romank-msftliuw
authored andcommitted
Drivers: hv: Free msginfo when the buffer fails to decrypt
The early failure path in __vmbus_establish_gpadl() doesn't deallocate msginfo if the buffer fails to decrypt. Fix the leak by breaking out the cleanup code into a separate function and calling it where required. Fixes: d4dccf3 ("Drivers: hv: vmbus: Mark vmbus ring buffer visible to host in Isolation VM") Reported-by: Michael Kelley <mkhlinux@outlook.com> Closes: https://lore.kernel.org/linux-hyperv/SN6PR02MB41573796F9787F67E0E97049D472A@SN6PR02MB4157.namprd02.prod.outlook.com Signed-off-by: Roman Kisel <romank@linux.microsoft.com> Reviewed-by: Michael Kelley <mhklinux@outlook.com> Signed-off-by: Wei Liu <wei.liu@kernel.org>
1 parent 0a4534b commit 5101645

1 file changed

Lines changed: 18 additions & 6 deletions

File tree

drivers/hv/channel.c

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,21 @@ static int create_gpadl_header(enum hv_gpadl_type type, void *kbuffer,
410410
return 0;
411411
}
412412

413+
static void vmbus_free_channel_msginfo(struct vmbus_channel_msginfo *msginfo)
414+
{
415+
struct vmbus_channel_msginfo *submsginfo, *tmp;
416+
417+
if (!msginfo)
418+
return;
419+
420+
list_for_each_entry_safe(submsginfo, tmp, &msginfo->submsglist,
421+
msglistentry) {
422+
kfree(submsginfo);
423+
}
424+
425+
kfree(msginfo);
426+
}
427+
413428
/*
414429
* __vmbus_establish_gpadl - Establish a GPADL for a buffer or ringbuffer
415430
*
@@ -429,7 +444,7 @@ static int __vmbus_establish_gpadl(struct vmbus_channel *channel,
429444
struct vmbus_channel_gpadl_header *gpadlmsg;
430445
struct vmbus_channel_gpadl_body *gpadl_body;
431446
struct vmbus_channel_msginfo *msginfo = NULL;
432-
struct vmbus_channel_msginfo *submsginfo, *tmp;
447+
struct vmbus_channel_msginfo *submsginfo;
433448
struct list_head *curr;
434449
u32 next_gpadl_handle;
435450
unsigned long flags;
@@ -459,6 +474,7 @@ static int __vmbus_establish_gpadl(struct vmbus_channel *channel,
459474
dev_warn(&channel->device_obj->device,
460475
"Failed to set host visibility for new GPADL %d.\n",
461476
ret);
477+
vmbus_free_channel_msginfo(msginfo);
462478
return ret;
463479
}
464480
}
@@ -535,12 +551,8 @@ static int __vmbus_establish_gpadl(struct vmbus_channel *channel,
535551
spin_lock_irqsave(&vmbus_connection.channelmsg_lock, flags);
536552
list_del(&msginfo->msglistentry);
537553
spin_unlock_irqrestore(&vmbus_connection.channelmsg_lock, flags);
538-
list_for_each_entry_safe(submsginfo, tmp, &msginfo->submsglist,
539-
msglistentry) {
540-
kfree(submsginfo);
541-
}
542554

543-
kfree(msginfo);
555+
vmbus_free_channel_msginfo(msginfo);
544556

545557
if (ret) {
546558
/*

0 commit comments

Comments
 (0)