Skip to content

Commit dd4542d

Browse files
committed
Merge branch 'linus' of git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6
Pull crypto fixes from Herbert Xu: - Fix missed wake-up race in padata - Use crypto_memneq in ccp - Fix version check in ccp - Fix fuzz test failure in ccp - Fix potential double free in crypto4xx - Fix compile warning in stm32 * 'linus' of git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6: padata: use smp_mb in padata_reorder to avoid orphaned padata jobs crypto: ccp - Fix SEV_VERSION_GREATER_OR_EQUAL crypto: ccp/gcm - use const time tag comparison. crypto: ccp - memset structure fields to zero before reuse crypto: crypto4xx - fix a potential double free in ppc4xx_trng_probe crypto: stm32/hash - Fix incorrect printk modifier for size_t
2 parents 40ef768 + cf144f8 commit dd4542d

File tree

5 files changed

+38
-11
lines changed

5 files changed

+38
-11
lines changed

drivers/crypto/amcc/crypto4xx_trng.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,6 @@ void ppc4xx_trng_probe(struct crypto4xx_core_device *core_dev)
108108
return;
109109

110110
err_out:
111-
of_node_put(trng);
112111
iounmap(dev->trng_base);
113112
kfree(rng);
114113
dev->trng_base = NULL;

drivers/crypto/ccp/ccp-ops.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,7 @@ static int ccp_run_aes_gcm_cmd(struct ccp_cmd_queue *cmd_q,
622622

623623
unsigned long long *final;
624624
unsigned int dm_offset;
625+
unsigned int jobid;
625626
unsigned int ilen;
626627
bool in_place = true; /* Default value */
627628
int ret;
@@ -660,9 +661,11 @@ static int ccp_run_aes_gcm_cmd(struct ccp_cmd_queue *cmd_q,
660661
p_tag = scatterwalk_ffwd(sg_tag, p_inp, ilen);
661662
}
662663

664+
jobid = CCP_NEW_JOBID(cmd_q->ccp);
665+
663666
memset(&op, 0, sizeof(op));
664667
op.cmd_q = cmd_q;
665-
op.jobid = CCP_NEW_JOBID(cmd_q->ccp);
668+
op.jobid = jobid;
666669
op.sb_key = cmd_q->sb_key; /* Pre-allocated */
667670
op.sb_ctx = cmd_q->sb_ctx; /* Pre-allocated */
668671
op.init = 1;
@@ -813,6 +816,13 @@ static int ccp_run_aes_gcm_cmd(struct ccp_cmd_queue *cmd_q,
813816
final[0] = cpu_to_be64(aes->aad_len * 8);
814817
final[1] = cpu_to_be64(ilen * 8);
815818

819+
memset(&op, 0, sizeof(op));
820+
op.cmd_q = cmd_q;
821+
op.jobid = jobid;
822+
op.sb_key = cmd_q->sb_key; /* Pre-allocated */
823+
op.sb_ctx = cmd_q->sb_ctx; /* Pre-allocated */
824+
op.init = 1;
825+
op.u.aes.type = aes->type;
816826
op.u.aes.mode = CCP_AES_MODE_GHASH;
817827
op.u.aes.action = CCP_AES_GHASHFINAL;
818828
op.src.type = CCP_MEMTYPE_SYSTEM;
@@ -840,7 +850,8 @@ static int ccp_run_aes_gcm_cmd(struct ccp_cmd_queue *cmd_q,
840850
if (ret)
841851
goto e_tag;
842852

843-
ret = memcmp(tag.address, final_wa.address, AES_BLOCK_SIZE);
853+
ret = crypto_memneq(tag.address, final_wa.address,
854+
AES_BLOCK_SIZE) ? -EBADMSG : 0;
844855
ccp_dm_free(&tag);
845856
}
846857

drivers/crypto/ccp/psp-dev.c

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,6 @@
2424
#include "sp-dev.h"
2525
#include "psp-dev.h"
2626

27-
#define SEV_VERSION_GREATER_OR_EQUAL(_maj, _min) \
28-
((psp_master->api_major) >= _maj && \
29-
(psp_master->api_minor) >= _min)
30-
3127
#define DEVICE_NAME "sev"
3228
#define SEV_FW_FILE "amd/sev.fw"
3329
#define SEV_FW_NAME_SIZE 64
@@ -47,6 +43,15 @@ MODULE_PARM_DESC(psp_probe_timeout, " default timeout value, in seconds, during
4743
static bool psp_dead;
4844
static int psp_timeout;
4945

46+
static inline bool sev_version_greater_or_equal(u8 maj, u8 min)
47+
{
48+
if (psp_master->api_major > maj)
49+
return true;
50+
if (psp_master->api_major == maj && psp_master->api_minor >= min)
51+
return true;
52+
return false;
53+
}
54+
5055
static struct psp_device *psp_alloc_struct(struct sp_device *sp)
5156
{
5257
struct device *dev = sp->dev;
@@ -588,7 +593,7 @@ static int sev_ioctl_do_get_id2(struct sev_issue_cmd *argp)
588593
int ret;
589594

590595
/* SEV GET_ID is available from SEV API v0.16 and up */
591-
if (!SEV_VERSION_GREATER_OR_EQUAL(0, 16))
596+
if (!sev_version_greater_or_equal(0, 16))
592597
return -ENOTSUPP;
593598

594599
if (copy_from_user(&input, (void __user *)argp->data, sizeof(input)))
@@ -651,7 +656,7 @@ static int sev_ioctl_do_get_id(struct sev_issue_cmd *argp)
651656
int ret;
652657

653658
/* SEV GET_ID available from SEV API v0.16 and up */
654-
if (!SEV_VERSION_GREATER_OR_EQUAL(0, 16))
659+
if (!sev_version_greater_or_equal(0, 16))
655660
return -ENOTSUPP;
656661

657662
/* SEV FW expects the buffer it fills with the ID to be
@@ -1053,7 +1058,7 @@ void psp_pci_init(void)
10531058
psp_master->sev_state = SEV_STATE_UNINIT;
10541059
}
10551060

1056-
if (SEV_VERSION_GREATER_OR_EQUAL(0, 15) &&
1061+
if (sev_version_greater_or_equal(0, 15) &&
10571062
sev_update_firmware(psp_master->dev) == 0)
10581063
sev_get_api_version();
10591064

drivers/crypto/stm32/stm32-hash.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ static int stm32_hash_xmit_cpu(struct stm32_hash_dev *hdev,
338338

339339
len32 = DIV_ROUND_UP(length, sizeof(u32));
340340

341-
dev_dbg(hdev->dev, "%s: length: %d, final: %x len32 %i\n",
341+
dev_dbg(hdev->dev, "%s: length: %zd, final: %x len32 %i\n",
342342
__func__, length, final, len32);
343343

344344
hdev->flags |= HASH_FLAGS_CPU;

kernel/padata.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,12 @@ static void padata_reorder(struct parallel_data *pd)
267267
* The next object that needs serialization might have arrived to
268268
* the reorder queues in the meantime, we will be called again
269269
* from the timer function if no one else cares for it.
270+
*
271+
* Ensure reorder_objects is read after pd->lock is dropped so we see
272+
* an increment from another task in padata_do_serial. Pairs with
273+
* smp_mb__after_atomic in padata_do_serial.
270274
*/
275+
smp_mb();
271276
if (atomic_read(&pd->reorder_objects)
272277
&& !(pinst->flags & PADATA_RESET))
273278
mod_timer(&pd->timer, jiffies + HZ);
@@ -387,6 +392,13 @@ void padata_do_serial(struct padata_priv *padata)
387392
list_add_tail(&padata->list, &pqueue->reorder.list);
388393
spin_unlock(&pqueue->reorder.lock);
389394

395+
/*
396+
* Ensure the atomic_inc of reorder_objects above is ordered correctly
397+
* with the trylock of pd->lock in padata_reorder. Pairs with smp_mb
398+
* in padata_reorder.
399+
*/
400+
smp_mb__after_atomic();
401+
390402
put_cpu();
391403

392404
/* If we're running on the wrong CPU, call padata_reorder() via a

0 commit comments

Comments
 (0)