Skip to content

Commit 568c98a

Browse files
committed
Merge tag 'v6.10-p2' of git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6
Pull crypto fixes from Herbert Xu: "Fix a bug in the new ecc P521 code as well as a buggy fix in qat" * tag 'v6.10-p2' of git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6: crypto: ecc - Prevent ecc_digits_from_bytes from reading too many bytes crypto: qat - Fix ADF_DEV_RESET_SYNC memory leak
2 parents eb6a933 + c6ab5c9 commit 568c98a

File tree

3 files changed

+29
-27
lines changed

3 files changed

+29
-27
lines changed

crypto/ecc.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,28 @@ const struct ecc_curve *ecc_get_curve(unsigned int curve_id)
6868
}
6969
EXPORT_SYMBOL(ecc_get_curve);
7070

71+
void ecc_digits_from_bytes(const u8 *in, unsigned int nbytes,
72+
u64 *out, unsigned int ndigits)
73+
{
74+
int diff = ndigits - DIV_ROUND_UP(nbytes, sizeof(u64));
75+
unsigned int o = nbytes & 7;
76+
__be64 msd = 0;
77+
78+
/* diff > 0: not enough input bytes: set most significant digits to 0 */
79+
if (diff > 0) {
80+
ndigits -= diff;
81+
memset(&out[ndigits - 1], 0, diff * sizeof(u64));
82+
}
83+
84+
if (o) {
85+
memcpy((u8 *)&msd + sizeof(msd) - o, in, o);
86+
out[--ndigits] = be64_to_cpu(msd);
87+
in += o;
88+
}
89+
ecc_swap_digits(in, out, ndigits);
90+
}
91+
EXPORT_SYMBOL(ecc_digits_from_bytes);
92+
7193
static u64 *ecc_alloc_digits_space(unsigned int ndigits)
7294
{
7395
size_t len = ndigits * sizeof(u64);

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

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,7 @@ static void adf_device_reset_worker(struct work_struct *work)
130130
if (adf_dev_restart(accel_dev)) {
131131
/* The device hanged and we can't restart it so stop here */
132132
dev_err(&GET_DEV(accel_dev), "Restart device failed\n");
133-
if (reset_data->mode == ADF_DEV_RESET_ASYNC ||
134-
completion_done(&reset_data->compl))
133+
if (reset_data->mode == ADF_DEV_RESET_ASYNC)
135134
kfree(reset_data);
136135
WARN(1, "QAT: device restart failed. Device is unusable\n");
137136
return;
@@ -147,16 +146,8 @@ static void adf_device_reset_worker(struct work_struct *work)
147146
adf_dev_restarted_notify(accel_dev);
148147
clear_bit(ADF_STATUS_RESTARTING, &accel_dev->status);
149148

150-
/*
151-
* The dev is back alive. Notify the caller if in sync mode
152-
*
153-
* If device restart will take a more time than expected,
154-
* the schedule_reset() function can timeout and exit. This can be
155-
* detected by calling the completion_done() function. In this case
156-
* the reset_data structure needs to be freed here.
157-
*/
158-
if (reset_data->mode == ADF_DEV_RESET_ASYNC ||
159-
completion_done(&reset_data->compl))
149+
/* The dev is back alive. Notify the caller if in sync mode */
150+
if (reset_data->mode == ADF_DEV_RESET_ASYNC)
160151
kfree(reset_data);
161152
else
162153
complete(&reset_data->compl);
@@ -191,10 +182,10 @@ static int adf_dev_aer_schedule_reset(struct adf_accel_dev *accel_dev,
191182
if (!timeout) {
192183
dev_err(&GET_DEV(accel_dev),
193184
"Reset device timeout expired\n");
185+
cancel_work_sync(&reset_data->reset_work);
194186
ret = -EFAULT;
195-
} else {
196-
kfree(reset_data);
197187
}
188+
kfree(reset_data);
198189
return ret;
199190
}
200191
return 0;

include/crypto/internal/ecc.h

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -64,19 +64,8 @@ static inline void ecc_swap_digits(const void *in, u64 *out, unsigned int ndigit
6464
* @out Output digits array
6565
* @ndigits: Number of digits to create from byte array
6666
*/
67-
static inline void ecc_digits_from_bytes(const u8 *in, unsigned int nbytes,
68-
u64 *out, unsigned int ndigits)
69-
{
70-
unsigned int o = nbytes & 7;
71-
__be64 msd = 0;
72-
73-
if (o) {
74-
memcpy((u8 *)&msd + sizeof(msd) - o, in, o);
75-
out[--ndigits] = be64_to_cpu(msd);
76-
in += o;
77-
}
78-
ecc_swap_digits(in, out, ndigits);
79-
}
67+
void ecc_digits_from_bytes(const u8 *in, unsigned int nbytes,
68+
u64 *out, unsigned int ndigits);
8069

8170
/**
8271
* ecc_is_key_valid() - Validate a given ECDH private key

0 commit comments

Comments
 (0)