Skip to content

Commit 5ab982a

Browse files
vittyvkgregkh
authored andcommitted
Drivers: hv: don't leak memory in vmbus_establish_gpadl()
commit 7cc80c98070ccc7940fc28811c92cca0a681015d upstream. In some cases create_gpadl_header() allocates submessages but we never free them. [sumits] Note for stable: Upstream commit 4d63763296ab7865a98bc29cc7d77145815ef89f: (Drivers: hv: get rid of redundant messagecount in create_gpadl_header()) changes the list usage to initialize list header in all cases; that patch isn't added to stable, so the current patch is modified a little bit from the upstream commit to check if the list is valid or not. Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com> Signed-off-by: K. Y. Srinivasan <kys@microsoft.com> Signed-off-by: Sumit Semwal <sumit.semwal@linaro.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 702db97 commit 5ab982a

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

drivers/hv/channel.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
375375
struct vmbus_channel_gpadl_header *gpadlmsg;
376376
struct vmbus_channel_gpadl_body *gpadl_body;
377377
struct vmbus_channel_msginfo *msginfo = NULL;
378-
struct vmbus_channel_msginfo *submsginfo;
378+
struct vmbus_channel_msginfo *submsginfo, *tmp;
379379
u32 msgcount;
380380
struct list_head *curr;
381381
u32 next_gpadl_handle;
@@ -437,6 +437,13 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
437437
list_del(&msginfo->msglistentry);
438438
spin_unlock_irqrestore(&vmbus_connection.channelmsg_lock, flags);
439439

440+
if (msgcount > 1) {
441+
list_for_each_entry_safe(submsginfo, tmp, &msginfo->submsglist,
442+
msglistentry) {
443+
kfree(submsginfo);
444+
}
445+
}
446+
440447
kfree(msginfo);
441448
return ret;
442449
}

0 commit comments

Comments
 (0)