Commit Graph
858 Commits
Author SHA1 Message Date
Jan Janssen c4ba5fef78 boot: Fix calls to ResetSystem
gnu-efi falsely declares a return type for ResetSystem when it should be
void. The spec also says that it never returns, so just assert.
2022-06-23 18:41:35 +02:00
Jan Janssen 01d81c126b meson: Reorder cflags for sd-boot
Currently, -Wall and -Wextra override previously passed flags like
-Wno-unused-parameter. This reorders them to be passed before any
optional flags. -Wsign-compare is part of -Wextra and therefore dropped.
-nostdlib is a link-stage flag and dropped as it is already part of
efi_ldflags.
2022-06-17 12:57:41 +09:00
Yu Watanabe 288bafa952 Merge pull request #23691 from medhefgo/efi-clang
efi: Add parse_number8/16
2022-06-11 05:01:24 +09:00
Yu Watanabe 3e808e0769 Merge pull request #23701 from medhefgo/boot-mem
boot: Use memcpy/memset provided by firmware
2022-06-11 04:29:27 +09:00
Shreenidhi Shedi 1dea9f1268 boot: use efi_memcpy inplace of memcpy
`efi_memcpy` does some validations before referencing pointers, it is
the safer option for this case.

Fixes: CID#1489876
2022-06-11 04:25:35 +09:00
Jan Janssen 8494bd1ced boot: Use memcpy/memset provided by firmware
These are significantly faster and safe us from rolling our own
optimized versions.
2022-06-10 15:54:06 +02:00
Jan Janssen 2b0af8e76a boot: Mark memcmp/memcpy/memset aliases as used
The compiler may emit calls to these but also optimize the function away
somehow, breaking at link stage. Marking them as used prevents this.
2022-06-10 15:54:02 +02:00
Jan Janssen f23b2a04e6 efi-string: Remove one more |= for bool
This one was missed in #23589.
2022-06-10 14:14:57 +02:00
Jan Janssen 153381952b boot: Use parse_number16 for boot counter parsing 2022-06-10 11:50:13 +02:00
Jan Janssen 1621ab4600 boot: Drop use of Atoi 2022-06-10 11:50:13 +02:00
Jan Janssen 72bd3458e5 boot: Add parse_number8/16 2022-06-10 11:50:13 +02:00
Yu Watanabe da5fb1877d boot/efi-string: check the end of haystack before testing remaining pattern
Fixes buffer-overflow reported at https://github.com/systemd/systemd/pull/23589#issuecomment-1151820341.
2022-06-10 12:05:38 +09:00
Jan Janssen 55233913c8 boot: Drop use of DuplicateDevicePath 2022-06-09 12:50:13 +02:00
Jan Janssen e17fd5538f boot: Don't copy device path
BS->LocateDevicePath only advances the passed device path pointer.
It does not actually modify it, so there is no need to make a copy.
2022-06-09 12:50:13 +02:00
Jan Janssen b05d69ed72 boot: Drop use of LibLocateHandle 2022-06-09 12:50:13 +02:00
Jan Janssen b04f818417 boot: Drop use of UnpackDevicePath
Device paths are a packed data structure and the UEFI spec is clear that
members may be misaligned.

In this case all accesses are aligned except for the signature. We can
simply memcpy it instead of making a whole (aligned) copy of the device
path.
2022-06-09 12:50:13 +02:00
Jan Janssen 79a2b916a0 boot: Drop use of FileDevicePath 2022-06-09 12:50:13 +02:00
Jan Janssen 0af26643d0 boot: Use xmalloc
This drops the unused xnew0 and xallocate_zero_pool as there is only two
users of it. _cleanup_freepool_ will be phased out once the types in the
declarations are changed/renamed.
2022-06-09 12:50:13 +02:00
Jan Janssen 9148312fab boot: Add xmalloc 2022-06-09 12:50:13 +02:00
Jan Janssen 5594ebee99 boot: Drop use of DevicePathFromHandle 2022-06-09 12:50:13 +02:00
Jan Janssen 6a261332bc boot: Drop use of LibLocateProtocol 2022-06-09 12:50:13 +02:00
Jan Janssen f747ca3ec3 boot: Drop use of LibOpenRoot 2022-06-09 12:50:13 +02:00
Jan Janssen 7ebce8145e boot: Drop use of LibGetSystemConfigurationTable 2022-06-09 12:50:13 +02:00
Jan Janssen 23742af522 boot: Drop use of MetaiMatch
A future commit will add support for unicode collation protocol that
allows case folding and comparing strings with locale awareness. But it
only operates on whole strings, so fnmatch cannot use those without a
heavy cost. Instead we just case fold the patterns instead (the IDs we
try to match are already lower case).
2022-06-09 12:50:13 +02:00
Jan Janssen 0e8ecba96e boot: Add efi_fnmatch
Unlike MetaiMatch from the UEFI spec/EDK2 this implementation is
intended to be compatible with POSIX fnmatch.
2022-06-09 12:50:08 +02:00
Zbigniew Jędrzejewski-Szmek da60e5b5c7 bootctl: inline iterator variable 2022-06-07 15:17:06 +02:00
Yu Watanabe 095e173a04 boot: use CMP() macro for safety 2022-06-03 04:20:46 +09:00
Yu Watanabe 42e785d096 boot: make several functions inline
Follow-ups for #23512.
2022-06-03 04:20:46 +09:00
Yu Watanabe a54e635d02 boot: fix typo 2022-06-03 04:20:46 +09:00
Yu Watanabe 9db25d01ef Merge pull request #23531 from yuwata/sd-bus-drop-version-2
sd-bus: drop version 2 format support
2022-06-01 14:51:44 +09:00
Yu Watanabe b4e7df4a47 boot: use ALIGN4() 2022-06-01 03:41:15 +09:00
Jan Janssen 7783ab5df1 boot: Use xstrdup8/16
Note that xstrdup is now safe to call with a NULL pointer and will
just return NULL in that case.
2022-05-31 15:15:01 +02:00
Jan Janssen 101f68ff33 boot: Add xstrdup8/16 2022-05-31 15:15:01 +02:00
Jan Janssen bbc1f2eac5 boot: Use memcmp/memcpy/memset 2022-05-31 15:15:01 +02:00
Jan Janssen f7967716e3 boot: Add memcmp/memcpy/memset 2022-05-31 15:14:56 +02:00
Jan Janssen 60c2af56d6 boot: Use strsize8/16 2022-05-31 15:14:56 +02:00
Jan Janssen 96dc0dd387 boot: Add strsize8/16 2022-05-31 15:14:54 +02:00
Jan Janssen fb67588c62 boot: Use strchr8/16 2022-05-31 15:13:58 +02:00
Jan Janssen 5d7e0e8341 boot: Add strchr8/16 2022-05-31 15:13:58 +02:00
Jan Janssen 08ed842b56 boot: Use strcpy8/16 2022-05-31 15:10:48 +02:00
Jan Janssen ef4d71ad7f boot: Add strcpy8/16 2022-05-31 15:10:48 +02:00
Jan Janssen fc178cf1f8 boot: Use strtolower8/16 2022-05-31 15:10:48 +02:00
Jan Janssen 98850528bf boot: Add strtolower8/16 2022-05-31 15:10:45 +02:00
Jan Janssen 3d5127c68f boot: Use strcmp16 for cpio sorting 2022-05-31 15:09:10 +02:00
Jan Janssen ec436bdf16 boot: Use strcmp8/16
This also replaces streq and similar functions for consistency. Note
that streq16 is null pointer safe, so streq_ptr can be safely replaced
too.
2022-05-31 15:09:10 +02:00
Jan Janssen 0d933d024a boot: Add strcmp8/16 2022-05-31 15:09:06 +02:00
Jan Janssen 5f49747255 boot: Use strlen8/16
The casts in this and the next few commits are curently necessary
because CHAR8 is defined as uint8_t in gnu-efi, while char is signed.
Once we switch from gnu-efi typedefs to stdint types, the casts
will be dropped.
2022-05-31 14:18:43 +02:00
Jan Janssen 9080ffd4cd boot: Add strlen8/16 2022-05-31 14:18:43 +02:00
Jan Janssen 11f9a32de0 boot: Use stddef.h offsetof 2022-05-31 14:18:43 +02:00
Jason A. Donenfeld 87cb1ab676 Simplify random number selection
We currently have a convoluted and complex selection of which random
numbers to use. We can simplify this down to two functions that cover
all of our use cases:

1) Randomness for crypto: this one needs to wait until the RNG is
   initialized. So it uses getrandom(0). If that's not available, it
   polls on /dev/random, and then reads from /dev/urandom. This function
   returns whether or not it was successful, as before.

2) Randomness for other things: this one uses getrandom(GRND_INSECURE).
   If it's not available it uses getrandom(GRND_NONBLOCK). And if that
   would block, then it falls back to /dev/urandom. And if /dev/urandom
   isn't available, it uses the fallback code. It never fails and
   doesn't return a value.

These two cases match all the uses of randomness inside of systemd.

I would prefer to make both of these return void, and get rid of the
fallback code, and simply assert in the incredibly unlikely case that
/dev/urandom doesn't exist. But Luca disagrees, so this commit attempts
to instead keep case (1) returning a return value, which all the callers
already check, and fix the fallback code in (2) to be less bad than
before.

For the less bad fallback code for (2), we now use auxval and some
timestamps, together with various counters representing the invocation,
hash it all together and provide the output. Provided that AT_RANDOM is
secure, this construction is probably okay too, though notably it
doesn't have any forward secrecy. Fortunately, it's only used by
random_bytes() and not by crypto_random_bytes().
2022-05-31 09:20:52 +02:00