Browse Source

TPM: Avoid reference to potentially freed memory

Reference to the 'np' node is dropped before dereferencing the 'sizep' and
'basep' pointers, which could by then point to junk if the node has been
freed.

Refactor code to call 'of_node_put' later.

Fixes: c5df39262dd5 ("drivers/char/tpm: Add securityfs support for event log")
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Reviewed-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Acked-by: Peter Huewe <PeterHuewe@gmx.de>
Christophe JAILLET 9 years ago
parent
commit
eb8ed1eb9a
1 changed files with 2 additions and 1 deletions
  1. 2 1
      drivers/char/tpm/tpm_of.c

+ 2 - 1
drivers/char/tpm/tpm_of.c

@@ -53,17 +53,18 @@ int read_log(struct tpm_bios_log *log)
 		goto cleanup_eio;
 		goto cleanup_eio;
 	}
 	}
 
 
-	of_node_put(np);
 	log->bios_event_log = kmalloc(*sizep, GFP_KERNEL);
 	log->bios_event_log = kmalloc(*sizep, GFP_KERNEL);
 	if (!log->bios_event_log) {
 	if (!log->bios_event_log) {
 		pr_err("%s: ERROR - Not enough memory for BIOS measurements\n",
 		pr_err("%s: ERROR - Not enough memory for BIOS measurements\n",
 		       __func__);
 		       __func__);
+		of_node_put(np);
 		return -ENOMEM;
 		return -ENOMEM;
 	}
 	}
 
 
 	log->bios_event_log_end = log->bios_event_log + *sizep;
 	log->bios_event_log_end = log->bios_event_log + *sizep;
 
 
 	memcpy(log->bios_event_log, __va(*basep), *sizep);
 	memcpy(log->bios_event_log, __va(*basep), *sizep);
+	of_node_put(np);
 
 
 	return 0;
 	return 0;