Re: [PATCH 06/11] tpm: Add full HMAC and encrypt/decrypt session handling code

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sat, 2022-12-10 at 08:17 +0300, Dan Carpenter wrote:
> Hi James,
> 
> https://git-scm.com/docs/git-format-patch#_base_tree_information]
> 
> url:   
> https://github.com/intel-lab-lkp/linux/commits/James-Bottomley/add-integrity-and-security-to-TPM2-transactions/20221210-001335
> patch link:   
> https://lore.kernel.org/r/20221209160611.30207-7-James.Bottomley%40HansenPartnership.com
> patch subject: [PATCH 06/11] tpm: Add full HMAC and encrypt/decrypt
> session handling code
> config: x86_64-randconfig-m001
> compiler: gcc-11 (Debian 11.3.0-8) 11.3.0
> 
> If you fix the issue, kindly add following tag where applicable
> > Reported-by: kernel test robot <lkp@xxxxxxxxx>
> > Reported-by: Dan Carpenter <error27@xxxxxxxxx>
> 
> New smatch warnings:
> drivers/char/tpm/tpm2-sessions.c:294 tpm_buf_append_salt() warn:
> possible memory leak of 'secret'
> drivers/char/tpm/tpm2-sessions.c:890 tpm2_start_auth_session() warn:
> possible memory leak of 'auth'
> 
> Old smatch warnings:
> drivers/char/tpm/tpm2-sessions.c:331 tpm_buf_append_salt() warn:
> possible memory leak of 'secret'

Hm, yes, I thought I'd fixed it up, but apparently not.

This differential should fix all the leaks.  I'll add it to the next
revision.  I also found a non standard name algorithm problem with
session handle appends, so I need to fix that as well.

Sorry about forgetting to fix this,

James


---

diff --git a/drivers/char/tpm/tpm2-sessions.c b/drivers/char/tpm/tpm2-sessions.c
index 89dd9494bf9a..914c49abab03 100644
--- a/drivers/char/tpm/tpm2-sessions.c
+++ b/drivers/char/tpm/tpm2-sessions.c
@@ -291,7 +291,7 @@ static void tpm_buf_append_salt(struct tpm_buf *buf, struct tpm_chip *chip,
 	kpp = crypto_alloc_kpp("ecdh-nist-p256", CRYPTO_ALG_INTERNAL, 0);
 	if (IS_ERR(kpp)) {
 		dev_err(&chip->dev, "crypto ecdh allocation failed\n");
-		return;
+		goto out_free;
 	}
 
 	buf_len = crypto_ecdh_key_len(&p);
@@ -329,6 +329,8 @@ static void tpm_buf_append_salt(struct tpm_buf *buf, struct tpm_chip *chip,
 	KDFe(secret, "SECRET", x, chip->ec_point_x, auth->salt);
  out:
 	crypto_free_kpp(kpp);
+ out_free:
+	kfree(secret);
 }
 
 /**
@@ -887,7 +889,7 @@ int tpm2_start_auth_session(struct tpm_chip *chip, struct tpm2_auth **authp)
 	rc = tpm2_load_context(chip, chip->tpmkeycontext, &offset,
 			       &nullkey);
 	if (rc)
-		return rc;
+		goto out;
 
 	auth->chip = chip;
 	auth->session = TPM_HEADER_SIZE;




[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux Kernel]     [Linux Kernel Hardening]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux SCSI]

  Powered by Linux