Skip to content

Commit c2d443a

Browse files
herbertxgregkh
authored andcommitted
crypto: qat - Fix ADF_DEV_RESET_SYNC memory leak
commit d3b17c6 upstream. Using completion_done to determine whether the caller has gone away only works after a complete call. Furthermore it's still possible that the caller has not yet called wait_for_completion, resulting in another potential UAF. Fix this by making the caller use cancel_work_sync and then freeing the memory safely. Fixes: 7d42e09 ("crypto: qat - resolve race condition during AER recovery") Cc: <[email protected]> #6.8+ Signed-off-by: Herbert Xu <[email protected]> Reviewed-by: Giovanni Cabiddu <[email protected]> Signed-off-by: Herbert Xu <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent d141043 commit c2d443a

File tree

1 file changed

+5
-14
lines changed

1 file changed

+5
-14
lines changed

drivers/crypto/intel/qat/qat_common/adf_aer.c

+5-14
Original file line numberDiff line numberDiff line change
@@ -92,25 +92,16 @@ static void adf_device_reset_worker(struct work_struct *work)
9292
if (adf_dev_restart(accel_dev)) {
9393
/* The device hanged and we can't restart it so stop here */
9494
dev_err(&GET_DEV(accel_dev), "Restart device failed\n");
95-
if (reset_data->mode == ADF_DEV_RESET_ASYNC ||
96-
completion_done(&reset_data->compl))
95+
if (reset_data->mode == ADF_DEV_RESET_ASYNC)
9796
kfree(reset_data);
9897
WARN(1, "QAT: device restart failed. Device is unusable\n");
9998
return;
10099
}
101100
adf_dev_restarted_notify(accel_dev);
102101
clear_bit(ADF_STATUS_RESTARTING, &accel_dev->status);
103102

104-
/*
105-
* The dev is back alive. Notify the caller if in sync mode
106-
*
107-
* If device restart will take a more time than expected,
108-
* the schedule_reset() function can timeout and exit. This can be
109-
* detected by calling the completion_done() function. In this case
110-
* the reset_data structure needs to be freed here.
111-
*/
112-
if (reset_data->mode == ADF_DEV_RESET_ASYNC ||
113-
completion_done(&reset_data->compl))
103+
/* The dev is back alive. Notify the caller if in sync mode */
104+
if (reset_data->mode == ADF_DEV_RESET_ASYNC)
114105
kfree(reset_data);
115106
else
116107
complete(&reset_data->compl);
@@ -145,10 +136,10 @@ static int adf_dev_aer_schedule_reset(struct adf_accel_dev *accel_dev,
145136
if (!timeout) {
146137
dev_err(&GET_DEV(accel_dev),
147138
"Reset device timeout expired\n");
139+
cancel_work_sync(&reset_data->reset_work);
148140
ret = -EFAULT;
149-
} else {
150-
kfree(reset_data);
151141
}
142+
kfree(reset_data);
152143
return ret;
153144
}
154145
return 0;

0 commit comments

Comments
 (0)