Skip to contentSkip to conversation

eCryptfs: Release mutex on hash error path

PATCH New Michael Halcrow 1 participant 1 message Nov 2, 2007 1 message not in the archive Ecrypt file system

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

PATCH 1/1 eCryptfs: Release mutex on hash error path

Quoted 2 lines · Kazuki Ohta

When IS_ERR(desc.tfm) is true, unlocking
crypt_stat->cs_hash_tfm_mutex is forgotten.

Thanks for reporting this, Kazuki.
---

Release the crypt_stat hash mutex on allocation error. Check for error conditions when doing crypto hash calls.

---
 fs/ecryptfs/crypto.c |   26 ++++++++++++++++++++++----
 1 files changed, 22 insertions(+), 4 deletions(-)
fs/ecryptfs/crypto.c +22 -4
index a0f53aa..70f7aab 100644
@@ -115,11 +115,29 @@ static int ecryptfs_calculate_md5(char *dst,
 		}
 		crypt_stat->hash_tfm = desc.tfm;
 	}
-	crypto_hash_init(&desc);
-	crypto_hash_update(&desc, &sg, len);
-	crypto_hash_final(&desc, dst);
-	mutex_unlock(&crypt_stat->cs_hash_tfm_mutex);
+	rc = crypto_hash_init(&desc);
+	if (rc) {
+		printk(KERN_ERR
+		       "%s: Error initializing crypto hash; rc = [%d]\n",
+		       __FUNCTION__, rc);
+		goto out;
+	}
+	rc = crypto_hash_update(&desc, &sg, len);
+	if (rc) {
+		printk(KERN_ERR
+		       "%s: Error updating crypto hash; rc = [%d]\n",
+		       __FUNCTION__, rc);
+		goto out;
+	}
+	rc = crypto_hash_final(&desc, dst);
+	if (rc) {
+		printk(KERN_ERR
+		       "%s: Error finalizing crypto hash; rc = [%d]\n",
+		       __FUNCTION__, rc);
+		goto out;
+	}
 out:
+	mutex_unlock(&crypt_stat->cs_hash_tfm_mutex);
 	return rc;
 }
 
Signature · 1 line
1.5.0.6