Merge branch 'next' into for-linus
James Morris [Mon, 9 Jan 2012 01:16:48 +0000 (12:16 +1100)]
Conflicts:
security/integrity/evm/evm_crypto.c

Resolved upstream fix vs. next conflict manually.

Signed-off-by: James Morris <jmorris@namei.org>

1  2 
include/linux/security.h
security/integrity/evm/evm_crypto.c

diff --combined include/linux/security.h
@@@ -590,6 -590,8 +590,8 @@@ static inline void security_free_mnt_op
   *    @reqprot contains the protection requested by the application.
   *    @prot contains the protection that will be applied by the kernel.
   *    @flags contains the operational flags.
+  *    @addr contains virtual address that will be used for the operation.
+  *    @addr_only contains a boolean: 0 if file-backed VMA, otherwise 1.
   *    Return 0 if permission is granted.
   * @file_mprotect:
   *    Check permissions before changing memory access permissions.
@@@ -2044,7 -2046,7 +2046,7 @@@ static inline void security_inode_free(
  static inline int security_inode_init_security(struct inode *inode,
                                                struct inode *dir,
                                                const struct qstr *qstr,
-                                               initxattrs initxattrs,
+                                               const initxattrs initxattrs,
                                                void *fs_data)
  {
        return 0;
@@@ -2056,7 -2058,7 +2058,7 @@@ static inline int security_old_inode_in
                                                   char **name, void **value,
                                                   size_t *len)
  {
 -      return 0;
 +      return -EOPNOTSUPP;
  }
  
  static inline int security_inode_create(struct inode *dir,
@@@ -26,44 -26,56 +26,56 @@@ static unsigned char evmkey[MAX_KEY_SIZ
  static int evmkey_len = MAX_KEY_SIZE;
  
  struct crypto_shash *hmac_tfm;
+ struct crypto_shash *hash_tfm;
  
  static DEFINE_MUTEX(mutex);
  
- static struct shash_desc *init_desc(void)
 -static struct shash_desc *init_desc(const char type)
++static struct shash_desc *init_desc(char type)
  {
-       int rc;
+       long rc;
+       char *algo;
+       struct crypto_shash **tfm;
        struct shash_desc *desc;
  
-       if (hmac_tfm == NULL) {
+       if (type == EVM_XATTR_HMAC) {
+               tfm = &hmac_tfm;
+               algo = evm_hmac;
+       } else {
+               tfm = &hash_tfm;
+               algo = evm_hash;
+       }
+       if (*tfm == NULL) {
                mutex_lock(&mutex);
-               if (hmac_tfm)
+               if (*tfm)
                        goto out;
-               hmac_tfm = crypto_alloc_shash(evm_hmac, 0, CRYPTO_ALG_ASYNC);
-               if (IS_ERR(hmac_tfm)) {
-                       pr_err("Can not allocate %s (reason: %ld)\n",
-                              evm_hmac, PTR_ERR(hmac_tfm));
-                       rc = PTR_ERR(hmac_tfm);
-                       hmac_tfm = NULL;
+               *tfm = crypto_alloc_shash(algo, 0, CRYPTO_ALG_ASYNC);
+               if (IS_ERR(*tfm)) {
+                       rc = PTR_ERR(*tfm);
+                       pr_err("Can not allocate %s (reason: %ld)\n", algo, rc);
+                       *tfm = NULL;
                        mutex_unlock(&mutex);
                        return ERR_PTR(rc);
                }
-               rc = crypto_shash_setkey(hmac_tfm, evmkey, evmkey_len);
-               if (rc) {
-                       crypto_free_shash(hmac_tfm);
-                       hmac_tfm = NULL;
-                       mutex_unlock(&mutex);
-                       return ERR_PTR(rc);
+               if (type == EVM_XATTR_HMAC) {
+                       rc = crypto_shash_setkey(*tfm, evmkey, evmkey_len);
+                       if (rc) {
+                               crypto_free_shash(*tfm);
+                               *tfm = NULL;
+                               mutex_unlock(&mutex);
+                               return ERR_PTR(rc);
+                       }
                }
  out:
                mutex_unlock(&mutex);
        }
  
-       desc = kmalloc(sizeof(*desc) + crypto_shash_descsize(hmac_tfm),
+       desc = kmalloc(sizeof(*desc) + crypto_shash_descsize(*tfm),
                        GFP_KERNEL);
        if (!desc)
                return ERR_PTR(-ENOMEM);
  
-       desc->tfm = hmac_tfm;
+       desc->tfm = *tfm;
        desc->flags = CRYPTO_TFM_REQ_MAY_SLEEP;
  
        rc = crypto_shash_init(desc);
@@@ -108,9 -120,11 +120,11 @@@ static void hmac_add_misc(struct shash_
   * the hmac using the requested xattr value. Don't alloc/free memory for
   * each xattr, but attempt to re-use the previously allocated memory.
   */
- int evm_calc_hmac(struct dentry *dentry, const char *req_xattr_name,
-                 const char *req_xattr_value, size_t req_xattr_value_len,
-                 char *digest)
+ static int evm_calc_hmac_or_hash(struct dentry *dentry,
+                               const char *req_xattr_name,
+                               const char *req_xattr_value,
+                               size_t req_xattr_value_len,
+                               char type, char *digest)
  {
        struct inode *inode = dentry->d_inode;
        struct shash_desc *desc;
  
        if (!inode->i_op || !inode->i_op->getxattr)
                return -EOPNOTSUPP;
-       desc = init_desc();
+       desc = init_desc(type);
        if (IS_ERR(desc))
                return PTR_ERR(desc);
  
@@@ -156,6 -170,22 +170,22 @@@ out
        return error;
  }
  
+ int evm_calc_hmac(struct dentry *dentry, const char *req_xattr_name,
+                 const char *req_xattr_value, size_t req_xattr_value_len,
+                 char *digest)
+ {
+       return evm_calc_hmac_or_hash(dentry, req_xattr_name, req_xattr_value,
+                               req_xattr_value_len, EVM_XATTR_HMAC, digest);
+ }
+ int evm_calc_hash(struct dentry *dentry, const char *req_xattr_name,
+                 const char *req_xattr_value, size_t req_xattr_value_len,
+                 char *digest)
+ {
+       return evm_calc_hmac_or_hash(dentry, req_xattr_name, req_xattr_value,
+                               req_xattr_value_len, IMA_XATTR_DIGEST, digest);
+ }
  /*
   * Calculate the hmac and update security.evm xattr
   *
@@@ -186,7 -216,7 +216,7 @@@ int evm_init_hmac(struct inode *inode, 
  {
        struct shash_desc *desc;
  
-       desc = init_desc();
+       desc = init_desc(EVM_XATTR_HMAC);
        if (IS_ERR(desc)) {
                printk(KERN_INFO "init_desc failed\n");
                return PTR_ERR(desc);