Merge branch 'linus' of git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6
authorLinus Torvalds <torvalds@linux-foundation.org>
Fri, 19 Jul 2019 19:23:37 +0000 (12:23 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Fri, 19 Jul 2019 19:23:37 +0000 (12:23 -0700)
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

1  2 
drivers/crypto/amcc/crypto4xx_trng.c
drivers/crypto/ccp/ccp-ops.c
drivers/crypto/ccp/psp-dev.c
drivers/crypto/stm32/stm32-hash.c

index 02a6bed3b062d591d759ba762c3acbfbaaacfd2a,8a3ed40312061f9e877c2219602a177a3491d5a0..f10a87e541edaaf5ffc7edeeb9c5a366c6134886
@@@ -1,8 -1,11 +1,8 @@@
 +// SPDX-License-Identifier: GPL-2.0-only
  /*
   * Generic PowerPC 44x RNG driver
   *
   * Copyright 2011 IBM Corporation
 - *
 - * This program is free software; you can redistribute it and/or modify it
 - * under the terms of the GNU General Public License as published by the
 - * Free Software Foundation; version 2 of the License.
   */
  
  #include <linux/module.h>
@@@ -108,7 -111,6 +108,6 @@@ void ppc4xx_trng_probe(struct crypto4xx
        return;
  
  err_out:
-       of_node_put(trng);
        iounmap(dev->trng_base);
        kfree(rng);
        dev->trng_base = NULL;
index 866b2e05ca775602568f437007742b9fa4364e43,3ebe031773d56842aa4640303fc3c3b121fac2d8..c69ed4bae2eb1045dfab71f0f884954756cde4f1
@@@ -1,4 -1,4 +1,4 @@@
 -// SPDX-License-Identifier: GPL-2.0
 +// SPDX-License-Identifier: GPL-2.0-only
  /*
   * AMD Cryptographic Coprocessor (CCP) driver
   *
@@@ -622,6 -622,7 +622,7 @@@ static int ccp_run_aes_gcm_cmd(struct c
  
        unsigned long long *final;
        unsigned int dm_offset;
+       unsigned int jobid;
        unsigned int ilen;
        bool in_place = true; /* Default value */
        int ret;
                p_tag = scatterwalk_ffwd(sg_tag, p_inp, ilen);
        }
  
+       jobid = CCP_NEW_JOBID(cmd_q->ccp);
        memset(&op, 0, sizeof(op));
        op.cmd_q = cmd_q;
-       op.jobid = CCP_NEW_JOBID(cmd_q->ccp);
+       op.jobid = jobid;
        op.sb_key = cmd_q->sb_key; /* Pre-allocated */
        op.sb_ctx = cmd_q->sb_ctx; /* Pre-allocated */
        op.init = 1;
        final[0] = cpu_to_be64(aes->aad_len * 8);
        final[1] = cpu_to_be64(ilen * 8);
  
+       memset(&op, 0, sizeof(op));
+       op.cmd_q = cmd_q;
+       op.jobid = jobid;
+       op.sb_key = cmd_q->sb_key; /* Pre-allocated */
+       op.sb_ctx = cmd_q->sb_ctx; /* Pre-allocated */
+       op.init = 1;
+       op.u.aes.type = aes->type;
        op.u.aes.mode = CCP_AES_MODE_GHASH;
        op.u.aes.action = CCP_AES_GHASHFINAL;
        op.src.type = CCP_MEMTYPE_SYSTEM;
                if (ret)
                        goto e_tag;
  
-               ret = memcmp(tag.address, final_wa.address, AES_BLOCK_SIZE);
+               ret = crypto_memneq(tag.address, final_wa.address,
+                                   AES_BLOCK_SIZE) ? -EBADMSG : 0;
                ccp_dm_free(&tag);
        }
  
index de5a8ca70d3da2918e48d91ff89b602a21872c0a,2ff87b4d934858dc39146ce845140c82ac93632f..6b17d179ef8a0574bcfb6c77a0119c6b765f6177
@@@ -1,4 -1,4 +1,4 @@@
 -// SPDX-License-Identifier: GPL-2.0
 +// SPDX-License-Identifier: GPL-2.0-only
  /*
   * AMD Platform Security Processor (PSP) interface
   *
  #include "sp-dev.h"
  #include "psp-dev.h"
  
- #define SEV_VERSION_GREATER_OR_EQUAL(_maj, _min)      \
-               ((psp_master->api_major) >= _maj &&     \
-                (psp_master->api_minor) >= _min)
  #define DEVICE_NAME           "sev"
  #define SEV_FW_FILE           "amd/sev.fw"
  #define SEV_FW_NAME_SIZE      64
@@@ -47,6 -43,15 +43,15 @@@ MODULE_PARM_DESC(psp_probe_timeout, " d
  static bool psp_dead;
  static int psp_timeout;
  
+ static inline bool sev_version_greater_or_equal(u8 maj, u8 min)
+ {
+       if (psp_master->api_major > maj)
+               return true;
+       if (psp_master->api_major == maj && psp_master->api_minor >= min)
+               return true;
+       return false;
+ }
  static struct psp_device *psp_alloc_struct(struct sp_device *sp)
  {
        struct device *dev = sp->dev;
@@@ -588,7 -593,7 +593,7 @@@ static int sev_ioctl_do_get_id2(struct 
        int ret;
  
        /* SEV GET_ID is available from SEV API v0.16 and up */
-       if (!SEV_VERSION_GREATER_OR_EQUAL(0, 16))
+       if (!sev_version_greater_or_equal(0, 16))
                return -ENOTSUPP;
  
        if (copy_from_user(&input, (void __user *)argp->data, sizeof(input)))
@@@ -651,7 -656,7 +656,7 @@@ static int sev_ioctl_do_get_id(struct s
        int ret;
  
        /* SEV GET_ID available from SEV API v0.16 and up */
-       if (!SEV_VERSION_GREATER_OR_EQUAL(0, 16))
+       if (!sev_version_greater_or_equal(0, 16))
                return -ENOTSUPP;
  
        /* SEV FW expects the buffer it fills with the ID to be
@@@ -1053,7 -1058,7 +1058,7 @@@ void psp_pci_init(void
                psp_master->sev_state = SEV_STATE_UNINIT;
        }
  
-       if (SEV_VERSION_GREATER_OR_EQUAL(0, 15) &&
+       if (sev_version_greater_or_equal(0, 15) &&
            sev_update_firmware(psp_master->dev) == 0)
                sev_get_api_version();
  
index 23061f2bc74bdf56202490f5a186698ffcf1df04,7c81f0f234ae464647cf77f856f7f8bf698334f3..2b70d8796f25b5884920b8708760963e89503d42
@@@ -1,9 -1,23 +1,9 @@@
 +// SPDX-License-Identifier: GPL-2.0-only
  /*
   * This file is part of STM32 Crypto driver for Linux.
   *
   * Copyright (C) 2017, STMicroelectronics - All Rights Reserved
   * Author(s): Lionel DEBIEVE <lionel.debieve@st.com> for STMicroelectronics.
 - *
 - * License terms: GPL V2.0.
 - *
 - * This program is free software; you can redistribute it and/or modify it
 - * under the terms of the GNU General Public License version 2 as published by
 - * the Free Software Foundation.
 - *
 - * This program is distributed in the hope that it will be useful, but
 - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
 - * details.
 - *
 - * You should have received a copy of the GNU General Public License along with
 - * this program. If not, see <http://www.gnu.org/licenses/>.
 - *
   */
  
  #include <linux/clk.h>
@@@ -338,7 -352,7 +338,7 @@@ static int stm32_hash_xmit_cpu(struct s
  
        len32 = DIV_ROUND_UP(length, sizeof(u32));
  
-       dev_dbg(hdev->dev, "%s: length: %d, final: %x len32 %i\n",
+       dev_dbg(hdev->dev, "%s: length: %zd, final: %x len32 %i\n",
                __func__, length, final, len32);
  
        hdev->flags |= HASH_FLAGS_CPU;