]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
TPM: Avoid reference to potentially freed memory
authorChristophe JAILLET <christophe.jaillet@wanadoo.fr>
Thu, 22 Oct 2015 20:32:41 +0000 (22:32 +0200)
committerLuis Henriques <luis.henriques@canonical.com>
Sun, 13 Dec 2015 17:49:45 +0000 (17:49 +0000)
commit eb8ed1eb9a158c460d10205eaff71fd4ac67c160 upstream.

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>
[ luis: backported to 3.16: adjusted context ]
Signed-off-by: Luis Henriques <luis.henriques@canonical.com>
drivers/char/tpm/tpm_of.c

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