tpm: vtpm_proxy: Introduce flag to prevent sysfs entries
PATCH 1/1 tpm: vtpm_proxy: Introduce flag to prevent sysfs entries
Introduce TPM_VTPM_PROXY_NO_SYSFS flag that prevents a vtpm_proxy driver instance from having the typical sysfs entries that shows the state of the TPM. The flag is to be set in the ioctl creating the vtpm_proxy device pair and maps on a new chip flags TPM_CHIP_FLAG_NO_SYSFS.
This flag would be set by a container management stack to prevent TPM related information leakage between containers who share entries in sysfs.
--- drivers/char/tpm/tpm-chip.c | 2 +- drivers/char/tpm/tpm.h | 1 + drivers/char/tpm/tpm_vtpm_proxy.c | 5 ++++- include/uapi/linux/vtpm_proxy.h | 3 ++- 4 files changed, 8 insertions(+), 3 deletions(-)
drivers/char/tpm/tpm-chip.c +1 -1
@@ -278,7 +278,7 @@ static void tpm_del_char_device(struct tpm_chip *chip)static int tpm1_chip_register (struct tpm_chip *chip) { -if (chip->flags &TPM_CHIP_FLAG_TPM2 ) +if (chip->flags & (TPM_CHIP_FLAG_TPM2 |TPM_CHIP_FLAG_NO_SYSFS ))return 0 ;tpm_sysfs_add_device (chip);
drivers/char/tpm/tpm.h +1 -0
@@ -143,6 +143,7 @@ enum tpm_chip_flags {TPM_CHIP_FLAG_TPM2 =BIT (1 ),TPM_CHIP_FLAG_IRQ =BIT (2 ),TPM_CHIP_FLAG_VIRTUAL =BIT (3 ), + TPM_CHIP_FLAG_NO_SYSFS = BIT(4), }; struct tpm_chip {
drivers/char/tpm/tpm_vtpm_proxy.c +4 -1
@@ -50,7 +50,7 @@ struct proxy_dev { };/* all supported flags */ -#define VTPM_PROXY_FLAGS_ALL (VTPM_PROXY_FLAG_TPM2) +#define VTPM_PROXY_FLAGS_ALL (VTPM_PROXY_FLAG_TPM2 | VTPM_PROXY_FLAG_NO_SYSFS)static struct workqueue_struct *workqueue;
@@ -490,6 +490,9 @@ static struct file *vtpm_proxy_create_device(if (proxy_dev->flags &VTPM_PROXY_FLAG_TPM2 ) proxy_dev->chip->flags |=TPM_CHIP_FLAG_TPM2 ; +if (proxy_dev->flags &VTPM_PROXY_FLAG_NO_SYSFS ) + proxy_dev->chip->flags |=TPM_CHIP_FLAG_NO_SYSFS ; +vtpm_proxy_work_start (proxy_dev); vtpm_new_dev->fd = fd;
include/uapi/linux/vtpm_proxy.h +2 -1
@@ -29,7 +29,8 @@ struct vtpm_proxy_new_dev { };/* above flags */ -#define VTPM_PROXY_FLAG_TPM2 1/* emulator is TPM 2 */ +#define VTPM_PROXY_FLAG_TPM2 1/* emulator is TPM 2 */ +#define VTPM_PROXY_FLAG_NO_SYSFS 2/* no sysfs for vTPM proxy instance */ #define VTPM_PROXY_IOC_NEW_DEV _IOWR(0xa1, 0x00, struct vtpm_proxy_new_dev)
Signature · 9 lines
2.4.3 ------------------------------------------------------------------------------ Attend Shape: An AT&T Tech Expo July 15-16. Meet us at AT&T Park in San Francisco, CA to explore cutting-edge tech and listen to tech luminaries present their vision of the future. This family event has something for everyone, including kids. Get more information and register today. http://sdm.link/attshape
Quoted 4 lines · Stefan Berger
Introduce
TPM_VTPM_PROXY_NO_SYSFSflag that prevents avtpm_proxydriver instance from having the typical sysfs entries that shows the state of the TPM. The flag is to be set in the ioctl creating thevtpm_proxydevice pair and maps on a new chip flagsTPM_CHIP_FLAG_NO_SYSFS.
No other subsystem does something so goofy, this really needs to be part of namespace support for TPM.
Why can't you just make the sysfs files unreadable in user space? If a container can make them readable again can't it also just create the chardev node?
Jason
------------------------------------------------------------------------------
Attend Shape: An AT&T Tech Expo July 15-16. Meet us at AT&T Park in San Francisco, CA to explore cutting-edge tech and listen to tech luminaries present their vision of the future. This family event has something for everyone, including kids. Get more information and register today.
http://sdm.link/attshape
Quoted 7 lines · Jason Gunthorpe
Quoted 4 lines · Stefan Berger
Introduce
TPM_VTPM_PROXY_NO_SYSFSflag that prevents avtpm_proxydriver instance from having the typical sysfs entries that shows the state of the TPM. The flag is to be set in the ioctl creating thevtpm_proxydevice pair and maps on a new chip flagsTPM_CHIP_FLAG_NO_SYSFS.No other subsystem does something so goofy, this really needs to be part of namespace support for TPM.
And I am not sure how to go about this. TPM2 by the way doesn't have such entries, so it's much better from that perspective.
Quoted 2 lines
Why can't you just make the sysfs files unreadable in user space?
There are actually ways to go about this. Likely bind-mounting over /sys/device/virtual/tpm would be one solution to hide all virtual TPM device. Another is applying an AppArmor policy to the container denying access to tpm directories or entries. SELinux would not be so easy.
The flag in this patch seemed like a 'cheap' way to eliminate that problem as well.
Quoted 2 lines
If a container can make them readable again can't it also just create the chardev node?
What do you mean by making them readable again? The chardev node can be created inside the container with the major and minor numbers as it was created with the ioctl.
Stefan
Quoted 3 lines
Jason
------------------------------------------------------------------------------
Attend Shape: An AT&T Tech Expo July 15-16. Meet us at AT&T Park in San Francisco, CA to explore cutting-edge tech and listen to tech luminaries present their vision of the future. This family event has something for everyone, including kids. Get more information and register today.
http://sdm.link/attshape
Quoted 11 lines · Stefan Berger
Quoted 7 lines · Jason Gunthorpe
Quoted 4 lines · Stefan Berger
Introduce
TPM_VTPM_PROXY_NO_SYSFSflag that prevents avtpm_proxydriver instance from having the typical sysfs entries that shows the state of the TPM. The flag is to be set in the ioctl creating thevtpm_proxydevice pair and maps on a new chip flagsTPM_CHIP_FLAG_NO_SYSFS.No other subsystem does something so goofy, this really needs to be part of namespace support for TPM.
And I am not sure how to go about this. TPM2 by the way doesn't have such entries, so it's much better from that perspective.
Presumably this will become obvious when you figure out how to make namespaces work for IMA.. tpm #0 will have to change, and that will have to impact the sysfs layout.
Quoted 6 lines
Quoted 1 line
Why can't you just make the sysfs files unreadable in user space?
There are actually ways to go about this. Likely bind-mounting over
/sys/device/virtual/tpmwould be one solution to hide all virtual TPM device. Another is applying an AppArmor policy to the container denying access to tpm directories or entries. SELinux would not be so easy.
Seems reasonable
Quoted 2 lines
The flag in this patch seemed like a 'cheap' way to eliminate that problem as well.
Generally hacks like this are discouraged in the kernel.
Quoted 6 lines
Quoted 2 lines
If a container can make them readable again can't it also just create the chardev node?
What do you mean by making them readable again? The chardev node can be created inside the container with the major and minor numbers as it was created with the ioctl.
Well, root in the container can undo all sorts of things. It can unbind mount the sysfs, it could change file permissions and it could manually create the char dev nodes. AFAIK the only way to protect against root in the container is to have full kernel namespace support for the device..
Jason
------------------------------------------------------------------------------
Attend Shape: An AT&T Tech Expo July 15-16. Meet us at AT&T Park in San Francisco, CA to explore cutting-edge tech and listen to tech luminaries present their vision of the future. This family event has something for everyone, including kids. Get more information and register today.
http://sdm.link/attshape
Quoted 15 lines · Stefan Berger
Quoted 7 lines · Jason Gunthorpe
Quoted 4 lines · Stefan Berger
Introduce
TPM_VTPM_PROXY_NO_SYSFSflag that prevents avtpm_proxydriver instance from having the typical sysfs entries that shows the state of the TPM. The flag is to be set in the ioctl creating thevtpm_proxydevice pair and maps on a new chip flagsTPM_CHIP_FLAG_NO_SYSFS.No other subsystem does something so goofy, this really needs to be part of namespace support for TPM.
And I am not sure how to go about this. TPM2 by the way doesn't have such entries, so it's much better from that perspective.
Quoted 2 lines
Why can't you just make the sysfs files unreadable in user space?
Quoted 7 lines
There are actually ways to go about this. Likely bind-mounting over
/sys/device/virtual/tpmwould be one solution to hide all virtual TPM device. Another is applying an AppArmor policy to the container denying access to tpm directories or entries. SELinux would not be so easy.The flag in this patch seemed like a 'cheap' way to eliminate that problem as well.
Does it have any other qualities that would make this better than bind mounting?
/Jarkko
Quoted 18 lines · Jarkko Sakkinen
Quoted 17 lines · Stefan Berger
Quoted 7 lines · Jason Gunthorpe
Quoted 4 lines · Stefan Berger
Introduce
TPM_VTPM_PROXY_NO_SYSFSflag that prevents avtpm_proxydriver instance from having the typical sysfs entries that shows the state of the TPM. The flag is to be set in the ioctl creating thevtpm_proxydevice pair and maps on a new chip flagsTPM_CHIP_FLAG_NO_SYSFS.No other subsystem does something so goofy, this really needs to be part of namespace support for TPM.
And I am not sure how to go about this. TPM2 by the way doesn't have such entries, so it's much better from that perspective.
Quoted 1 line
Why can't you just make the sysfs files unreadable in user space?
There are actually ways to go about this. Likely bind-mounting over
/sys/device/virtual/tpmwould be one solution to hide all virtual TPM device. Another is applying an AppArmor policy to the container denying access to tpm directories or entries. SELinux would not be so easy.
Quoted 4 lines
Quoted 2 lines
The flag in this patch seemed like a 'cheap' way to eliminate that problem as well.
Does it have any other qualities that would make this better than bind mounting?
Not sure what to argue with. Maybe setting a bit on an ioctl that needs to be executed would be a good argument.
stefan
Quoted 3 lines
/Jarkko
------------------------------------------------------------------------------
Attend Shape: An AT&T Tech Expo July 15-16. Meet us at AT&T Park in San Francisco, CA to explore cutting-edge tech and listen to tech luminaries present their vision of the future. This family event has something for everyone, including kids. Get more information and register today.
http://sdm.link/attshape