Skip to content

Commit 483fd65

Browse files
pilotAlpalherbertx
authored andcommitted
crypto: qat - validate slices count returned by FW
The function adf_send_admin_tl_start() enables the telemetry (TL) feature on a QAT device by sending the ICP_QAT_FW_TL_START message to the firmware. This triggers the FW to start writing TL data to a DMA buffer in memory and returns an array containing the number of accelerators of each type (slices) supported by this HW. The pointer to this array is stored in the adf_tl_hw_data data structure called slice_cnt. The array slice_cnt is then used in the function tl_print_dev_data() to report in debugfs only statistics about the supported accelerators. An incorrect value of the elements in slice_cnt might lead to an out of bounds memory read. At the moment, there isn't an implementation of FW that returns a wrong value, but for robustness validate the slice count array returned by FW. Fixes: 69e7649 ("crypto: qat - add support for device telemetry") Signed-off-by: Lucas Segarra Fernandez <[email protected]> Reviewed-by: Damian Muszynski <[email protected]> Reviewed-by: Giovanni Cabiddu <[email protected]> Signed-off-by: Herbert Xu <[email protected]>
1 parent 23e4099 commit 483fd65

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,5 +149,6 @@ void adf_gen4_init_tl_data(struct adf_tl_hw_data *tl_data)
149149
tl_data->sl_exec_counters = sl_exec_counters;
150150
tl_data->rp_counters = rp_counters;
151151
tl_data->num_rp_counters = ARRAY_SIZE(rp_counters);
152+
tl_data->max_sl_cnt = ADF_GEN4_TL_MAX_SLICES_PER_TYPE;
152153
}
153154
EXPORT_SYMBOL_GPL(adf_gen4_init_tl_data);

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,20 @@ static int validate_tl_data(struct adf_tl_hw_data *tl_data)
4141
return 0;
4242
}
4343

44+
static int validate_tl_slice_counters(struct icp_qat_fw_init_admin_slice_cnt *slice_count,
45+
u8 max_slices_per_type)
46+
{
47+
u8 *sl_counter = (u8 *)slice_count;
48+
int i;
49+
50+
for (i = 0; i < ADF_TL_SL_CNT_COUNT; i++) {
51+
if (sl_counter[i] > max_slices_per_type)
52+
return -EINVAL;
53+
}
54+
55+
return 0;
56+
}
57+
4458
static int adf_tl_alloc_mem(struct adf_accel_dev *accel_dev)
4559
{
4660
struct adf_tl_hw_data *tl_data = &GET_TL_DATA(accel_dev);
@@ -214,6 +228,13 @@ int adf_tl_run(struct adf_accel_dev *accel_dev, int state)
214228
return ret;
215229
}
216230

231+
ret = validate_tl_slice_counters(&telemetry->slice_cnt, tl_data->max_sl_cnt);
232+
if (ret) {
233+
dev_err(dev, "invalid value returned by FW\n");
234+
adf_send_admin_tl_stop(accel_dev);
235+
return ret;
236+
}
237+
217238
telemetry->hbuffs = state;
218239
atomic_set(&telemetry->state, state);
219240

drivers/crypto/intel/qat/qat_common/adf_telemetry.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ struct adf_tl_hw_data {
4040
u8 num_dev_counters;
4141
u8 num_rp_counters;
4242
u8 max_rp;
43+
u8 max_sl_cnt;
4344
};
4445

4546
struct adf_telemetry {

0 commit comments

Comments
 (0)