• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

systemd / systemd / 23367620641

20 Mar 2026 07:25PM UTC coverage: 72.606% (+0.3%) from 72.351%
23367620641

push

github

bluca
kmod-setup: load vsock_loopback alongside vsock

Loading vmw_vsock_virtio_transport early at boot causes vsock to be
resident before any application opens an AF_VSOCK socket. Because the
kernel skips autoloading when the vsock module is already present,
vsock_loopback never gets loaded automatically, and any subsequent
bind() to VMADDR_CID_LOCAL fails with EADDRNOTAVAIL.

Fix this by explicitly loading vsock_loopback on virtio or VMWare
machines via the new may_have_vsock_looopback() helper, wich covers both
vmw_vsock_virtio_transport and vmware_vsock_vmci_transport case.
vsock_loopback is the only module that registers a transport for
VMADDR_CID_LOCAL (CID 1) and has no hard dependency from any of the
vsock transport modules.

Fixes: #41100
Follow-up for 381c78db4

2 of 2 new or added lines in 1 file covered. (100.0%)

2634 existing lines in 55 files now uncovered.

316477 of 435881 relevant lines covered (72.61%)

1159615.85 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

61.54
/src/integritysetup/integritysetup.c
1
/* SPDX-License-Identifier: LGPL-2.1-or-later */
2

3
#include <stdio.h>
4
#include <sys/stat.h>
5

6
#include "alloc-util.h"
7
#include "argv-util.h"
8
#include "cryptsetup-util.h"
9
#include "fileio.h"
10
#include "integrity-util.h"
11
#include "log.h"
12
#include "main-func.h"
13
#include "path-util.h"
14
#include "pretty-print.h"
15
#include "string-table.h"
16
#include "string-util.h"
17
#include "time-util.h"
18
#include "verbs.h"
19

20
static uint32_t arg_activate_flags;
21
static int arg_percent;
22
static usec_t arg_commit_time;
23
static char *arg_existing_data_device;
24
static IntegrityAlgorithm arg_integrity_algorithm = _INTEGRITY_ALGORITHM_INVALID;
25

26
STATIC_DESTRUCTOR_REGISTER(arg_existing_data_device, freep);
20✔
27

28
/* Integrity algorithm names used by dm-integrity */
29
static const char* const dm_integrity_algorithm_table[_INTEGRITY_ALGORITHM_MAX] = {
30
        [INTEGRITY_ALGORITHM_CRC32]        = "crc32",
31
        [INTEGRITY_ALGORITHM_CRC32C]       = "crc32c",
32
        [INTEGRITY_ALGORITHM_XXHASH64]     = "xxhash64",
33
        [INTEGRITY_ALGORITHM_SHA1]         = "sha1",
34
        [INTEGRITY_ALGORITHM_SHA256]       = "sha256",
35
        [INTEGRITY_ALGORITHM_HMAC_SHA256]  = "hmac(sha256)",
36
        [INTEGRITY_ALGORITHM_HMAC_SHA512]  = "hmac(sha512)",
37
        [INTEGRITY_ALGORITHM_PHMAC_SHA256] = "phmac(sha256)",
38
        [INTEGRITY_ALGORITHM_PHMAC_SHA512] = "phmac(sha512)",
39
};
40

41
DEFINE_PRIVATE_STRING_TABLE_LOOKUP_TO_STRING(dm_integrity_algorithm, IntegrityAlgorithm);
10✔
42

UNCOV
43
static int help(void) {
×
UNCOV
44
        _cleanup_free_ char *link = NULL;
×
UNCOV
45
        int r;
×
46

47
        r = terminal_urlify_man("systemd-integritysetup@.service", "8", &link);
×
UNCOV
48
        if (r < 0)
×
UNCOV
49
                return log_oom();
×
50

51
        printf("%s attach VOLUME DEVICE [HMAC_KEY_FILE|-] [OPTIONS]\n"
×
52
               "%s detach VOLUME\n\n"
53
               "Attach or detach an integrity protected block device.\n"
54
               "\nSee the %s for details.\n",
55
               program_invocation_short_name,
56
               program_invocation_short_name,
57
               link);
58

59
        return 0;
60
}
61

UNCOV
62
static int load_key_file(
×
63
                const char *key_file,
64
                void **ret_key_file_contents,
65
                size_t *ret_key_file_size) {
66
        int r;
×
67
        _cleanup_(erase_and_freep) char *tmp_key_file_contents = NULL;
×
68
        size_t tmp_key_file_size;
×
69

UNCOV
70
        if (!path_is_absolute(key_file))
×
UNCOV
71
                return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "key file not absolute path: %s", key_file);
×
72

UNCOV
73
        r = read_full_file_full(
×
74
                        AT_FDCWD, key_file, UINT64_MAX, DM_MAX_KEY_SIZE,
75
                        READ_FULL_FILE_SECURE|READ_FULL_FILE_WARN_WORLD_READABLE|READ_FULL_FILE_CONNECT_SOCKET|READ_FULL_FILE_FAIL_WHEN_LARGER,
76
                        NULL,
77
                        &tmp_key_file_contents, &tmp_key_file_size);
UNCOV
78
        if (r < 0)
×
UNCOV
79
                return log_error_errno(r, "Failed to process key file: %m");
×
80

UNCOV
81
        if (ret_key_file_contents && ret_key_file_size) {
×
UNCOV
82
                *ret_key_file_contents = TAKE_PTR(tmp_key_file_contents);
×
UNCOV
83
                *ret_key_file_size = tmp_key_file_size;
×
84
        }
85

86
        return 0;
87
}
88

89
static const char *integrity_algorithm_select(const void *key_file_buf) {
10✔
UNCOV
90
        IntegrityAlgorithm a = arg_integrity_algorithm >= 0
×
91
                ? arg_integrity_algorithm
92
                : (key_file_buf ? INTEGRITY_ALGORITHM_HMAC_SHA256 : INTEGRITY_ALGORITHM_CRC32C);
10✔
93

94
        return dm_integrity_algorithm_to_string(a);
10✔
95
}
96

97
static int verb_attach(int argc, char *argv[], uintptr_t _data, void *userdata) {
10✔
98
        _cleanup_(crypt_freep) struct crypt_device *cd = NULL;
10✔
99
        crypt_status_info status;
10✔
100
        _cleanup_(erase_and_freep) void *key_buf = NULL;
10✔
101
        size_t key_buf_size = 0;
10✔
102
        int r;
10✔
103

104
        /* attach name device optional_key_file optional_options */
105

106
        assert(argc >= 3 && argc <= 5);
10✔
107

108
        const char *volume = argv[1],
10✔
109
                *device = argv[2],
10✔
110
                *key_file = mangle_none(argc > 3 ? argv[3] : NULL),
10✔
111
                *options = mangle_none(argc > 4 ? argv[4] : NULL);
10✔
112

113
        if (!filename_is_valid(volume))
10✔
UNCOV
114
                return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Volume name '%s' is not valid.", volume);
×
115

116
        if (key_file) {
10✔
UNCOV
117
                r = load_key_file(key_file, &key_buf, &key_buf_size);
×
UNCOV
118
                if (r < 0)
×
119
                        return r;
120
        }
121

122
        if (options) {
10✔
123
                r = parse_integrity_options(options, &arg_activate_flags, &arg_percent,
10✔
124
                                            &arg_commit_time, &arg_existing_data_device, &arg_integrity_algorithm);
125
                if (r < 0)
10✔
126
                        return r;
127
        }
128

129
        r = crypt_init(&cd, device);
10✔
130
        if (r < 0)
10✔
UNCOV
131
                return log_error_errno(r, "Failed to open integrity device %s: %m", device);
×
132

133
        cryptsetup_enable_logging(cd);
10✔
134

135
        status = crypt_status(cd, volume);
10✔
136
        if (IN_SET(status, CRYPT_ACTIVE, CRYPT_BUSY)) {
10✔
UNCOV
137
                log_info("Volume %s already active.", volume);
×
UNCOV
138
                return 0;
×
139
        }
140

141
        r = crypt_load(cd,
30✔
142
                       CRYPT_INTEGRITY,
143
                       &(struct crypt_params_integrity) {
10✔
144
                               .journal_watermark = arg_percent,
145
                               .journal_commit_time = DIV_ROUND_UP(arg_commit_time, USEC_PER_SEC),
10✔
146
                               .integrity = integrity_algorithm_select(key_buf),
10✔
147
                       });
148
        if (r < 0)
10✔
149
                return log_error_errno(r, "Failed to load integrity superblock: %m");
×
150

151
        if (!isempty(arg_existing_data_device)) {
10✔
152
                r = crypt_set_data_device(cd, arg_existing_data_device);
5✔
153
                if (r < 0)
5✔
154
                        return log_error_errno(r, "Failed to add separate data device: %m");
×
155
        }
156

157
        r = crypt_activate_by_volume_key(cd, volume, key_buf, key_buf_size, arg_activate_flags);
10✔
158
        if (r < 0)
10✔
UNCOV
159
                return log_error_errno(r, "Failed to set up integrity device: %m");
×
160

161
        return 0;
162
}
163

164
static int verb_detach(int argc, char *argv[], uintptr_t _data, void *userdata) {
10✔
165
        _cleanup_(crypt_freep) struct crypt_device *cd = NULL;
10✔
166
        int r;
10✔
167

168
        assert(argc == 2);
10✔
169

170
        const char *volume = argv[1];
10✔
171

172
        if (!filename_is_valid(volume))
10✔
173
                return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Volume name '%s' is not valid.", volume);
×
174

175
        r = crypt_init_by_name(&cd, volume);
10✔
176
        if (r == -ENODEV) {
10✔
UNCOV
177
                log_info("Volume %s already inactive.", volume);
×
UNCOV
178
                return 0;
×
179
        }
180
        if (r < 0)
10✔
UNCOV
181
                return log_error_errno(r, "crypt_init_by_name() failed: %m");
×
182

183
        cryptsetup_enable_logging(cd);
10✔
184

185
        r = crypt_deactivate(cd, volume);
10✔
186
        if (r < 0)
10✔
UNCOV
187
                return log_error_errno(r, "Failed to deactivate: %m");
×
188

189
        return 0;
190
}
191

192
static int run(int argc, char *argv[]) {
20✔
193
        if (argv_looks_like_help(argc, argv))
20✔
UNCOV
194
                return help();
×
195

196
        log_setup();
20✔
197

198
        cryptsetup_enable_logging(NULL);
20✔
199

200
        umask(0022);
20✔
201

202
        static const Verb verbs[] = {
20✔
203
                { "attach", 3, 5, 0, verb_attach },
204
                { "detach", 2, 2, 0, verb_detach },
205
                {}
206
        };
207

208
        return dispatch_verb(argc, argv, verbs, NULL);
20✔
209
}
210

211
DEFINE_MAIN_FUNCTION(run);
20✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc