Use PCR10 of sha256 PCR bank
eduardolfalcao at gmail.com
Hello guys.
I am new to TPM2, and I'm trying it for approx 3 weeks.
First, I set up my environment, and configured the default IMA policy:
#!/bin/sh
# PROC_SUPER_MAGICdont_measure fsmagic=0x9fa0
# SYSFS_MAGICdont_measure fsmagic=0x62656572
# DEBUGFS_MAGICdont_measure fsmagic=0x64626720
# TMPFS_MAGICdont_measure fsmagic=0x01021994
# RAMFS_MAGICdont_measure fsmagic=0x858458f6
# SECURITYFS_MAGICdont_measure fsmagic=0x73636673
# MEASUREMENTS
measure func=BPRM_CHECK
measure func=FILE_MMAP mask=MAY_EXEC
measure func=MODULE_CHECK uid=0
The I configured the grub to use sha256:
sudo sed -i 's/GRUB_CMDLINE_LINUX=""/GRUB_CMDLINE_LINUX="ima_policy=tcb ima_hash=sha256"/' /etc/default/grub sudo update-grub
After rebooting, I just noticed that PCR10 is used for sha1, but it is not used for sha256.
ubuntu(a)ubuntu:~$ tpm2_pcrread sha1: 0 : 0x4F7F3D318FC01183E7DE3A0DCC4BE34FBCCDBA7D 1 : 0xD0DF6DEABE5A83A927BE7F1AC5C76DF42B5FF333 2 : 0x9D360B5F970A10C59FBF023EF5C5D9E546ABDDCD 3 : 0xB2A83B0EBF2F8374299A5B2BDFC31EA955AD7236 4 : 0x8AF8DEDB82AC4B6C134217F96D6CCA75B71283E2 5 : 0x0E892480CC081670FC80BCDF3B87EA3FB1D218D4 6 : 0xB2A83B0EBF2F8374299A5B2BDFC31EA955AD7236 7 : 0x518BD167271FBB64589C61E43D8C0165861431D8 8 : 0x0000000000000000000000000000000000000000 9 : 0x0000000000000000000000000000000000000000 10: 0xBB07F51CB74DC7BE01AF413A0557C0DA6FD1E61A 11: 0x0000000000000000000000000000000000000000 12: 0x0000000000000000000000000000000000000000 13: 0x0000000000000000000000000000000000000000 14: 0x0000000000000000000000000000000000000000 15: 0x0000000000000000000000000000000000000000 16: 0x0000000000000000000000000000000000000000 17: 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF 18: 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF 19: 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF 20: 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF 21: 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF 22: 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF 23: 0x0000000000000000000000000000000000000000 sha256: 0 : 0xE4B28BC5903BADFD7F4D33EA968A902B25CAB39599DE43E9BD1D86A4235905EF 1 : 0x150FD1738628C5852A6FF5B63B3185EFA55B3BB37E19ADC1A40522182061A33D 2 : 0xD907F34E551760DAE63FD94BFC44B2D629CB556596D3914C4170B1F3D605A3FE 3 : 0x3D458CFE55CC03EA1F443F1562BEEC8DF51C75E14A9FCF9A7234A13F198E7969 4 : 0x3D3B637E8C2D01305762025C4F3B7E3DEB169D8976A29607C387DC028A5514B8 5 : 0xAB79C14B70120A8F628C73B4D9B460A980752EEDED1B149A6D3DFED57E8ACABB 6 : 0x3D458CFE55CC03EA1F443F1562BEEC8DF51C75E14A9FCF9A7234A13F198E7969 7 : 0x65CAF8DD1E0EA7A6347B635D2B379C93B9A1351EDC2AFC3ECDA700E534EB3068 8 : 0x0000000000000000000000000000000000000000000000000000000000000000 9 : 0x0000000000000000000000000000000000000000000000000000000000000000 10: 0x0000000000000000000000000000000000000000000000000000000000000000 11: 0x0000000000000000000000000000000000000000000000000000000000000000 12: 0x0000000000000000000000000000000000000000000000000000000000000000 13: 0x0000000000000000000000000000000000000000000000000000000000000000 14: 0x0000000000000000000000000000000000000000000000000000000000000000 15: 0x0000000000000000000000000000000000000000000000000000000000000000 16: 0x0000000000000000000000000000000000000000000000000000000000000000 17: 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF 18: 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF 19: 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF 20: 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF 21: 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF 22: 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF 23: 0x0000000000000000000000000000000000000000000000000000000000000000
How do I manage to use sha256 and get the IMA measurements displayed on PCR10 of sha256 bank? Could anyone help me?
Best regards :)
nicolasoliver03 at gmail.com
Hi Eduardo!
Glad to know there is somebody else playing the IMA game :)
For my case, it happens automatically on any Fedora host since F31.
Also, the IMA measurement logic is kernel responsibility, tpm2-software only allows you to read what the kernel already did.
Which Linux flavor are you using?
eduardolfalcao at gmail.com
Quoted 1 line
Hi Eduardo!
Hi Nicolas. :)
Quoted 6 lines
Glad to know there is somebody else playing the IMA game :)
For my case, it happens automatically on any Fedora host since F31.
Also, the IMA measurement logic is kernel responsibility, tpm2-software only allows you to read what the kernel already did.
Then, I assume there is something else to be configured on my OS. Is that what you think?
Quoted 2 lines
Which Linux flavor are you using?
It is Ubuntu 16.04.6 LTS.
ubuntu(a)ubuntu:~$ uname -a Linux ubuntu 4.4.0-178-generic #208-Ubuntu SMP Sun Apr 5 23:45:10 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux ubuntu(a)ubuntu:~$ cat /etc/os-release NAME="Ubuntu" VERSION="16.04.6 LTS (Xenial Xerus)" ID=ubuntu ID_LIKE=debian PRETTY_NAME="Ubuntu 16.04.6 LTS" VERSION_ID="16.04"
Thanks for the help.
Eduardo Falcão <eduardolfalcao at gmail.com>
Inspecting the measurements collected by IMA I just saw that boot aggregate is created with sha1, but then all measurements are extended with sha256.
10 e54afd0b8be44bda96d19b3ba154abf0122f80f0 ima-ng sha1:8bec961a62ee4589db6506002d974fee2d5cf2c6 boot_aggregate
10 71f5a9db669451d369635f6ff3a2aeb623ba5282 ima-ng sha256:4cadb747c2e6d894228198fe9091d3f289c704edf82ddbd5945c54ec847d0bb6 /init
10 b2a44047548e6ec6791fc2455fdf70beebac20d0 ima-ng sha256:c3b773ac00b68d908431b73e68c1b5f4229748dd386f651b6503198d3bfc9780 /bin/sh 10 2e200610d43da1cbd2a41dc6fe0b48b43faa4fcc ima-ng sha256:0f754eab280e5ff0b65c46bdd1cc16e8aff944c834379df2632cd5f261afe3bb /lib/x86_64-linux-gnu/ld-2.23.so 10 c50746154c54730caaaae10fe2cf43e2d34c243f ima-ng sha256:6261d3a53a3ee7de728effa63be8ddbc4daecfdf2e40951cd04b5e8d091b1a9b /etc/ld.so.cache 10 e16f2cc0281caf744454631d937bff59641c455d ima-ng sha256:74ca69ada4429ae5fce87f7e3addb56f1b53964599e8526244fecd164b3c4b44 /lib/x86_64-linux-gnu/libc-2.23.so 10 0f8b2256c6159adfec34fc26b0f70f62b189e9a6 ima-ng sha256:91f2413151b7b0451ce0b6cedc7e5919931acf792d9a26645c0deb3bc230d9fe /conf/arch.conf 10 37b7648c357ee449e136fc15a7a0ffcc50ef46a9 ima-ng sha256:3ab885510eee04a49f638e98226f5bd96ed707da20d0e8a937c13ce33a889e1b /conf/initramfs.conf 10 6f56f95b5b78bc076ebdd77242a16203c44c5813 ima-ng sha256:ed5f0d4f1363d1a9fc7967b9dba2f0e0db75b88ad39fd1d0f5a6efd3f2d170dc /scripts/functions
nicolasoliver03 at gmail.com
As today, IMA is harcoded to make the boot_aggregate entry in SHA1
So the ima_hash=sha256 option is activated after the boot_aggregate. It is the same for me in Fedora 31. It would be nice if somebody contributed to the kernel and fixes this, or at least harcode it to sha256 :)
What I can see from you initial message is that you get all the digest from the measured boot process (PCR 0 to 7) in both SHA1 and SHA256 PCRs, which means that your BIOS to TPM interaction is working fine. In Fedora, you would see additional measurements in the PCR 8 and 9 corresponding to the digests of the components that grub2 reads (config, kernel and kernel config, and initiramfs).
But when IMA is measuring stuff, you get only PCR SHA1 digests. I think this is related to the 4.4 kernel version. The oldest kernel I used to validate IMA was a 4.17, and I am currently using 5.6. I believe there is no option to control which PCR banks IMA uses, it should measure in all the available PCR 10s by default. Is upgrading to Ubuntu 18.04 or 20.04 possible for you? Also, Ubuntu 16.04 is EOL since April 2019, so you have other good reasons to upgrade :)
Eduardo Falcão <eduardolfalcao at gmail.com>
Thank you, Nicolas.
Your reasoning makes total sense to me.
I'll try upgrading my ubuntu to check if this issue is solved.
Best regards
Roberts
Quoted 23 lines
-----Original Message-----
From: nicolasoliver03(a)gmail.com [mailto:nicolasoliver03(a)gmail.com]
Sent: Friday, May 8, 2020 10:55 AM
To: tpm2(a)lists.01.org
Subject: [tpm2] Re: Use PCR10 of sha256 PCR bankAs today, IMA is harcoded to make the
boot_aggregateentry in SHA1https://github.com/torvalds/linux/blob/ac438771ccb4479528594c7e19f2c39cf181
4a86/security/integrity/ima/ima_init.c#L59So the ima_hash=sha256 option is activated after the
boot_aggregate. It is the same for me in Fedora 31. It would be nice if somebody contributed to the kernel and fixes this, or at least harcode it to sha256 :)What I can see from you initial message is that you get all the digest from the measured boot process (PCR 0 to 7) in both SHA1 and SHA256 PCRs, which means that your BIOS to TPM interaction is working fine. In Fedora, you would see additional measurements in the PCR 8 and 9 corresponding to the digests of the components that grub2 reads (config, kernel and kernel config, and initiramfs).
Quoted 6 lines
But when IMA is measuring stuff, you get only PCR SHA1 digests. I think this is related to the 4.4 kernel version. The oldest kernel I used to validate IMA was a 4.17, and I am currently using 5.6. I believe there is no option to control which PCR banks IMA uses, it should measure in all the available PCR 10s by default. Is upgrading to Ubuntu 18.04 or 20.04 possible for you? Also, Ubuntu 16.04 is EOL since April 2019, so you have other good reasons to upgrade :)
They likely limit it because hashing things for N digests is pretty slow. However, the Code could be taught that if it's extending to a tpm2 chip to use sha256 and sha1 for The older < 1.2 chips.
I through together, an untested kernel patch here, that should at least cover that one Case you pointed out earlier, but their might be others, I don't know. If there are others It might be worth a different approach where IMA just asks what the best algorithm is and associates all tpm events with that algorithm, rather than having to do it at a bunch of spots in the code.
Not 100% sure how IMA is internally constructed.
Here is a link to that patch if you wanna give it a go
https://github.com/tpm2-software/tpm2-tools/issues/2009#issuecomment-625961138
Quoted 4 lines
_______________________________________________
tpm2 mailing list -- tpm2(a)lists.01.org
To unsubscribe send an email to tpm2-leave(a)lists.01.org %(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s
Roberts
Quoted 43 lines
Quoted 17 lines
-----Original Message-----
From: nicolasoliver03(a)gmail.com [mailto:nicolasoliver03(a)gmail.com]
Sent: Friday, May 8, 2020 10:55 AM
To: tpm2(a)lists.01.org
Subject: [tpm2] Re: Use PCR10 of sha256 PCR bankAs today, IMA is harcoded to make the
boot_aggregateentry in SHA1https://github.com/torvalds/linux/blob/ac438771ccb4479528594c7e19f2c39
cf181
4a86/security/integrity/ima/ima_init.c#L59So the ima_hash=sha256 option is activated after the
boot_aggregate. It is the same for me in Fedora 31. It would be nice if somebody contributed to the kernel and fixes this, or at least harcode it to sha256 :)Quoted 5 lines
What I can see from you initial message is that you get all the digest from the measured boot process (PCR 0 to 7) in both SHA1 and SHA256 PCRs, which means that your BIOS to TPM interaction is working fine. In Fedora, you would see additional measurements in the PCR 8 and 9 corresponding to the digests of the components that grub2 reads (config,
kernel and kernel config, and initiramfs).
Quoted 8 lines
But when IMA is measuring stuff, you get only PCR SHA1 digests. I think this is related to the 4.4 kernel version. The oldest kernel I used to validate IMA was a 4.17, and I am currently using 5.6. I believe there is no option to control which PCR banks IMA uses, it should measure in all the available PCR 10s by default. Is upgrading to Ubuntu 18.04 or 20.04 possible for you? Also, Ubuntu 16.04 is EOL since April 2019, so you have other good reasons to upgrade :)
They likely limit it because hashing things for N digests is pretty slow. However, the Code could be taught that if it's extending to a tpm2 chip to use sha256 and sha1 for The older < 1.2 chips.
I through together, an untested kernel patch here, that should at least cover that one Case you pointed out earlier, but their might be others, I don't know. If there are others It might be worth a different approach where IMA just asks what the best algorithm is and associates all tpm events with that algorithm, rather than having to do it at a bunch of spots in the code.
Not 100% sure how IMA is internally constructed.
Quoted 4 lines
Here is a link to that patch if you wanna give it a go
https://github.com/tpm2-software/tpm2-tools/issues/2009#issuecomment-
625961138
FYI there is a patchlist on IMA already doing what we want, see:
https://lore.kernel.org/linux-integrity/20200325104712.25694-1-roberto.sassu(a)huawei.com/
Bill
nicolasoliver03 at gmail.com
Great!
Additionally in that patch, there is a tool that provides IMA event log parsing here https://github.com/initlove/attest-tools
Apparently, it requires the IBM TSS stack.
I would be nice if the https://github.com/tpm2-software/tpm2-tools/blob/master/tools/misc/tpm2_eventlog.c tool supported the IMA event log as well