Commit Graph

1762 Commits

Author SHA1 Message Date
Stefan Berger
8522c9dfad man: Add rsa-keysize-4096 to possible capabilties output of swtpm
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2025-05-08 20:49:36 -04:00
Stefan Berger
e3668c9f26 swtpm_setup: Add support for RSA-4096 keys for EKs
Add support for RSA-4096 kyes for EKs. This requires users to choose the
default-v2 profile because this is the only profile that currently enables
this type of a key.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2025-05-08 20:49:36 -04:00
Stefan Berger
8a3592fb02 tests: Extend regex to allow for optional RSA-4096 keys
libtpms v0.11 will support RSA-4096 keys. Adjust the test case
regex for optional output of 'tpm2-rsa-keysize-4096'.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2025-05-07 10:28:58 -04:00
Stefan Berger
fdb2b546d4 samples: Have 2 more files shellcheck'ed
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2025-05-02 09:50:19 -04:00
Stefan Berger
6d951a7a35 debian: Do not user parallel testing to avoid timeouts
The build for RISC-V causes timeouts when running tests in parallel due
to the CPU being emulated. Avoid the timeouts by not running parallel
tests.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2025-04-29 21:32:07 -04:00
Stefan Berger
4d2e967423 tests: Use proper command line options on GNU/Hurd systems
GNU/Hurd systems use the same sed/sha1sum/state command lines as Linux
and Cygwin.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2025-04-28 20:38:14 -04:00
Stefan Berger
6df68dcde5 swtpm: Make swtpm compilable on GNU/Hurd systems
Fix issues related to headers to make swtpm compilable on GNU/Hurd systems.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2025-04-28 20:38:14 -04:00
Stefan Berger
bfa18c8208 swtpm_setup: Define PATH_MAX on GNU/Hurd systems since undefined there
Per documentation GNU/Hurd does not define PATH_MAX. Therefore, define it
ourselves.

https://www.gnu.org/software/libc/manual/html_node/Limits-for-Files.html

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2025-04-28 20:38:14 -04:00
Stefan Berger
9bdd62d1e9 swtpm: Define ACCESSPERMS if not defined in sys/stat.h
Define ACCESSPERMS if it is not defined, such as for example on Alpine.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2025-04-26 14:50:30 -04:00
Stefan Berger
b602ca0b81 swtpm: Factor-out code to file_read
Move the file reading parts from SWTPM_NVRAM_LoadData_Dir into file_read.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2025-04-26 14:06:47 -04:00
Stefan Berger
9e2c3a1dec swtpm: Factor-out code to file_write
Move the file writing parts from SWTPM_NVRAM_StoreData_Dir into file_write.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2025-04-26 14:06:47 -04:00
Stefan Berger
7d2ee6ebc2 swtpm: Remove unused fsync code from directory backend
Remove the unused fsync code from the directory backend since it could not
be used due to potential reason for TPM command timeouts.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2025-04-26 14:06:47 -04:00
Stefan Berger
a507efb5b7 ci: Update from ubuntu-20.04 to ubuntu-24.04 due to EOL
Github actions does not run ubuntu-20.04 anymore due to EOL. Update the
20.04 entries to use 24.04.

cpp-coveralls needs an older version of python3 due to pkgutil.ImpImporter
having disappeared in more recent python versions. Therefore, leave
test-coveralls at 22.04.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2025-04-16 16:38:52 -04:00
Stefan Berger
8ad31a72ab swtpm.spec: Apply previous changes also to swtpm.spec.in
Suggested-by: Ajeeth Adithya <ajeeth.adithya@nutanix.com>
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2025-04-11 18:20:50 -04:00
Ajeeth Adithya
738d9e13c1 swtpm.spec: Change the order of uninstallation of the SELinux modules
Reverse the order of uninstallation of the ‘swtpm’ and ‘swtpm_svirt’
selinux modules. The current order fails because 'swtpm-svirt' module
has a dependency on the 'swtpm' module. This results in the ‘swtpm'
module not being cleaned up during %postun:

$ semodule -l | grep swtpm
swtpm
swtpm_svirt

$ semodule -n -X 200 -s targeted -r swtpm
libsemanage.semanage_direct_remove_key: Removing last swtpm module (no other swtpm module exists at another priority).
Failed to resolve typeattributeset statement at /var/lib/selinux/targeted/tmp/modules/200/swtpm_svirt/cil:4
/sbin/semodule:  Failed!

$ sudo semodule -n -X 200 -s targeted -r swtpm_svirt
libsemanage.semanage_direct_remove_key: Removing last swtpm_svirt module (no other swtpm_svirt module exists at another priority).

$ semodule -l | grep swtpm
swtpm

Signed-off-by: Ajeeth Adithya <ajeeth.adithya@nutanix.com>
2025-04-09 17:53:57 -04:00
Ajeeth Adithya
84c5ca58db swtpm.spec: Back up the default file contexts
Add the %selinux_relabel_pre macro in the %pre section to back up the
current file contexts lists. This is required since %selinux_relabel_post
macro in the %posttrans section uses the backup to revert to the original contexts.

Signed-off-by: Ajeeth Adithya <ajeeth.adithya@nutanix.com>
2025-04-09 17:53:57 -04:00
Stefan Berger
a79d2d0671 swtpm: Close connection_fd.fd before assigning new value (CID 459830)
Coverity complains that the assignment of connection_fd.fd = mlp->fd
leaks the value of connection_fd.fd. However, the logic is so that
this cannot happen because further down in the loop:

1) only when connection_fd.fd < 0, then pollfds[DATA_SERVER_FD] gets
   a value
2) connection_fd.fd = accept() only happens if 1) happened

However, if mlp->flags & MAIN_LOOP_FLAG_USE_FD is != 0 then
connection_fd was assigned a value and 1) never happens.

=> Fix the Coverity complaint even though it is a false positive.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2025-04-09 10:20:46 -04:00
Stefan Berger
36a93edca6 ci: Add a coverity workflow
Trigger the coverity scan workflow when pushing to coverity_scan branch.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2025-04-08 22:33:38 -04:00
Stefan Berger
8a42a2f7e8 swtpm: Use custom profile's Algorithms when removing FIPS-disabled ones
Use the custom profile's Algorithms when adjusting them for FIPS mode,
rather than the list of all implemented Algorithms. The list of implemented
Algorithms contains for example elliptic curve identifiers, such as
ecc-nist-p192, ecc-nist-p224, ecc-nist-p256, ecc-nist-p384, ecc-nist-p521,
ecc-bn-p256, ecc-bn-p638, that are not part of the custom profile but are
enabled with the ecc-min-size=192, ecc-nist, and ecc-bn shortcuts there.
Using the algorithms of the custom profile avoids confusion since otherwise
the additional ecc-nist-* and ecc-bn-* algorithm identifiers appear in the
modified custom profile even though the were not part of the original one.

Test:

  swtpm_setup --tpm2 --tpmstate . --overwrite \
     --profile-name custom --profile-remove-disabled fips-host

  before:
  ...,ecc,ecc-min-size=224,ecc-nist,ecc-bn,ecc-nist-p224,ecc-nist-p256,
      ecc-nist-p384,ecc-nist-p521,ecc-bn-p256,ecc-bn-p638,ecc-sm2-p256,...

  now:

  ...,ecc,ecc-min-size=224,ecc-nist,ecc-bn,ecc-sm2-p256,...

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2025-04-04 12:21:27 -04:00
Stefan Berger
7243fddab6 sample: Enable passing usual curve names secp256r1 or secp384r1
Enable passing the usual curve names of secp256r1 and secp384r1 instead
of ecc256 and ecc384 on the command line of swtpm-create-tpmca.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2025-04-01 12:50:34 -04:00
Stefan Berger
58c9549cdc samples: Support different key algorithms for created TPM 2 CA
Extend swtpm-create-tpm to support rsa2048 (default), rsa3072, ecc256
(NIST P256), and ecc384 (NIST P384) for the created TPM 2 CA. The names
are taken from the output of:

  tpm2_ptool addkey --help

ecc521 does not seem to work with the TPM 2 stack even though it is
advertised as a possible option.

Extend an existing test case to create an ecc256 key and extend man page.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2025-03-30 19:17:25 -04:00
Stefan Berger
64bbdcadad swtpm_setup: Do not pass a TPM 2 profile to swtpm when reconfiguring
Ensure that no profile is passed to the TPM 2 when it is to be reconfigured
by:

- Showing an error if user tries to pass a profile when also --reconfigure
  is passed
- Not taking the default profile from the swtpm_setup.conf configuration
  file if the user did not pass a profile

Extend an existing test case with a default profile in its swtpm_setup.conf
so that the above 2nd item is tested.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2025-03-28 11:35:22 -04:00
Stefan Berger
2c4cd12050 swtpm_setup: Use DISTRO_PROFILES_DIR when listing profiles (fix path issue)
When listing profiles, then the profiles in the distro directory did not
show up since the directory formed by 'DATAROOTDIR "swtpm/profiles"' was
missing a '/' at the end of DATAROOTDIR. Use DISTRO_PROFILES_DIR instead.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2025-03-26 08:41:59 -04:00
Stefan Berger
5af1ee9edf ci: Run apt-get update
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2025-02-24 09:21:18 -05:00
Stefan Berger
1cee599a4d selinux: Add rule to allow swtpm_t opening of virt_log_t files (BZ 2278123)
Link: https://bugzilla.redhat.com/show_bug.cgi?id=2278123#c40
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2025-02-24 09:21:18 -05:00
Stefan Berger
0528ac733b github: Disable docker workflow since not pushing to docker hub anymore
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2025-01-20 11:50:19 -05:00
Marc-André Lureau
cfe93d90b6 SELinux: add NFS permissions for swtpm_t
swtpm fails with a NFS mount. `setsebool virt_use_nfs on` should fix it.

Resolves: https://issues.redhat.com/browse/RHEL-73809

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2025-01-20 11:04:23 -05:00
Marc-André Lureau
01e804ff0a SELinux: allow to map state file
Specify vtpm state to a file instead of dir:

<tpm model="tpm-crb">
  <backend type="emulator" version="2.0">
    <source type="file" path="/var/lib/libvirt/swtpm/mytest/mytpm2-00.permall"/>
  </backend>
</tpm>

$ virsh start avocado-vt-vm1
error: Failed to start domain 'avocado-vt-vm1'
error: internal error: Could not run '/usr/bin/swtpm_setup'. exitstatus: 1; Check error log '/var/log/swtpm/libvirt/qemu/avocado-vt-vm1-swtpm.log' for details.

$ cat /var/log/swtpm/libvirt/qemu/avocado-vt-vm1-swtpm.log
SWTPM_NVRAM_LinearFile_Mmap: Could not mmap file: Permission denied
/usr/bin/swtpm exit with status 256:

$ ausearch -m avc
----
time->Thu Dec 12 08:43:07 2024
type=PROCTITLE msg=audit(1734010987.020:1455): proctitle=2F7573722F62696E2F737774706D00736F636B6574002D2D7072696E742D737461746573002D2D74706D7374617465006261636B656E642D7572693D66696C653A2F2F2F7661722F6C69622F6C6962766972742F737774706D2F6D79746573742F6D7974706D322D30302E7065726D616C6C002D2D74706D32002D2D6C6F67
type=SYSCALL msg=audit(1734010987.020:1455): arch=c000003e syscall=9 success=no exit=-13 a0=0 a1=c0 a2=3 a3=1 items=0 ppid=22547 pid=22549 auid=4294967295 uid=59 gid=59 euid=59 suid=59 fsuid=59 egid=59 sgid=59 fsgid=59 tty=(none) ses=4294967295 comm="swtpm" exe="/usr/bin/swtpm" subj=system_u:system_r:swtpm_t:s0 key=(null)
type=AVC msg=audit(1734010987.020:1455): avc:  denied  { map } for
pid=22549 comm="swtpm"
path="/var/lib/libvirt/swtpm/mytest/mytpm2-00.permall" dev="dm-0"
ino=202744025 scontext=system_u:system_r:swtpm_t:s0
tcontext=system_u:object_r:virt_var_lib_t:s0 tclass=file permissive=0

Resolves: https://issues.redhat.com/browse/RHEL-70835

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2025-01-20 11:04:23 -05:00
Stefan Berger
3d6a8b75b3 swtpm: Fix build error on 32bit systems due to inconsistent _FILE_OFFSET_BITS
Some checks failed
Docker / build (push) Has been cancelled
Fix the following build error due to missing include of config.h where
_FILE_OFFSET_BITS is defined and leads to different sizes of off_t depending
on whether it is defined and/or included:

tpmlib.h:76:7: error: type of 'tpmlib_handle_tcg_tpm2_cmd_header' does not match original declaration [-Werror=lto-type-mismatch]
   76 | off_t tpmlib_handle_tcg_tpm2_cmd_header(const unsigned char *command,
      |       ^
tpmlib.c:576:7: note: return value type mismatch
  576 | off_t tpmlib_handle_tcg_tpm2_cmd_header(const unsigned char *command,
      |       ^
tpmlib.c:576:7: note: 'tpmlib_handle_tcg_tpm2_cmd_header' was previously declared here
tpmlib.c:576:7: note: code may be misoptimized unless '-fno-strict-aliasing' is used
lto1: all warnings being treated as errors
lto-wrapper: fatal error: gcc returned 1 exit status

Link: https://bugzilla.redhat.com/show_bug.cgi?id=2334600
Fixes: 599e2436d4 ("configure.ac: enable 64-bit file API on 32-bit systems")
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2024-12-27 17:48:32 -05:00
Stefan Berger
3a8e779e11 SELinux: Add rule for swtpm to be able to read password from pipe
Some checks are pending
Docker / build (push) Waiting to run
Link: https://bugzilla.redhat.com/show_bug.cgi?id=2334271
Resolves: https://github.com/stefanberger/swtpm/issues/964
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2024-12-26 18:28:03 -05:00
Stefan Berger
5344c0a9c3 ci: Consolidate linter into container run and remove simple test
Some checks failed
Docker / build (push) Has been cancelled
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-12-16 10:09:06 -05:00
Stefan Berger
daf3b1ee27 ci: Add github actions to replace Travis
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-12-16 10:09:06 -05:00
Marc-André Lureau
544b3981c4 swtpm-setup: fix invalid path
Make sure there is a '/' after DATAROOTDIR.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2024-12-16 07:46:45 -05:00
Stefan Berger
c5c4af9efd man: Improve swtpm_setup --tpm option documentation
Some checks failed
Docker / lint (push) Has been cancelled
Docker / build (push) Has been cancelled
Docker / test (push) Has been cancelled
Improve the swtpm_setup --tpm option documentation that did not mention
that the socket option must be passed along when swtpm is being used.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-12-10 11:06:38 -05:00
Stefan Berger
314f5f411b Travis: Downgrade to setuptools 59.6.0 to avoid error in 71.x
There seems to be a well known error in setuptools 71.x that prevents
installation of cpp-coveralls on Travis now:

File "/usr/local/lib/python3.10/dist-packages/setuptools/_core_metadata.py", line 285, in _distribution_fullname

    canonicalize_version(version, strip_trailing_zero=False),

TypeError: canonicalize_version() got an unexpected keyword argument 'strip_trailing_zero'

Fall back to the default version that is used in Ubuntu Jammy (59.6.0)
since later versions also lead to the same error.

Link: https://github.com/pypa/setuptools/issues/4483
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-12-02 15:24:57 -05:00
Stefan Berger
62a5767f90 build-sys: Bump up version to 0.11.0 at beginning of dev cycle
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-12-02 15:24:57 -05:00
Stefan Berger
ad4427ab8c debian/rpm: Adjust changelog for 0.10.0 release
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-11-15 14:19:43 -05:00
Stefan Berger
34fe38b527 CHANGES: Add documentation for changes in 0.10.0
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-11-15 14:19:43 -05:00
Stefan Berger
3001ce11ee debian: Use --disable-hardening to avoid multiple usages of -D_FORTIFY_SOURCE=.
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-11-15 14:19:43 -05:00
Stefan Berger
5f5a227721 rpm: Build swtpm-tests package from installed tests
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-11-15 07:52:59 -05:00
Stefan Berger
d059f40c61 swtpm/swtpm_setup: Initialize variables with NULL for RPM build
When building an rpm with swtpm.spec on Fedora 40 this type of errors
appear on variables that normally do not need to be initialized.

In file included from /usr/include/glib-2.0/glib.h:117,
                 from profile.c:14:
In function ‘g_autoptr_cleanup_generic_gfree’,
    inlined from ‘profile_gather_local’ at profile.c:307:23,
    inlined from ‘profile_printall’ at profile.c:366:10:
/usr/include/glib-2.0/glib/glib-autocleanups.h:32:3: error: ‘dir’ may be used uninitialized [-Werror=maybe-uninitialized]
   32 |   g_free (*pp);
      |   ^~~~~~~~~~~~
profile.c: In function ‘profile_printall’:
profile.c:307:23: note: ‘dir’ was declared here
  307 |     g_autofree gchar *dir;
      |                       ^~~

Include string.h since in some older build environments strcmp and strlen
do not have prototypes otherwise.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-11-15 07:52:59 -05:00
Stefan Berger
89f7a0545d swtpm: Check for null pointer from parsing string value
Check for a null pointer from parsing the string value in
json_get_submap_value(). All callers assume that the returned value is
non-NULL and therefore ensure that there is always a valid string.
However, all callers also provide trusted input from TPMLIB_GetInfo that
should never cause a NULL pointer.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-11-13 16:47:17 -05:00
Stefan Berger
fcda38b463 swtpm_setup: Handle case when returned profile Name is null
The profile '{"Name": null}' will not lead to a parser error but return
NULL for the 'Name'. Therefore, check for variable name being a NULL
pointer. Since the user may provide this type of profile this could have
lead to crashes when name was accessed.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-11-13 16:47:17 -05:00
Stefan Berger
e02bf61a22 swtpm_cert: Move error message about importing signing key into else branch
Move the error message about the failure to import a signing key into the
else branch where it should be (all other branches of the if-then-else
statement have a check already). Also mention the key's filename and hint
at possibly corrupted key.

Link: https://bugzilla.redhat.com/show_bug.cgi?id=2325901
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-11-13 13:52:07 -05:00
Stefan Berger
4eb51c38d9 swtpm_setup: Add missing --print-profiles to help screen
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-11-12 20:53:07 -05:00
Stefan Berger
bf4fc05517 swtpm: Fix name of variable passed to TPM_DEBUG
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-11-08 12:41:36 -05:00
Stefan Berger
f6f858eada man: Add some clarification to the nameing of profiles in files
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-11-08 11:57:26 -05:00
Stefan Berger
2c8865a3ac man: Format JSON maps for better display
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-11-08 11:57:26 -05:00
Stefan Berger
28345d008b swtpm_setup: Comment flags for storage primary key and deprecate --create-spk
Comment the flags used for creating the storage primary key.
Deprecate the --create-spk option since it may create an RSA-3072 key
and it creates a NIST P384 instead of NIST P256, both of which users may
not expect and know how to use.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-11-07 08:33:04 -05:00
Stefan Berger
cc52b200b0 debian: Add rule to allow usage of /var/tmp directory (QEMU)
QEMU's functional tests need access to /var/tmp/**. To avoid the following
type of AppArmor permission failures add a rule that allows access to
/var/tmp/**.

 type=AVC msg=audit(1730829888.863:260): apparmor="DENIED" \
   operation="mknod" class="file" profile="swtpm" \
   name="/var/tmp/qemu_3r9txw7z/swtpm-socket" pid=3925 comm="swtpm" \
   requested_mask="c" denied_mask="c" fsuid=1000 ouid=1000FSUID="stefanb" \
   OUID="stefanb"

[ To run the QEMU's functional tests use the following command:
    make check-functional ]

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-11-06 15:22:58 -05:00