Skip to content

Commit 08b0c89

Browse files
Dan Carpenterthomashvmw
authored andcommitted
drm/vmwgfx: Fix double free in vmw_recv_msg()
We recently added a kfree() after the end of the loop: if (retries == RETRIES) { kfree(reply); return -EINVAL; } There are two problems. First the test is wrong and because retries equals RETRIES if we succeed on the last iteration through the loop. Second if we fail on the last iteration through the loop then the kfree is a double free. When you're reading this code, please note the break statement at the end of the while loop. This patch changes the loop so that if it's not successful then "reply" is NULL and we can test for that afterward. Cc: <[email protected]> Fixes: 6b7c3b8 ("drm/vmwgfx: fix memory leak when too many retries have occurred") Signed-off-by: Dan Carpenter <[email protected]> Reviewed-by: Thomas Hellstrom <[email protected]> Signed-off-by: Thomas Hellstrom <[email protected]>
1 parent 6b7c3b8 commit 08b0c89

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

drivers/gpu/drm/vmwgfx/vmwgfx_msg.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ static int vmw_recv_msg(struct rpc_channel *channel, void **msg,
353353
!!(HIGH_WORD(ecx) & MESSAGE_STATUS_HB));
354354
if ((HIGH_WORD(ebx) & MESSAGE_STATUS_SUCCESS) == 0) {
355355
kfree(reply);
356-
356+
reply = NULL;
357357
if ((HIGH_WORD(ebx) & MESSAGE_STATUS_CPT) != 0) {
358358
/* A checkpoint occurred. Retry. */
359359
continue;
@@ -377,7 +377,7 @@ static int vmw_recv_msg(struct rpc_channel *channel, void **msg,
377377

378378
if ((HIGH_WORD(ecx) & MESSAGE_STATUS_SUCCESS) == 0) {
379379
kfree(reply);
380-
380+
reply = NULL;
381381
if ((HIGH_WORD(ecx) & MESSAGE_STATUS_CPT) != 0) {
382382
/* A checkpoint occurred. Retry. */
383383
continue;
@@ -389,10 +389,8 @@ static int vmw_recv_msg(struct rpc_channel *channel, void **msg,
389389
break;
390390
}
391391

392-
if (retries == RETRIES) {
393-
kfree(reply);
392+
if (!reply)
394393
return -EINVAL;
395-
}
396394

397395
*msg_len = reply_len;
398396
*msg = reply;

0 commit comments

Comments
 (0)