|
1 | 1 | // SPDX-License-Identifier: (BSD-3-Clause OR GPL-2.0-only)
|
2 | 2 | /* Copyright(c) 2014 - 2020 Intel Corporation */
|
| 3 | +#include <linux/align.h> |
3 | 4 | #include <linux/slab.h>
|
4 | 5 | #include <linux/ctype.h>
|
5 | 6 | #include <linux/kernel.h>
|
@@ -1414,16 +1415,21 @@ static int qat_uclo_map_auth_fw(struct icp_qat_fw_loader_handle *handle,
|
1414 | 1415 | struct icp_qat_fw_auth_desc *auth_desc;
|
1415 | 1416 | struct icp_qat_auth_chunk *auth_chunk;
|
1416 | 1417 | u64 virt_addr, bus_addr, virt_base;
|
1417 |
| - unsigned int length, simg_offset = sizeof(*auth_chunk); |
| 1418 | + unsigned int simg_offset = sizeof(*auth_chunk); |
1418 | 1419 | struct icp_qat_simg_ae_mode *simg_ae_mode;
|
1419 | 1420 | struct icp_firml_dram_desc img_desc;
|
| 1421 | + int ret; |
1420 | 1422 |
|
1421 |
| - length = (css_hdr->fw_type == CSS_AE_FIRMWARE) ? |
1422 |
| - ICP_QAT_CSS_AE_SIMG_LEN(handle) + simg_offset : |
1423 |
| - size + ICP_QAT_CSS_FWSK_PAD_LEN(handle) + simg_offset; |
1424 |
| - if (qat_uclo_simg_alloc(handle, &img_desc, length)) { |
| 1423 | + ret = qat_uclo_simg_alloc(handle, &img_desc, ICP_QAT_CSS_RSA4K_MAX_IMAGE_LEN); |
| 1424 | + if (ret) { |
1425 | 1425 | pr_err("QAT: error, allocate continuous dram fail\n");
|
1426 |
| - return -ENOMEM; |
| 1426 | + return ret; |
| 1427 | + } |
| 1428 | + |
| 1429 | + if (!IS_ALIGNED(img_desc.dram_size, 8) || !img_desc.dram_bus_addr) { |
| 1430 | + pr_debug("QAT: invalid address\n"); |
| 1431 | + qat_uclo_simg_free(handle, &img_desc); |
| 1432 | + return -EINVAL; |
1427 | 1433 | }
|
1428 | 1434 |
|
1429 | 1435 | auth_chunk = img_desc.dram_base_addr_v;
|
@@ -1481,6 +1487,13 @@ static int qat_uclo_map_auth_fw(struct icp_qat_fw_loader_handle *handle,
|
1481 | 1487 | auth_desc->img_high = (unsigned int)(bus_addr >> BITS_IN_DWORD);
|
1482 | 1488 | auth_desc->img_low = (unsigned int)bus_addr;
|
1483 | 1489 | auth_desc->img_len = size - ICP_QAT_AE_IMG_OFFSET(handle);
|
| 1490 | + if (bus_addr + auth_desc->img_len > img_desc.dram_bus_addr + |
| 1491 | + ICP_QAT_CSS_RSA4K_MAX_IMAGE_LEN) { |
| 1492 | + pr_err("QAT: insufficient memory size for authentication data\n"); |
| 1493 | + qat_uclo_simg_free(handle, &img_desc); |
| 1494 | + return -ENOMEM; |
| 1495 | + } |
| 1496 | + |
1484 | 1497 | memcpy((void *)(uintptr_t)virt_addr,
|
1485 | 1498 | (void *)(image + ICP_QAT_AE_IMG_OFFSET(handle)),
|
1486 | 1499 | auth_desc->img_len);
|
|
0 commit comments