X Tutup
Skip to content

Commit bd4dea7

Browse files
poetteringyuwata
authored andcommitted
veritysetup: fix memory corruption
We must copy the option string, since in one case we are called with a pointer into dynamic memory that will be freed by the caller. As discussed here: https://github.com/systemd/systemd/pull/22908/files#r839394490 Follow-up for: systemd#22908
1 parent 95cd219 commit bd4dea7

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

src/veritysetup/veritysetup.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717
#include "terminal-util.h"
1818

1919
static uint32_t arg_activate_flags = CRYPT_ACTIVATE_READONLY;
20-
static const char *arg_root_hash_signature = NULL;
20+
static char *arg_root_hash_signature = NULL;
21+
22+
STATIC_DESTRUCTOR_REGISTER(arg_root_hash_signature, freep);
2123

2224
static int help(void) {
2325
_cleanup_free_ char *link = NULL;
@@ -39,13 +41,17 @@ static int help(void) {
3941
}
4042

4143
static int save_roothashsig_option(const char *option, bool strict) {
44+
int r;
4245

4346
if (path_is_absolute(option) || startswith(option, "base64:")) {
4447
if (!HAVE_CRYPT_ACTIVATE_BY_SIGNED_KEY)
4548
return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP),
4649
"Activation of verity device with signature requested, but cryptsetup does not support crypt_activate_by_signed_key().");
4750

48-
arg_root_hash_signature = option;
51+
r = free_and_strdup_warn(&arg_root_hash_signature, option);
52+
if (r < 0)
53+
return r;
54+
4955
return true;
5056
}
5157

@@ -60,10 +66,10 @@ static int parse_options(const char *options) {
6066
int r;
6167

6268
/* backward compatibility with the obsolete ROOTHASHSIG positional argument */
63-
r = save_roothashsig_option(options, false);
69+
r = save_roothashsig_option(options, /* strict= */ false);
6470
if (r < 0)
6571
return r;
66-
if (r == 1) {
72+
if (r > 0) {
6773
log_warning("Usage of ROOTHASHSIG positional argument is deprecated. "
6874
"Please use the option root-hash-signature=%s instead.", options);
6975
return 0;
@@ -99,7 +105,7 @@ static int parse_options(const char *options) {
99105
arg_activate_flags |= CRYPT_ACTIVATE_PANIC_ON_CORRUPTION;
100106
#endif
101107
else if ((val = startswith(word, "root-hash-signature="))) {
102-
r = save_roothashsig_option(val, true);
108+
r = save_roothashsig_option(val, /* strict= */ true);
103109
if (r < 0)
104110
return r;
105111

0 commit comments

Comments
 (0)
X Tutup