Skip to content

Commit 72f6e0e

Browse files
aguerinIntelherbertx
authored andcommitted
crypto: qat - add limit to linked list parsing
adf_copy_key_value_data() copies data from userland to kernel, based on a linked link provided by userland. If userland provides a circular list (or just a very long one) then it would drive a long loop where allocation occurs in every loop. This could lead to low memory conditions. Adding a limit to stop endless loop. Signed-off-by: Adam Guerin <[email protected]> Co-developed-by: Ciunas Bennett <[email protected]> Signed-off-by: Ciunas Bennett <[email protected]> Reviewed-by: Giovanni Cabiddu <[email protected]> Signed-off-by: Herbert Xu <[email protected]>
1 parent 0cb3c9c commit 72f6e0e

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

drivers/crypto/qat/qat_common/adf_ctl_drv.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
#include "adf_cfg_common.h"
1717
#include "adf_cfg_user.h"
1818

19+
#define ADF_CFG_MAX_SECTION 512
20+
#define ADF_CFG_MAX_KEY_VAL 256
21+
1922
#define DEVICE_NAME "qat_adf_ctl"
2023

2124
static DEFINE_MUTEX(adf_ctl_lock);
@@ -137,10 +140,11 @@ static int adf_copy_key_value_data(struct adf_accel_dev *accel_dev,
137140
struct adf_user_cfg_key_val key_val;
138141
struct adf_user_cfg_key_val *params_head;
139142
struct adf_user_cfg_section section, *section_head;
143+
int i, j;
140144

141145
section_head = ctl_data->config_section;
142146

143-
while (section_head) {
147+
for (i = 0; section_head && i < ADF_CFG_MAX_SECTION; i++) {
144148
if (copy_from_user(&section, (void __user *)section_head,
145149
sizeof(*section_head))) {
146150
dev_err(&GET_DEV(accel_dev),
@@ -156,7 +160,7 @@ static int adf_copy_key_value_data(struct adf_accel_dev *accel_dev,
156160

157161
params_head = section.params;
158162

159-
while (params_head) {
163+
for (j = 0; params_head && j < ADF_CFG_MAX_KEY_VAL; j++) {
160164
if (copy_from_user(&key_val, (void __user *)params_head,
161165
sizeof(key_val))) {
162166
dev_err(&GET_DEV(accel_dev),

0 commit comments

Comments
 (0)