Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

TPM: get_event_name stack corruption

get_event_name uses sprintf to fill a buffer declared on the stack. It fills
the buffer 2 bytes at a time. What the code doesn't take into account is that
sprintf(buf, "%02x", data) actually writes 3 bytes. 2 bytes for the data and
then it nul terminates the string. Since we declare buf to be 40 characters
long and then we write 40 bytes of data into buf sprintf is going to write 41
characters. The fix is to leave room in buf for the nul terminator.

Signed-off-by: Eric Paris <eparis@redhat.com>
Signed-off-by: James Morris <jmorris@namei.org>

authored by

Eric Paris and committed by
James Morris
fbaa5869 279e677f

+2 -1
+2 -1
drivers/char/tpm/tpm_bios.c
··· 212 212 unsigned char * event_entry) 213 213 { 214 214 const char *name = ""; 215 - char data[40] = ""; 215 + /* 41 so there is room for 40 data and 1 nul */ 216 + char data[41] = ""; 216 217 int i, n_len = 0, d_len = 0; 217 218 struct tcpa_pc_event *pc_event; 218 219