summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2019-07-19 15:23:37 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2019-07-19 15:23:37 -0400
commitdd4542d2823ac55cb86450960423f55e818aa182 (patch)
tree6f8a8a2b939fd1ce6088a707948125ba63bb2151
parent40ef768ab6eecc1b51461a034274350b31fc29d1 (diff)
parentcf144f81a99d1a3928f90b0936accfd3f45c9a0a (diff)
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
-rw-r--r--drivers/crypto/amcc/crypto4xx_trng.c1
-rw-r--r--drivers/crypto/ccp/ccp-ops.c15
-rw-r--r--drivers/crypto/ccp/psp-dev.c19
-rw-r--r--drivers/crypto/stm32/stm32-hash.c2
-rw-r--r--kernel/padata.c12
5 files changed, 38 insertions, 11 deletions
diff --git a/drivers/crypto/amcc/crypto4xx_trng.c b/drivers/crypto/amcc/crypto4xx_trng.c
index 02a6bed3b062..f10a87e541ed 100644
--- a/drivers/crypto/amcc/crypto4xx_trng.c
+++ b/drivers/crypto/amcc/crypto4xx_trng.c
@@ -108,7 +108,6 @@ void ppc4xx_trng_probe(struct crypto4xx_core_device *core_dev)
108 return; 108 return;
109 109
110err_out: 110err_out:
111 of_node_put(trng);
112 iounmap(dev->trng_base); 111 iounmap(dev->trng_base);
113 kfree(rng); 112 kfree(rng);
114 dev->trng_base = NULL; 113 dev->trng_base = NULL;
diff --git a/drivers/crypto/ccp/ccp-ops.c b/drivers/crypto/ccp/ccp-ops.c
index 866b2e05ca77..c69ed4bae2eb 100644
--- a/drivers/crypto/ccp/ccp-ops.c
+++ b/drivers/crypto/ccp/ccp-ops.c
@@ -622,6 +622,7 @@ static int ccp_run_aes_gcm_cmd(struct ccp_cmd_queue *cmd_q,
622 622
623 unsigned long long *final; 623 unsigned long long *final;
624 unsigned int dm_offset; 624 unsigned int dm_offset;
625 unsigned int jobid;
625 unsigned int ilen; 626 unsigned int ilen;
626 bool in_place = true; /* Default value */ 627 bool in_place = true; /* Default value */
627 int ret; 628 int ret;
@@ -660,9 +661,11 @@ static int ccp_run_aes_gcm_cmd(struct ccp_cmd_queue *cmd_q,
660 p_tag = scatterwalk_ffwd(sg_tag, p_inp, ilen); 661 p_tag = scatterwalk_ffwd(sg_tag, p_inp, ilen);
661 } 662 }
662 663
664 jobid = CCP_NEW_JOBID(cmd_q->ccp);
665
663 memset(&op, 0, sizeof(op)); 666 memset(&op, 0, sizeof(op));
664 op.cmd_q = cmd_q; 667 op.cmd_q = cmd_q;
665 op.jobid = CCP_NEW_JOBID(cmd_q->ccp); 668 op.jobid = jobid;
666 op.sb_key = cmd_q->sb_key; /* Pre-allocated */ 669 op.sb_key = cmd_q->sb_key; /* Pre-allocated */
667 op.sb_ctx = cmd_q->sb_ctx; /* Pre-allocated */ 670 op.sb_ctx = cmd_q->sb_ctx; /* Pre-allocated */
668 op.init = 1; 671 op.init = 1;
@@ -813,6 +816,13 @@ static int ccp_run_aes_gcm_cmd(struct ccp_cmd_queue *cmd_q,
813 final[0] = cpu_to_be64(aes->aad_len * 8); 816 final[0] = cpu_to_be64(aes->aad_len * 8);
814 final[1] = cpu_to_be64(ilen * 8); 817 final[1] = cpu_to_be64(ilen * 8);
815 818
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;
816 op.u.aes.mode = CCP_AES_MODE_GHASH; 826 op.u.aes.mode = CCP_AES_MODE_GHASH;
817 op.u.aes.action = CCP_AES_GHASHFINAL; 827 op.u.aes.action = CCP_AES_GHASHFINAL;
818 op.src.type = CCP_MEMTYPE_SYSTEM; 828 op.src.type = CCP_MEMTYPE_SYSTEM;
@@ -840,7 +850,8 @@ static int ccp_run_aes_gcm_cmd(struct ccp_cmd_queue *cmd_q,
840 if (ret) 850 if (ret)
841 goto e_tag; 851 goto e_tag;
842 852
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;
844 ccp_dm_free(&tag); 855 ccp_dm_free(&tag);
845 } 856 }
846 857
diff --git a/drivers/crypto/ccp/psp-dev.c b/drivers/crypto/ccp/psp-dev.c
index de5a8ca70d3d..6b17d179ef8a 100644
--- a/drivers/crypto/ccp/psp-dev.c
+++ b/drivers/crypto/ccp/psp-dev.c
@@ -24,10 +24,6 @@
24#include "sp-dev.h" 24#include "sp-dev.h"
25#include "psp-dev.h" 25#include "psp-dev.h"
26 26
27#define SEV_VERSION_GREATER_OR_EQUAL(_maj, _min) \
28 ((psp_master->api_major) >= _maj && \
29 (psp_master->api_minor) >= _min)
30
31#define DEVICE_NAME "sev" 27#define DEVICE_NAME "sev"
32#define SEV_FW_FILE "amd/sev.fw" 28#define SEV_FW_FILE "amd/sev.fw"
33#define SEV_FW_NAME_SIZE 64 29#define SEV_FW_NAME_SIZE 64
@@ -47,6 +43,15 @@ MODULE_PARM_DESC(psp_probe_timeout, " default timeout value, in seconds, during
47static bool psp_dead; 43static bool psp_dead;
48static int psp_timeout; 44static int psp_timeout;
49 45
46static 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
50static struct psp_device *psp_alloc_struct(struct sp_device *sp) 55static struct psp_device *psp_alloc_struct(struct sp_device *sp)
51{ 56{
52 struct device *dev = sp->dev; 57 struct device *dev = sp->dev;
@@ -588,7 +593,7 @@ static int sev_ioctl_do_get_id2(struct sev_issue_cmd *argp)
588 int ret; 593 int ret;
589 594
590 /* SEV GET_ID is available from SEV API v0.16 and up */ 595 /* 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))
592 return -ENOTSUPP; 597 return -ENOTSUPP;
593 598
594 if (copy_from_user(&input, (void __user *)argp->data, sizeof(input))) 599 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)
651 int ret; 656 int ret;
652 657
653 /* SEV GET_ID available from SEV API v0.16 and up */ 658 /* 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))
655 return -ENOTSUPP; 660 return -ENOTSUPP;
656 661
657 /* SEV FW expects the buffer it fills with the ID to be 662 /* SEV FW expects the buffer it fills with the ID to be
@@ -1053,7 +1058,7 @@ void psp_pci_init(void)
1053 psp_master->sev_state = SEV_STATE_UNINIT; 1058 psp_master->sev_state = SEV_STATE_UNINIT;
1054 } 1059 }
1055 1060
1056 if (SEV_VERSION_GREATER_OR_EQUAL(0, 15) && 1061 if (sev_version_greater_or_equal(0, 15) &&
1057 sev_update_firmware(psp_master->dev) == 0) 1062 sev_update_firmware(psp_master->dev) == 0)
1058 sev_get_api_version(); 1063 sev_get_api_version();
1059 1064
diff --git a/drivers/crypto/stm32/stm32-hash.c b/drivers/crypto/stm32/stm32-hash.c
index 23061f2bc74b..2b70d8796f25 100644
--- a/drivers/crypto/stm32/stm32-hash.c
+++ b/drivers/crypto/stm32/stm32-hash.c
@@ -338,7 +338,7 @@ static int stm32_hash_xmit_cpu(struct stm32_hash_dev *hdev,
338 338
339 len32 = DIV_ROUND_UP(length, sizeof(u32)); 339 len32 = DIV_ROUND_UP(length, sizeof(u32));
340 340
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",
342 __func__, length, final, len32); 342 __func__, length, final, len32);
343 343
344 hdev->flags |= HASH_FLAGS_CPU; 344 hdev->flags |= HASH_FLAGS_CPU;
diff --git a/kernel/padata.c b/kernel/padata.c
index 2d2fddbb7a4c..15a8ad63f4ff 100644
--- a/kernel/padata.c
+++ b/kernel/padata.c
@@ -267,7 +267,12 @@ static void padata_reorder(struct parallel_data *pd)
267 * The next object that needs serialization might have arrived to 267 * The next object that needs serialization might have arrived to
268 * the reorder queues in the meantime, we will be called again 268 * the reorder queues in the meantime, we will be called again
269 * from the timer function if no one else cares for it. 269 * 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.
270 */ 274 */
275 smp_mb();
271 if (atomic_read(&pd->reorder_objects) 276 if (atomic_read(&pd->reorder_objects)
272 && !(pinst->flags & PADATA_RESET)) 277 && !(pinst->flags & PADATA_RESET))
273 mod_timer(&pd->timer, jiffies + HZ); 278 mod_timer(&pd->timer, jiffies + HZ);
@@ -387,6 +392,13 @@ void padata_do_serial(struct padata_priv *padata)
387 list_add_tail(&padata->list, &pqueue->reorder.list); 392 list_add_tail(&padata->list, &pqueue->reorder.list);
388 spin_unlock(&pqueue->reorder.lock); 393 spin_unlock(&pqueue->reorder.lock);
389 394
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
390 put_cpu(); 402 put_cpu();
391 403
392 /* If we're running on the wrong CPU, call padata_reorder() via a 404 /* If we're running on the wrong CPU, call padata_reorder() via a