Message ID | 20210709153903.691945-2-stefanb@linux.vnet.ibm.com |
---|---|
State | Accepted |
Headers | show |
Series | tcgbios: Use the proper hashes for the TPM 2 PCR banks | expand |
On 7/9/21 11:38 AM, Stefan Berger wrote: > From: Stefan Berger <stefanb@linux.ibm.com> > > Change the format of the S_CRTM_VERSION string to ucs-2 since this > is what seems to be commonly used by other firmwares following > insight from a TCG work group member. > > Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru> > Tested-by: Stefan Berger <stefanb@linux.ibm.com> Signed-off-by: Stefan Berger <stefanb@linux.ibm.com> > --- > Makefile.gen | 2 +- > lib/libtpm/Makefile | 1 + > lib/libtpm/tcgbios.c | 23 ++++++++++++----------- > make.rules | 3 ++- > 4 files changed, 16 insertions(+), 13 deletions(-) > > diff --git a/Makefile.gen b/Makefile.gen > index f18c57a..6f78829 100644 > --- a/Makefile.gen > +++ b/Makefile.gen > @@ -164,7 +164,7 @@ distclean_gen: clean_top > > common-libs: > @echo " ====== Building common libraries ======" > - $(MAKE) -C $(LIBCMNDIR) $(COMMON_LIBS) > + $(MAKE) -C $(LIBCMNDIR) $(COMMON_LIBS) RELEASE=-DRELEASE=\"\\\"$(RELEASE)\\\"\" > > board-libs: > $(MAKE) -C lib $(MAKEARG) > diff --git a/lib/libtpm/Makefile b/lib/libtpm/Makefile > index 9d32dfc..895dbfd 100644 > --- a/lib/libtpm/Makefile > +++ b/lib/libtpm/Makefile > @@ -15,6 +15,7 @@ TOPCMNDIR ?= ../.. > CPPFLAGS = -I../libc/include $(CPUARCHDEF) -I$(INCLBRDDIR) \ > -I$(INCLCMNDIR) -I$(INCLCMNDIR)/$(CPUARCH) -I$(SLOFCMNDIR) > CPPFLAGS += -I../libhvcall > +CPPFLAGS += $(RELEASE) > > LDFLAGS = -nostdlib > > diff --git a/lib/libtpm/tcgbios.c b/lib/libtpm/tcgbios.c > index dcf0cc6..24ac83c 100644 > --- a/lib/libtpm/tcgbios.c > +++ b/lib/libtpm/tcgbios.c > @@ -1108,24 +1108,25 @@ uint32_t tpm_measure_gpt(void) > > uint32_t tpm_measure_scrtm(void) > { > - uint32_t rc; > - char *version_start = strstr((char *)&print_version, "FW Version"); > - char *version_end; > - uint32_t version_length; > + uint32_t rc, i; > char *slof_text_start = (char *)&_slof_text; > uint32_t slof_text_length = (long)&_slof_text_end - (long)&_slof_text; > const char *scrtm = "S-CRTM Contents"; > - > - version_end = strchr(version_start, '\r'); > - version_length = version_end - version_start; > +#define _TT(a, x) a##x > +#define _T(a, x) _TT(a, x) > + unsigned short ucs2_version[] = _T(L, RELEASE); > > dprintf("Measure S-CRTM Version: addr = %p, length = %d\n", > - version_start, version_length); > + ucs2_version, ucs2_length); > + > + for (i = 0; i < ARRAY_SIZE(ucs2_version); ++i) > + ucs2_version[i] = cpu_to_le16(ucs2_version[i]); > > rc = tpm_add_measurement_to_log(0, EV_S_CRTM_VERSION, > - version_start, version_length, > - (uint8_t *)version_start, > - version_length); > + (char *)ucs2_version, > + sizeof(ucs2_version), > + (uint8_t *)ucs2_version, > + sizeof(ucs2_version)); > if (rc) > return rc; > > diff --git a/make.rules b/make.rules > index 885eea3..d37c365 100644 > --- a/make.rules > +++ b/make.rules > @@ -79,6 +79,7 @@ CPP ?= $(CROSS)cpp > WARNFLAGS = -Wall -Wmissing-prototypes -Wstrict-prototypes -Wformat-security -Wextra -Wno-unused-parameter > CFLAGS ?= -g -O2 -fno-builtin -ffreestanding -nostdinc -msoft-float \ > -fno-strict-aliasing -mno-altivec -mabi=no-altivec \ > - -fno-stack-protector -fno-asynchronous-unwind-tables $(WARNFLAGS) > + -fno-stack-protector -fno-asynchronous-unwind-tables $(WARNFLAGS) \ > + -fshort-wchar > > export CC AS LD CLEAN OBJCOPY OBJDUMP STRIP AR RANLIB CFLAGS
diff --git a/Makefile.gen b/Makefile.gen index f18c57a..6f78829 100644 --- a/Makefile.gen +++ b/Makefile.gen @@ -164,7 +164,7 @@ distclean_gen: clean_top common-libs: @echo " ====== Building common libraries ======" - $(MAKE) -C $(LIBCMNDIR) $(COMMON_LIBS) + $(MAKE) -C $(LIBCMNDIR) $(COMMON_LIBS) RELEASE=-DRELEASE=\"\\\"$(RELEASE)\\\"\" board-libs: $(MAKE) -C lib $(MAKEARG) diff --git a/lib/libtpm/Makefile b/lib/libtpm/Makefile index 9d32dfc..895dbfd 100644 --- a/lib/libtpm/Makefile +++ b/lib/libtpm/Makefile @@ -15,6 +15,7 @@ TOPCMNDIR ?= ../.. CPPFLAGS = -I../libc/include $(CPUARCHDEF) -I$(INCLBRDDIR) \ -I$(INCLCMNDIR) -I$(INCLCMNDIR)/$(CPUARCH) -I$(SLOFCMNDIR) CPPFLAGS += -I../libhvcall +CPPFLAGS += $(RELEASE) LDFLAGS = -nostdlib diff --git a/lib/libtpm/tcgbios.c b/lib/libtpm/tcgbios.c index dcf0cc6..24ac83c 100644 --- a/lib/libtpm/tcgbios.c +++ b/lib/libtpm/tcgbios.c @@ -1108,24 +1108,25 @@ uint32_t tpm_measure_gpt(void) uint32_t tpm_measure_scrtm(void) { - uint32_t rc; - char *version_start = strstr((char *)&print_version, "FW Version"); - char *version_end; - uint32_t version_length; + uint32_t rc, i; char *slof_text_start = (char *)&_slof_text; uint32_t slof_text_length = (long)&_slof_text_end - (long)&_slof_text; const char *scrtm = "S-CRTM Contents"; - - version_end = strchr(version_start, '\r'); - version_length = version_end - version_start; +#define _TT(a, x) a##x +#define _T(a, x) _TT(a, x) + unsigned short ucs2_version[] = _T(L, RELEASE); dprintf("Measure S-CRTM Version: addr = %p, length = %d\n", - version_start, version_length); + ucs2_version, ucs2_length); + + for (i = 0; i < ARRAY_SIZE(ucs2_version); ++i) + ucs2_version[i] = cpu_to_le16(ucs2_version[i]); rc = tpm_add_measurement_to_log(0, EV_S_CRTM_VERSION, - version_start, version_length, - (uint8_t *)version_start, - version_length); + (char *)ucs2_version, + sizeof(ucs2_version), + (uint8_t *)ucs2_version, + sizeof(ucs2_version)); if (rc) return rc; diff --git a/make.rules b/make.rules index 885eea3..d37c365 100644 --- a/make.rules +++ b/make.rules @@ -79,6 +79,7 @@ CPP ?= $(CROSS)cpp WARNFLAGS = -Wall -Wmissing-prototypes -Wstrict-prototypes -Wformat-security -Wextra -Wno-unused-parameter CFLAGS ?= -g -O2 -fno-builtin -ffreestanding -nostdinc -msoft-float \ -fno-strict-aliasing -mno-altivec -mabi=no-altivec \ - -fno-stack-protector -fno-asynchronous-unwind-tables $(WARNFLAGS) + -fno-stack-protector -fno-asynchronous-unwind-tables $(WARNFLAGS) \ + -fshort-wchar export CC AS LD CLEAN OBJCOPY OBJDUMP STRIP AR RANLIB CFLAGS