From: Dean Nelson <dnelson@redhat.com> Date: Wed, 10 Jun 2009 14:06:51 -0400 Subject: [char] TPM: get_event_name stack corruption Message-id: 20090610180625.7084.66870.sendpatchset@localhost.localdomain O-Subject: [RHEL5.4 PATCH] TPM: get_event_name stack corruption Bugzilla: 503905 RH-Acked-by: Prarit Bhargava <prarit@redhat.com> RH-Acked-by: Pete Zaitcev <zaitcev@redhat.com> RH-Acked-by: John Feeney <jfeeney@redhat.com> RH-Acked-by: Jiri Pirko <jpirko@redhat.com> RH-Acked-by: Eugene Teo <eugene@redhat.com> 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. This patch is a backport of an upstream commit (see http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commit;h=fbaa58696cef848de818768783ef185bd3f05158). Applied the patch to a top-of-tree RHEL5 git repository and built, installed and booted a kernel on hardware without the TPM chip. For what it's worth I did an 'insmod tpm_bios.ko'. Resolves BZ 503905. diff --git a/drivers/char/tpm/tpm_bios.c b/drivers/char/tpm/tpm_bios.c index da4b14e..49fb8ad 100644 --- a/drivers/char/tpm/tpm_bios.c +++ b/drivers/char/tpm/tpm_bios.c @@ -214,7 +214,8 @@ static int get_event_name(char *dest, struct tcpa_event *event, unsigned char * event_entry) { const char *name = ""; - char data[40] = ""; + /* 41 so there is room for 40 data and 1 nul */ + char data[41] = ""; int i, n_len = 0, d_len = 0; struct tcpa_pc_event *pc_event;