stefanberger / swtpm

Libtpms-based TPM emulator with socket, character device, and Linux CUSE interface.
Other
564 stars 136 forks source link

swtpm: Use fchmod to set mode bits provided by user #861

Closed stefanberger closed 3 months ago

stefanberger commented 3 months ago

The mode bits that the user provided were only applied with open() and were subject to masking with the value of current umask. When umask was set to 0027 the test case test_commandline was failing because the mode bits on the create TPM state file were not the expected ones (masked by umask). Therefore, set the mode bits using fchmod if the user provided them, otherwise do not set them. This way the mode bits will be set to the values the user requested.

Currently the directory storage backend was setting the mode bits to the default value (0640) after opening the TPM state file. Now, if the user did not provide any mode bits then the mode bits will be set so that the file can be written to as owner. This ensures that at least mode bits 0600 are set by default. However, if the user provided mode bit flags then these will be used without modification.