Commit Graph

268 Commits

Author SHA1 Message Date
Lennart Poettering 6b000af4f2 tree-wide: avoid some loaded terms
https://tools.ietf.org/html/draft-knodel-terminology-02
https://lwn.net/Articles/823224/

This gets rid of most but not occasions of these loaded terms:

1. scsi_id and friends are something that is supposed to be removed from
   our tree (see #7594)

2. The test suite defines an API used by the ubuntu CI. We can remove
   this too later, but this needs to be done in sync with the ubuntu CI.

3. In some cases the terms are part of APIs we call or where we expose
   concepts the kernel names the way it names them. (In particular all
   remaining uses of the word "slave" in our codebase are like this,
   it's used by the POSIX PTY layer, by the network subsystem, the mount
   API and the block device subsystem). Getting rid of the term in these
   contexts would mean doing some major fixes of the kernel ABI first.

Regarding the replacements: when whitelist/blacklist is used as noun we
replace with with allow list/deny list, and when used as verb with
allow-list/deny-list.
2020-06-25 09:00:19 +02:00
Lennart Poettering 6930d069a3 cryptsetup: pass selected mode to crypt_load() when doing LUKS
This doesn't fix anything IRL, but is a bit cleaner, since it makes sure
that arg_type is properly passed to crypt_load() in all cases.

We actually never set arg_type to CRYPT_LUKS2, which is why this wasn't
noticed before, but theoretically this might change one day, and
existing comments suggest it as possible value for arg_type, hence let's
process it properly.
2020-06-09 14:24:21 +02:00
Lennart Poettering 5af39ac850 cryptsetup: try to load bitlocker superblock only if requested
let's do automatic discovery only for our native LUKS/LUKS2 headers,
since they are Linux stuff, and let's require that BitLocker to be
requested explicitly.

This makes sure cryptsetup without either "luks" nor "bitlk" in the
option string will work. Right now it would fail because we'd load the
superblock once with luks and once with bitlk and one of them would
necessarily fail.

Follow-up for #15979
2020-06-09 14:24:15 +02:00
Maxim Fomin 6cc27c29ad Add 'bitlk' option to mount Bitlocker drives with cryptsetup. 2020-06-09 08:12:55 +02:00
Lennart Poettering 53ac130b51 cryptsetup: support tmp= file system argument
Let's catch up with Debian a bit more.

This also changes the default from ext2 to ext4.

Fixes: #952
2020-05-26 17:11:34 +02:00
Lennart Poettering 4eb08bdb71 cryptsetup: fix minor indentation issue 2020-05-19 17:28:43 +02:00
Lennart Poettering 0ba6f85ed3 cryptsetup: optionally, see if empty password works for unlocking the file system
This adds a new switch try-empty-password. If set and none of PKCS#11 or
key files work, it is attempted to unlock the volume with an empty
password, before the user is asked for a password.

Usecase: an installer generates an OS image on one system, which is the
booted up for the first time in a possibly different system. The image
is encrypted using a random volume key, but an empty password. A tool
that runs on first boot then queries the user for a password to set or
enrols the volume in the TPM, removing the empty password. (Of course, in
such a scenario it is important to never reuse the installer image on
multiple systems as they all will have the same volume key, but that's a
different question.)
2020-05-19 17:28:40 +02:00
Lennart Poettering 2424fb7e7b cryptsetup: fix minor memory leak 2020-05-19 17:28:36 +02:00
Lennart Poettering c6b1d7d1da cryptsetup: also check for /dev/hwrng as random device node 2020-05-19 17:28:33 +02:00
Lennart Poettering cb6c9283b5 cryptsetup: make sure to return EAGAIN on wrong tcrypt password too
Only then we'll try again to ask the user for a password.

Fixes: #12152
2020-05-19 17:28:29 +02:00
Lennart Poettering 7407f68980 cryptsetup: automatically load luks keys off disk
Let's make loading of keys a bit more automatic and define a common
place where key files can be placed. Specifically, whenever a volume of
name "foo" is attempted, search for a key file in
/etc/cryptsetup-keys.d/foo.key and /run/cryptsetup-keys.d/foo.key,
unless a key file is declared explicitly.

With this scheme we have a simple discovery in place that should make it
more straightfoward wher to place keys, and requires no explicit
configuration to be used.
2020-05-19 17:28:25 +02:00
Lennart Poettering 23769fb371 cryptsetup: split out key loading from pkcs11 code and teach search path logic
Let's do some rearrangements, so that we can later on use this to
automatically search for a key file.
2020-05-19 17:28:16 +02:00
Lennart Poettering d3d49e7649 cryptsetup: optionally remove key file after use
This is useful when the key file is acquired dynamically in some form
and should be erased after use.

Note that this code tries to be robust, and removes the key file both on
success and on failure.
2020-05-19 17:28:13 +02:00
Lennart Poettering 8ced40c09b cryptsetup: catch up with debian crypttab options a bit
Support some aliases Debian added, and drop some options that Debian
dropped from our list of unsupported options.
2020-05-19 17:28:09 +02:00
Lennart Poettering db2c56b0dd cryptsetup-generator: use systemd-makefs for implementation of "swap" and "tmp" options
This way we can take benefit of the correct block device locking we just
added.

I was thinking whether to instead pull in a regular
systemd-makefs@.service instance, but I couldn't come up with a reason
to, and thus opted for just doing the minimal patch and just replacing
the simply mkfs calls.

Fixes: #10179
Replaces: #13162
2020-05-18 20:50:03 +02:00
Zbigniew Jędrzejewski-Szmek 162392b75a tree-wide: spellcheck using codespell
Fixes #15436.
2020-04-16 18:00:40 +02:00
Lennart Poettering a7e8855879 units: introduce blockdev@.target for properly ordering mounts/swaps against cryptsetup
Let's hook it into both cryptsetup-generator and gpt-auto-generator with
a shared implementation in generator.c

Fixes: #8472
2020-01-21 20:23:13 +01:00
Lennart Poettering 6bbd539e5e cryptsetup-generator: order after cryptsetup-pre.target unconditionally 2020-01-21 20:23:10 +01:00
Lennart Poettering 49685fb314 cryptsetup-generator: break overly long line 2020-01-21 20:23:06 +01:00
Frantisek Sumsal e514aa1eea tree-wide: yet another batch of coccinelle recommendations
Prettify certain parts of the codebase using coccinelle transformations
(no functional changes).
2020-01-02 13:32:55 +01:00
Lennart Poettering 6789dd57f0 cryptsetup-pkcs11: just return zero on success, no need to return anything else 2019-12-17 18:54:07 +01:00
Lennart Poettering 3ded1d616a cryptsetup-pkcs11: line break some overly long lines 2019-12-17 18:54:04 +01:00
Lennart Poettering 12f69587e9 cryptsetup-pkcs11: refuse keys above 16MiB size 2019-12-17 18:54:00 +01:00
Lennart Poettering 13b6c4c8de
Merge pull request #14267 from poettering/pkcs11-cryptsetup
just the pkcs11 hookup for classic cryptsetup (/etc/crypttab) split out of the homed PR
2019-12-17 15:30:32 +01:00
Lennart Poettering c16782577b
Merge pull request #14241 from keszybz/resume-timeout
Bump resume timeout to infinity
2019-12-17 10:34:43 +01:00
Lennart Poettering 086697094e cryptsetup: add native pkcs#11 support to cryptsetup
This adds a new crypttab option for volumes "pkcs11-uri=" which takes a
PKCS#11 URI. When used the key stored in the line's key file is
decrypted with the private key the PKCS#11 URI indiciates.

This means any smartcard that can store private RSA keys is usable for
unlocking LUKS devices.
2019-12-09 19:25:25 +01:00
Franck Bui 1dc85eff1d crypsetup: introduce x-initrd.attach option
This option is an indication for PID1 that the entry in crypttab is handled by
initrd only and therefore it shouldn't interfer during the usual start-up and
shutdown process.

It should be primarily used with the encrypted device containing the root FS as
we want to keep it (and thus its encrypted device) until the very end of the
shutdown process, i.e. when initrd takes over.

This option is the counterpart of "x-initrd.mount" used in fstab.

Note that the slice containing the cryptsetup services also needs to drop the
usual shutdown dependencies as it's required by the cryptsetup services.

Fixes: #14224
2019-12-05 11:43:02 +01:00
Zbigniew Jędrzejewski-Szmek 7cecc56316 cryptsetup-generator: unconfuse writing of the device timeout
The code was using timeout=0 as the default option string. This option string
was ultimately passed to generator_write_timeouts(), which only looks for
comment=systemd.device-timeout= or x-systemd.device-timeout=, i.e. the whole
call path was bogus. Let's rework this: generator_write_timeouts() now writes
any timeouts if configured by the user. create_disk() writes out it's own
timeout, but with lower priority. Since the code path that was calling
timeout=0 was not effective, the only change is that we stop overwriting the
timeout if explicitly configured by the user.

In both code paths, ignore failure to write.
2019-12-03 17:20:19 +01:00
Michal Sekletár 408c81f624 cryptsetup: reduce the chance that we will be OOM killed
cryptsetup introduced optional locking scheme that should serialize
unlocking keyslots which use memory hard key derivation
function (argon2). Using the serialization should prevent OOM situation
in early boot while unlocking encrypted volumes.
2019-11-27 18:34:36 +01:00
Lennart Poettering 9120aa820b cryptsetup: use STR_IN_SET() where appropriate
Note that this slightly changes behaviour: "none" is only allowed as
option, if it's the only option specified, but not in combination with
other options. I think this makes more sense, since it's the choice when
no options shall be specified.
2019-11-19 15:34:09 +01:00
Lennart Poettering 9c5253ffec cryptsetup: minor coding style clean-ups 2019-11-19 15:34:09 +01:00
Zbigniew Jędrzejewski-Szmek ed4ad48897 Allow overriding /etc/fstab with $SYSTEMD_FSTAB 2019-11-13 22:04:51 +01:00
Zbigniew Jędrzejewski-Szmek 32c6237a7c cryptsetup-generator: guess whether the keyfile argument is two items or one
Fixes #13615.

See the inline comment for documentation.
2019-11-13 22:04:45 +01:00
Zbigniew Jędrzejewski-Szmek 3f5ac3038e cryptsetup-generator: allow overriding /run/systemd/cryptsetup with $RUNTIME_DIRECTORY
I added a fairly vague entry to docs/ENVIRONMENT because I think it is worth
mentioning there (in case someone is looking for any environment variable that
might be relevant).
2019-11-13 22:04:38 +01:00
Zbigniew Jędrzejewski-Szmek a6c57e74c5 cryptsetup-generator: allow overriding crypttab path with $SYSTEMD_CRYPTAB 2019-11-13 17:55:51 +01:00
Yu Watanabe 455fa9610c tree-wide: drop string.h when string-util.h or friends are included 2019-11-04 00:30:32 +09:00
Jay Strict d90874b4e2 cryptsetup: bump minimum libcryptsetup version to v2.0.1
libcryptsetup v2.0.1 introduced new API calls, supporting 64 bit wide
integers for `keyfile_offset`. This change invokes the new function
call, gets rid of the warning that was added in #7689, and removes
redundant #ifdefery and constant definitions.
See https://gitlab.com/cryptsetup/cryptsetup/issues/359.

Fixes #7677.
2019-10-01 13:34:06 +02:00
Zbigniew Jędrzejewski-Szmek fef716b28b cryptsetup: don't assert on variable which is optional
50d2eba27b (commitcomment-34519739)

In add_crypttab_devices() split_keyspec is called on the keyfile argument,
which may be NULL.
2019-08-01 09:49:24 +02:00
Zbigniew Jędrzejewski-Szmek 5d2100dc4c cryptsetup: use unabbrieviated variable names
Now that "ret_" has been added to the output variables, we can name
the internal variables without artificial abbrevs.
2019-08-01 08:13:13 +02:00
Lennart Poettering f4ea8432e6 cryptsetup-generator: fix coverity issue
Fixes coverity issue 1403772
2019-07-31 09:38:59 +02:00
shinygold 50d2eba27b cryptsetup: add keyfile-timeout to allow a keydev timeout and allow to fallback to a password if it fails. 2019-07-17 14:00:29 +02:00
Lennart Poettering 0e3cb57dae cryptsetup: no need to zero-initialize zero-initialized structures 2019-07-16 12:40:22 +02:00
Lennart Poettering b910cc72c0 tree-wide: get rid of strappend()
It's a special case of strjoin(), so no need to keep both. In particular
as typing strjoin() is even shoert than strappend().
2019-07-12 14:31:12 +09:00
Ivan Shapovalov 568a84048e cryptsetup: enable libcryptsetup debug logging if we want it
Even if we set a log callback that would accept debug messages, libcryptsetup
needs debug logging enabled explicitly for it to happen.
2019-07-08 16:02:41 +03:00
Ivan Shapovalov 8c71b2cd44 cryptsetup: set libcryptsetup global log callback too 2019-07-06 13:56:19 +03:00
Lubomir Rintel 844d5a87c9 cryptsetup-generator: fix luks-* entry parsing from crypttab
This reverts a part of commit 49fe5c0996 ('tree-wide: port various places
over to STARTSWITH_SET()') that replaced a pair of startswith() calls
with STARTSWITH_SET().

They were in fact for a different strings (device vs. name), botching
the crypttap parsing.
2019-06-28 10:18:59 +02:00
Michael Stapelberg 307472654c
cryptsetup: comment: crypt_setup → crypt_format 2019-06-27 09:38:30 +02:00
Lennart Poettering c6134d3e2f path-util: get rid of prefix_root()
prefix_root() is equivalent to path_join() in almost all ways, hence
let's remove it.

There are subtle differences though: prefix_root() will try shorten
multiple "/" before and after the prefix. path_join() doesn't do that.
This means prefix_root() might return a string shorter than both its
inputs combined, while path_join() never does that. I like the
path_join() semantics better, hence I think dropping prefix_root() is
totally OK. In the end the strings generated by both functon should
always be identical in terms of path_equal() if not streq().

This leaves prefix_roota() in place. Ideally we'd have path_joina(), but
I don't think we can reasonably implement that as a macro. or maybe we
can? (if so, sounds like something for a later PR)

Also add in a few missing OOM checks
2019-06-21 08:42:55 +09:00
Zbigniew Jędrzejewski-Szmek 665b0af866
Merge pull request #12636 from mbroz/master
Cryptsetup: call crypt_load() once for LUKS and support LUKS2 tokens
2019-05-30 14:27:22 +02:00
Roberto Santalla 38ab1ec9c8 cryptsetup: Add dependency for detached header
Fixes #12650

cryptsetup: Extract dependency check to a separate function

cryptsetup: style improvements, error checking
Return early on failure/nothing to do
Removed braces from single-line ifs
Check return value of  fstab_filter_options

cryptsetup: code style
2019-05-30 09:42:50 +02:00