Skip to content

eBPF-based security platform

treewide: name return codes ret

Daniel Borkmann1ff305a2572b
diff --git a/AGENTS.md b/AGENTS.md
index af2f83f4..607eeaeb 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -122,6 +122,8 @@ package for `bpm info`.
`va_list` forms, which only `util/string.c` and the `xasprintf()` of
`util/malloc.c` call, and `check-style.sh` rejects them outside
`testing/`.
+- **Name a return code `ret`**, as the kernel does, and an errno from a
+ callee that a function keeps beside the value it returns `err`.
- **Declare locals in reverse-Christmas-tree order** (the netdev
convention): longest declaration line first, shortest last. Group
declarations that have no initializer dependency and sort them by
diff --git a/builtin-attest.c b/builtin-attest.c
index 279968c6..81919ae4 100644
--- a/builtin-attest.c
+++ b/builtin-attest.c
@@ -184,14 +184,14 @@ static int member_add_file(struct members *m, const char *path)
{
struct shirudo_measured_upatch *e;
struct shirudo_upatch u;
- int rc;
+ int ret;
if (m->n >= ATTEST_MEMBERS_MAX)
return -E2BIG;
- rc = upatch_open(path, &u);
- if (rc) {
- pr_err("attest: open %s: %s", path, strerror(-rc));
- return rc;
+ ret = upatch_open(path, &u);
+ if (ret) {
+ pr_err("attest: open %s: %s", path, strerror(-ret));
+ return ret;
}
e = &m->set[m->n++];
memcpy(e->name, u.hdr.name, UPATCH_NAME_MAX);
@@ -486,7 +486,7 @@ static int cmd_attest_verify(int argc, const char **argv)
char *evidence = NULL, *report;
size_t evidence_len = 0, nonce_len = 0, i;
bool have_cert = false, have_nonce = false, have_tree_root = false;
- int rc, ret = 2;
+ int err, ret = 2;
m.set = xcalloc(ATTEST_MEMBERS_MAX, sizeof(*m.set));
report = xmalloc(ATTEST_REPORT_MAX);
@@ -647,14 +647,14 @@ static int cmd_attest_verify(int argc, const char **argv)
}
if (read_evidence(evidence_path, &evidence, &evidence_len))
goto out;
- rc = attest_verify(evidence, evidence_len, &x, report,
- ATTEST_REPORT_MAX);
+ err = attest_verify(evidence, evidence_len, &x, report,
+ ATTEST_REPORT_MAX);
fputs(report, stdout);
- if (rc == -EINVAL) {
+ if (err == -EINVAL) {
pr_err("attest verify: %s is not a shirudo evidence document",
evidence_path);
ret = 2;
- } else if (rc) {
+ } else if (err) {
printf("verdict: FAIL\n");
ret = 1;
} else {
@@ -677,7 +677,7 @@ static int cmd_attest_challenge(int argc, const char **argv)
char *evidence = NULL, *doc = NULL, *report;
char hex[2 * TPM_CREDENTIAL_LEN + 1];
size_t evidence_len = 0, len = 0, cap = 0, i, n;
- int rc, ret = 2;
+ int err, ret = 2;
report = xmalloc(ATTEST_REPORT_MAX);
if (!report)
@@ -724,16 +724,16 @@ static int cmd_attest_challenge(int argc, const char **argv)
}
if (read_evidence(evidence_path, &evidence, &evidence_len))
goto out;
- rc = attest_challenge_make(evidence, evidence_len, &pol,
- credential, &doc, &len, &cap, report,
- ATTEST_REPORT_MAX);
+ err = attest_challenge_make(evidence, evidence_len, &pol,
+ credential, &doc, &len, &cap, report,
+ ATTEST_REPORT_MAX);
fputs(report, stdout);
- if (rc == -EINVAL) {
+ if (err == -EINVAL) {
pr_err("attest challenge: %s carries no endorsement key",
evidence_path);
goto out;
}
- if (rc) {
+ if (err) {
printf("verdict: FAIL\n");
ret = 1;
goto out;
@@ -748,11 +748,11 @@ static int cmd_attest_challenge(int argc, const char **argv)
ret = 1;
goto out;
}
- rc = write_complete(fd, doc, len) ||
+ err = write_complete(fd, doc, len) ||
write_complete(fd, "\n", 1) ? -EIO : 0;
- if (close(fd) && !rc)
- rc = -EIO;
- if (rc) {
+ if (close(fd) && !err)
+ err = -EIO;
+ if (err) {
pr_err("attest challenge: write %s: %s", out_path,
strerror(errno));
ret = 1;
@@ -779,7 +779,7 @@ static int cmd_attest_evidence(int argc, const char **argv)
const char *out_path = NULL, *challenge_path = NULL;
char *doc = NULL;
size_t nonce_len = 0, len = 0, cap = 0, i;
- int rc;
+ int ret;
for (i = 1; i < (size_t)argc; i++) {
const char *a = argv[i];
@@ -819,25 +819,25 @@ static int cmd_attest_evidence(int argc, const char **argv)
}
request = challenge_path ? &challenge : NULL;
- rc = shirudo_attest_evidence_config(nonce, nonce_len, mask, request,
- shirudo_image_update_context(),
- &doc, &len, &cap);
- if (rc == -ENXIO) {
+ ret = shirudo_attest_evidence_config(nonce, nonce_len, mask, request,
+ shirudo_image_update_context(),
+ &doc, &len, &cap);
+ if (ret == -ENXIO) {
pr_err("attest: no TPM answered (tpm_error)");
return 1;
}
- if (rc == -ENODEV) {
+ if (ret == -ENODEV) {
pr_err("attest: register 0x%08X is not bound this boot "
"(tpm_error); run shirudo init first",
NV_INDEX);
return 1;
}
- if (rc == -EKEYREJECTED) {
+ if (ret == -EKEYREJECTED) {
pr_err("attest: the challenge was refused (tampered?)");
return 1;
}
- if (rc) {
- pr_err("attest: evidence failed: %s", strerror(-rc));
+ if (ret) {
+ pr_err("attest: evidence failed: %s", strerror(-ret));
return 1;
}
if (out_path) {
@@ -846,23 +846,23 @@ static int cmd_attest_evidence(int argc, const char **argv)
if (fd < 0) {
pr_err("attest: open %s: %s", out_path, strerror(-fd));
- rc = fd;
+ ret = fd;
} else {
if (write_complete(fd, doc, len) ||
write_complete(fd, "\n", 1))
- rc = -EIO;
- if (close(fd) && !rc)
- rc = -EIO;
- if (rc)
+ ret = -EIO;
+ if (close(fd) && !ret)
+ ret = -EIO;
+ if (ret)
pr_err("attest: write %s: %s", out_path,
strerror(errno));
}
} else if (fwrite(doc, 1, len, stdout) != len ||
fputc('\n', stdout) == EOF) {
- rc = -EIO;
+ ret = -EIO;
}
xfree(doc, cap);
- return rc ? 1 : 0;
+ return ret ? 1 : 0;
}
int cmd_attest(int argc, const char **argv)
diff --git a/builtin-bpm.c b/builtin-bpm.c
index 497155d3..ec94def3 100644
--- a/builtin-bpm.c
+++ b/builtin-bpm.c
@@ -77,24 +77,24 @@ static int prepare_direct_install(const char *raw, struct bpm_source *source,
char package_name[BPM_MAX_NAME] = {};
char endpoint[BPM_MAX_ENDPOINT];
char url[PATH_MAX];
- int n_layers, rc;
-
- rc = bpm_oci_parse_pull_ref(raw, &c, repository, sizeof(repository), tag,
- sizeof(tag));
- if (rc)
- return rc;
- rc = bpm_oci_url(&c, repository, "manifests", tag, url, sizeof(url));
- if (rc)
- return rc;
- rc = bpm_oci_get_memory(&c, url,
- "application/vnd.oci.image.manifest.v1+json",
- &manifest);
- if (rc)
+ int n_layers, ret;
+
+ ret = bpm_oci_parse_pull_ref(raw, &c, repository, sizeof(repository), tag,
+ sizeof(tag));
+ if (ret)
+ return ret;
+ ret = bpm_oci_url(&c, repository, "manifests", tag, url, sizeof(url));
+ if (ret)
+ return ret;
+ ret = bpm_oci_get_memory(&c, url,
+ "application/vnd.oci.image.manifest.v1+json",
+ &manifest);
+ if (ret)
goto out;
- rc = bpm_oci_parse_manifest(manifest.data, manifest.len, layers,
- ARRAY_SIZE(layers), &n_layers, package_name,
- sizeof(package_name));
- if (rc)
+ ret = bpm_oci_parse_manifest(manifest.data, manifest.len, layers,
+ ARRAY_SIZE(layers), &n_layers, package_name,
+ sizeof(package_name));
+ if (ret)
goto out;
if (!package_name[0]) {
const char *base = strrchr(repository, '/');
@@ -103,11 +103,11 @@ static int prepare_direct_install(const char *raw, struct bpm_source *source,
base ? base + 1 : repository);
}
if (!bpm_package_name_ok(package_name)) {
- rc = -EINVAL;
+ ret = -EINVAL;
goto out;
}
if (strsprintf(endpoint, sizeof(endpoint), "oci://%s", c.registry) < 0) {
- rc = -ENAMETOOLONG;
+ ret = -ENAMETOOLONG;
goto out;
}
memset(source, 0, sizeof(*source));
@@ -120,10 +120,10 @@ static int prepare_direct_install(const char *raw, struct bpm_source *source,
/* package_install treats a non-digest reference as a tag. */
bpm_copy_string(entry->manifest_digest, sizeof(entry->manifest_digest), tag);
entry->package_size = -1;
- rc = 0;
+ ret = 0;
out:
bpm_buffer_free(&manifest);
- return rc;
+ return ret;
}
/*
@@ -140,32 +140,32 @@ static int download_package(const char *raw, const char *destination, int fd)
char repository[BPM_MAX_ENDPOINT], tag[BPM_MAX_NAME];
char url[PATH_MAX], filename[PATH_MAX], title[PATH_MAX];
char digest[65], package_name[BPM_MAX_NAME] = {};
- int n_layers = 0, out = fd, rc;
-
- rc = bpm_oci_parse_pull_ref(raw, &c, repository, sizeof(repository),
- tag, sizeof(tag));
- if (rc)
- return rc;
- rc = bpm_oci_url(&c, repository, "manifests", tag, url, sizeof(url));
- if (rc)
- return rc;
- rc = bpm_oci_get_memory(&c, url,
- "application/vnd.oci.image.manifest.v1+json",
- &manifest);
- if (rc)
+ int n_layers = 0, out = fd, ret;
+
+ ret = bpm_oci_parse_pull_ref(raw, &c, repository, sizeof(repository),
+ tag, sizeof(tag));
+ if (ret)
+ return ret;
+ ret = bpm_oci_url(&c, repository, "manifests", tag, url, sizeof(url));
+ if (ret)
+ return ret;
+ ret = bpm_oci_get_memory(&c, url,
+ "application/vnd.oci.image.manifest.v1+json",
+ &manifest);
+ if (ret)
goto out;
- rc = bpm_oci_parse_manifest(manifest.data, manifest.len, layers,
- ARRAY_SIZE(layers), &n_layers, package_name,
- sizeof(package_name));
- if (rc)
+ ret = bpm_oci_parse_manifest(manifest.data, manifest.len, layers,
+ ARRAY_SIZE(layers), &n_layers, package_name,
+ sizeof(package_name));
+ if (ret)
goto out;
bpm_trim(package_name, package_name, sizeof(package_name));
for (int i = 0; i < n_layers; i++) {
if (strcmp(layers[i].media, BPM_PACKAGE_MEDIA))
continue;
- rc = bpm_oci_url(&c, repository, "blobs", layers[i].digest,
- url, sizeof(url));
- if (rc)
+ ret = bpm_oci_url(&c, repository, "blobs", layers[i].digest,
+ url, sizeof(url));
+ if (ret)
goto out;
/* A cut title would name another file; fall back to the package name. */
if (bpm_trim(layers[i].title, title, sizeof(title)))
@@ -183,12 +183,12 @@ static int download_package(const char *raw, const char *destination, int fd)
if (package_name[0])
base = package_name;
if (!bpm_package_name_ok(base)) {
- rc = -EINVAL;
+ ret = -EINVAL;
goto out;
}
if (strsprintf(filename, sizeof(filename), "%s-%s.bee",
base, tag) < 0) {
- rc = -ENAMETOOLONG;
+ ret = -ENAMETOOLONG;
goto out;
}
}
@@ -197,31 +197,31 @@ static int download_package(const char *raw, const char *destination, int fd)
O_WRONLY | O_CREAT | O_TRUNC,
0644);
if (out < 0) {
- rc = out;
+ ret = out;
goto out;
}
}
- rc = bpm_oci_get_file(&c, url, BPM_PACKAGE_MEDIA, out,
- layers[i].size);
+ ret = bpm_oci_get_file(&c, url, BPM_PACKAGE_MEDIA, out,
+ layers[i].size);
if (!destination)
close(out);
- if (!rc && (sha256_file_hex(filename, digest, sizeof(digest)) ||
- !bpm_digest_matches(layers[i].digest, digest)))
- rc = -EKEYREJECTED;
- if (!rc && layers[i].size >= 0) {
+ if (!ret && (sha256_file_hex(filename, digest, sizeof(digest)) ||
+ !bpm_digest_matches(layers[i].digest, digest)))
+ ret = -EKEYREJECTED;
+ if (!ret && layers[i].size >= 0) {
struct stat st;
if (stat(filename, &st) || st.st_size != layers[i].size)
- rc = -EKEYREJECTED;
+ ret = -EKEYREJECTED;
}
- if (rc && !destination)
+ if (ret && !destination)
unlink(filename);
goto out;
}
- rc = -EINVAL;
+ ret = -EINVAL;
out:
bpm_buffer_free(&manifest);
- return rc;
+ return ret;
}
static int pull_package(const char *raw)
@@ -233,7 +233,7 @@ static int copy_file_ex(const char *src, const char *dst, mode_t mode,
bool exclusive)
{
struct stat in_st, out_st;
- int in, out, rc = 0;
+ int in, out, ret = 0;
__u8 buf[65536];
ssize_t n;
@@ -253,19 +253,19 @@ static int copy_file_ex(const char *src, const char *dst, mode_t mode,
return out;
}
while ((n = read(in, buf, sizeof(buf))) > 0) {
- rc = write_complete(out, buf, (size_t)n);
- if (rc)
+ ret = write_complete(out, buf, (size_t)n);
+ if (ret)
break;
}
- if (n < 0 && !rc)
- rc = -errno;
- if (fsync(out) && !rc)
- rc = -errno;
+ if (n < 0 && !ret)
+ ret = -errno;
+ if (fsync(out) && !ret)
+ ret = -errno;
close(in);
close(out);
- if (rc)
+ if (ret)
unlink(dst);
- return rc;
+ return ret;
}
static int copy_file(const char *src, const char *dst, mode_t mode)
@@ -342,13 +342,13 @@ static int load_source(const char *name, struct bpm_source *s)
{
char path[PATH_MAX], *line = NULL;
size_t capacity = 0;
- int got, rc = 0;
+ int got, ret = 0;
FILE *fp;
memset(s, 0, sizeof(*s));
- rc = source_path(name, path, sizeof(path));
- if (rc)
- return rc;
+ ret = source_path(name, path, sizeof(path));
+ if (ret)
+ return ret;
fp = source_open(path);
if (!fp)
return -errno;
@@ -357,18 +357,18 @@ static int load_source(const char *name, struct bpm_source *s)
return -EPERM;
}
if (strscpy(s->name, name, sizeof(s->name)) < 0)
- rc = -ENAMETOOLONG;
- while (!rc && (got = read_text_line(fp, &line, &capacity,
- PATH_MAX - 1)) != 0) {
- rc = got < 0 ? got :
+ ret = -ENAMETOOLONG;
+ while (!ret && (got = read_text_line(fp, &line, &capacity,
+ PATH_MAX - 1)) != 0) {
+ ret = got < 0 ? got :
bpm_parse_source_line(line,
s->endpoint, sizeof(s->endpoint),
s->key_file, sizeof(s->key_file));
}
libc_free(line);
fclose(fp);
- if (rc)
- return rc;
+ if (ret)
+ return ret;
if (!s->endpoint[0] || !s->key_file[0])
return -EINVAL;
/* With a config image the key file is the image's, named from its root. */
@@ -386,25 +386,25 @@ static int verify_with_source_key(const struct bpm_source *s,
const __u8 *data, size_t len,
const __u8 *sig, size_t sig_len)
{
- int fd, rc;
+ int fd, ret;
if (!shirudo_image_config_active())
return bpm_verify_cms(data, len, sig, sig_len, s->key_file);
fd = shirudo_image_open_relative(s->key_file, O_RDONLY);
if (fd < 0)
return fd;
- rc = bpm_verify_cms_fd(data, len, sig, sig_len, fd);
+ ret = bpm_verify_cms_fd(data, len, sig, sig_len, fd);
close(fd);
- return rc;
+ return ret;
}
static int save_source(const struct bpm_source *s)
{
char path[PATH_MAX], data[PATH_MAX * 2];
- int rc = source_path(s->name, path, sizeof(path));
+ int ret = source_path(s->name, path, sizeof(path));
- if (rc)
- return rc;
+ if (ret)
+ return ret;
if (strsprintf(data, sizeof(data), "endpoint = %s\nkey_file = %s\n",
s->endpoint, s->key_file) < 0)
return -E2BIG;
@@ -413,26 +413,26 @@ static int save_source(const struct bpm_source *s)
static int with_bpm_lock(void)
{
- int fd, rc;
+ int fd, ret;
- rc = seal_mkdir_p(LOCKS_DIR, 0700);
- if (rc)
- return rc;
+ ret = seal_mkdir_p(LOCKS_DIR, 0700);
+ if (ret)
+ return ret;
fd = seal_open(BPM_LOCK_PATH, O_RDWR | O_CREAT, 0600);
if (fd < 0)
return fd;
if (flock(fd, LOCK_EX)) {
- rc = -errno;
+ ret = -errno;
close(fd);
- return rc;
+ return ret;
}
return fd;
}
-static int bpm_fail(const char *action, int rc)
+static int bpm_fail(const char *action, int ret)
{
- if (rc < 0)
- pr_err("bpm %s: %s", action, strerror(-rc));
+ if (ret < 0)
+ pr_err("bpm %s: %s", action, strerror(-ret));
else
pr_err("bpm %s failed", action);
return 1;
@@ -453,7 +453,7 @@ static int sha256_file_hex(const char *path, char *hex, size_t hex_sz)
__u8 digest[CRYPTO_SHA256_LEN];
__u8 buf[65536];
ssize_t nr;
- int fd, rc = -EIO;
+ int fd, ret = -EIO;
if (hex_sz < 65 || sha256_init(&ctx) != 0)
return -EINVAL;
@@ -469,11 +469,11 @@ static int sha256_file_hex(const char *path, char *hex, size_t hex_sz)
if (nr < 0 || sha256_final(&ctx, digest) != 0)
goto done;
hex_encode(digest, sizeof(digest), hex);
- rc = 0;
+ ret = 0;
done:
close(fd);
sha256_free(&ctx);
- return rc;
+ return ret;
}
static int print_package_readme(const char *source)
@@ -483,40 +483,40 @@ static int print_package_readme(const char *source)
__u8 *beefile = NULL, *readme = NULL;
const char *archive = source;
char package_dir[101];
- int fd, rc;
+ int fd, ret;
if (!strncmp(source, "oci://", 6)) {
fd = mkstemp(temporary);
if (fd < 0)
return -errno;
archive = temporary;
- rc = download_package(source, archive, fd);
+ ret = download_package(source, archive, fd);
close(fd);
- if (rc)
+ if (ret)
goto out;
}
- rc = bpm_pkg_read_member_in(archive, "Beefile", NULL, package_dir,
- sizeof(package_dir), &beefile, &beefile_len,
- 4u * 1024u * 1024u);
- if (rc) {
- if (rc == -ENOENT)
+ ret = bpm_pkg_read_member_in(archive, "Beefile", NULL, package_dir,
+ sizeof(package_dir), &beefile, &beefile_len,
+ 4u * 1024u * 1024u);
+ if (ret) {
+ if (ret == -ENOENT)
pr_err("bpm info: package %s does not include Beefile", source);
goto out;
}
- rc = bpm_pkg_read_member_in(archive, "README.md", package_dir, NULL, 0,
- &readme, &readme_len, 4u * 1024u * 1024u);
- if (rc) {
- if (rc == -ENOENT)
+ ret = bpm_pkg_read_member_in(archive, "README.md", package_dir, NULL, 0,
+ &readme, &readme_len, 4u * 1024u * 1024u);
+ if (ret) {
+ if (ret == -ENOENT)
pr_err("bpm info: package %s does not include README.md", source);
goto out;
}
- rc = write_complete(STDOUT_FILENO, readme, readme_len);
+ ret = write_complete(STDOUT_FILENO, readme, readme_len);
out:
xfree(beefile, beefile_len + 1);
xfree(readme, readme_len + 1);
if (archive == temporary)
unlink(temporary);
- return rc;
+ return ret;
}
struct bpm_upatches_ctx {
@@ -573,18 +573,18 @@ static int print_upatch_member(void *ctx, const char *member, char type)
static int bpm_info_archive(const char *source, char temporary[])
{
- int fd, rc;
+ int fd, ret;
if (strncmp(source, "oci://", 6))
return 0;
fd = mkstemp(temporary);
if (fd < 0)
return -errno;
- rc = download_package(source, temporary, fd);
+ ret = download_package(source, temporary, fd);
close(fd);
- if (rc)
+ if (ret)
unlink(temporary);
- return rc;
+ return ret;
}
static int print_package_upatches(const char *source, bool all)
@@ -595,22 +595,22 @@ static int print_package_upatches(const char *source, bool all)
const char *archive = source;
char package_dir[101];
struct bpm_upatches_ctx ctx = { .all = all };
- int rc;
+ int ret;
- rc = bpm_info_archive(source, temporary);
- if (rc)
- return rc;
+ ret = bpm_info_archive(source, temporary);
+ if (ret)
+ return ret;
if (!strncmp(source, "oci://", 6))
archive = temporary;
- rc = bpm_pkg_read_member_in(archive, "Beefile", NULL, package_dir,
- sizeof(package_dir), &beefile, &beefile_len,
- 4u * 1024u * 1024u);
- if (!rc)
- rc = bpm_pkg_visit_members(archive, package_dir,
- print_upatch_member, &ctx);
- if (!rc && ctx.len)
- rc = write_complete(STDOUT_FILENO, ctx.list, ctx.len);
- if (rc == -ENOENT)
+ ret = bpm_pkg_read_member_in(archive, "Beefile", NULL, package_dir,
+ sizeof(package_dir), &beefile, &beefile_len,
+ 4u * 1024u * 1024u);
+ if (!ret)
+ ret = bpm_pkg_visit_members(archive, package_dir,
+ print_upatch_member, &ctx);
+ if (!ret && ctx.len)
+ ret = write_complete(STDOUT_FILENO, ctx.list, ctx.len);
+ if (ret == -ENOENT)
pr_err("bpm info upatches: package %s does not include Beefile",
source);
if (beefile)
@@ -619,7 +619,7 @@ static int print_package_upatches(const char *source, bool all)
xfree(ctx.list, ctx.cap);
if (archive == temporary)
unlink(temporary);
- return rc;
+ return ret;
}
static int print_package_upatch_data(const char *source, const char *member,
@@ -632,52 +632,52 @@ static int print_package_upatch_data(const char *source, const char *member,
const char *archive = source;
char package_dir[101];
struct shirudo_upatch u = {};
- int rc;
+ int ret;
if (!bpm_archive_rel_ok(member) || strncmp(member, "upatches/", 9) ||
strlen(member) < sizeof(suffix) - 1 ||
strcmp(member + strlen(member) - (sizeof(suffix) - 1), suffix) ||
strchr(member + 9, '/'))
return -EINVAL;
- rc = bpm_info_archive(source, temporary);
- if (rc)
- return rc;
+ ret = bpm_info_archive(source, temporary);
+ if (ret)
+ return ret;
if (!strncmp(source, "oci://", 6))
archive = temporary;
- rc = bpm_pkg_read_member_in(archive, "Beefile", NULL, package_dir,
- sizeof(package_dir), &beefile, &beefile_len,
- 4u * 1024u * 1024u);
- if (rc) {
- if (rc == -ENOENT)
+ ret = bpm_pkg_read_member_in(archive, "Beefile", NULL, package_dir,
+ sizeof(package_dir), &beefile, &beefile_len,
+ 4u * 1024u * 1024u);
+ if (ret) {
+ if (ret == -ENOENT)
pr_err("bpm info data: package %s does not include Beefile",
source);
goto out;
}
- rc = bpm_pkg_read_member_in(archive, member, package_dir, NULL, 0,
- &bytes, &upatch_len,
- UPATCH_FILE_MAX);
- if (rc) {
- if (rc == -ENOENT)
+ ret = bpm_pkg_read_member_in(archive, member, package_dir, NULL, 0,
+ &bytes, &upatch_len,
+ UPATCH_FILE_MAX);
+ if (ret) {
+ if (ret == -ENOENT)
pr_err("bpm info data: package %s has no member %s",
source, member);
goto out;
}
- rc = upatch_open_memory(bytes, upatch_len, &u);
- if (rc) {
+ ret = upatch_open_memory(bytes, upatch_len, &u);
+ if (ret) {
pr_err("bpm info data: %s is not a valid upatch", member);
goto out;
}
if (upatch_is_unload(&u)) {
pr_err("bpm info data: %s is an unload directive", member);
- rc = -EINVAL;
+ ret = -EINVAL;
goto out;
}
- rc = upatch_rodata_print(&u, member, json);
- if (rc == -ENODATA)
+ ret = upatch_rodata_print(&u, member, json);
+ if (ret == -ENODATA)
pr_err("bpm info data: %s has no loader .rodata map data", member);
- else if (rc == -ENOENT || rc == -EOPNOTSUPP)
+ else if (ret == -ENOENT || ret == -EOPNOTSUPP)
pr_err("bpm info data: %s has no supported BTF .rodata data", member);
- else if (rc == -EINVAL)
+ else if (ret == -EINVAL)
pr_err("bpm info data: cannot decode .rodata in %s", member);
out:
upatch_close(&u);
@@ -687,38 +687,38 @@ out:
xfree(bytes, upatch_len + 1);
if (archive == temporary)
unlink(temporary);
- return rc;
+ return ret;
}
static int cert_matches_active(const char *path)
{
struct shirudo_cert a = {}, b = {};
__u8 da[CRYPTO_SHA256_LEN], db[CRYPTO_SHA256_LEN];
- int rc = -EINVAL;
+ int ret = -EINVAL;
if (!cert_read_file(path, &a) &&
!cert_read_file(CERT_PATH, &b) &&
!cert_pubkey_digest(&a, da) &&
!cert_pubkey_digest(&b, db) &&
!memcmp(da, db, sizeof(da)))
- rc = 0;
+ ret = 0;
cert_free(&a);
cert_free(&b);
- return rc;
+ return ret;
}
static int key_file_fingerprint(const char *path, char hex[65])
{
struct shirudo_cert cert = {};
__u8 digest[CRYPTO_SHA256_LEN];
- int rc;
+ int ret;
- rc = cert_read_file(path, &cert);
- if (!rc)
- rc = cert_pubkey_digest(&cert, digest);
+ ret = cert_read_file(path, &cert);
+ if (!ret)
+ ret = cert_pubkey_digest(&cert, digest);
cert_free(&cert);
- if (rc)
- return rc;
+ if (ret)
+ return ret;
hex_encode(digest, sizeof(digest), hex);
return 0;
}
@@ -728,14 +728,14 @@ static int install_key_file(const char *src)
char hex[65], dst[PATH_MAX];
bool active, made = false;
struct stat st;
- int rc;
-
- rc = key_file_fingerprint(src, hex);
- if (rc)
- return rc;
- rc = seal_mkdir_p(KEYS_DIR, 0700);
- if (rc)
- return rc;
+ int ret;
+
+ ret = key_file_fingerprint(src, hex);
+ if (ret)
+ return ret;
+ ret = seal_mkdir_p(KEYS_DIR, 0700);
+ if (ret)
+ return ret;
active = lstat(CERT_PATH, &st) == 0;
if (!active && errno != ENOENT)
return -errno;
@@ -753,26 +753,26 @@ static int install_key_file(const char *src)
} else {
if (errno != ENOENT)
return -errno;
- rc = copy_file_ex(src, dst, 0644, true);
- if (rc)
- return rc;
+ ret = copy_file_ex(src, dst, 0644, true);
+ if (ret)
+ return ret;
made = true;
}
if (active)
return 0;
if (symlink(dst, CERT_PATH)) {
if (errno != EEXIST) {
- rc = -errno;
+ ret = -errno;
goto undo;
}
- rc = cert_matches_active(src) ? -EPERM : 0;
+ ret = cert_matches_active(src) ? -EPERM : 0;
goto undo;
}
- rc = seal_inherit_path(CERT_PATH);
+ ret = seal_inherit_path(CERT_PATH);
undo:
- if (rc && made)
+ if (ret && made)
unlink(dst);
- return rc;
+ return ret;
}
static int extract_package_cert(const char *archive, char *out, size_t out_sz)
@@ -780,11 +780,11 @@ static int extract_package_cert(const char *archive, char *out, size_t out_sz)
char tmp[] = "/tmp/shirudo-bpm-cert-XXXXXX";
__u8 *body = NULL;
size_t len = 0;
- int fd, rc;
+ int fd, ret;
- rc = bpm_pkg_read_member(archive, "cert.der", &body, &len, 1024 * 1024);
- if (rc)
- return rc;
+ ret = bpm_pkg_read_member(archive, "cert.der", &body, &len, 1024 * 1024);
+ if (ret)
+ return ret;
if (sizeof(tmp) > out_sz) {
xfree(body, len + 1);
return -ENAMETOOLONG;
@@ -794,33 +794,33 @@ static int extract_package_cert(const char *archive, char *out, size_t out_sz)
xfree(body, len + 1);
return -errno;
}
- rc = write_complete(fd, body, len);
- if (close(fd) && !rc)
- rc = -errno;
+ ret = write_complete(fd, body, len);
+ if (close(fd) && !ret)
+ ret = -errno;
xfree(body, len + 1);
- if (rc)
+ if (ret)
unlink(tmp);
else
bpm_copy_string(out, out_sz, tmp);
- return rc;
+ return ret;
}
static int key_source_file(const char *source, char *temp, size_t temp_sz)
{
char archive[] = "/tmp/shirudo-bpm-key-XXXXXX";
size_t len = strlen(source);
- int fd, rc;
+ int fd, ret;
if (!strncmp(source, "oci://", 6)) {
fd = mkstemp(archive);
if (fd < 0)
return -errno;
- rc = download_package(source, archive, fd);
+ ret = download_package(source, archive, fd);
close(fd);
- if (!rc)
- rc = extract_package_cert(archive, temp, temp_sz);
+ if (!ret)
+ ret = extract_package_cert(archive, temp, temp_sz);
unlink(archive);
- return rc;
+ return ret;
}
if (len >= 4 && !strcmp(source + len - 4, ".bee"))
return extract_package_cert(source, temp, temp_sz);
@@ -838,7 +838,7 @@ static int list_keys(void)
size_t count = 0, cap = 0;
struct dirent *entry;
DIR *dir;
- int rc = 0;
+ int ret = 0;
dir = opendir(KEYS_DIR);
if (!dir)
@@ -851,7 +851,7 @@ static int list_keys(void)
errno = 0;
entry = readdir(dir);
if (!entry) {
- rc = -errno;
+ ret = -errno;
break;
}
if (strlen(entry->d_name) != 68 ||
@@ -871,20 +871,20 @@ static int list_keys(void)
next = xreallocarray(fingerprints, cap, count + 1,
sizeof(*next));
if (!next) {
- rc = -ENOMEM;
+ ret = -ENOMEM;
break;
}
fingerprints = next;
cap = count + 1;
fingerprints[count] = xstrdup(hex);
if (!fingerprints[count]) {
- rc = -ENOMEM;
+ ret = -ENOMEM;
break;
}
count++;
}
closedir(dir);
- if (!rc && count) {
+ if (!ret && count) {
qsort(fingerprints, count, sizeof(*fingerprints),
key_fingerprint_compare);
for (size_t i = 0; i < count; i++)
@@ -893,7 +893,7 @@ static int list_keys(void)
for (size_t i = 0; i < count; i++)
xstrfree(fingerprints[i]);
xfree(fingerprints, cap * sizeof(*fingerprints));
- return rc;
+ return ret;
}
struct state_sink {
@@ -927,20 +927,20 @@ static int state_read(struct bpm_state_entry *st, int *n)
{
__u8 *body;
size_t len;
- int rc;
+ int ret;
struct state_sink sink = { .items = st };
struct shirudo_json_array arr = { on_state_entry, &sink };
struct shirudo_json_field sub[4], root[1];
__s64 unused = 0;
- rc = read_file(BPM_STATE_PATH, 8u * 1024u * 1024u,
- &body, &len);
- if (rc == -ENOENT) {
+ ret = read_file(BPM_STATE_PATH, 8u * 1024u * 1024u,
+ &body, &len);
+ if (ret == -ENOENT) {
*n = 0;
return 0;
}
- if (rc)
- return rc;
+ if (ret)
+ return ret;
sub[0] = (struct shirudo_json_field){
.key = "name", .type = SHIRUDO_JSON_T_STRING,
.dst = sink.scratch.name, .dst_cap = sizeof(sink.scratch.name),
@@ -964,10 +964,10 @@ static int state_read(struct bpm_state_entry *st, int *n)
.dst = &arr, .sub = sub, .n_sub = ARRAY_SIZE(sub),
};
(void)unused;
- rc = json_parse((const char *)body, len, root, ARRAY_SIZE(root));
+ ret = json_parse((const char *)body, len, root, ARRAY_SIZE(root));
xfree(body, len + 1);
- if (rc || !root[0].seen)
- return rc ? rc : -EINVAL;
+ if (ret || !root[0].seen)
+ return ret ? ret : -EINVAL;
*n = sink.n;
return 0;
}
@@ -976,7 +976,7 @@ static int state_write(const struct bpm_state_entry *st, int n)
{
char buf[1024 * 1024];
struct shirudo_json_emit e = { .buf = buf, .cap = sizeof(buf) };
- int rc;
+ int ret;
json_obj_open(&e);
json_kv_int(&e, "schema", 1);
@@ -993,11 +993,11 @@ static int state_write(const struct bpm_state_entry *st, int n)
json_obj_close(&e);
if (e.err)
return -E2BIG;
- rc = seal_mkdir_p(BPM_VAR_DIR, 0700);
- if (!rc)
- rc = seal_write_file(BPM_STATE_PATH, buf, e.len,
- 0600);
- return rc;
+ ret = seal_mkdir_p(BPM_VAR_DIR, 0700);
+ if (!ret)
+ ret = seal_write_file(BPM_STATE_PATH, buf, e.len,
+ 0600);
+ return ret;
}
static int load_cached_index(const char *source, struct bpm_index_entry *entries, int *n)
@@ -1005,17 +1005,17 @@ static int load_cached_index(const char *source, struct bpm_index_entry *entries
char path[PATH_MAX];
__u8 *body;
size_t len;
- int rc;
-
- rc = cache_path(source, path, sizeof(path));
- if (rc)
- return rc;
- rc = read_file(path, 64u * 1024u * 1024u, &body, &len);
- if (rc)
- return rc;
- rc = bpm_index_parse(body, len, entries, n);
+ int ret;
+
+ ret = cache_path(source, path, sizeof(path));
+ if (ret)
+ return ret;
+ ret = read_file(path, 64u * 1024u * 1024u, &body, &len);
+ if (ret)
+ return ret;
+ ret = bpm_index_parse(body, len, entries, n);
xfree(body, len + 1);
- return rc;
+ return ret;
}
static int repo_update_one(const char *name)
@@ -1026,31 +1026,31 @@ static int repo_update_one(const char *name)
int nl = 0;
struct bpm_buffer manifest = {}, index = {}, sig = {};
char url[PATH_MAX], cache[PATH_MAX], dir[PATH_MAX];
- int rc;
-
- rc = load_source(name, &s);
- if (rc)
- return rc;
- rc = bpm_oci_parse_endpoint(s.endpoint, &c);
- if (rc)
- return rc;
- rc = bpm_oci_url(&c, BPM_INDEX_REPOSITORY, "manifests", BPM_INDEX_TAG, url, sizeof(url));
- if (rc)
- return rc;
- rc = bpm_oci_get_memory(&c, url, BPM_MANIFEST_MEDIA, &manifest);
- if (rc)
+ int ret;
+
+ ret = load_source(name, &s);
+ if (ret)
+ return ret;
+ ret = bpm_oci_parse_endpoint(s.endpoint, &c);
+ if (ret)
+ return ret;
+ ret = bpm_oci_url(&c, BPM_INDEX_REPOSITORY, "manifests", BPM_INDEX_TAG, url, sizeof(url));
+ if (ret)
+ return ret;
+ ret = bpm_oci_get_memory(&c, url, BPM_MANIFEST_MEDIA, &manifest);
+ if (ret)
goto out;
- rc = bpm_oci_parse_manifest(manifest.data, manifest.len, layers,
- ARRAY_SIZE(layers), &nl, NULL, 0);
- if (rc)
+ ret = bpm_oci_parse_manifest(manifest.data, manifest.len, layers,
+ ARRAY_SIZE(layers), &nl, NULL, 0);
+ if (ret)
goto out;
- rc = bpm_oci_get_signed(&c, BPM_INDEX_REPOSITORY, layers, nl,
- BPM_INDEX_MEDIA, BPM_INDEX_SIG_MEDIA, &index, &sig);
- if (rc)
+ ret = bpm_oci_get_signed(&c, BPM_INDEX_REPOSITORY, layers, nl,
+ BPM_INDEX_MEDIA, BPM_INDEX_SIG_MEDIA, &index, &sig);
+ if (ret)
goto out;
if (verify_with_source_key(&s, index.data, index.len, sig.data,
sig.len)) {
- rc = -EKEYREJECTED;
+ ret = -EKEYREJECTED;
goto out;
}
{
@@ -1058,26 +1058,26 @@ static int repo_update_one(const char *name)
int checked_n = 0;
if (bpm_index_parse(index.data, index.len, checked, &checked_n)) {
- rc = -EINVAL;
+ ret = -EINVAL;
goto out;
}
}
if (strsprintf(dir, sizeof(dir), "%s/%s", BPM_REPOS_DIR, name) < 0) {
- rc = -ENAMETOOLONG;
+ ret = -ENAMETOOLONG;
goto out;
}
- rc = seal_mkdir_p(dir, 0700);
- if (rc)
+ ret = seal_mkdir_p(dir, 0700);
+ if (ret)
goto out;
- rc = cache_path(name, cache, sizeof(cache));
- if (rc)
+ ret = cache_path(name, cache, sizeof(cache));
+ if (ret)
goto out;
- rc = seal_write_file(cache, index.data, index.len, 0600);
+ ret = seal_write_file(cache, index.data, index.len, 0600);
out:
bpm_buffer_free(&manifest);
bpm_buffer_free(&index);
bpm_buffer_free(&sig);
- return rc;
+ return ret;
}
static int find_entry(const struct bpm_index_entry *e, int n, const char *name,
@@ -1137,7 +1137,7 @@ static int package_install(const struct bpm_source *s, const struct bpm_index_en
struct bpm_buffer manifest = {};
char url[PATH_MAX], archive[PATH_MAX] = {}, dir[PATH_MAX], package_dir[PATH_MAX];
char digest[65];
- int fd, rc;
+ int fd, ret;
DIR *d;
struct dirent *de;
bool found_package = false, extracted = false;
@@ -1146,15 +1146,15 @@ static int package_install(const struct bpm_source *s, const struct bpm_index_en
char old_unloads[128][PATH_MAX];
int nloaded = 0, nactive = 0, nold = 0, nold_removed = 0;
(void)old_version;
- rc = bpm_oci_parse_endpoint(s->endpoint, &c);
- if (rc)
- return rc;
- rc = bpm_oci_url(&c, entry->repository[0] ? entry->repository : entry->name,
- "manifests", entry->manifest_digest, url, sizeof(url));
- if (rc)
- return rc;
- rc = bpm_oci_get_memory(&c, url, "application/vnd.oci.image.manifest.v1+json", &manifest);
- if (rc)
+ ret = bpm_oci_parse_endpoint(s->endpoint, &c);
+ if (ret)
+ return ret;
+ ret = bpm_oci_url(&c, entry->repository[0] ? entry->repository : entry->name,
+ "manifests", entry->manifest_digest, url, sizeof(url));
+ if (ret)
+ return ret;
+ ret = bpm_oci_get_memory(&c, url, "application/vnd.oci.image.manifest.v1+json", &manifest);
+ if (ret)
goto out;
/*
* Repository indexes carry a sha256 manifest digest; direct OCI
@@ -1166,88 +1166,88 @@ static int package_install(const struct bpm_source *s, const struct bpm_index_en
if (bpm_sha256_hex(manifest.data, manifest.len, manifest_hex,
sizeof(manifest_hex)) ||
!bpm_digest_matches(entry->manifest_digest, manifest_hex)) {
- rc = -EKEYREJECTED;
+ ret = -EKEYREJECTED;
goto out;
}
}
- rc = bpm_oci_parse_manifest(manifest.data, manifest.len, layers,
- ARRAY_SIZE(layers), &nl, NULL, 0);
- if (rc)
+ ret = bpm_oci_parse_manifest(manifest.data, manifest.len, layers,
+ ARRAY_SIZE(layers), &nl, NULL, 0);
+ if (ret)
goto out;
for (int i = 0; i < nl; i++) {
if (strcmp(layers[i].media, BPM_PACKAGE_MEDIA))
continue;
found_package = true;
if (entry->package_digest[0] && strcmp(entry->package_digest, layers[i].digest)) {
- rc = -EKEYREJECTED;
+ ret = -EKEYREJECTED;
goto out;
}
if (entry->package_size > 0 && entry->package_size != layers[i].size) {
- rc = -EKEYREJECTED;
+ ret = -EKEYREJECTED;
goto out;
}
- rc = bpm_oci_url(&c, entry->repository[0] ? entry->repository : entry->name,
- "blobs", layers[i].digest, url, sizeof(url));
- if (rc)
+ ret = bpm_oci_url(&c, entry->repository[0] ? entry->repository : entry->name,
+ "blobs", layers[i].digest, url, sizeof(url));
+ if (ret)
goto out;
if (strsprintf(dir, sizeof(dir), "%s/%s", BPM_PACKAGES_DIR,
entry->name) < 0) {
- rc = -ENAMETOOLONG;
+ ret = -ENAMETOOLONG;
goto out;
}
- rc = seal_mkdir_p(dir, 0700);
- if (rc)
+ ret = seal_mkdir_p(dir, 0700);
+ if (ret)
goto out;
if (strsprintf(package_dir, sizeof(package_dir), "%s/%s", dir,
entry->version) < 0) {
- rc = -ENAMETOOLONG;
+ ret = -ENAMETOOLONG;
goto out;
}
- rc = seal_mkdir_p(BPM_STAGING_DIR, 0700);
- if (rc)
+ ret = seal_mkdir_p(BPM_STAGING_DIR, 0700);
+ if (ret)
goto out;
if (strsprintf(archive, sizeof(archive), "%s/%s-%s.bee",
BPM_STAGING_DIR, entry->name,
entry->version) < 0) {
- rc = -ENAMETOOLONG;
+ ret = -ENAMETOOLONG;
goto out;
}
fd = seal_open(archive, O_WRONLY | O_CREAT | O_TRUNC |
O_NOFOLLOW, 0600);
if (fd < 0) {
- rc = fd;
+ ret = fd;
goto out;
}
- rc = bpm_oci_get_file(&c, url, BPM_PACKAGE_MEDIA, fd,
- layers[i].size);
+ ret = bpm_oci_get_file(&c, url, BPM_PACKAGE_MEDIA, fd,
+ layers[i].size);
close(fd);
- if (rc) {
+ if (ret) {
unlink(archive);
goto out;
}
if (sha256_file_hex(archive, digest, sizeof(digest)) ||
!bpm_digest_matches(layers[i].digest, digest)) {
- rc = -EKEYREJECTED;
+ ret = -EKEYREJECTED;
goto out;
}
if (access(package_dir, F_OK) == 0) {
- rc = -EEXIST;
+ ret = -EEXIST;
goto out;
}
extracted = true;
- rc = bpm_pkg_extract(archive, package_dir);
- if (rc)
+ ret = bpm_pkg_extract(archive, package_dir);
+ if (ret)
goto out;
{
char cert[PATH_MAX];
if (strsprintf(cert, sizeof(cert), "%s/cert.der",
package_dir) < 0) {
- rc = -ENAMETOOLONG;
+ ret = -ENAMETOOLONG;
goto out;
}
if (cert_matches_active(cert)) {
- rc = -EKEYREJECTED;
+ ret = -EKEYREJECTED;
goto out;
}
}
@@ -1256,12 +1256,12 @@ static int package_install(const struct bpm_source *s, const struct bpm_index_en
if (strsprintf(updir, sizeof(updir), "%s/upatches",
package_dir) < 0) {
- rc = -ENAMETOOLONG;
+ ret = -ENAMETOOLONG;
goto out;
}
d = opendir(updir);
if (!d) {
- rc = -errno;
+ ret = -errno;
goto out;
}
}
@@ -1275,22 +1275,22 @@ static int package_install(const struct bpm_source *s, const struct bpm_index_en
continue;
if (strsprintf(up, sizeof(up), "%s/upatches/%s", package_dir,
de->d_name) < 0) {
- rc = -ENAMETOOLONG;
+ ret = -ENAMETOOLONG;
break;
}
if (stat(up, &st) || !S_ISREG(st.st_mode))
continue;
if (nloaded >= 128) {
- rc = -E2BIG;
+ ret = -E2BIG;
break;
}
strscpy(loaded[nloaded], up, sizeof(loaded[nloaded]));
nloaded++;
}
closedir(d);
- if (rc || !nloaded) {
- if (!rc)
- rc = -EINVAL;
+ if (ret || !nloaded) {
+ if (!ret)
+ ret = -EINVAL;
goto out;
}
/* Measured in name order, not in the file system's. */
@@ -1300,7 +1300,7 @@ static int package_install(const struct bpm_source *s, const struct bpm_index_en
if (strsprintf(olddir, sizeof(olddir), "%s/upatches",
old_path) < 0) {
- rc = -ENAMETOOLONG;
+ ret = -ENAMETOOLONG;
goto out;
}
d = opendir(olddir);
@@ -1318,7 +1318,7 @@ static int package_install(const struct bpm_source *s, const struct bpm_index_en
sizeof(old_unloads[nold]) ||
dir_len + 1 + base_len + strlen(".upatch") + 1 >=
sizeof(old_loads[nold])) {
- rc = -ENAMETOOLONG;
+ ret = -ENAMETOOLONG;
break;
}
memcpy(old_unloads[nold], olddir, dir_len);
@@ -1338,7 +1338,7 @@ static int package_install(const struct bpm_source *s, const struct bpm_index_en
sort_old_pairs(old_unloads, old_loads, nold);
for (int old_i = 0; old_i < nold; old_i++) {
if (shirudo_upatch_remove(old_unloads[old_i])) {
- rc = -EIO;
+ ret = -EIO;
for (int restore_i = nold_removed - 1;
restore_i >= 0; restore_i--)
(void)shirudo_upatch_install(old_loads[restore_i]);
@@ -1349,7 +1349,7 @@ static int package_install(const struct bpm_source *s, const struct bpm_index_en
}
for (int loaded_i = 0; loaded_i < nloaded; loaded_i++) {
if (shirudo_upatch_install(loaded[loaded_i])) {
- rc = -EIO;
+ ret = -EIO;
goto rollback;
}
nactive++;
@@ -1367,8 +1367,8 @@ static int package_install(const struct bpm_source *s, const struct bpm_index_en
}
break;
}
- if (!rc && !found_package)
- rc = -EINVAL;
+ if (!ret && !found_package)
+ ret = -EINVAL;
goto out;
rollback:
for (int active_i = nactive - 1; active_i >= 0; active_i--) {
@@ -1398,12 +1398,12 @@ rollback:
(void)shirudo_upatch_install(old_loads[restore_i]);
out:
bpm_buffer_free(&manifest);
- if (rc && archive[0])
+ if (ret && archive[0])
unlink(archive);
/* What failed to install must not block the next attempt. */
- if (rc && extracted)
+ if (ret && extracted)
(void)remove_tree(package_dir);
- return rc;
+ return ret;
}
static int parse_package_ref(const char *raw, char *source, size_t ssz,
@@ -1540,7 +1540,7 @@ static int load_tree_config(struct bpm_tree_config *cfg)
{
size_t capacity = 0;
char *line = NULL;
- int got, rc = 0;
+ int got, ret = 0;
FILE *fp;
*cfg = (struct bpm_tree_config){};
@@ -1551,19 +1551,19 @@ static int load_tree_config(struct bpm_tree_config *cfg)
fclose(fp);
return -EPERM;
}
- while (!rc && (got = read_text_line(fp, &line, &capacity,
- PATH_MAX - 1)) != 0) {
+ while (!ret && (got = read_text_line(fp, &line, &capacity,
+ PATH_MAX - 1)) != 0) {
if (got < 0 ||
bpm_parse_tree_line(line, cfg->endpoint,
sizeof(cfg->endpoint),
cfg->reference,
sizeof(cfg->reference)))
- rc = -EINVAL;
+ ret = -EINVAL;
}
libc_free(line);
fclose(fp);
- if (rc)
- return rc;
+ if (ret)
+ return ret;
if (!cfg->endpoint[0] || !cfg->reference[0])
return -EINVAL;
return 0;
@@ -1589,11 +1589,11 @@ static int tree_fetch_publication(const struct bpm_tree_config *cfg,
{
struct bpm_oci_client c = {};
char repository[BPM_MAX_ENDPOINT];
- int rc = bpm_oci_parse_tree_repo(cfg->endpoint, &c,
- repository, sizeof(repository));
+ int ret = bpm_oci_parse_tree_repo(cfg->endpoint, &c,
+ repository, sizeof(repository));
- if (rc)
- return rc;
+ if (ret)
+ return ret;
return bpm_tree_fetch_publication(&c, repository, cfg->reference,
shirudo_cert_path(), pub,
manifest_digest, digest_sz);
@@ -1605,19 +1605,19 @@ static int tree_verify_upatch(const char *path, const char *expected,
struct shirudo_upatch u;
char name[UPATCH_NAME_MAX + 1];
char actual[65];
- int rc = upatch_open(path, &u);
+ int ret = upatch_open(path, &u);
- if (rc)
- return rc;
+ if (ret)
+ return ret;
memcpy(name, u.hdr.name, UPATCH_NAME_MAX);
name[UPATCH_NAME_MAX] = '\0';
hex_encode(u.hdr.payload_sha256, 32, actual);
if (!bpm_digest_matches(expected, actual) ||
(id && strcmp(name, id)) ||
upatch_is_unload(&u) != unload)
- rc = -EKEYREJECTED;
+ ret = -EKEYREJECTED;
upatch_close(&u);
- return rc;
+ return ret;
}
static int tree_pull_artifact(const struct shirudo_tree_operation *op,
@@ -1628,7 +1628,7 @@ static int tree_pull_artifact(const struct shirudo_tree_operation *op,
struct bpm_buffer manifest = {}, blob = {};
char repository[BPM_MAX_ENDPOINT], url[PATH_MAX], cache[PATH_MAX];
char hex[65];
- int nl = 0, rc;
+ int nl = 0, ret;
if (!tree_digest_valid(op->artifact.layer_digest))
return -EINVAL;
@@ -1646,60 +1646,60 @@ static int tree_pull_artifact(const struct shirudo_tree_operation *op,
return tree_verify_upatch(path, op->artifact.payload_sha256, op->id,
!strcmp(op->op, "delete"));
}
- rc = bpm_oci_parse_tree_repo(op->artifact.repository, &c, repository,
- sizeof(repository));
- if (rc)
- return rc;
- rc = bpm_oci_url(&c, repository, "manifests",
- op->artifact.manifest_digest, url, sizeof(url));
- if (rc)
- return rc;
- rc = bpm_oci_get_memory(&c, url,
- "application/vnd.oci.image.manifest.v1+json", &manifest);
- if (rc)
+ ret = bpm_oci_parse_tree_repo(op->artifact.repository, &c, repository,
+ sizeof(repository));
+ if (ret)
+ return ret;
+ ret = bpm_oci_url(&c, repository, "manifests",
+ op->artifact.manifest_digest, url, sizeof(url));
+ if (ret)
+ return ret;
+ ret = bpm_oci_get_memory(&c, url,
+ "application/vnd.oci.image.manifest.v1+json", &manifest);
+ if (ret)
goto out;
if (bpm_sha256_hex(manifest.data, manifest.len, hex, sizeof(hex)) ||
!bpm_digest_matches(op->artifact.manifest_digest, hex)) {
- rc = -EKEYREJECTED;
+ ret = -EKEYREJECTED;
goto out;
}
- rc = bpm_oci_parse_manifest(manifest.data, manifest.len, layers,
- ARRAY_SIZE(layers), &nl, NULL, 0);
- if (rc)
+ ret = bpm_oci_parse_manifest(manifest.data, manifest.len, layers,
+ ARRAY_SIZE(layers), &nl, NULL, 0);
+ if (ret)
goto out;
for (int i = 0; i < nl; i++) {
if (strcmp(layers[i].digest, op->artifact.layer_digest) ||
strcmp(layers[i].media, BPM_UPATCH_MEDIA))
continue;
- rc = bpm_oci_url(&c, repository, "blobs", layers[i].digest,
- url, sizeof(url));
- if (rc)
+ ret = bpm_oci_url(&c, repository, "blobs", layers[i].digest,
+ url, sizeof(url));
+ if (ret)
goto out;
- rc = bpm_oci_get_blob(&c, url, layers[i].media, &blob);
- if (rc)
+ ret = bpm_oci_get_blob(&c, url, layers[i].media, &blob);
+ if (ret)
goto out;
if (bpm_sha256_hex(blob.data, blob.len, hex, sizeof(hex)) ||
!bpm_digest_matches(layers[i].digest, hex) ||
(layers[i].size >= 0 && (__s64)blob.len != layers[i].size))
- rc = -EKEYREJECTED;
- if (rc)
+ ret = -EKEYREJECTED;
+ if (ret)
goto out;
- rc = seal_mkdir_p(BPM_TREE_ARTIFACTS_DIR, 0700);
- if (rc)
+ ret = seal_mkdir_p(BPM_TREE_ARTIFACTS_DIR, 0700);
+ if (ret)
goto out;
- rc = seal_write_file(cache, blob.data, blob.len, 0600);
- if (rc)
+ ret = seal_write_file(cache, blob.data, blob.len, 0600);
+ if (ret)
goto out;
bpm_copy_string(path, path_sz, cache);
- rc = tree_verify_upatch(path, op->artifact.payload_sha256, op->id,
- !strcmp(op->op, "delete"));
+ ret = tree_verify_upatch(path, op->artifact.payload_sha256, op->id,
+ !strcmp(op->op, "delete"));
goto out;
}
- rc = -ENOENT;
+ ret = -ENOENT;
out:
bpm_buffer_free(&manifest);
bpm_buffer_free(&blob);
- return rc;
+ return ret;
}
static int tree_write_report(const char *path, const struct shirudo_tree_state *s,
@@ -1728,18 +1728,18 @@ static int tree_write_report(const char *path, const struct shirudo_tree_state *
if (e.err)
return e.err;
if (path) {
- int fd, rc;
+ int fd, ret;
fd = seal_output_open(path, O_WRONLY | O_CREAT | O_TRUNC,
0600);
if (fd < 0)
return fd;
- rc = write_complete(fd, buf, e.len);
- if (!rc)
- rc = write_complete(fd, "\n", 1);
- if (close(fd) && !rc)
- rc = -errno;
- return rc;
+ ret = write_complete(fd, buf, e.len);
+ if (!ret)
+ ret = write_complete(fd, "\n", 1);
+ if (close(fd) && !ret)
+ ret = -errno;
+ return ret;
}
printf("%s\n", buf);
return 0;
@@ -1749,7 +1749,7 @@ static int tree_write_pending(const struct shirudo_tree_operation *op)
{
char buf[1024];
struct shirudo_json_emit e = { .buf = buf, .cap = sizeof(buf) };
- int rc;
+ int ret;
json_obj_open(&e);
json_kv_int(&e, "schema", 1);
@@ -1759,9 +1759,9 @@ static int tree_write_pending(const struct shirudo_tree_operation *op)
json_obj_close(&e);
if (e.err)
return e.err;
- rc = seal_mkdir_p(BPM_TREE_VAR_DIR, 0700);
- if (rc)
- return rc;
+ ret = seal_mkdir_p(BPM_TREE_VAR_DIR, 0700);
+ if (ret)
+ return ret;
return seal_write_file(BPM_TREE_PENDING_PATH, buf,
e.len, 0600);
}
@@ -1769,13 +1769,13 @@ static int tree_write_pending(const struct shirudo_tree_operation *op)
static int tree_status_write(const char *id, const char *status)
{
char path[PATH_MAX];
- int rc;
+ int ret;
if (!id || !upatch_name_valid(id) || !status || !status[0])
return -EINVAL;
- rc = seal_mkdir_p(BPM_TREE_STATUS_DIR, 0700);
- if (rc)
- return rc;
+ ret = seal_mkdir_p(BPM_TREE_STATUS_DIR, 0700);
+ if (ret)
+ return ret;
if (strsprintf(path, sizeof(path), "%s/%s",
BPM_TREE_STATUS_DIR, id) < 0)
return -ENAMETOOLONG;
@@ -1813,17 +1813,17 @@ static int tree_read_pending(struct bpm_tree_pending *pending)
pending->operation_digest, sizeof(pending->operation_digest),
0, NULL, 0 },
};
- int rc = read_file(BPM_TREE_PENDING_PATH, 64u * 1024u,
- &body, &len);
- if (rc)
- return rc;
- rc = json_parse((const char *)body, len, fields, ARRAY_SIZE(fields));
- if (!rc && (schema != 1 || pending->seq <= 0 ||
- !upatch_name_valid(pending->id) ||
- !tree_digest_valid(pending->operation_digest)))
- rc = -EINVAL;
+ int ret = read_file(BPM_TREE_PENDING_PATH, 64u * 1024u,
+ &body, &len);
+ if (ret)
+ return ret;
+ ret = json_parse((const char *)body, len, fields, ARRAY_SIZE(fields));
+ if (!ret && (schema != 1 || pending->seq <= 0 ||
+ !upatch_name_valid(pending->id) ||
+ !tree_digest_valid(pending->operation_digest)))
+ ret = -EINVAL;
xfree(body, len + 1);
- return rc;
+ return ret;
}
/*
@@ -1837,12 +1837,12 @@ static int tree_measure_locked(const struct shirudo_tree_operation *op,
__u8 event[32], chain[32];
struct shirudo_json_emit e;
char line[4096], chain_hex[65];
- int rc;
+ int ret;
chain_tree_event(op->seq, operation_digest, event);
- rc = chain_extend(event, chain);
- if (rc)
- return rc;
+ ret = chain_extend(event, chain);
+ if (ret)
+ return ret;
hex_encode(chain, 32, chain_hex);
e = (struct shirudo_json_emit){ .buf = line, .cap = sizeof(line) };
@@ -1863,14 +1863,14 @@ static int tree_measure_locked(const struct shirudo_tree_operation *op,
static int tree_measure_operation(const struct shirudo_tree_operation *op,
const __u8 operation_digest[32])
{
- int lock, rc;
+ int lock, ret;
lock = eventlog_lock();
if (lock < 0)
return lock;
- rc = tree_measure_locked(op, operation_digest);
+ ret = tree_measure_locked(op, operation_digest);
eventlog_unlock(lock);
- return rc;
+ return ret;
}
/*
@@ -1884,13 +1884,13 @@ static int tree_recover_pending(const struct shirudo_tree_publication *pub,
const struct shirudo_tree_operation *op = NULL;
__u8 digest[32], previous[32], next[32], replay[32];
bool applied = false, event_present = false;
- int rc;
+ int ret;
- rc = tree_read_pending(&pending);
- if (rc == -ENOENT)
+ ret = tree_read_pending(&pending);
+ if (ret == -ENOENT)
return 0;
- if (rc)
- return rc;
+ if (ret)
+ return ret;
for (int i = 0; i < pub->n_operations; i++) {
if (pub->operations[i].seq == pending.seq &&
!strcmp(pub->operations[i].id, pending.id) &&
@@ -1911,31 +1911,31 @@ static int tree_recover_pending(const struct shirudo_tree_publication *pub,
return -EINVAL;
sha256_2(previous, sizeof(previous), digest, sizeof(digest), next);
- rc = tree_event_replay(replay);
- if (!rc) {
+ ret = tree_event_replay(replay);
+ if (!ret) {
if (ct_eq(replay, next, sizeof(replay))) {
applied = true;
event_present = true;
} else if (!ct_eq(replay, previous, sizeof(replay))) {
return -EKEYREJECTED;
}
- } else if (rc != -ENOENT) {
+ } else if (ret != -ENOENT) {
return -EKEYREJECTED;
}
/* Still pre-operation; retry normally. */
if (!applied)
return 0;
if (!event_present) {
- rc = tree_event_append(op->seq, op->operation_digest, next);
- if (rc)
- return rc;
+ ret = tree_event_append(op->seq, op->operation_digest, next);
+ if (ret)
+ return ret;
}
hex_encode(next, sizeof(next), state->projection_root);
hex_encode(next, sizeof(next), state->projection_root_tpm);
state->last_seq = op->seq;
- rc = tree_state_write(state);
- if (rc)
- return rc;
+ ret = tree_state_write(state);
+ if (ret)
+ return ret;
(void)unlink(BPM_TREE_PENDING_PATH);
return 0;
}
@@ -1964,28 +1964,28 @@ static int tree_validate_operation(const struct shirudo_tree_operation *op)
}
static void tree_sync_report_error(const char *phase,
- const struct shirudo_tree_operation *op, int rc)
+ const struct shirudo_tree_operation *op, int ret)
{
int err;
- if (rc > 0) {
+ if (ret > 0) {
if (op)
pr_err("bpm tree sync: phase=%s seq=%lld id=%s rc=%d "
"(command status)", phase, (__s64)op->seq,
- op->id, rc);
+ op->id, ret);
else
pr_err("bpm tree sync: phase=%s rc=%d (command status)",
- phase, rc);
+ phase, ret);
return;
}
- err = rc < 0 ? -rc : 0;
+ err = ret < 0 ? -ret : 0;
if (op)
pr_err("bpm tree sync: phase=%s seq=%lld id=%s rc=%d (%s)",
- phase, (__s64)op->seq, op->id, rc,
+ phase, (__s64)op->seq, op->id, ret,
err ? strerror(err) : "success");
else
- pr_err("bpm tree sync: phase=%s rc=%d (%s)", phase, rc,
+ pr_err("bpm tree sync: phase=%s rc=%d (%s)", phase, ret,
err ? strerror(err) : "success");
}
@@ -2000,10 +2000,10 @@ static int cmd_bpm_tree_sync(int argc, const char **argv)
bool same_manifest;
int selected = 0, skipped = 0, applied = 0, module_skipped = 0;
int tpm_available = 0;
- int rc;
+ int ret;
if (argc < 2 || strcmp(argv[1], "sync")) {
- rc = -EINVAL;
+ ret = -EINVAL;
goto out;
}
for (int i = 2; i < argc; i++) {
@@ -2020,66 +2020,66 @@ static int cmd_bpm_tree_sync(int argc, const char **argv)
}
} else if (is_help(argv[i])) {
printf("usage: shirudo bpm tree sync [--dry-run] [--report=<path>]\n");
- rc = 0;
+ ret = 0;
goto out;
} else {
- rc = -EINVAL;
+ ret = -EINVAL;
goto out;
}
}
- rc = load_tree_config(&cfg);
+ ret = load_tree_config(&cfg);
/* Optional integration: manual `shirudo upatch` remains valid. */
- if (rc == -ENOENT) {
- rc = 0;
+ if (ret == -ENOENT) {
+ ret = 0;
goto out;
}
- if (rc)
+ if (ret)
goto out;
- rc = tree_state_read(&state);
- if (!rc)
+ ret = tree_state_read(&state);
+ if (!ret)
have_state = true;
- else if (rc != -ENOENT)
+ else if (ret != -ENOENT)
goto out;
- rc = tree_fetch_publication(&cfg, &pub, manifest_digest,
- sizeof(manifest_digest));
- if (rc)
+ ret = tree_fetch_publication(&cfg, &pub, manifest_digest,
+ sizeof(manifest_digest));
+ if (ret)
goto out;
if (pub.parent_manifest_digest[0] &&
!tree_digest_valid(pub.parent_manifest_digest)) {
- rc = -EINVAL;
+ ret = -EINVAL;
goto out;
}
/* Snapshot compaction belongs to a later schema. */
if (pub.base_seq != 0) {
- rc = -ENOTSUP;
+ ret = -ENOTSUP;
goto out;
}
if (pub.n_operations && pub.operations[0].seq != pub.base_seq + 1) {
- rc = -EINVAL;
+ ret = -EINVAL;
goto out;
}
if (pub.n_operations && pub.head_seq != pub.operations[pub.n_operations - 1].seq) {
- rc = -EINVAL;
+ ret = -EINVAL;
goto out;
}
if (!pub.n_operations && pub.head_seq != pub.base_seq) {
- rc = -EINVAL;
+ ret = -EINVAL;
goto out;
}
for (int i = 0; i < pub.n_operations; i++) {
- rc = tree_validate_operation(&pub.operations[i]);
- if (rc) {
- tree_sync_report_error("operation_validate", &pub.operations[i], rc);
+ ret = tree_validate_operation(&pub.operations[i]);
+ if (ret) {
+ tree_sync_report_error("operation_validate", &pub.operations[i], ret);
goto out;
}
}
same_manifest = have_state && !strcmp(state.manifest_digest, manifest_digest);
if (have_state && strcmp(state.tree_id, pub.tree_id)) {
- rc = -EINVAL;
+ ret = -EINVAL;
goto out;
}
if (have_state && !same_manifest && pub.generation <= state.generation) {
- rc = -ERANGE;
+ ret = -ERANGE;
goto out;
}
/*
@@ -2090,20 +2090,20 @@ static int cmd_bpm_tree_sync(int argc, const char **argv)
pub.generation == state.generation + 1 &&
pub.parent_manifest_digest[0] &&
strcmp(pub.parent_manifest_digest, state.manifest_digest)) {
- rc = -ERANGE;
+ ret = -ERANGE;
goto out;
}
if (have_state && pub.head_seq < state.last_seq) {
- rc = -ERANGE;
+ ret = -ERANGE;
goto out;
}
/* The publication must contain the cursor base. */
if (have_state && pub.base_seq > state.last_seq) {
- rc = -ERANGE;
+ ret = -ERANGE;
goto out;
}
if (!have_state && pub.base_seq != 0) {
- rc = -ERANGE;
+ ret = -ERANGE;
goto out;
}
if (!have_state) {
@@ -2114,9 +2114,9 @@ static int cmd_bpm_tree_sync(int argc, const char **argv)
memset(state.projection_root_tpm, '0', 64);
state.projection_root_tpm[64] = '\0';
}
- rc = tree_recover_pending(&pub, &state);
- if (rc) {
- tree_sync_report_error("pending_recovery", NULL, rc);
+ ret = tree_recover_pending(&pub, &state);
+ if (ret) {
+ tree_sync_report_error("pending_recovery", NULL, ret);
goto out;
}
tpm_available = chain_bound();
@@ -2128,12 +2128,12 @@ static int cmd_bpm_tree_sync(int argc, const char **argv)
if (op->seq <= state.last_seq)
continue;
- rc = tree_selector_matches(&op->selector);
- if (rc < 0) {
- tree_sync_report_error("selector_evaluate", op, rc);
+ ret = tree_selector_matches(&op->selector);
+ if (ret < 0) {
+ tree_sync_report_error("selector_evaluate", op, ret);
goto out;
}
- if (!rc) {
+ if (!ret) {
skipped++;
if (!dry_run)
state.last_seq = op->seq;
@@ -2142,79 +2142,79 @@ static int cmd_bpm_tree_sync(int argc, const char **argv)
selected++;
if (dry_run)
continue;
- rc = tree_digest_hex(op->operation_digest, digest);
- if (rc) {
- tree_sync_report_error("operation_digest_parse", op, rc);
- rc = -EINVAL;
+ ret = tree_digest_hex(op->operation_digest, digest);
+ if (ret) {
+ tree_sync_report_error("operation_digest_parse", op, ret);
+ ret = -EINVAL;
goto out;
}
if (op->expected_payload_sha256[0] &&
strcmp(op->expected_payload_sha256, op->artifact.payload_sha256)) {
tree_sync_report_error("expected_payload_digest", op,
-EKEYREJECTED);
- rc = -EKEYREJECTED;
+ ret = -EKEYREJECTED;
goto out;
}
- rc = tree_write_pending(op);
- if (rc) {
- tree_sync_report_error("pending_write", op, rc);
+ ret = tree_write_pending(op);
+ if (ret) {
+ tree_sync_report_error("pending_write", op, ret);
goto out;
}
- rc = tree_pull_artifact(op, artifact, sizeof(artifact));
- if (rc) {
- tree_sync_report_error("artifact_fetch_or_verify", op, rc);
+ ret = tree_pull_artifact(op, artifact, sizeof(artifact));
+ if (ret) {
+ tree_sync_report_error("artifact_fetch_or_verify", op, ret);
goto out;
}
if (!strcmp(op->op, "add")) {
- rc = shirudo_upatch_install(artifact);
+ ret = shirudo_upatch_install(artifact);
} else if (!strcmp(op->op, "delete")) {
- rc = shirudo_upatch_remove(artifact);
+ ret = shirudo_upatch_remove(artifact);
} else {
- rc = -EINVAL;
+ ret = -EINVAL;
goto out;
}
- if (rc == UPATCH_INSTALL_TARGET_MISSING &&
+ if (ret == UPATCH_INSTALL_TARGET_MISSING &&
!strcmp(op->op, "add")) {
skipped_module = true;
- rc = 0;
+ ret = 0;
module_skipped++;
pr_warn("bpm tree: skipped %s: module not loaded", op->id);
}
- if (rc) {
- tree_sync_report_error("upatch_install", op, rc);
+ if (ret) {
+ tree_sync_report_error("upatch_install", op, ret);
goto out;
}
if (hex_decode(state.projection_root, previous, 32)) {
tree_sync_report_error("projection_root_decode", op, -EINVAL);
- rc = -EINVAL;
+ ret = -EINVAL;
goto out;
}
- rc = tree_measure_operation(op, digest);
- if (rc) {
- tree_sync_report_error("register_extend", op, rc);
+ ret = tree_measure_operation(op, digest);
+ if (ret) {
+ tree_sync_report_error("register_extend", op, ret);
goto out;
}
sha256_2(previous, 32, digest, 32, next);
hex_encode(next, 32, state.projection_root);
hex_encode(next, 32, state.projection_root_tpm);
- rc = tree_event_append(op->seq, op->operation_digest, next);
- if (rc) {
- tree_sync_report_error("tree_event_append", op, rc);
+ ret = tree_event_append(op->seq, op->operation_digest, next);
+ if (ret) {
+ tree_sync_report_error("tree_event_append", op, ret);
goto out;
}
state.last_seq = op->seq;
applied++;
- rc = tree_state_write(&state);
- if (rc) {
- tree_sync_report_error("tree_state_commit", op, rc);
+ ret = tree_state_write(&state);
+ if (ret) {
+ tree_sync_report_error("tree_state_commit", op, ret);
goto out;
}
if (skipped_module)
- rc = tree_status_write(op->id, "skipped: module not loaded");
+ ret = tree_status_write(op->id, "skipped: module not loaded");
else
tree_status_clear(op->id);
- if (rc) {
- tree_sync_report_error("tree_status_write", op, rc);
+ if (ret) {
+ tree_sync_report_error("tree_status_write", op, ret);
goto out;
}
(void)unlink(BPM_TREE_PENDING_PATH);
@@ -2225,19 +2225,19 @@ static int cmd_bpm_tree_sync(int argc, const char **argv)
manifest_digest);
if (!state.tree_id[0])
bpm_copy_string(state.tree_id, sizeof(state.tree_id), pub.tree_id);
- rc = tree_state_write(&state);
- if (rc) {
- tree_sync_report_error("tree_state_commit_final", NULL, rc);
+ ret = tree_state_write(&state);
+ if (ret) {
+ tree_sync_report_error("tree_state_commit_final", NULL, ret);
goto out;
}
}
/* "-" is standard output, where the report goes without --report. */
- rc = tree_write_report(report[0] && strcmp(report, "-") ? report : NULL,
- &state, selected, skipped, applied,
- module_skipped, dry_run, tpm_available);
+ ret = tree_write_report(report[0] && strcmp(report, "-") ? report : NULL,
+ &state, selected, skipped, applied,
+ module_skipped, dry_run, tpm_available);
out:
tree_publication_free(&pub);
- return rc;
+ return ret;
}
static void bpm_tree_usage(void)
@@ -2284,7 +2284,7 @@ static int package_uninstall(const struct bpm_state_entry *st)
char dir[PATH_MAX], updir[PATH_MAX];
char (*unloads)[PATH_MAX];
struct dirent *de;
- int n = 0, rc = 0;
+ int n = 0, ret = 0;
DIR *d;
if (strsprintf(updir, sizeof(updir), "%s/upatches", st->path) < 0)
@@ -2298,7 +2298,7 @@ static int package_uninstall(const struct bpm_state_entry *st)
*/
d = opendir(updir);
if (!d && errno != ENOENT) {
- rc = -errno;
+ ret = -errno;
goto out;
}
while (d && (de = readdir(d))) {
@@ -2309,38 +2309,38 @@ static int package_uninstall(const struct bpm_state_entry *st)
".unload.upatch"))
continue;
if (n >= 128) {
- rc = -E2BIG;
+ ret = -E2BIG;
break;
}
if (strsprintf(unloads[n], PATH_MAX, "%s/%s", updir, de->d_name) < 0) {
- rc = -ENAMETOOLONG;
+ ret = -ENAMETOOLONG;
break;
}
n++;
}
if (d)
closedir(d);
- if (rc)
+ if (ret)
goto out;
qsort(unloads, (size_t)n, PATH_MAX, path_compare_desc);
for (int i = 0; i < n; i++) {
if (shirudo_upatch_remove(unloads[i])) {
pr_err("bpm uninstall: unload %s failed", unloads[i]);
- rc = -EIO;
+ ret = -EIO;
goto out;
}
}
if (strsprintf(dir, sizeof(dir), "%s/%s", BPM_PACKAGES_DIR,
st->name) < 0) {
- rc = -ENAMETOOLONG;
+ ret = -ENAMETOOLONG;
goto out;
}
- rc = remove_tree(dir);
- if (rc == -ENOENT)
- rc = 0;
+ ret = remove_tree(dir);
+ if (ret == -ENOENT)
+ ret = 0;
out:
xfree(unloads, 128 * PATH_MAX);
- return rc;
+ return ret;
}
static const struct shirudo_help_item bpm_subcmds[] = {
@@ -2380,7 +2380,7 @@ static int bpm_exec_operator(const char *sub, int argc, const char **argv)
const char **helper_argv = xcalloc((size_t)argc + 2,
sizeof(*helper_argv));
char label[64];
- int rc;
+ int ret;
if (!helper_argv)
return bpm_fail(sub, -ENOMEM);
@@ -2392,9 +2392,9 @@ static int bpm_exec_operator(const char *sub, int argc, const char **argv)
helper_argv[2] = sub;
for (int i = 3; i < argc + 1; i++)
helper_argv[i] = argv[i - 1];
- rc = shirudo_build_exec(label, (char **)helper_argv);
+ ret = shirudo_build_exec(label, (char **)helper_argv);
xfree(helper_argv, ((size_t)argc + 2) * sizeof(*helper_argv));
- return rc;
+ return ret;
}
static const struct shirudo_help bpm_target_help = {
@@ -2441,14 +2441,14 @@ static void bpm_info_usage(void)
"Package may be a local .bee file or an oci:// reference.\n");
}
-static int bpm_finish(int lock, int rc, const char *action)
+static int bpm_finish(int lock, int ret, const char *action)
{
if (lock >= 0) {
flock(lock, LOCK_UN);
close(lock);
}
curl_global_cleanup();
- return rc ? bpm_fail(action, rc) : 0;
+ return ret ? bpm_fail(action, ret) : 0;
}
static const struct shirudo_help_item bpm_key_subcmds[] = {
@@ -2476,7 +2476,7 @@ static int cmd_bpm_key(int argc, const char **argv)
{
char temp[PATH_MAX] = {}, hex[65];
const char *sub, *src;
- int rc;
+ int ret;
if (argc < 2 || is_help(argv[1])) {
print_help(&bpm_key_help);
@@ -2506,25 +2506,25 @@ static int cmd_bpm_key(int argc, const char **argv)
return 1;
}
if (!strcmp(sub, "list")) {
- rc = list_keys();
- return rc ? bpm_fail("key list", rc) : 0;
+ ret = list_keys();
+ return ret ? bpm_fail("key list", ret) : 0;
}
if (curl_global_init(CURL_GLOBAL_DEFAULT) != CURLE_OK)
return bpm_fail("initialize curl", -EIO);
src = argv[2];
- rc = key_source_file(src, temp, sizeof(temp));
- if (!rc) {
+ ret = key_source_file(src, temp, sizeof(temp));
+ if (!ret) {
if (temp[0])
src = temp;
- rc = key_file_fingerprint(src, hex);
- if (!rc && !strcmp(sub, "add"))
- rc = install_key_file(src);
- if (!rc)
+ ret = key_file_fingerprint(src, hex);
+ if (!ret && !strcmp(sub, "add"))
+ ret = install_key_file(src);
+ if (!ret)
puts(hex);
}
if (temp[0])
unlink(temp);
- return bpm_finish(-1, rc, !strcmp(sub, "add") ?
+ return bpm_finish(-1, ret, !strcmp(sub, "add") ?
"key add" : "key fingerprint");
}
@@ -2558,7 +2558,7 @@ int cmd_bpm(int argc, const char **argv)
if (!strcmp(sub, "info")) {
bool json = false, all = false;
const char *source;
- int rc;
+ int ret;
if (argc == 3 && is_help(argv[2])) {
bpm_info_usage();
@@ -2594,12 +2594,12 @@ int cmd_bpm(int argc, const char **argv)
if (curl_global_init(CURL_GLOBAL_DEFAULT) != CURLE_OK)
return bpm_fail("initialize curl", -EIO);
if (!strcmp(argv[2], "upatches"))
- rc = print_package_upatches(source, all);
+ ret = print_package_upatches(source, all);
else if (!strcmp(argv[2], "data"))
- rc = print_package_upatch_data(source, argv[4], json);
+ ret = print_package_upatch_data(source, argv[4], json);
else
- rc = print_package_readme(source);
- return bpm_finish(-1, rc, "info");
+ ret = print_package_readme(source);
+ return bpm_finish(-1, ret, "info");
}
if (!strcmp(sub, "tree") && (argc < 3 || is_help(argv[2]))) {
bpm_tree_usage();
@@ -2614,7 +2614,7 @@ int cmd_bpm(int argc, const char **argv)
if (!strcmp(sub, "build") || !strcmp(sub, "push"))
return bpm_exec_operator(sub, argc, argv);
if (!strcmp(sub, "pull")) {
- int rc;
+ int ret;
if (argc == 3 && is_help(argv[2])) {
bpm_pull_usage();
@@ -2626,11 +2626,11 @@ int cmd_bpm(int argc, const char **argv)
}
if (curl_global_init(CURL_GLOBAL_DEFAULT) != CURLE_OK)
return bpm_fail("initialize curl", -EIO);
- rc = pull_package(argv[2]);
- return bpm_finish(-1, rc, "pull");
+ ret = pull_package(argv[2]);
+ return bpm_finish(-1, ret, "pull");
}
if (!strcmp(sub, "repo") && argc >= 3 && !strcmp(argv[2], "update")) {
- int lock, rc = 0;
+ int lock, ret = 0;
if (argc > 4)
return 2;
@@ -2644,7 +2644,7 @@ int cmd_bpm(int argc, const char **argv)
struct dirent *entry;
if (!d && errno != ENOENT)
- rc = -errno;
+ ret = -errno;
/* One unreachable registry must not hold back the others. */
while (d && (entry = readdir(d))) {
size_t len = strlen(entry->d_name);
@@ -2654,21 +2654,21 @@ int cmd_bpm(int argc, const char **argv)
continue;
if (strsprintf(source, sizeof(source), "%.*s",
(int)(len - 5), entry->d_name) < 0) {
- rc = -ENAMETOOLONG;
+ ret = -ENAMETOOLONG;
continue;
}
if (repo_update_one(source))
- rc = -EIO;
+ ret = -EIO;
}
if (d)
closedir(d);
} else {
- rc = repo_update_one(argv[3]);
+ ret = repo_update_one(argv[3]);
}
- return bpm_finish(lock, rc, "repo update");
+ return bpm_finish(lock, ret, "repo update");
}
if (!strcmp(sub, "tree")) {
- int lock, rc;
+ int lock, ret;
if (argc > 6)
return 2;
@@ -2688,8 +2688,8 @@ int cmd_bpm(int argc, const char **argv)
lock = with_bpm_lock();
if (lock < 0)
return bpm_finish(-1, lock, "lock");
- rc = cmd_bpm_tree_sync(argc - 1, argv + 1);
- return bpm_finish(lock, rc, "tree sync");
+ ret = cmd_bpm_tree_sync(argc - 1, argv + 1);
+ return bpm_finish(lock, ret, "tree sync");
}
if (!strcmp(sub, "key"))
return cmd_bpm_key(argc - 1, argv + 1);
@@ -2700,7 +2700,7 @@ int cmd_bpm(int argc, const char **argv)
struct bpm_state_entry state[BPM_MAX_STATE];
struct bpm_index_entry selected;
bool direct = !strncmp(argv[2], "oci://", 6);
- int n_entries, n_state, lock, rc, i;
+ int n_entries, n_state, lock, ret, i;
if (curl_global_init(CURL_GLOBAL_DEFAULT) != CURLE_OK)
return bpm_fail("initialize curl", -EIO);
@@ -2708,15 +2708,15 @@ int cmd_bpm(int argc, const char **argv)
if (lock < 0)
return bpm_finish(-1, lock, "lock");
if (direct) {
- rc = prepare_direct_install(argv[2], &source_cfg, &selected);
+ ret = prepare_direct_install(argv[2], &source_cfg, &selected);
} else {
- rc = parse_package_ref(argv[2], source, sizeof(source), name,
- sizeof(name), version, sizeof(version));
+ ret = parse_package_ref(argv[2], source, sizeof(source), name,
+ sizeof(name), version, sizeof(version));
}
- if (!rc)
- rc = state_read(state, &n_state);
- if (rc)
- return bpm_finish(lock, rc, "install");
+ if (!ret)
+ ret = state_read(state, &n_state);
+ if (ret)
+ return bpm_finish(lock, ret, "install");
for (i = 0; i < n_state; i++) {
if (!strcmp(state[i].name, direct ? selected.name : name))
/*
@@ -2728,20 +2728,20 @@ int cmd_bpm(int argc, const char **argv)
return bpm_finish(lock, 0, "install");
}
if (!direct) {
- rc = load_source(source, &source_cfg);
- if (!rc)
- rc = load_cached_index(source, entries, &n_entries);
- if (!rc)
- rc = find_entry(entries, n_entries, name,
- version[0] ? version : NULL, &selected);
- }
- if (rc)
- return bpm_finish(lock, rc, "install");
+ ret = load_source(source, &source_cfg);
+ if (!ret)
+ ret = load_cached_index(source, entries, &n_entries);
+ if (!ret)
+ ret = find_entry(entries, n_entries, name,
+ version[0] ? version : NULL, &selected);
+ }
+ if (ret)
+ return bpm_finish(lock, ret, "install");
if (n_state >= BPM_MAX_STATE)
return bpm_finish(lock, -E2BIG, "install");
- rc = package_install(&source_cfg, &selected, NULL, NULL);
- if (rc)
- return bpm_finish(lock, rc, "install");
+ ret = package_install(&source_cfg, &selected, NULL, NULL);
+ if (ret)
+ return bpm_finish(lock, ret, "install");
bpm_copy_string(state[n_state].name, sizeof(state[n_state].name),
direct ? selected.name : name);
bpm_copy_string(state[n_state].version, sizeof(state[n_state].version),
@@ -2753,8 +2753,8 @@ int cmd_bpm(int argc, const char **argv)
direct ? selected.name : name,
selected.version) < 0)
return bpm_finish(lock, -ENAMETOOLONG, "install");
- rc = state_write(state, n_state + 1);
- if (rc) {
+ ret = state_write(state, n_state + 1);
+ if (ret) {
/* Unlisted, the package could never be removed. */
if (package_uninstall(&state[n_state]))
pr_err("bpm install: %s stays installed but "
@@ -2764,11 +2764,11 @@ int cmd_bpm(int argc, const char **argv)
"state could not be written",
state[n_state].name);
}
- return bpm_finish(lock, rc, "write state");
+ return bpm_finish(lock, ret, "write state");
}
if (!strcmp(sub, "list")) {
struct bpm_state_entry *state;
- int n_state, rc;
+ int n_state, ret;
if (argc != 2) {
fprintf(stderr, "usage: shirudo bpm list\n");
@@ -2777,16 +2777,16 @@ int cmd_bpm(int argc, const char **argv)
state = xcalloc(BPM_MAX_STATE, sizeof(*state));
if (!state)
return bpm_fail("list", -ENOMEM);
- rc = state_read(state, &n_state);
- for (int i = 0; !rc && i < n_state; i++)
+ ret = state_read(state, &n_state);
+ for (int i = 0; !ret && i < n_state; i++)
printf("%s %s %s\n", state[i].name, state[i].version,
state[i].source);
xfree(state, BPM_MAX_STATE * sizeof(*state));
- return rc ? bpm_fail("list", rc) : 0;
+ return ret ? bpm_fail("list", ret) : 0;
}
if (!strcmp(sub, "uninstall")) {
struct bpm_state_entry *state;
- int n_state, lock, rc, i;
+ int n_state, lock, ret, i;
if (argc != 3 || is_help(argv[2])) {
fprintf(stderr, "usage: shirudo bpm uninstall <package>\n");
@@ -2802,35 +2802,35 @@ int cmd_bpm(int argc, const char **argv)
xfree(state, BPM_MAX_STATE * sizeof(*state));
return bpm_finish(-1, lock, "lock");
}
- rc = state_read(state, &n_state);
- for (i = 0; !rc && i < n_state; i++) {
+ ret = state_read(state, &n_state);
+ for (i = 0; !ret && i < n_state; i++) {
if (!strcmp(state[i].name, argv[2]))
break;
}
- if (!rc && i == n_state)
- rc = -ENOENT;
- if (!rc)
- rc = package_uninstall(&state[i]);
- if (!rc) {
+ if (!ret && i == n_state)
+ ret = -ENOENT;
+ if (!ret)
+ ret = package_uninstall(&state[i]);
+ if (!ret) {
memmove(&state[i], &state[i + 1],
(size_t)(n_state - i - 1) * sizeof(*state));
- rc = state_write(state, n_state - 1);
+ ret = state_write(state, n_state - 1);
}
xfree(state, BPM_MAX_STATE * sizeof(*state));
- return bpm_finish(lock, rc, "uninstall");
+ return bpm_finish(lock, ret, "uninstall");
}
if (!strcmp(sub, "upgrade") && argc == 2) {
struct bpm_state_entry state[BPM_MAX_STATE];
- int n_state, lock, rc, wrc, i;
+ int n_state, lock, ret, wrc, i;
if (curl_global_init(CURL_GLOBAL_DEFAULT) != CURLE_OK)
return bpm_fail("initialize curl", -EIO);
lock = with_bpm_lock();
if (lock < 0)
return bpm_finish(-1, lock, "lock");
- rc = state_read(state, &n_state);
- if (rc)
- return bpm_finish(lock, rc, "read state");
+ ret = state_read(state, &n_state);
+ if (ret)
+ return bpm_finish(lock, ret, "read state");
for (i = 0; i < n_state; i++) {
struct bpm_index_entry entries[BPM_MAX_ENTRIES], selected;
struct bpm_source source_cfg;
@@ -2839,38 +2839,38 @@ int cmd_bpm(int argc, const char **argv)
if (!strcmp(state[i].source, "direct"))
continue;
- rc = load_source(state[i].source, &source_cfg);
- if (!rc)
- rc = load_cached_index(state[i].source, entries, &n_entries);
- if (!rc)
- rc = find_entry(entries, n_entries, state[i].name, NULL,
- &selected);
- if (rc == -ENOENT) {
- rc = 0;
+ ret = load_source(state[i].source, &source_cfg);
+ if (!ret)
+ ret = load_cached_index(state[i].source, entries, &n_entries);
+ if (!ret)
+ ret = find_entry(entries, n_entries, state[i].name, NULL,
+ &selected);
+ if (ret == -ENOENT) {
+ ret = 0;
continue;
}
- if (rc)
+ if (ret)
break;
if (bpm_semver_compare(selected.version, state[i].version) <= 0)
continue;
- rc = package_install(&source_cfg, &selected, state[i].path,
- state[i].version);
- if (rc)
+ ret = package_install(&source_cfg, &selected, state[i].path,
+ state[i].version);
+ if (ret)
break;
bpm_copy_string(state[i].version, sizeof(state[i].version),
selected.version);
if (strsprintf(path, sizeof(path), "%s/%s/%s",
BPM_PACKAGES_DIR, state[i].name,
selected.version) < 0) {
- rc = -ENAMETOOLONG;
+ ret = -ENAMETOOLONG;
break;
}
bpm_copy_string(state[i].path, sizeof(state[i].path), path);
}
/* Packages upgraded before a failure stay on record. */
wrc = state_write(state, n_state);
- if (rc)
- return bpm_finish(lock, rc, "upgrade");
+ if (ret)
+ return bpm_finish(lock, ret, "upgrade");
return bpm_finish(lock, wrc, "write state");
}
return 2;
diff --git a/builtin-config.c b/builtin-config.c
index 7dc87383..a2335cd1 100644
--- a/builtin-config.c
+++ b/builtin-config.c
@@ -39,7 +39,7 @@ int cmd_config(int argc, const char **argv)
bool image_mode = shirudo_image_config_active();
struct shirudo_config cfg;
bool file_present;
- int rc;
+ int ret;
int i;
for (i = 1; i < argc; i++) {
@@ -53,10 +53,10 @@ int cmd_config(int argc, const char **argv)
}
file_present = access(CONF_PATH, F_OK) == 0;
- rc = config_load(&cfg);
- if (rc && rc != -ENOENT) {
+ ret = config_load(&cfg);
+ if (ret && ret != -ENOENT) {
pr_err("config: load %s: %s",
- CONF_PATH, strerror(-rc));
+ CONF_PATH, strerror(-ret));
return 1;
}
diff --git a/builtin-genkey.c b/builtin-genkey.c
index bb9a9360..8cab095a 100644
--- a/builtin-genkey.c
+++ b/builtin-genkey.c
@@ -47,16 +47,16 @@
static int ensure_keys_dir(const char *keys_dir)
{
- int rc;
+ int ret;
if (!strcmp(keys_dir, "/")) {
pr_err("keys dir cannot be /");
return -EINVAL;
}
- rc = seal_mkdir_p(keys_dir, 0700);
- if (rc)
- pr_err("mkdir %s: %s", keys_dir, strerror(-rc));
- return rc;
+ ret = seal_mkdir_p(keys_dir, 0700);
+ if (ret)
+ pr_err("mkdir %s: %s", keys_dir, strerror(-ret));
+ return ret;
}
static int check_user_keys_dir(const char *keys_dir)
@@ -64,7 +64,7 @@ static int check_user_keys_dir(const char *keys_dir)
char component[NAME_MAX + 1];
struct stat st;
const char *p, *end;
- int dirfd, nextfd, rc = 0;
+ int dirfd, nextfd, ret = 0;
if (keys_dir[0] != '/')
return -EINVAL;
@@ -72,9 +72,9 @@ static int check_user_keys_dir(const char *keys_dir)
if (dirfd < 0)
return -errno;
if (fstat(dirfd, &st) != 0) {
- rc = -errno;
+ ret = -errno;
close(dirfd);
- return rc;
+ return ret;
}
if (st.st_uid != 0 || (st.st_mode & 0022)) {
close(dirfd);
@@ -89,7 +89,7 @@ static int check_user_keys_dir(const char *keys_dir)
if (!len)
continue;
if (len > NAME_MAX) {
- rc = -ENAMETOOLONG;
+ ret = -ENAMETOOLONG;
break;
}
memcpy(component, p, len);
@@ -97,11 +97,11 @@ static int check_user_keys_dir(const char *keys_dir)
nextfd = openat(dirfd, component,
O_RDONLY | O_DIRECTORY | O_CLOEXEC | O_NOFOLLOW);
if (nextfd < 0) {
- rc = -errno;
+ ret = -errno;
break;
}
if (fstat(nextfd, &st) != 0) {
- rc = -errno;
+ ret = -errno;
close(nextfd);
break;
}
@@ -109,7 +109,7 @@ static int check_user_keys_dir(const char *keys_dir)
if ((st.st_uid != 0 && st.st_uid != geteuid()) ||
(final && st.st_uid != geteuid()) ||
(st.st_mode & 0022)) {
- rc = -EPERM;
+ ret = -EPERM;
close(nextfd);
break;
}
@@ -119,7 +119,7 @@ static int check_user_keys_dir(const char *keys_dir)
break;
}
close(dirfd);
- return rc;
+ return ret;
}
static EVP_PKEY *gen_keypair(void)
@@ -159,7 +159,7 @@ static int add_ext(X509 *c, int nid, const char *value)
{
X509_EXTENSION *ex;
X509V3_CTX ctx;
- int rc;
+ int ret;
X509V3_set_ctx_nodb(&ctx);
X509V3_set_ctx(&ctx, c, c, NULL, NULL, 0);
@@ -169,9 +169,9 @@ static int add_ext(X509 *c, int nid, const char *value)
openssl_complain("X509V3_EXT_conf_nid");
return -1;
}
- rc = X509_add_ext(c, ex, -1);
+ ret = X509_add_ext(c, ex, -1);
X509_EXTENSION_free(ex);
- if (rc != 1) {
+ if (ret != 1) {
openssl_complain("X509_add_ext");
return -1;
}
@@ -237,7 +237,7 @@ static int build_cert(X509 *c, EVP_PKEY *pkey)
static int write_private_pem(EVP_PKEY *pkey, const char *path)
{
- int fd, rc = -1;
+ int fd, ret = -1;
FILE *fp = NULL;
fd = open(path, O_WRONLY | O_CREAT | O_EXCL, 0600);
@@ -263,20 +263,20 @@ static int write_private_pem(EVP_PKEY *pkey, const char *path)
pr_err("flush %s: %s", path, strerror(errno));
goto out;
}
- rc = 0;
+ ret = 0;
out:
if (fp)
fclose(fp);
else if (fd >= 0)
close(fd);
- if (rc != 0)
+ if (ret != 0)
unlink(path);
- return rc;
+ return ret;
}
static int write_cert_der(X509 *c, const char *path)
{
- int fd, rc = -1;
+ int fd, ret = -1;
BIO *bio = NULL;
fd = open(path, O_WRONLY | O_CREAT | O_EXCL, 0600);
@@ -301,15 +301,15 @@ static int write_cert_der(X509 *c, const char *path)
pr_err("fsync %s: %s", path, strerror(errno));
goto out;
}
- rc = 0;
+ ret = 0;
out:
if (bio)
BIO_free(bio);
if (fd >= 0)
close(fd);
- if (rc != 0)
+ if (ret != 0)
unlink(path);
- return rc;
+ return ret;
}
/*
@@ -395,7 +395,7 @@ int cmd_genkey(int argc, const char **argv)
const char *keys_dir;
X509 *cert = NULL;
int force = 0;
- int rc = 1;
+ int ret = 1;
for (int i = 1; i < argc; i++) {
if (strcmp(argv[i], "--force") == 0 ||
@@ -418,29 +418,29 @@ int cmd_genkey(int argc, const char **argv)
keys_dir = keys_dir_resolve(keys_dir_arg);
- rc = key_paths(keys_dir, pkey_path, sizeof(pkey_path),
- cert_path, sizeof(cert_path));
- if (rc) {
+ ret = key_paths(keys_dir, pkey_path, sizeof(pkey_path),
+ cert_path, sizeof(cert_path));
+ if (ret) {
pr_err("genkey: invalid keys dir %s: %s",
- keys_dir, strerror(-rc));
+ keys_dir, strerror(-ret));
return 1;
}
if (ensure_keys_dir(keys_dir) != 0)
return 1;
if (geteuid() != 0 && strcmp(keys_dir, KEYS_DIR) == 0) {
- rc = check_user_keys_dir(keys_dir);
- if (rc) {
+ ret = check_user_keys_dir(keys_dir);
+ if (ret) {
pr_err("genkey: default keys dir %s is not safe for user key "
"generation: %s", KEYS_DIR,
- strerror(-rc));
+ strerror(-ret));
pr_err("it must be owned by the current user and not writable "
"by group or others");
pr_err("rerun with sudo or pass --keys-dir <dir>");
return 1;
}
}
- rc = 1;
+ ret = 1;
if (!force && (path_exists(pkey_path) ||
path_exists(cert_path))) {
@@ -504,11 +504,11 @@ int cmd_genkey(int argc, const char **argv)
cert_path, VALIDITY_DAYS);
pr_audit("genkey: created shirudo %s signing material at %s",
GENKEY_ALG, keys_dir);
- rc = 0;
+ ret = 0;
out:
if (cert)
X509_free(cert);
if (pkey)
EVP_PKEY_free(pkey);
- return rc;
+ return ret;
}
diff --git a/builtin-image.c b/builtin-image.c
index 8813007b..29bbe5a3 100644
--- a/builtin-image.c
+++ b/builtin-image.c
@@ -22,7 +22,7 @@ static void image_help(void)
int cmd_image(int argc, const char **argv)
{
- int rc;
+ int ret;
if (argc == 2 && !strcmp(argv[1], "--list-cmds")) {
puts("build verify update status");
@@ -44,22 +44,22 @@ int cmd_image(int argc, const char **argv)
helper[1] = "image";
for (i = 1; i < argc; i++)
helper[i + 1] = (char *)argv[i];
- rc = shirudo_build_exec(!strcmp(argv[1], "build") ?
- "image build" : "image verify", helper);
+ ret = shirudo_build_exec(!strcmp(argv[1], "build") ?
+ "image build" : "image verify", helper);
xfree(helper, bytes);
- return rc;
+ return ret;
}
if (!strcmp(argv[1], "update") && argc == 3) {
- rc = shirudo_image_update(argv[2]);
+ ret = shirudo_image_update(argv[2]);
} else if (!strcmp(argv[1], "status") && argc == 2) {
- rc = shirudo_image_status();
+ ret = shirudo_image_status();
} else {
image_help();
return 2;
}
- if (rc == -EINPROGRESS)
+ if (ret == -EINPROGRESS)
pr_err("image: activation is pending; further changes are blocked");
- else if (rc)
- pr_err("image %s: %s", argv[1], strerror(-rc));
- return rc ? 1 : 0;
+ else if (ret)
+ pr_err("image %s: %s", argv[1], strerror(-ret));
+ return ret ? 1 : 0;
}
diff --git a/builtin-init.c b/builtin-init.c
index 9389b3b0..3dfcb683 100644
--- a/builtin-init.c
+++ b/builtin-init.c
@@ -84,13 +84,13 @@ static int keyring_holds_set(key_serial_t ring,
{
struct keyring_cert certs[KEYS_MAX];
size_t i;
- int rc;
+ int ret;
for (i = 0; i < set->n; i++) {
- rc = keys_cert_der(&set->certs[i], &certs[i].der,
- &certs[i].len);
- if (rc)
- return rc;
+ ret = keys_cert_der(&set->certs[i], &certs[i].der,
+ &certs[i].len);
+ if (ret)
+ return ret;
}
return keyring_holds_exactly(ring, certs, set->n);
}
@@ -110,18 +110,18 @@ static int init_bpf_keyring(key_serial_t ring,
{
bool sealed = false;
size_t i;
- int rc;
+ int ret;
for (i = 0; i < set->n && !sealed; i++) {
const __u8 *der = NULL;
size_t der_sz = 0;
key_serial_t key;
- rc = keys_cert_der(&set->certs[i], &der, &der_sz);
- if (rc) {
+ ret = keys_cert_der(&set->certs[i], &der, &der_sz);
+ if (ret) {
pr_err("read %s: %s", set->certs[i].path,
- strerror(-rc));
- return rc;
+ strerror(-ret));
+ return ret;
}
key = keyring_bpf_add_cert(der, der_sz);
if (key >= 0) {
@@ -146,30 +146,30 @@ static int init_bpf_keyring(key_serial_t ring,
sealed = true;
}
if (!sealed) {
- rc = keyring_bpf_seal();
- if (rc == -EEXIST) {
+ ret = keyring_bpf_seal();
+ if (ret == -EEXIST) {
pr_err("bpf keyring serial=%d carries a restriction "
"init did not install (tampered)", (int)ring);
return -EKEYREJECTED;
}
- if (rc) {
+ if (ret) {
pr_err("bpf keyring: certificates enrolled but the "
"keyring could not be sealed: %s",
- strerror(-rc));
- return rc;
+ strerror(-ret));
+ return ret;
}
}
- rc = keyring_holds_set(ring, set);
- if (rc < 0) {
- pr_err("bpf keyring: compare: %s", strerror(-rc));
- return rc;
+ ret = keyring_holds_set(ring, set);
+ if (ret < 0) {
+ pr_err("bpf keyring: compare: %s", strerror(-ret));
+ return ret;
}
- if (!rc && sealed && keyring_holds_exactly(ring, NULL, 0) == 1) {
+ if (!ret && sealed && keyring_holds_exactly(ring, NULL, 0) == 1) {
pr_err("bpf keyring serial=%d was sealed empty at boot; boot "
"with bpf.keyring_unsealed=1", (int)ring);
return -ENOKEY;
}
- if (!rc) {
+ if (!ret) {
pr_err("bpf keyring serial=%d is sealed around keys other than "
"the %zu trusted certificate%s (tampered)", (int)ring,
set->n, set->n == 1 ? "" : "s");
@@ -191,13 +191,13 @@ static int init_keyring(void)
struct shirudo_trusted_set set;
struct shirudo_identity id;
key_serial_t ring;
- int rc;
+ int ret;
ring = keyring_bpf_serial();
if (ring <= 0) {
- rc = ring ? ring : -ENOKEY;
- pr_err("bpf keyring lookup: %s", strerror(-rc));
- return rc;
+ ret = ring ? ring : -ENOKEY;
+ pr_err("bpf keyring lookup: %s", strerror(-ret));
+ return ret;
}
if (!identity_read(&id)) {
if (id.keyring_type != SIG_KEYRING_BPF ||
@@ -206,12 +206,12 @@ static int init_keyring(void)
return -EKEYREJECTED;
return 0;
}
- rc = shirudo_image_boot_keys(&set);
- if (rc)
- return rc;
- rc = init_bpf_keyring(ring, &set);
- if (rc && rc != -EEXIST)
- return rc;
+ ret = shirudo_image_boot_keys(&set);
+ if (ret)
+ return ret;
+ ret = init_bpf_keyring(ring, &set);
+ if (ret && ret != -EEXIST)
+ return ret;
enrolled = set;
return 0;
}
@@ -242,29 +242,29 @@ static int is_bpffs_mounted(const char *path)
static int init_bpffs(void)
{
struct stat parent, run;
- int rc;
-
- rc = seal_mkdir_p(VAR_LIB, 0700);
- if (rc) {
- pr_err("mkdir %s: %s", VAR_LIB, strerror(-rc));
- return rc;
- }
- rc = seal_mkdir_p(RUN_DIR, 0700);
- if (rc) {
- pr_err("mkdir %s: %s", RUN_DIR, strerror(-rc));
- return rc;
- }
- rc = is_bpffs_mounted(BPFFS_DIR);
- if (rc < 0)
- return rc;
- if (rc)
+ int ret;
+
+ ret = seal_mkdir_p(VAR_LIB, 0700);
+ if (ret) {
+ pr_err("mkdir %s: %s", VAR_LIB, strerror(-ret));
+ return ret;
+ }
+ ret = seal_mkdir_p(RUN_DIR, 0700);
+ if (ret) {
+ pr_err("mkdir %s: %s", RUN_DIR, strerror(-ret));
+ return ret;
+ }
+ ret = is_bpffs_mounted(BPFFS_DIR);
+ if (ret < 0)
+ return ret;
+ if (ret)
return 0;
if (stat(RUN_DIR, &parent) || stat("/run", &run))
return -errno;
if (parent.st_dev == run.st_dev) {
- rc = seal_label(RUN_DIR);
- if (rc)
- return rc;
+ ret = seal_label(RUN_DIR);
+ if (ret)
+ return ret;
if (mount("tmpfs", RUN_DIR, "tmpfs",
MS_NOSUID | MS_NODEV | MS_NOEXEC,
"mode=0700,size=16M"))
@@ -275,22 +275,22 @@ static int init_bpffs(void)
return -errno;
/* So that the init record left here is sealed from its creation. */
- rc = seal_label(RUN_DIR);
- if (rc)
- return rc;
- rc = seal_mkdir_p(BPFFS_DIR, 0700);
- if (rc) {
+ ret = seal_label(RUN_DIR);
+ if (ret)
+ return ret;
+ ret = seal_mkdir_p(BPFFS_DIR, 0700);
+ if (ret) {
pr_err("mkdir %s: %s",
- BPFFS_DIR, strerror(-rc));
- return rc;
+ BPFFS_DIR, strerror(-ret));
+ return ret;
}
- rc = is_bpffs_mounted(BPFFS_DIR);
- if (rc < 0) {
- pr_err("read /proc/self/mounts: %s", strerror(-rc));
- return rc;
+ ret = is_bpffs_mounted(BPFFS_DIR);
+ if (ret < 0) {
+ pr_err("read /proc/self/mounts: %s", strerror(-ret));
+ return ret;
}
- if (rc) {
+ if (ret) {
pr_info("bpffs already mounted at %s", BPFFS_DIR);
return 0;
}
@@ -353,7 +353,7 @@ static int share_policy_maps(struct bpf_object *source,
{
struct bpf_map *from, *to;
size_t i;
- int rc;
+ int ret;
for (i = 0; i < ARRAY_SIZE(shirudo_guard_maps); i++) {
from = bpf_object__find_map_by_name(source,
@@ -362,9 +362,9 @@ static int share_policy_maps(struct bpf_object *source,
shirudo_guard_maps[i].name);
if (!from || !to)
return -ENOENT;
- rc = bpf_map__reuse_fd(to, bpf_map__fd(from));
- if (rc)
- return rc;
+ ret = bpf_map__reuse_fd(to, bpf_map__fd(from));
+ if (ret)
+ return ret;
}
return 0;
}
@@ -376,7 +376,7 @@ static int attach_guard_group(struct bpf_object *obj,
{
struct bpf_program *program;
size_t i;
- int rc;
+ int ret;
for (i = 0; i < count; i++) {
program = bpf_object__find_program_by_name(obj, guards[i].prog);
@@ -384,10 +384,10 @@ static int attach_guard_group(struct bpf_object *obj,
pr_err("program %s missing", guards[i].prog);
return -ENOENT;
}
- rc = attach_pin(program, guards[i].pin, &links[i]);
- if (rc) {
- pr_err("attach %s: %s", guards[i].prog, strerror(-rc));
- return rc;
+ ret = attach_pin(program, guards[i].pin, &links[i]);
+ if (ret) {
+ pr_err("attach %s: %s", guards[i].prog, strerror(-ret));
+ return ret;
}
}
return 0;
@@ -527,7 +527,7 @@ static int freeze_task_maps(struct bpf_object *obj)
.trusted = TASK_BOOTSTRAP,
};
struct bpf_map *map;
- int fd, pidfd, rc = 0;
+ int fd, pidfd, ret = 0;
__u32 i;
pidfd = syscall(SYS_pidfd_open, getpid(), 0);
@@ -539,24 +539,24 @@ static int freeze_task_maps(struct bpf_object *obj)
map = bpf_object__find_map_by_name(obj, expected->name);
if (!map) {
- rc = -ENOENT;
+ ret = -ENOENT;
break;
}
fd = bpf_map__fd(map);
if (i == SHIRUDO_GUARD_TASKS &&
bpf_map_update_elem(fd, &pidfd, &authority, BPF_ANY)) {
- rc = -errno;
+ ret = -errno;
break;
}
/* Expected roots change for each mapping. */
if ((i != SHIRUDO_GUARD_ROOTS && bpf_map_freeze(fd)) ||
bpf_obj_pin(fd, expected->pin)) {
- rc = -errno;
+ ret = -errno;
break;
}
}
close(pidfd);
- return rc;
+ return ret;
}
/*
@@ -569,19 +569,19 @@ static int record_attestation_key(struct shirudo_identity *id)
{
struct shirudo_tpm_key ak = {};
struct shirudo_tpm *tpm;
- int rc;
+ int ret;
- rc = tpm_open(&tpm);
- if (rc)
- return rc;
- rc = tpm_ak_create(tpm, &ak);
- if (!rc) {
+ ret = tpm_open(&tpm);
+ if (ret)
+ return ret;
+ ret = tpm_ak_create(tpm, &ak);
+ if (!ret) {
memcpy(id->ak_name, ak.name, ak.name_len);
id->ak_name_len = (__u32)ak.name_len;
tpm_key_flush(tpm, &ak);
}
tpm_close(tpm);
- return rc;
+ return ret;
}
static int init_lsm(void)
@@ -919,7 +919,7 @@ static int boot_restore(bool recorded,
{
struct shirudo_measured_upatch *set = NULL;
struct dirent **names = NULL;
- int n, i, rc = 0;
+ int n, i, ret = 0;
size_t cnt = 0;
*out_set = NULL;
@@ -956,13 +956,13 @@ static int boot_restore(bool recorded,
struct shirudo_upatch u;
int fd;
- if (rc)
+ if (ret)
goto next;
if (strsprintf(path, sizeof(path), "%s/%s", UPATCHES_DIR,
names[i]->d_name) < 0) {
pr_err("boot-restore: path too long: %s",
names[i]->d_name);
- rc = -ENAMETOOLONG;
+ ret = -ENAMETOOLONG;
goto next;
}
if (!seal_owns(path)) {
@@ -990,7 +990,7 @@ static int boot_restore(bool recorded,
pr_err("boot-restore: %s is loaded with a "
"payload other than the archived one "
"(tampered)", set[cnt].name);
- rc = -EINVAL;
+ ret = -EINVAL;
goto next;
}
pr_info("boot-restore: %s already loaded",
@@ -1003,13 +1003,13 @@ static int boot_restore(bool recorded,
"after the register was bound this boot "
"(tampered); unload it or reboot",
names[i]->d_name);
- rc = -EPERM;
+ ret = -EPERM;
goto next;
}
if (shirudo_upatch_apply(path) != 0) {
pr_err("boot-restore: failed to apply %s",
names[i]->d_name);
- rc = -EINVAL;
+ ret = -EINVAL;
goto next;
}
cnt++;
@@ -1018,9 +1018,9 @@ next:
}
libc_free(names);
- if (rc) {
+ if (ret) {
xfree(set, (size_t)n * sizeof(*set));
- return rc;
+ return ret;
}
*out_set = set;
@@ -1142,19 +1142,19 @@ static int chain_extend_init(struct shirudo_measured_upatch *set, size_t n)
{
__u8 cert_sha[32], set_digest[32], tree_root[32], init_digest[32];
struct shirudo_chain_init_info info;
- int rc;
+ int ret;
{
struct shirudo_config cfg;
__u64 max_bytes;
bool full;
- rc = config_load(&cfg);
- if (rc) {
+ ret = config_load(&cfg);
+ if (ret) {
explicit_bzero(&cfg, sizeof(cfg));
pr_err("chain: configuration unreadable: %s",
- strerror(-rc));
- return rc;
+ strerror(-ret));
+ return ret;
}
max_bytes = cfg.eventlog_max_bytes;
full = eventlog_would_exceed(max_bytes);
@@ -1171,10 +1171,10 @@ static int chain_extend_init(struct shirudo_measured_upatch *set, size_t n)
pr_err("chain: no certificate enrolled");
return -ENOENT;
}
- rc = keys_set_digest(&enrolled, cert_sha);
- if (rc) {
- pr_err("chain: cannot hash the enrolled set: %s", strerror(-rc));
- return rc;
+ ret = keys_set_digest(&enrolled, cert_sha);
+ if (ret) {
+ pr_err("chain: cannot hash the enrolled set: %s", strerror(-ret));
+ return ret;
}
/*
@@ -1183,37 +1183,37 @@ static int chain_extend_init(struct shirudo_measured_upatch *set, size_t n)
* predictor shares (util/attest.c).
*/
tree_root_at_boot(tree_root);
- rc = chain_init_event(cert_sha, set, n, tree_root, set_digest,
- init_digest);
+ ret = chain_init_event(cert_sha, set, n, tree_root, set_digest,
+ init_digest);
- if (rc) {
- pr_err("chain: cannot hash the init event: %s", strerror(-rc));
- return rc;
+ if (ret) {
+ pr_err("chain: cannot hash the init event: %s", strerror(-ret));
+ return ret;
}
- rc = chain_init(init_digest, &info);
- if (rc == -ENODEV) {
+ ret = chain_init(init_digest, &info);
+ if (ret == -ENODEV) {
pr_err("tpm: not usable; shirudo requires a TPM 2.0 "
"(tpm_error)");
- return rc;
+ return ret;
}
- if (rc == -EEXIST) {
+ if (ret == -EEXIST) {
pr_err("tpm: the register this boot recorded is gone or "
"replaced; refusing to bind another before the next "
"TPM reset (tampered)");
- return rc;
+ return ret;
}
- if (rc == -EACCES) {
+ if (ret == -EACCES) {
pr_err("tpm: register 0x%08X cannot be bound (tpm_error); on "
"a TPM with owner auth set, supply it via "
"tpm.owner_auth in /etc/shirudo/shirudo.conf or "
"SHIRUDO_TPM_OWNER_AUTH", NV_INDEX);
- return rc;
+ return ret;
}
- if (rc) {
+ if (ret) {
pr_err("tpm: register extend failed -- chain NOT advanced "
"while LSM active (tpm_error); operator must "
"reconcile");
- return rc;
+ return ret;
}
if (info.reused) {
pr_info("tpm: register already bound this boot; chain "
@@ -1221,12 +1221,12 @@ static int chain_extend_init(struct shirudo_measured_upatch *set, size_t n)
return 0;
}
- rc = append_init_event(set, n, cert_sha, set_digest, tree_root,
- init_digest, &info);
- if (rc) {
+ ret = append_init_event(set, n, cert_sha, set_digest, tree_root,
+ init_digest, &info);
+ if (ret) {
pr_err("eventlog: append failed after extend -- chain/log "
"desync; operator must reconcile");
- return rc;
+ return ret;
}
pr_info("tpm: register bound in the %s and extended (index 0x%08X, "
@@ -1282,7 +1282,7 @@ static int initrd_enter(void)
struct statfs root;
char src[PATH_MAX];
struct stat st;
- int rc;
+ int ret;
/*
* /etc/initrd-release is root's to create on the root file system;
@@ -1304,10 +1304,10 @@ static int initrd_enter(void)
"there (x-initrd.mount)", src, sysroot());
return -ENOENT;
}
- rc = seal_mkdir_p(VAR_LIB, 0700);
- if (rc) {
- pr_err("initrd: mkdir %s: %s", VAR_LIB, strerror(-rc));
- return rc;
+ ret = seal_mkdir_p(VAR_LIB, 0700);
+ if (ret) {
+ pr_err("initrd: mkdir %s: %s", VAR_LIB, strerror(-ret));
+ return ret;
}
if (mount(src, VAR_LIB, NULL, MS_BIND | MS_REC, NULL) != 0) {
pr_err("initrd: bind %s at %s: %s", src, VAR_LIB,
@@ -1315,17 +1315,17 @@ static int initrd_enter(void)
return -errno;
}
if (statvfs(VAR_LIB, &state)) {
- rc = -errno;
- pr_err("initrd: statvfs %s: %s", src, strerror(-rc));
+ ret = -errno;
+ pr_err("initrd: statvfs %s: %s", src, strerror(-ret));
} else if (state.f_flag & ST_RDONLY) {
- rc = -EROFS;
+ ret = -EROFS;
pr_err("initrd: %s is read-only", src);
} else {
- rc = 0;
+ ret = 0;
}
- if (rc) {
+ if (ret) {
umount2(VAR_LIB, MNT_DETACH);
- return rc;
+ return ret;
}
pr_info("initrd: %s bound writable at %s for config recovery",
src, VAR_LIB);
@@ -1340,11 +1340,11 @@ static void initrd_leave(void)
strerror(errno));
}
-static int init_phase_error(int rc, const char *phase)
+static int init_phase_error(int ret, const char *phase)
{
- if (rc)
- pr_err("init: %s failed: %s", phase, strerror(-rc));
- return rc;
+ if (ret)
+ pr_err("init: %s failed: %s", phase, strerror(-ret));
+ return ret;
}
static int run_init(void)
@@ -1353,81 +1353,81 @@ static int run_init(void)
struct shirudo_eventlog_init rec;
bool recorded, bootstrap;
size_t n = 0;
- int rc;
+ int ret;
/* Only the run that brings enforcement up may label an unlabelled tree. */
- rc = shirudo_enforcement_active();
- if (rc < 0)
- return init_phase_error(rc, "reading the enforcement state");
- bootstrap = rc == 0;
- rc = init_bpffs();
- if (rc)
- return init_phase_error(rc, "private bpffs setup");
-
- rc = init_keyring();
- if (rc)
- return init_phase_error(rc, "BPF keyring initialization");
- rc = shirudo_image_boot_keys_close();
- if (rc)
- return init_phase_error(rc, "closing the boot key image");
+ ret = shirudo_enforcement_active();
+ if (ret < 0)
+ return init_phase_error(ret, "reading the enforcement state");
+ bootstrap = ret == 0;
+ ret = init_bpffs();
+ if (ret)
+ return init_phase_error(ret, "private bpffs setup");
+
+ ret = init_keyring();
+ if (ret)
+ return init_phase_error(ret, "BPF keyring initialization");
+ ret = shirudo_image_boot_keys_close();
+ if (ret)
+ return init_phase_error(ret, "closing the boot key image");
/* Seal writable state before the hooks attach, then adopt the initrd log. */
- rc = seal_label_tree(bootstrap);
- if (rc)
- return init_phase_error(rc, "sealing persistent state");
- rc = eventlog_adopt_pending();
- if (rc)
- return init_phase_error(rc, "adopting the pending eventlog");
-
- rc = init_lsm();
- if (rc)
- return init_phase_error(rc, "loading enforcement");
-
- rc = seal_label_tree(bootstrap);
- if (rc)
- return init_phase_error(rc, "sealing initialized state");
- rc = shirudo_image_runtime_mount();
- if (rc)
- return init_phase_error(rc, "mounting the authenticated runtime");
- rc = shirudo_image_boot();
- if (rc)
- return init_phase_error(rc, "loading authenticated boot settings");
- rc = keys_load(RUNTIME_DIR "/keys",
- KEYS_REVOKED_DIR, true, &enrolled);
- if (rc)
- return init_phase_error(rc, "loading trusted keys");
+ ret = seal_label_tree(bootstrap);
+ if (ret)
+ return init_phase_error(ret, "sealing persistent state");
+ ret = eventlog_adopt_pending();
+ if (ret)
+ return init_phase_error(ret, "adopting the pending eventlog");
+
+ ret = init_lsm();
+ if (ret)
+ return init_phase_error(ret, "loading enforcement");
+
+ ret = seal_label_tree(bootstrap);
+ if (ret)
+ return init_phase_error(ret, "sealing initialized state");
+ ret = shirudo_image_runtime_mount();
+ if (ret)
+ return init_phase_error(ret, "mounting the authenticated runtime");
+ ret = shirudo_image_boot();
+ if (ret)
+ return init_phase_error(ret, "loading authenticated boot settings");
+ ret = keys_load(RUNTIME_DIR "/keys",
+ KEYS_REVOKED_DIR, true, &enrolled);
+ if (ret)
+ return init_phase_error(ret, "loading trusted keys");
/*
* The record is the eventlog's, which root can hide behind a mount;
* the register is the TPM's, written once this boot by whoever bound
* it. Either says the restore has happened.
*/
- rc = eventlog_boot_init(&rec);
- if (rc && rc != -ENOENT) {
+ ret = eventlog_boot_init(&rec);
+ if (ret && ret != -ENOENT) {
pr_err("init: eventlog %s unreadable: %s", eventlog_path(),
- strerror(-rc));
- return rc;
+ strerror(-ret));
+ return ret;
}
- recorded = rc == 0 || chain_bound();
- rc = boot_restore(recorded, &set, &n);
- if (rc) {
+ recorded = ret == 0 || chain_bound();
+ ret = boot_restore(recorded, &set, &n);
+ if (ret) {
pr_err("init: boot-restore failed; further changes "
"and attestation remain blocked");
xfree(set, n * sizeof(*set));
- return init_phase_error(rc, "restoring boot upatches");
+ return init_phase_error(ret, "restoring boot upatches");
}
- rc = chain_extend_init(set, n);
+ ret = chain_extend_init(set, n);
xfree(set, n * sizeof(*set));
- if (rc) {
+ if (ret) {
pr_err("init: incomplete -- LSM active and upatches "
"loaded, but TPM register not advanced");
- return init_phase_error(rc, "binding the TPM register");
+ return init_phase_error(ret, "binding the TPM register");
}
- rc = shirudo_image_boot_complete();
- if (rc)
- return init_phase_error(rc, "completing authenticated boot");
+ ret = shirudo_image_boot_complete();
+ if (ret)
+ return init_phase_error(ret, "completing authenticated boot");
pr_info("init: complete (LSM active, writable state sealed)");
return 0;
@@ -1437,7 +1437,7 @@ int cmd_init(int argc, const char **argv)
{
struct shirudo_preflight_result res;
bool check_only = false;
- int i, rc;
+ int i, ret;
for (i = 1; i < argc; i++) {
const char *a = argv[i];
@@ -1456,9 +1456,9 @@ int cmd_init(int argc, const char **argv)
}
initrd_mode = in_initrd();
- rc = shirudo_image_bootstrap_load();
- if (rc < 0) {
- pr_err("init: authenticated image settings: %s", strerror(-rc));
+ ret = shirudo_image_bootstrap_load();
+ if (ret < 0) {
+ pr_err("init: authenticated image settings: %s", strerror(-ret));
return 1;
}
preflight_run(&res);
@@ -1475,9 +1475,9 @@ int cmd_init(int argc, const char **argv)
if (initrd_mode && initrd_enter())
return 1;
- rc = run_init();
+ ret = run_init();
shirudo_image_leave();
if (initrd_mode)
initrd_leave();
- return rc ? 1 : 0;
+ return ret ? 1 : 0;
}
diff --git a/builtin-keys.c b/builtin-keys.c
index d92e71ae..62734ccc 100644
--- a/builtin-keys.c
+++ b/builtin-keys.c
@@ -147,7 +147,7 @@ static int compute_spki_fpr(EVP_PKEY *pkey,
__u32 n = SHA256_DIGEST_LENGTH;
__u8 *der = NULL;
int der_len;
- int rc = -1;
+ int ret = -1;
der_len = i2d_PUBKEY(pkey, &der);
if (der_len <= 0) {
@@ -159,10 +159,10 @@ static int compute_spki_fpr(EVP_PKEY *pkey,
openssl_complain("EVP_Digest");
goto out;
}
- rc = 0;
+ ret = 0;
out:
OPENSSL_free(der);
- return rc;
+ return ret;
}
static void print_fpr(const char *label, const __u8 *fpr)
@@ -236,7 +236,7 @@ static int dump_signing_key(const char *pkey_path,
__u8 fpr_priv[SHA256_DIGEST_LENGTH];
char alg_s[64];
EVP_PKEY *priv;
- int rc = 0;
+ int ret = 0;
if (!path_exists(pkey_path)) {
printf("Signing key (%s):\n", pkey_path);
@@ -255,7 +255,7 @@ static int dump_signing_key(const char *pkey_path,
printf(" %-22s %s\n", "Algorithm:", alg_s);
if (compute_spki_fpr(priv, fpr_priv) != 0) {
- rc = -1;
+ ret = -1;
goto out;
}
print_fpr("SPKI fingerprint:", fpr_priv);
@@ -267,11 +267,11 @@ static int dump_signing_key(const char *pkey_path,
printf(" %-22s %s\n", "Cert match:",
"MISMATCH (private key does NOT match cert)");
pr_warn("keys: private key and cert have different public keys");
- rc = -1;
+ ret = -1;
}
out:
EVP_PKEY_free(priv);
- return rc;
+ return ret;
}
static int keys_dump_disk_material(const char *cert_path,
@@ -280,7 +280,7 @@ static int keys_dump_disk_material(const char *cert_path,
X509 *cert;
EVP_PKEY *pub;
__u8 cert_spki_fpr[SHA256_DIGEST_LENGTH];
- int rc;
+ int ret;
cert = read_cert_der(cert_path);
if (!cert)
@@ -296,13 +296,13 @@ static int keys_dump_disk_material(const char *cert_path,
return 1;
}
- rc = dump_operator_cert(cert, cert_path, cert_spki_fpr);
- if (rc == 0) {
+ ret = dump_operator_cert(cert, cert_path, cert_spki_fpr);
+ if (ret == 0) {
printf("\n");
- rc = dump_signing_key(pkey_path, cert_spki_fpr);
+ ret = dump_signing_key(pkey_path, cert_spki_fpr);
}
X509_free(cert);
- return rc ? 1 : 0;
+ return ret ? 1 : 0;
}
/* A keyring init froze: its serial and the keys it recorded in it. */
@@ -337,7 +337,7 @@ static int keys_list_keyring(key_serial_t ring, const struct keys_anchor *a,
bool frozen = !id_rc && a->frozen > 0;
struct keyring_link *links = NULL;
size_t n = 0, i;
- int rc;
+ int ret;
printf("Keyring (%s):\n", a->label);
printf(" %-22s %d\n", "Serial:", (int)ring);
@@ -354,9 +354,9 @@ static int keys_list_keyring(key_serial_t ring, const struct keys_anchor *a,
strerror(-id_rc));
}
- rc = keyring_links(ring, &links, &n);
- if (rc) {
- pr_err("keyring list: %s", strerror(-rc));
+ ret = keyring_links(ring, &links, &n);
+ if (ret) {
+ pr_err("keyring list: %s", strerror(-ret));
return 1;
}
printf(" Members (%zu):\n", n);
@@ -381,13 +381,13 @@ static int keys_list_keyring(key_serial_t ring, const struct keys_anchor *a,
return 0;
}
-static void keyring_absent(const struct keys_anchor *a, key_serial_t rc,
+static void keyring_absent(const struct keys_anchor *a, key_serial_t ret,
int id_rc)
{
printf("Keyring (%s):\n", a->label);
- if (rc != (key_serial_t)-ENOKEY)
+ if (ret != (key_serial_t)-ENOKEY)
printf(" %-22s lookup error: %s\n", "Present:",
- strerror(-rc));
+ strerror(-ret));
else if (!id_rc && a->frozen > 0)
printf(" %-22s no (gone: init froze serial %d this boot)\n",
"Present:", (int)a->frozen);
@@ -484,18 +484,18 @@ static int check_cert_algorithm(const __u8 *der, size_t der_sz,
{
struct shirudo_cert cert = {};
char name[64] = {};
- int rc;
+ int ret;
- rc = cert_read_der(der, der_sz, &cert);
- if (rc) {
+ ret = cert_read_der(der, der_sz, &cert);
+ if (ret) {
pr_err("keys add: %s is not a certificate", what);
- return rc;
+ return ret;
}
- rc = cert_key_algorithm(&cert, name, sizeof(name));
+ ret = cert_key_algorithm(&cert, name, sizeof(name));
cert_free(&cert);
- if (rc || strcmp(name, "ML-DSA-87")) {
+ if (ret || strcmp(name, "ML-DSA-87")) {
pr_err("keys add: %s is %s; shirudo accepts only ML-DSA-87",
- what, rc ? "of an unknown algorithm" : name);
+ what, ret ? "of an unknown algorithm" : name);
return -EKEYREJECTED;
}
return 0;
@@ -513,7 +513,7 @@ static int check_voucher_live(const struct shirudo_trusted_set *set,
const __u8 *der = NULL;
key_serial_t ring;
size_t der_sz = 0;
- int rc = 0;
+ int ret = 0;
size_t i;
if (identity_read(&id) ||
@@ -528,13 +528,13 @@ static int check_voucher_live(const struct shirudo_trusted_set *set,
}
if (i == set->n)
return -ENOKEY;
- rc = keys_cert_der(&set->certs[i], &der, &der_sz);
- if (rc)
- return rc;
- rc = keyring_holds_cert(ring, der, der_sz);
- if (rc < 0)
- return rc;
- return rc ? 0 : -ENOKEY;
+ ret = keys_cert_der(&set->certs[i], &der, &der_sz);
+ if (ret)
+ return ret;
+ ret = keyring_holds_cert(ring, der, der_sz);
+ if (ret < 0)
+ return ret;
+ return ret ? 0 : -ENOKEY;
}
static int keys_add(int argc, const char **argv)
@@ -548,7 +548,7 @@ static int keys_add(int argc, const char **argv)
char revoked[PATH_MAX];
const char *keys_dir;
char out[PATH_MAX];
- int rc = 1;
+ int ret = 1;
size_t i;
for (int a = 1; a < argc; a++) {
@@ -588,39 +588,39 @@ static int keys_add(int argc, const char **argv)
return 2;
}
- rc = keys_read_der(cert, &der, &der_sz);
- if (rc) {
- pr_err("keys add: read %s: %s", cert, strerror(-rc));
+ ret = keys_read_der(cert, &der, &der_sz);
+ if (ret) {
+ pr_err("keys add: read %s: %s", cert, strerror(-ret));
return 1;
}
- rc = keys_digest_der(der, der_sz, sha256, fp);
- if (rc) {
+ ret = keys_digest_der(der, der_sz, sha256, fp);
+ if (ret) {
pr_err("keys add: %s is not a certificate", cert);
goto out;
}
- rc = check_cert_algorithm(der, der_sz, cert);
- if (rc)
+ ret = check_cert_algorithm(der, der_sz, cert);
+ if (ret)
goto out;
hex_encode(fp, 32, fp_hex);
- rc = keys_load(keys_dir, NULL, true, &set);
- if (rc) {
+ ret = keys_load(keys_dir, NULL, true, &set);
+ if (ret) {
pr_err("keys add: no trusted set under %s: %s (install the "
- "primary certificate first)", keys_dir, strerror(-rc));
+ "primary certificate first)", keys_dir, strerror(-ret));
goto out;
}
if (keys_is_revoked(revoked, fp)) {
pr_err("keys add: %s was revoked on this target", fp_hex);
- rc = -EKEYREVOKED;
+ ret = -EKEYREVOKED;
goto out;
}
- rc = keys_read_der(vouch_path, &sig, &sig_sz);
- if (rc) {
- pr_err("keys add: read %s: %s", vouch_path, strerror(-rc));
+ ret = keys_read_der(vouch_path, &sig, &sig_sz);
+ if (ret) {
+ pr_err("keys add: read %s: %s", vouch_path, strerror(-ret));
goto out;
}
- rc = keys_verify_vouch(&set, der, der_sz, sig, sig_sz, by);
- if (rc) {
+ ret = keys_verify_vouch(&set, der, der_sz, sig, sig_sz, by);
+ if (ret) {
pr_err("keys add: %s does not vouch for %s under any of the "
"%zu trusted certificate%s", vouch_path, fp_hex, set.n,
set.n == 1 ? "" : "s");
@@ -628,12 +628,12 @@ static int keys_add(int argc, const char **argv)
}
hex_encode(by, 32, by_hex);
if (!strcmp(keys_dir, KEYS_DIR)) {
- rc = check_voucher_live(&set, by);
- if (rc) {
+ ret = check_voucher_live(&set, by);
+ if (ret) {
pr_err("keys add: the vouching certificate %s is not "
"in the bpf keyring this boot%s%s", by_hex,
- rc == -ENOKEY ? "" : ": ",
- rc == -ENOKEY ? "" : strerror(-rc));
+ ret == -ENOKEY ? "" : ": ",
+ ret == -ENOKEY ? "" : strerror(-ret));
goto out;
}
}
@@ -642,21 +642,21 @@ static int keys_add(int argc, const char **argv)
continue;
pr_info("keys add: %s is already trusted", fp_hex);
printf("%s\n", fp_hex);
- rc = 0;
+ ret = 0;
goto out;
}
/* A set past the limit would fail to load at all, init included. */
if (set.n >= KEYS_MAX) {
pr_err("keys add: the trusted set holds %d certificates, the "
"most a target enrols", KEYS_MAX);
- rc = -E2BIG;
+ ret = -E2BIG;
goto out;
}
- rc = keys_install(keys_dir, der, der_sz, sig, sig_sz, out,
- sizeof(out));
- if (rc) {
+ ret = keys_install(keys_dir, der, der_sz, sig, sig_sz, out,
+ sizeof(out));
+ if (ret) {
pr_err("keys add: install under %s/trusted: %s", keys_dir,
- strerror(-rc));
+ strerror(-ret));
goto out;
}
pr_audit("keys add: fingerprint=%s vouched_by=%s path=%s", fp_hex,
@@ -668,7 +668,7 @@ out:
if (sig)
xfree(sig, sig_sz);
xfree(der, der_sz);
- return rc ? 1 : 0;
+ return ret ? 1 : 0;
}
static const struct shirudo_help keys_revoke_help = {
@@ -708,26 +708,26 @@ static int measure_revoke_locked(const struct shirudo_trusted_cert *c,
{
__u8 event[32], chain[32];
char sha_hex[65], chain_hex[65];
- int rc;
+ int ret;
chain_key_event("shirudo-key-revoke", c->sha256, event);
- rc = chain_extend(event, chain);
- if (rc) {
+ ret = chain_extend(event, chain);
+ if (ret) {
pr_err("keys revoke: register %s (category: %s); the key is "
"revoked but the revocation is NOT measured; operator "
"must reconcile",
- rc == -ENODEV ? "unavailable" :
- rc == -EACCES ? "is not the one init bound" :
+ ret == -ENODEV ? "unavailable" :
+ ret == -EACCES ? "is not the one init bound" :
"extend failed",
- rc == -EACCES ? "tampered" : "tpm_error");
- return rc;
+ ret == -EACCES ? "tampered" : "tpm_error");
+ return ret;
}
hex_encode(c->sha256, 32, sha_hex);
- rc = append_key_event("key_revoke", fp_hex, sha_hex, event);
- if (rc) {
+ ret = append_key_event("key_revoke", fp_hex, sha_hex, event);
+ if (ret) {
pr_err("keys revoke: eventlog append failed after extend -- "
"chain/log desync; operator must reconcile");
- return rc;
+ return ret;
}
hex_encode(chain, 32, chain_hex);
pr_audit("key revoke measured: fingerprint=%s chain=%s", fp_hex,
@@ -738,7 +738,7 @@ static int measure_revoke_locked(const struct shirudo_trusted_cert *c,
static int measure_revoke(const struct shirudo_trusted_cert *c,
const char *fp_hex)
{
- int lock, rc;
+ int lock, ret;
lock = eventlog_lock();
if (lock < 0) {
@@ -746,9 +746,9 @@ static int measure_revoke(const struct shirudo_trusted_cert *c,
"revocation is NOT measured", strerror(-lock));
return lock;
}
- rc = measure_revoke_locked(c, fp_hex);
+ ret = measure_revoke_locked(c, fp_hex);
eventlog_unlock(lock);
- return rc;
+ return ret;
}
/*
@@ -762,7 +762,7 @@ static int purge_signed_by(const __u8 *der, size_t der_sz,
{
struct shirudo_cert cert = {};
struct dirent **names = NULL;
- int n, i, rc = 0, purged = 0;
+ int n, i, ret = 0, purged = 0;
*unloaded = 0;
if (cert_read_der(der, der_sz, &cert))
@@ -795,7 +795,7 @@ static int purge_signed_by(const __u8 *der, size_t der_sz,
if (prc < 0) {
pr_err("keys revoke: purge %s: %s", name,
strerror(-prc));
- rc = prc;
+ ret = prc;
continue;
}
pr_info("keys revoke: %s %s", name, prc ? "unloaded and purged" :
@@ -807,7 +807,7 @@ static int purge_signed_by(const __u8 *der, size_t der_sz,
libc_free(names[i]);
libc_free(names);
cert_free(&cert);
- return rc ? rc : purged;
+ return ret ? ret : purged;
}
int shirudo_keys_revoke_image(const __u8 *der, size_t size, bool boot)
@@ -816,7 +816,7 @@ int shirudo_keys_revoke_image(const __u8 *der, size_t size, bool boot)
key_serial_t ring, key;
char fingerprint[65];
size_t unloaded;
- int rc;
+ int ret;
ring = keyring_bpf_serial();
if (ring < 0)
@@ -825,22 +825,22 @@ int shirudo_keys_revoke_image(const __u8 *der, size_t size, bool boot)
if (key != -ENOKEY && key < 0)
return key;
if (key >= 0) {
- rc = keyring_unlink_key(ring, key);
- if (rc)
- return rc;
+ ret = keyring_unlink_key(ring, key);
+ if (ret)
+ return ret;
if (!boot) {
- rc = keys_digest_der(der, size, cert.sha256,
- cert.fingerprint);
- if (rc)
- return rc;
+ ret = keys_digest_der(der, size, cert.sha256,
+ cert.fingerprint);
+ if (ret)
+ return ret;
hex_encode(cert.fingerprint, 32, fingerprint);
- rc = measure_revoke(&cert, fingerprint);
- if (rc)
- return rc;
+ ret = measure_revoke(&cert, fingerprint);
+ if (ret)
+ return ret;
}
}
- rc = purge_signed_by(der, size, &unloaded);
- return rc < 0 ? rc : 0;
+ ret = purge_signed_by(der, size, &unloaded);
+ return ret < 0 ? ret : 0;
}
static int keys_revoke(int argc, const char **argv)
@@ -858,7 +858,7 @@ static int keys_vouch(int argc, const char **argv)
{
const char **helper_argv;
size_t sz;
- int rc;
+ int ret;
if (argc >= 2 && is_help(argv[1])) {
print_help(&keys_vouch_help);
@@ -872,9 +872,9 @@ static int keys_vouch(int argc, const char **argv)
helper_argv[2] = "vouch";
for (int i = 1; i < argc; i++)
helper_argv[i + 2] = argv[i];
- rc = shirudo_build_exec("keys vouch", (char **)helper_argv);
+ ret = shirudo_build_exec("keys vouch", (char **)helper_argv);
xfree(helper_argv, sz);
- return rc;
+ return ret;
}
static int keys_show(int argc, const char **argv);
@@ -905,7 +905,7 @@ static int keys_show(int argc, const char **argv)
char pkey_path[PATH_MAX];
char cert_path[PATH_MAX];
bool shown = false;
- int rc = 0, id_rc;
+ int ret = 0, id_rc;
for (int i = 1; i < argc; i++) {
if (strcmp(argv[i], "--keys-dir") == 0 &&
@@ -930,11 +930,11 @@ static int keys_show(int argc, const char **argv)
keys_dir = shirudo_image_config_active() ? RUNTIME_DIR "/keys" :
keys_dir_resolve(keys_dir_arg);
- rc = key_paths(keys_dir, pkey_path, sizeof(pkey_path),
- cert_path, sizeof(cert_path));
- if (rc) {
+ ret = key_paths(keys_dir, pkey_path, sizeof(pkey_path),
+ cert_path, sizeof(cert_path));
+ if (ret) {
pr_err("keys: invalid keys dir %s: %s",
- keys_dir, strerror(-rc));
+ keys_dir, strerror(-ret));
return 2;
}
@@ -946,7 +946,7 @@ static int keys_show(int argc, const char **argv)
*/
if (path_exists(cert_path)) {
if (keys_dump_disk_material(cert_path, pkey_path))
- rc = 1;
+ ret = 1;
shown = true;
}
@@ -993,7 +993,7 @@ static int keys_show(int argc, const char **argv)
if (shown)
printf("\n");
if (keys_list_keyring(ring, a, id_rc))
- rc = 1;
+ ret = 1;
shown = true;
} else if (ring == -ENOKEY && id_rc) {
if (shown) {
@@ -1005,7 +1005,7 @@ static int keys_show(int argc, const char **argv)
printf("\n");
keyring_absent(a, ring, id_rc);
shown = true;
- rc = 1;
+ ret = 1;
}
}
}
@@ -1015,7 +1015,7 @@ static int keys_show(int argc, const char **argv)
"\"%s\" kernel keyring -- run `shirudo genkey` "
"(operator) or `shirudo init` (target)",
cert_path, ".bpf");
- rc = 1;
+ ret = 1;
}
- return rc;
+ return ret;
}
diff --git a/builtin-status.c b/builtin-status.c
index 66ff9a00..0de0cad7 100644
--- a/builtin-status.c
+++ b/builtin-status.c
@@ -936,10 +936,10 @@ int cmd_status(int argc, const char **argv)
}
json = json_stdout || otel;
if (otel) {
- int rc = config_load(&otel_cfg);
+ int err = config_load(&otel_cfg);
- if (rc) {
- pr_err("status: load OTEL configuration: %s", strerror(-rc));
+ if (err) {
+ pr_err("status: load OTEL configuration: %s", strerror(-err));
return 1;
}
if (!otel_cfg.map_export_valid) {
@@ -1374,23 +1374,23 @@ int cmd_status(int argc, const char **argv)
(__s64)tamper.total : -1;
const char *severity_text;
int severity_number;
- int rc;
+ int err;
severity_number =
shirudo_status_otel_severity(otel_status,
&severity_text);
- rc = shirudo_otel_send_log_json(&otel_opts,
- "shirudo.keepalive",
- "shirudo.keepalive",
- severity_number,
- severity_text,
- otel_status,
- shirudo_version_id,
+ err = shirudo_otel_send_log_json(&otel_opts,
+ "shirudo.keepalive",
+ "shirudo.keepalive",
+ severity_number,
+ severity_text,
+ otel_status,
+ shirudo_version_id,
refused, json_buf,
strlen(json_buf));
- if (rc) {
+ if (err) {
pr_err("status: OTEL export failed: %s",
- strerror(-rc));
+ strerror(-err));
ret = 1;
}
}
diff --git a/builtin-upatch.c b/builtin-upatch.c
index 0f22fc47..489b69b8 100644
--- a/builtin-upatch.c
+++ b/builtin-upatch.c
@@ -282,7 +282,7 @@ static int cmd_upatch_info(int argc, const char **argv)
struct shirudo_upatch u;
const char *path = NULL;
bool json = false;
- int i, rc, ret = 1;
+ int i, err, ret = 1;
__u32 attach_len;
for (i = 1; i < argc; i++) {
@@ -308,9 +308,9 @@ static int cmd_upatch_info(int argc, const char **argv)
return 2;
}
- rc = upatch_open(path, &u);
- if (rc != 0) {
- pr_err("upatch info: %s: %s", path, strerror(-rc));
+ err = upatch_open(path, &u);
+ if (err != 0) {
+ pr_err("upatch info: %s: %s", path, strerror(-err));
return 1;
}
@@ -506,7 +506,7 @@ static int cmd_upatch_list(int argc, const char **argv)
{
struct dirent **persisted = NULL, **active = NULL;
struct shirudo_json_emit e = { .buf = NULL };
- int np, na, i, j, rc = 0;
+ int np, na, i, j, ret = 0;
bool json = false;
char *jbuf = NULL;
@@ -534,7 +534,7 @@ static int cmd_upatch_list(int argc, const char **argv)
if (json) {
jbuf = xmalloc(65536);
if (!jbuf) {
- rc = 1;
+ ret = 1;
goto out;
}
e.buf = jbuf;
@@ -632,7 +632,7 @@ static int cmd_upatch_list(int argc, const char **argv)
if (e.err) {
fprintf(stderr, "upatch list: json encode failed: %s\n",
strerror(-e.err));
- rc = 1;
+ ret = 1;
} else {
printf("%s\n", jbuf);
}
@@ -647,7 +647,7 @@ out:
libc_free(active);
if (jbuf)
xfree(jbuf, 65536);
- return rc;
+ return ret;
}
/*
@@ -793,7 +793,7 @@ static int prog_func_name(int prog_fd, const struct bpf_prog_info *base,
void *recs;
size_t recs_sz;
__u32 len;
- int rc = 0;
+ int ret = 0;
if (!out || cap == 0)
return -EINVAL;
@@ -813,29 +813,29 @@ static int prog_func_name(int prog_fd, const struct bpf_prog_info *base,
info.func_info = ptr_to_u64(recs);
len = sizeof(info);
if (bpf_prog_get_info_by_fd(prog_fd, &info, &len) != 0) {
- rc = -errno;
+ ret = -errno;
goto out_free;
}
memcpy(&fi, recs, sizeof(fi));
btf = btf__load_from_kernel_by_id(base->btf_id);
if (!btf) {
- rc = -errno;
+ ret = -errno;
goto out_free;
}
t = btf__type_by_id(btf, fi.type_id);
name = t ? btf__name_by_offset(btf, t->name_off) : NULL;
if (!name || !name[0]) {
- rc = -ENOENT;
+ ret = -ENOENT;
} else if (strlen(name) >= cap) {
- rc = -ENAMETOOLONG;
+ ret = -ENAMETOOLONG;
} else {
strscpy(out, name, cap);
- rc = 0;
+ ret = 0;
}
btf__free(btf);
out_free:
xfree(recs, recs_sz);
- return rc;
+ return ret;
}
static int cgroup_skb_attach_type_from_name(const char *name,
@@ -861,35 +861,35 @@ static int prog_attach_cgroup_skb_fallback(int prog_fd,
{
enum bpf_attach_type attach_type;
char func[128];
- int rc;
+ int ret;
strscpy(func, info->name, sizeof(func));
- rc = prog_func_name(prog_fd, info, func, sizeof(func));
- if (rc && !func[0]) {
+ ret = prog_func_name(prog_fd, info, func, sizeof(func));
+ if (ret && !func[0]) {
pr_err("program metadata says raw_tracepoint, but loaded "
"program type is cgroup_skb and function name is "
"unavailable; rebuild the upatch with cgroup_skb "
"metadata");
- return rc;
+ return ret;
}
- rc = cgroup_skb_attach_type_from_name(func, &attach_type);
- if (rc) {
+ ret = cgroup_skb_attach_type_from_name(func, &attach_type);
+ if (ret) {
pr_err("program metadata says raw_tracepoint, but loaded "
"program type is cgroup_skb and function '%s' does "
"not identify ingress or egress; rebuild the upatch "
"with cgroup_skb metadata", func);
- return rc;
+ return ret;
}
pr_warn("program metadata says raw_tracepoint, but loaded program "
"type is cgroup_skb; inferring %s from function '%s'",
attach_type == BPF_CGROUP_INET_EGRESS ? "egress" : "ingress",
func);
- rc = prog_attach_cgroup_skb(prog_fd, attach_type);
- if (rc >= 0)
+ ret = prog_attach_cgroup_skb(prog_fd, attach_type);
+ if (ret >= 0)
pr_info("attached cgroup_skb fallback as %s",
attach_type == BPF_CGROUP_INET_EGRESS ?
"egress" : "ingress");
- return rc;
+ return ret;
}
static int prog_attach_default(int prog_fd)
@@ -917,7 +917,7 @@ static int prog_attach_default(int prog_fd)
static int prog_attach_cgroup_skb(int prog_fd, enum bpf_attach_type attach_type)
{
union bpf_attr attr = {};
- int cgroup_fd, rc;
+ int cgroup_fd, ret;
long fd;
cgroup_fd = open("/sys/fs/cgroup", O_RDONLY | O_DIRECTORY | O_CLOEXEC);
@@ -928,9 +928,9 @@ static int prog_attach_cgroup_skb(int prog_fd, enum bpf_attach_type attach_type)
attr.link_create.target_fd = (__u32)cgroup_fd;
attr.link_create.attach_type = attach_type;
fd = syscall(__NR_bpf, BPF_LINK_CREATE, &attr, sizeof(attr));
- rc = fd >= 0 ? (int)fd : -errno;
+ ret = fd >= 0 ? (int)fd : -errno;
close(cgroup_fd);
- return rc;
+ return ret;
}
static int prog_attach_netfilter_ipv6_pre_routing(int prog_fd)
@@ -1057,7 +1057,7 @@ static int prepare_uprobe_targets(struct shirudo_prog_spec *specs,
__u32 build_id_len = 0;
char proc_path[64];
struct stat opened_stat;
- int path_fd, fd, rc;
+ int path_fd, fd, ret;
if (spec->kind != SHIRUDO_UPATCH_ATTACH_UPROBE_MULTI)
continue;
@@ -1065,9 +1065,9 @@ static int prepare_uprobe_targets(struct shirudo_prog_spec *specs,
if (path_fd < 0)
return -errno;
if (fstat(path_fd, &spec->target_stat) != 0) {
- rc = -errno;
+ ret = -errno;
close(path_fd);
- return rc;
+ return ret;
}
if (!S_ISREG(spec->target_stat.st_mode)) {
close(path_fd);
@@ -1083,9 +1083,9 @@ static int prepare_uprobe_targets(struct shirudo_prog_spec *specs,
if (fd < 0)
return -errno;
if (fstat(fd, &opened_stat) != 0) {
- rc = -errno;
+ ret = -errno;
close(fd);
- return rc;
+ return ret;
}
if (opened_stat.st_dev != spec->target_stat.st_dev ||
opened_stat.st_ino != spec->target_stat.st_ino) {
@@ -1098,10 +1098,10 @@ static int prepare_uprobe_targets(struct shirudo_prog_spec *specs,
return -ERANGE;
}
}
- rc = elf_build_id_fd(fd, build_id, &build_id_len);
- if (rc) {
+ ret = elf_build_id_fd(fd, build_id, &build_id_len);
+ if (ret) {
close(fd);
- return rc == -EACCES || rc == -EPERM ? rc : -ESTALE;
+ return ret == -EACCES || ret == -EPERM ? ret : -ESTALE;
}
if (build_id_len != spec->build_id_len ||
memcmp(build_id, spec->build_id, build_id_len) != 0) {
@@ -1180,16 +1180,16 @@ static int netns_initial(void)
{
socklen_t len = sizeof(__u64);
__u64 cookie = 0;
- int fd, rc;
+ int fd, ret;
fd = socket(AF_UNIX, SOCK_DGRAM | SOCK_CLOEXEC, 0);
if (fd < 0)
return -errno;
- rc = getsockopt(fd, SOL_SOCKET, SO_NETNS_COOKIE, &cookie, &len) ?
+ ret = getsockopt(fd, SOL_SOCKET, SO_NETNS_COOKIE, &cookie, &len) ?
-errno : 0;
close(fd);
- if (rc)
- return rc;
+ if (ret)
+ return ret;
return cookie == NET_NS_INIT_COOKIE ? 0 : -EXDEV;
}
@@ -1330,7 +1330,7 @@ static int attach_and_pin_progs(const struct shirudo_loader_ctx *cx,
char pin[PATH_MAX + 32];
bool *made = NULL;
int test_fd = -1;
- int rc;
+ int ret;
if (nr_progs == 0) {
pr_warn("upatch carries no programs to attach");
@@ -1339,11 +1339,11 @@ static int attach_and_pin_progs(const struct shirudo_loader_ctx *cx,
if (upatch_bpffs_name(bpffs_name, sizeof(bpffs_name), name))
return -ENAMETOOLONG;
- rc = mkdir_if_absent(BPFFS_UPATCHES_DIR, 0700, NULL);
- if (rc) {
+ ret = mkdir_if_absent(BPFFS_UPATCHES_DIR, 0700, NULL);
+ if (ret) {
pr_err("mkdir %s: %s", BPFFS_UPATCHES_DIR,
- strerror(-rc));
- return rc;
+ strerror(-ret));
+ return ret;
}
if (strsprintf(dir, sizeof(dir), "%s/%s",
BPFFS_UPATCHES_DIR, bpffs_name) < 0)
@@ -1354,9 +1354,9 @@ static int attach_and_pin_progs(const struct shirudo_loader_ctx *cx,
made = xcalloc(nr_progs, sizeof(*made));
if (!made)
return -ENOMEM;
- rc = mkdir_if_absent(dir, 0700, &made_dir);
- if (rc) {
- pr_err("mkdir %s: %s", dir, strerror(-rc));
+ ret = mkdir_if_absent(dir, 0700, &made_dir);
+ if (ret) {
+ pr_err("mkdir %s: %s", dir, strerror(-ret));
goto out;
}
count_attach_progs(specs, nr_progs, &attach_count);
@@ -1371,21 +1371,21 @@ static int attach_and_pin_progs(const struct shirudo_loader_ctx *cx,
if (inner_fd <= 0) {
pr_err("loader produced no fd for prog %u", i);
- rc = -EINVAL;
+ ret = -EINVAL;
goto out;
}
- rc = prog_pin_path(pin, sizeof(pin), dir, serializers_dir,
- spec, attach_count, attach_seen);
- if (rc)
+ ret = prog_pin_path(pin, sizeof(pin), dir, serializers_dir,
+ spec, attach_count, attach_seen);
+ if (ret)
goto out;
if (spec->role == SHIRUDO_UPATCH_PROG_ROLE_SERIALIZER) {
struct stat st;
- rc = mkdir_if_absent(serializers_dir, 0700,
- &made_serializers);
- if (rc) {
+ ret = mkdir_if_absent(serializers_dir, 0700,
+ &made_serializers);
+ if (ret) {
pr_err("mkdir %s: %s", serializers_dir,
- strerror(-rc));
+ strerror(-ret));
goto out;
}
/*
@@ -1393,15 +1393,15 @@ static int attach_and_pin_progs(const struct shirudo_loader_ctx *cx,
* bound to maps nothing reaches any more: replace it.
*/
if (stat(pin, &st) == 0 && unlink(pin)) {
- rc = -errno;
+ ret = -errno;
pr_err("unlink stale serializer pin %s: %s", pin,
- strerror(-rc));
+ strerror(-ret));
goto out;
}
- rc = obj_pin(inner_fd, pin);
- if (rc) {
+ ret = obj_pin(inner_fd, pin);
+ if (ret) {
pr_err("pin serializer %s: %s", pin,
- strerror(-rc));
+ strerror(-ret));
goto out;
}
made[i] = true;
@@ -1413,15 +1413,15 @@ static int attach_and_pin_progs(const struct shirudo_loader_ctx *cx,
test_fd = inner_fd;
if (stat(pin, &st) == 0 && unlink(pin)) {
- rc = -errno;
+ ret = -errno;
pr_err("unlink stale test-run pin %s: %s", pin,
- strerror(-rc));
+ strerror(-ret));
goto out;
}
- rc = obj_pin(inner_fd, pin);
- if (rc) {
+ ret = obj_pin(inner_fd, pin);
+ if (ret) {
pr_err("pin test-run program %s: %s", pin,
- strerror(-rc));
+ strerror(-ret));
goto out;
}
made[i] = true;
@@ -1445,23 +1445,23 @@ static int attach_and_pin_progs(const struct shirudo_loader_ctx *cx,
pr_err("attach prog %u (%s): %s",
i, attach_kind_name(spec->kind),
strerror(-link_fd));
- rc = link_fd;
+ ret = link_fd;
goto out;
}
/* Unpinned, a closed link detaches. */
- rc = link_matches_spec(link_fd, spec);
- if (rc) {
+ ret = link_matches_spec(link_fd, spec);
+ if (ret) {
pr_err("attach prog %u (%s %s): the link is not at "
"the site the metadata names: %s", i,
attach_kind_name(spec->kind), spec->target,
- strerror(-rc));
+ strerror(-ret));
close(link_fd);
goto out;
}
- rc = obj_pin(link_fd, pin);
+ ret = obj_pin(link_fd, pin);
close(link_fd);
- if (rc) {
- pr_err("pin %s: %s", pin, strerror(-rc));
+ if (ret) {
+ pr_err("pin %s: %s", pin, strerror(-ret));
goto out;
}
made[i] = true;
@@ -1473,18 +1473,18 @@ static int attach_and_pin_progs(const struct shirudo_loader_ctx *cx,
__u32 retval = 0;
/* A zero context is the load-time arena initialization call. */
- rc = prog_test_run(test_fd, init_ctx, sizeof(init_ctx),
- &retval);
- if (rc || (__s32)retval < 0) {
+ ret = prog_test_run(test_fd, init_ctx, sizeof(init_ctx),
+ &retval);
+ if (ret || (__s32)retval < 0) {
pr_err("initialize test-run arena: %s",
- rc ? strerror(-rc) : strerror(-(__s32)retval));
- if (!rc)
- rc = (__s32)retval;
+ ret ? strerror(-ret) : strerror(-(__s32)retval));
+ if (!ret)
+ ret = (__s32)retval;
goto out;
}
}
out:
- if (rc) {
+ if (ret) {
attach_seen = 0;
for (i = 0; i < nr_progs; i++) {
if (made[i] &&
@@ -1501,7 +1501,7 @@ out:
rmdir(dir);
}
xfree(made, nr_progs * sizeof(*made));
- return rc;
+ return ret;
}
/*
@@ -1516,7 +1516,7 @@ static int pin_upatch_maps(const struct shirudo_loader_ctx *cx,
char bpffs_name[UPATCH_BPFFS_NAME_MAX + 1];
char pin[PATH_MAX + 32];
__u32 i;
- int rc;
+ int ret;
if (nr_maps == 0)
return 0;
@@ -1527,10 +1527,10 @@ static int pin_upatch_maps(const struct shirudo_loader_ctx *cx,
return -ENAMETOOLONG;
if (strsprintf(maps_dir, sizeof(maps_dir), "%s/maps", dir) < 0)
return -ENAMETOOLONG;
- rc = mkdir_if_absent(maps_dir, 0700, NULL);
- if (rc) {
+ ret = mkdir_if_absent(maps_dir, 0700, NULL);
+ if (ret) {
pr_warn("upatch maps: mkdir %s: %s (continuing without "
- "map pins)", maps_dir, strerror(-rc));
+ "map pins)", maps_dir, strerror(-ret));
return 0;
}
for (i = 0; i < nr_maps; i++) {
@@ -1620,13 +1620,13 @@ static int trust_anchor_keyring(key_serial_t *keyring, key_serial_t *serial,
{
struct shirudo_identity id;
key_serial_t ring;
- int rc;
+ int ret;
- rc = identity_read(&id);
- if (rc) {
+ ret = identity_read(&id);
+ if (ret) {
pr_err("no trust anchor frozen this boot: %s (run `shirudo "
- "init`)", strerror(-rc));
- rep_fail(rep, "pre_flight", "keyring_missing", -rc,
+ "init`)", strerror(-ret));
+ rep_fail(rep, "pre_flight", "keyring_missing", -ret,
"no trust anchor frozen this boot");
return -1;
}
@@ -1678,7 +1678,7 @@ static int upatch_apply(const char *path, bool verify_only,
char upatch_name[UPATCH_NAME_MAX + 1];
char *vlog; /* shared PROG_LOAD / TEST_RUN log_buf */
size_t insn_cnt, ctx_sz = 0, prog_desc_off;
- int prog_fd = -1, map_fd = -1, rc;
+ int prog_fd = -1, map_fd = -1, ret;
struct shirudo_loader_ctx *cx = NULL;
__u32 retval = 0;
@@ -1689,10 +1689,10 @@ static int upatch_apply(const char *path, bool verify_only,
}
vlog[0] = '\0';
- rc = upatch_open(path, &u);
- if (rc) {
- pr_err("open %s: %s", path, strerror(-rc));
- rep_fail(rep, "parse", "parser_rejected", -rc,
+ ret = upatch_open(path, &u);
+ if (ret) {
+ pr_err("open %s: %s", path, strerror(-ret));
+ rep_fail(rep, "parse", "parser_rejected", -ret,
"cannot open .upatch");
xfree(vlog, VERIFIER_LOG_MAX);
return 1;
@@ -1708,7 +1708,7 @@ static int upatch_apply(const char *path, bool verify_only,
"use `shirudo upatch unload`", path);
rep_fail(rep, "parse", "parser_rejected", 0,
"is an UNLOAD directive");
- rc = 1;
+ ret = 1;
goto out;
}
if (u.hdr.loader_insns_len % sizeof(struct bpf_insn)) {
@@ -1716,12 +1716,12 @@ static int upatch_apply(const char *path, bool verify_only,
u.hdr.loader_insns_len, sizeof(struct bpf_insn));
rep_fail(rep, "parse", "parser_rejected", 0,
"loader_insns_len misaligned");
- rc = 1;
+ ret = 1;
goto out;
}
if (trust_anchor_keyring(&keyring, &serial, rep)) {
- rc = 1;
+ ret = 1;
goto out;
}
@@ -1758,7 +1758,7 @@ static int upatch_apply(const char *path, bool verify_only,
pr_err("upatch: refusing unsafe upatch name '%s'", upatch_name);
rep_fail(rep, "parse", "parser_rejected", 0,
"unsafe upatch name");
- rc = 1;
+ ret = 1;
goto out;
}
/* The header's copy of the name is what everything else reads. */
@@ -1770,7 +1770,7 @@ static int upatch_apply(const char *path, bool verify_only,
upatch_name);
rep_fail(rep, "parse", "parser_rejected", 0,
"name not signed");
- rc = 1;
+ ret = 1;
goto out;
}
@@ -1790,7 +1790,7 @@ static int upatch_apply(const char *path, bool verify_only,
"content (insns || data); refusing");
rep_fail(rep, "parse", "parser_rejected", 0,
"payload_sha256 mismatch");
- rc = 1;
+ ret = 1;
goto out;
}
}
@@ -1815,22 +1815,22 @@ static int upatch_apply(const char *path, bool verify_only,
upatch_name);
rep_fail(rep, "parse", "parser_rejected", 0,
"attach metadata not signed");
- rc = 1;
+ ret = 1;
goto out;
}
- rc = prog_specs_parse(attach, attach_len, u.hdr.nr_progs,
- &prog_specs);
- if (rc) {
+ ret = prog_specs_parse(attach, attach_len, u.hdr.nr_progs,
+ &prog_specs);
+ if (ret) {
pr_err("upatch program metadata rejected: %s",
- strerror(-rc));
- rep_fail(rep, "parse", "parser_rejected", -rc,
+ strerror(-ret));
+ rep_fail(rep, "parse", "parser_rejected", -ret,
"invalid program attach metadata");
- rc = 1;
+ ret = 1;
goto out;
}
- rc = prepare_uprobe_targets(prog_specs, u.hdr.nr_progs);
- if (rc) {
- int e = -rc;
+ ret = prepare_uprobe_targets(prog_specs, u.hdr.nr_progs);
+ if (ret) {
+ int e = -ret;
const char *cat;
if (e == ENOENT || e == ENOTDIR)
@@ -1847,7 +1847,7 @@ static int upatch_apply(const char *path, bool verify_only,
cat, strerror(e));
rep_fail(rep, "target_verify", cat, e,
"uprobe target verification failed");
- rc = 1;
+ ret = 1;
goto out;
}
}
@@ -1865,7 +1865,7 @@ static int upatch_apply(const char *path, bool verify_only,
pr_err("__loader.map: cannot hash the loader");
rep_fail(rep, "signed_loader_load", "unknown", EIO,
"loader digest failed");
- rc = 1;
+ ret = 1;
goto out;
}
map_fd = loader_map_create("__loader.map", u.hdr.data_len,
@@ -1877,30 +1877,30 @@ static int upatch_apply(const char *path, bool verify_only,
pr_err("__loader.map create: %s", strerror(err));
rep_fail(rep, "signed_loader_load", cat_from_load_errno(err),
err, "__loader.map create failed");
- rc = 1;
+ ret = 1;
goto out;
}
- rc = loader_map_update(map_fd, data, u.hdr.data_len);
- if (rc) {
+ ret = loader_map_update(map_fd, data, u.hdr.data_len);
+ if (ret) {
int err = errno;
pr_err("__loader.map update: %s", strerror(err));
rep_fail(rep, "signed_loader_load", cat_from_load_errno(err),
err, "__loader.map update failed");
- rc = 1;
+ ret = 1;
goto out;
}
/* The kernel refuses a signed load whose bound map is not frozen. */
- rc = loader_map_freeze(map_fd);
- if (rc) {
+ ret = loader_map_freeze(map_fd);
+ if (ret) {
int err = errno;
pr_err("__loader.map freeze: %s", strerror(err));
rep_fail(rep, "signed_loader_load", cat_from_load_errno(err),
err, "__loader.map freeze failed");
- rc = 1;
+ ret = 1;
goto out;
}
@@ -1922,7 +1922,7 @@ static int upatch_apply(const char *path, bool verify_only,
rep_fail(rep, "signed_loader_load", cat_from_load_errno(e), e,
"BPF_PROG_LOAD of signed loader failed");
report_set_log(rep, vlog);
- rc = 1;
+ ret = 1;
goto out;
}
@@ -1932,7 +1932,7 @@ static int upatch_apply(const char *path, bool verify_only,
u.hdr.data_len);
if (verify_only) {
- rc = 0;
+ ret = 0;
goto out;
}
@@ -1956,7 +1956,7 @@ static int upatch_apply(const char *path, bool verify_only,
pr_err("ctx alloc");
rep_fail(rep, "payload_load", "unknown", ENOMEM,
"ctx alloc failed");
- rc = 1;
+ ret = 1;
goto out;
}
vlog[0] = '\0';
@@ -1970,8 +1970,8 @@ static int upatch_apply(const char *path, bool verify_only,
cx->log_size = VERIFIER_LOG_MAX;
cx->log_buf = ptr_to_u64(vlog);
- rc = prog_test_run(prog_fd, cx, (__u32)ctx_sz, &retval);
- if (rc) {
+ ret = prog_test_run(prog_fd, cx, (__u32)ctx_sz, &retval);
+ if (ret) {
int err = errno;
pr_err("BPF_PROG_TEST_RUN: %s", strerror(err));
@@ -1980,7 +1980,7 @@ static int upatch_apply(const char *path, bool verify_only,
rep_fail(rep, "payload_load", "verifier_rejected", err,
"BPF_PROG_TEST_RUN failed");
report_set_log(rep, vlog);
- rc = 1;
+ ret = 1;
goto out;
}
if ((__s32)retval < 0) {
@@ -1997,7 +1997,7 @@ static int upatch_apply(const char *path, bool verify_only,
if (rep)
rep->loader_return = (__s32)retval;
report_set_log(rep, vlog);
- rc = 1;
+ ret = 1;
goto out;
}
@@ -2008,10 +2008,10 @@ static int upatch_apply(const char *path, bool verify_only,
* Without a pinned link a program detaches when this one-shot CLI
* exits.
*/
- rc = attach_and_pin_progs(cx, prog_desc_off, u.hdr.nr_progs,
- upatch_name, prog_specs);
- if (rc) {
- int e = -rc;
+ ret = attach_and_pin_progs(cx, prog_desc_off, u.hdr.nr_progs,
+ upatch_name, prog_specs);
+ if (ret) {
+ int e = -ret;
const char *cat;
if (e == ENOENT || e == ENOTDIR)
@@ -2028,7 +2028,7 @@ static int upatch_apply(const char *path, bool verify_only,
cat = "unknown";
rep_fail(rep, "link_create", cat, e, "attach or pin failed");
- rc = 1;
+ ret = 1;
goto out;
}
@@ -2041,7 +2041,7 @@ static int upatch_apply(const char *path, bool verify_only,
(int)serial, u.hdr.nr_progs);
if (rep)
rep->loader_return = (__s32)retval;
- rc = 0;
+ ret = 0;
out:
prog_specs_free(prog_specs, u.hdr.nr_progs);
xfree(vlog, VERIFIER_LOG_MAX);
@@ -2053,7 +2053,7 @@ out:
if (map_fd >= 0)
close(map_fd);
upatch_close(&u);
- return rc;
+ return ret;
}
int shirudo_upatch_apply(const char *path)
@@ -2073,15 +2073,15 @@ static int upatch_preflight(const char *expect_chain,
char have_hex[2 * CHAIN_DIGEST_LEN + 1];
char abi_detail[KERNEL_ABI_DETAIL_MAX];
key_serial_t keyring, serial;
- int fd, rc;
+ int fd, ret;
- rc = kernel_abi_check(abi_detail, sizeof(abi_detail));
- if (rc) {
+ ret = kernel_abi_check(abi_detail, sizeof(abi_detail));
+ if (ret) {
pr_err("upatch: pre-flight refused (category: "
"kernel_abi_unsupported, message: %s)", abi_detail);
rep_fail(rep, "pre_flight", "kernel_abi_unsupported",
EOPNOTSUPP, abi_detail);
- return rc;
+ return ret;
}
if (trust_anchor_keyring(&keyring, &serial, rep))
@@ -2104,15 +2104,15 @@ static int upatch_preflight(const char *expect_chain,
2 * CHAIN_DIGEST_LEN);
return -1;
}
- rc = chain_read(have);
- if (rc == -ENODEV) {
+ ret = chain_read(have);
+ if (ret == -ENODEV) {
pr_err("upatch load: pre-flight refused (category: tampered, "
"message: chain_drift) -- register unreadable, cannot "
"confirm --expect-chain");
return -1;
}
- if (rc) {
- pr_err("upatch load: chain read failed: %s", strerror(-rc));
+ if (ret) {
+ pr_err("upatch load: chain read failed: %s", strerror(-ret));
return -1;
}
if (!ct_eq(want, have, sizeof(want))) {
@@ -2199,11 +2199,11 @@ static int append_upatch_event(const char *type, const char *name,
const __u8 event[32], const char *reason)
{
char buf[4096];
- int rc;
+ int ret;
- rc = format_upatch_event(type, name, payload, event, reason,
- buf, sizeof(buf));
- return rc ? rc : eventlog_append(buf);
+ ret = format_upatch_event(type, name, payload, event, reason,
+ buf, sizeof(buf));
+ return ret ? ret : eventlog_append(buf);
}
/*
@@ -2220,45 +2220,45 @@ static int upatch_chain_event_locked(const char *tag, const char *type,
{
__u8 event[32], chain[32];
char chain_hex[65];
- int rc;
+ int ret;
if (out_chain)
out_chain[0] = '\0';
if (measured)
*measured = false;
- rc = chain_upatch_event(tag, name, payload, event);
- if (rc) {
+ ret = chain_upatch_event(tag, name, payload, event);
+ if (ret) {
pr_err("upatch %s: cannot hash the event (category: tpm_error)",
op);
- return rc;
+ return ret;
}
- rc = chain_extend(event, chain);
- if (rc == -ENODEV) {
+ ret = chain_extend(event, chain);
+ if (ret == -ENODEV) {
pr_err("upatch %s: TPM/register unavailable (category: "
"tpm_error) -- op done but NOT measured; shirudo "
"requires the register init bound this boot", op);
- return rc;
+ return ret;
}
- if (rc == -EACCES) {
+ if (ret == -EACCES) {
pr_err("upatch %s: register is not the one init bound "
"(category: tampered) -- op done but NOT measured; "
"operator must reconcile", op);
- return rc;
+ return ret;
}
- if (rc) {
+ if (ret) {
pr_err("upatch %s: chain extend failed (category: tpm_error) "
"-- op done but chain NOT advanced; operator must "
"reconcile", op);
- return rc;
+ return ret;
}
if (measured)
*measured = true;
- rc = append_upatch_event(type, name, payload, event, reason);
- if (rc) {
+ ret = append_upatch_event(type, name, payload, event, reason);
+ if (ret) {
pr_err("upatch %s: eventlog append failed after extend -- "
"chain/log desync; operator must reconcile", op);
- return rc;
+ return ret;
}
hex_encode(chain, 32, chain_hex);
if (out_chain)
@@ -2269,9 +2269,9 @@ static int upatch_chain_event_locked(const char *tag, const char *type,
}
/* A register other than the one init set up is a verdict, not a TPM fault. */
-static const char *chain_event_category(int rc, bool measured)
+static const char *chain_event_category(int ret, bool measured)
{
- return !measured && rc == -EACCES ? "tampered" : "tpm_error";
+ return !measured && ret == -EACCES ? "tampered" : "tpm_error";
}
static int upatch_chain_event(const char *tag, const char *type,
@@ -2279,7 +2279,7 @@ static int upatch_chain_event(const char *tag, const char *type,
const __u8 payload[32], const char *reason,
char out_chain[65], bool *measured)
{
- int lock, rc;
+ int lock, ret;
if (out_chain)
out_chain[0] = '\0';
@@ -2292,10 +2292,10 @@ static int upatch_chain_event(const char *tag, const char *type,
strerror(-lock));
return lock;
}
- rc = upatch_chain_event_locked(tag, type, op, name, payload, reason,
- out_chain, measured);
+ ret = upatch_chain_event_locked(tag, type, op, name, payload, reason,
+ out_chain, measured);
eventlog_unlock(lock);
- return rc;
+ return ret;
}
/*
@@ -2324,7 +2324,7 @@ static int append_json_record(const char *path, const char *json, size_t len)
struct stat st;
char last;
off_t original_size;
- int fd, rc = 0;
+ int fd, ret = 0;
if (!path || !path[0] || !json)
return -EINVAL;
@@ -2333,16 +2333,16 @@ static int append_json_record(const char *path, const char *json, size_t len)
return fd;
while (flock(fd, LOCK_EX) != 0) {
if (errno != EINTR) {
- rc = -errno;
+ ret = -errno;
goto out;
}
}
if (fstat(fd, &st) != 0) {
- rc = -errno;
+ ret = -errno;
goto out_unlock;
}
if (!S_ISREG(st.st_mode)) {
- rc = -EINVAL;
+ ret = -EINVAL;
goto out_unlock;
}
original_size = st.st_size;
@@ -2350,37 +2350,37 @@ static int append_json_record(const char *path, const char *json, size_t len)
ssize_t n = pread(fd, &last, 1, original_size - 1);
if (n != 1) {
- rc = n < 0 ? -errno : -EIO;
+ ret = n < 0 ? -errno : -EIO;
goto out_unlock;
}
if (last != '\n')
- rc = write_complete(fd, "\n", 1);
- }
- if (!rc)
- rc = write_complete(fd, json, len);
- if (!rc)
- rc = write_complete(fd, "\n", 1);
- if (!rc && fsync(fd) != 0)
- rc = -errno;
- if (rc && ftruncate(fd, original_size) != 0)
+ ret = write_complete(fd, "\n", 1);
+ }
+ if (!ret)
+ ret = write_complete(fd, json, len);
+ if (!ret)
+ ret = write_complete(fd, "\n", 1);
+ if (!ret && fsync(fd) != 0)
+ ret = -errno;
+ if (ret && ftruncate(fd, original_size) != 0)
pr_warn("upatch map: could not roll back partial JSON append to %s: %s",
path, strerror(errno));
out_unlock:
(void)flock(fd, LOCK_UN);
out:
- if (close(fd) != 0 && !rc)
- rc = -errno;
- return rc;
+ if (close(fd) != 0 && !ret)
+ ret = -errno;
+ return ret;
}
static int print_json_record(const char *json, size_t len)
{
- int rc;
+ int ret;
- rc = write_complete(STDOUT_FILENO, json, len);
- if (!rc)
- rc = write_complete(STDOUT_FILENO, "\n", 1);
- return rc;
+ ret = write_complete(STDOUT_FILENO, json, len);
+ if (!ret)
+ ret = write_complete(STDOUT_FILENO, "\n", 1);
+ return ret;
}
static int emit_json_record(const char *path, const char *json, size_t len)
@@ -2392,7 +2392,7 @@ static int emit_json_record(const char *path, const char *json, size_t len)
static int copy_file_atomic(const char *src, const char *dst)
{
char tmp[PATH_MAX + 8], buf[65536];
- int in, out, dir, rc = 0;
+ int in, out, dir, ret = 0;
ssize_t r;
if (strsprintf(tmp, sizeof(tmp), "%s.new", dst) < 0)
@@ -2407,25 +2407,25 @@ static int copy_file_atomic(const char *src, const char *dst)
return out;
}
while ((r = read(in, buf, sizeof(buf))) > 0) {
- rc = write_complete(out, buf, (size_t)r);
- if (rc)
+ ret = write_complete(out, buf, (size_t)r);
+ if (ret)
break;
}
- if (r < 0 && !rc)
- rc = -errno;
- if (!rc && fsync(out) != 0)
- rc = -errno;
+ if (r < 0 && !ret)
+ ret = -errno;
+ if (!ret && fsync(out) != 0)
+ ret = -errno;
close(in);
- if (close(out) != 0 && !rc)
- rc = -errno;
- if (rc) {
+ if (close(out) != 0 && !ret)
+ ret = -errno;
+ if (ret) {
unlink(tmp);
- return rc;
+ return ret;
}
if (rename(tmp, dst) != 0) {
- rc = -errno;
+ ret = -errno;
unlink(tmp);
- return rc;
+ return ret;
}
/* Persist the rename so a crash can't lose a "loaded" upatch. */
dir = open(UPATCHES_DIR, O_RDONLY | O_DIRECTORY | O_CLOEXEC);
@@ -2440,12 +2440,12 @@ static int persist_upatch(const char *src, const char *name)
{
char dst[PATH_MAX];
struct stat ss, ds;
- int rc;
+ int ret;
- rc = seal_mkdir_p(UPATCHES_DIR, 0700);
- if (rc) {
- pr_err("mkdir %s: %s", UPATCHES_DIR, strerror(-rc));
- return rc;
+ ret = seal_mkdir_p(UPATCHES_DIR, 0700);
+ if (ret) {
+ pr_err("mkdir %s: %s", UPATCHES_DIR, strerror(-ret));
+ return ret;
}
if (strsprintf(dst, sizeof(dst), "%s/%s.upatch", UPATCHES_DIR,
name) < 0)
@@ -2516,7 +2516,7 @@ static int parse_op_args(int argc, const char **argv, const char *verb,
static int wipe_dir_flat(const char *dir)
{
struct dirent *e;
- int dfd, rc = 0;
+ int dfd, ret = 0;
DIR *d;
d = opendir(dir);
@@ -2527,13 +2527,13 @@ static int wipe_dir_flat(const char *dir)
if (!strcmp(e->d_name, ".") || !strcmp(e->d_name, ".."))
continue;
if (unlinkat(dfd, e->d_name, 0) != 0 && errno != ENOENT) {
- rc = -errno;
+ ret = -errno;
break;
}
}
closedir(d);
- if (rc)
- return rc;
+ if (ret)
+ return ret;
if (rmdir(dir) != 0 && errno != ENOENT)
return -errno;
return 0;
@@ -2561,7 +2561,7 @@ static int remove_pin_dir(const char *name)
char serializers_dir[PATH_MAX + 16];
char bpffs_name[UPATCH_BPFFS_NAME_MAX + 1];
struct stat st;
- int rc;
+ int ret;
if (upatch_bpffs_name(bpffs_name, sizeof(bpffs_name), name))
return -ENAMETOOLONG;
@@ -2576,14 +2576,14 @@ static int remove_pin_dir(const char *name)
if (stat(dir, &st) != 0)
return -errno;
if (stat(maps_dir, &st) == 0) {
- rc = wipe_dir_flat(maps_dir);
- if (rc)
- return rc;
+ ret = wipe_dir_flat(maps_dir);
+ if (ret)
+ return ret;
}
if (stat(serializers_dir, &st) == 0) {
- rc = wipe_dir_flat(serializers_dir);
- if (rc)
- return rc;
+ ret = wipe_dir_flat(serializers_dir);
+ if (ret)
+ return ret;
}
return wipe_dir_flat(dir);
}
@@ -2598,38 +2598,38 @@ static int stage_upatch(const char *src, char *staged, size_t sz)
{
__u8 *buf = NULL;
size_t len = 0;
- int rc;
-
- rc = read_file(src, UPATCH_FILE_MAX, &buf, &len);
- if (rc)
- return rc;
- rc = seal_mkdir_p(INCOMING_DIR, 0700);
- if (!rc && strsprintf(staged, sz, "%s/load-%d.upatch",
- INCOMING_DIR, (int)getpid()) < 0)
- rc = -ENAMETOOLONG;
- if (!rc)
- rc = seal_write_file(staged, buf, len, 0600);
+ int ret;
+
+ ret = read_file(src, UPATCH_FILE_MAX, &buf, &len);
+ if (ret)
+ return ret;
+ ret = seal_mkdir_p(INCOMING_DIR, 0700);
+ if (!ret && strsprintf(staged, sz, "%s/load-%d.upatch",
+ INCOMING_DIR, (int)getpid()) < 0)
+ ret = -ENAMETOOLONG;
+ if (!ret)
+ ret = seal_write_file(staged, buf, len, 0600);
xfree(buf, len + 1);
- if (rc)
+ if (ret)
staged[0] = '\0';
- return rc;
+ return ret;
}
/* Take a load the register did not record back out: pins, then archive. */
static void unload_unmeasured(const char *name)
{
char persisted[PATH_MAX];
- int rc;
+ int ret;
- rc = remove_pin_dir(name);
- if (!rc && strsprintf(persisted, sizeof(persisted), "%s/%s.upatch",
- UPATCHES_DIR, name) >= 0 &&
+ ret = remove_pin_dir(name);
+ if (!ret && strsprintf(persisted, sizeof(persisted), "%s/%s.upatch",
+ UPATCHES_DIR, name) >= 0 &&
unlink(persisted) != 0 && errno != ENOENT)
- rc = -errno;
- if (rc)
+ ret = -errno;
+ if (ret)
pr_err("upatch load: %s is loaded but not measured and could "
"not be undone: %s; operator must reconcile", name,
- strerror(-rc));
+ strerror(-ret));
else
pr_err("upatch load: %s was not measured; the load was undone",
name);
@@ -2644,7 +2644,7 @@ static int cmd_upatch_load(int argc, const char **argv)
struct shirudo_upatch u;
struct shirudo_op_report rep = { .op = "upatch_load", .phase = "done" };
bool no_precheck, no_version_check, have_id = false, measured;
- int rc, ret = 1;
+ int err, ret = 1;
for (int i = 1; i < argc; i++) {
if (is_help(argv[i])) {
@@ -2652,29 +2652,29 @@ static int cmd_upatch_load(int argc, const char **argv)
return 0;
}
}
- rc = parse_op_args(argc, argv, "load", &upatch_load_help,
- &file, &expect_chain, &expect_version_id,
- &no_precheck, &no_version_check, &report);
- if (rc)
- return rc;
+ err = parse_op_args(argc, argv, "load", &upatch_load_help,
+ &file, &expect_chain, &expect_version_id,
+ &no_precheck, &no_version_check, &report);
+ if (err)
+ return err;
rep.path = file;
if (version_gate(expect_version_id, no_version_check, &rep, "load") != 0)
goto done;
- rc = stage_upatch(file, staged, sizeof(staged));
- if (rc) {
- pr_err("upatch load: read %s: %s", file, strerror(-rc));
- rep_fail(&rep, "parse", "parser_rejected", -rc,
+ err = stage_upatch(file, staged, sizeof(staged));
+ if (err) {
+ pr_err("upatch load: read %s: %s", file, strerror(-err));
+ rep_fail(&rep, "parse", "parser_rejected", -err,
"cannot read .upatch");
goto done;
}
file = staged;
- rc = upatch_open(file, &u);
- if (rc) {
- pr_err("open %s: %s", file, strerror(-rc));
- rep_fail(&rep, "parse", "parser_rejected", -rc,
+ err = upatch_open(file, &u);
+ if (err) {
+ pr_err("open %s: %s", file, strerror(-err));
+ rep_fail(&rep, "parse", "parser_rejected", -err,
"cannot open .upatch");
goto done;
}
@@ -2722,24 +2722,24 @@ static int cmd_upatch_load(int argc, const char **argv)
* caller who stops this process first gets the same at the next
* init, which refuses to restore what the register does not cover.
*/
- rc = persist_upatch(file, name);
- if (rc) {
+ err = persist_upatch(file, name);
+ if (err) {
pr_err("upatch load: loaded but failed to persist to %s: %s "
- "-- not measured", UPATCHES_DIR, strerror(-rc));
+ "-- not measured", UPATCHES_DIR, strerror(-err));
unload_unmeasured(name);
- rep_fail(&rep, "persist", "unknown", -rc,
+ rep_fail(&rep, "persist", "unknown", -err,
"persist failed; the load was undone");
goto done;
}
- rc = upatch_chain_event("shirudo-upatch", "upatch_load", "load",
- name, payload, NULL, rep.chain_after,
- &measured);
- if (rc) {
+ err = upatch_chain_event("shirudo-upatch", "upatch_load", "load",
+ name, payload, NULL, rep.chain_after,
+ &measured);
+ if (err) {
if (!measured)
unload_unmeasured(name);
- rep_fail(&rep, "tpm_extend", chain_event_category(rc, measured),
- rc, measured ?
+ rep_fail(&rep, "tpm_extend", chain_event_category(err, measured),
+ err, measured ?
"eventlog append failed after the extend" :
"chain extend failed; the load was undone");
goto done;
@@ -2770,7 +2770,7 @@ static int cmd_upatch_unload(int argc, const char **argv)
struct shirudo_upatch u;
struct shirudo_op_report rep = { .op = "upatch_unload", .phase = "done" };
bool no_precheck, no_version_check;
- int rc, ret = 1;
+ int err, ret = 1;
for (int i = 1; i < argc; i++) {
if (is_help(argv[i])) {
@@ -2778,11 +2778,11 @@ static int cmd_upatch_unload(int argc, const char **argv)
return 0;
}
}
- rc = parse_op_args(argc, argv, "unload", &upatch_unload_help,
- &file, &expect_chain, &expect_version_id,
- &no_precheck, &no_version_check, &report);
- if (rc)
- return rc;
+ err = parse_op_args(argc, argv, "unload", &upatch_unload_help,
+ &file, &expect_chain, &expect_version_id,
+ &no_precheck, &no_version_check, &report);
+ if (err)
+ return err;
rep.path = file;
if (version_gate(expect_version_id, no_version_check, &rep, "unload") != 0)
@@ -2793,19 +2793,19 @@ static int cmd_upatch_unload(int argc, const char **argv)
* signature check covers must be the bytes read back after it, and
* a file of root's is root's to rewrite between the two.
*/
- rc = stage_upatch(file, staged, sizeof(staged));
- if (rc) {
- pr_err("upatch unload: read %s: %s", file, strerror(-rc));
- rep_fail(&rep, "parse", "parser_rejected", -rc,
+ err = stage_upatch(file, staged, sizeof(staged));
+ if (err) {
+ pr_err("upatch unload: read %s: %s", file, strerror(-err));
+ rep_fail(&rep, "parse", "parser_rejected", -err,
"cannot read .upatch");
goto done;
}
file = staged;
- rc = upatch_open(file, &u);
- if (rc) {
- pr_err("open %s: %s", file, strerror(-rc));
- rep_fail(&rep, "parse", "parser_rejected", -rc,
+ err = upatch_open(file, &u);
+ if (err) {
+ pr_err("open %s: %s", file, strerror(-err));
+ rep_fail(&rep, "parse", "parser_rejected", -err,
"cannot open .upatch");
goto done;
}
@@ -2921,19 +2921,19 @@ static int cmd_upatch_unload(int argc, const char **argv)
* fails after the event leaves a shield the register says is gone,
* which the next status reports and the operator can repeat.
*/
- rc = upatch_chain_event("shirudo-unload", "upatch_unload", "unload",
- name, payload, NULL, rep.chain_after, NULL);
- if (rc) {
- rep_fail(&rep, "tpm_extend", chain_event_category(rc, false),
- rc, "chain extend failed; nothing detached");
+ err = upatch_chain_event("shirudo-unload", "upatch_unload", "unload",
+ name, payload, NULL, rep.chain_after, NULL);
+ if (err) {
+ rep_fail(&rep, "tpm_extend", chain_event_category(err, false),
+ err, "chain extend failed; nothing detached");
goto done;
}
- rc = remove_pin_dir(name);
- if (rc) {
+ err = remove_pin_dir(name);
+ if (err) {
pr_err("upatch unload: measured, but failed to remove the pin "
- "for %s: %s; repeat the unload", name, strerror(-rc));
- rep_fail(&rep, "pin", "detach_failed", -rc,
+ "for %s: %s; repeat the unload", name, strerror(-err));
+ rep_fail(&rep, "pin", "detach_failed", -err,
"pin removal failed after the event was measured");
goto done;
}
@@ -2970,37 +2970,37 @@ int shirudo_upatch_purge(const char *name, const char *reason)
char persisted[PATH_MAX];
struct shirudo_upatch u;
bool loaded;
- int fd, rc;
+ int fd, ret;
if (!safe_upatch_name(name))
return -EINVAL;
if (strsprintf(persisted, sizeof(persisted), "%s/%s.upatch",
UPATCHES_DIR, name) < 0)
return -ENAMETOOLONG;
- rc = seal_open_read(persisted);
- if (rc < 0)
- return rc;
- fd = rc;
- rc = upatch_open_fd(fd, &u);
+ ret = seal_open_read(persisted);
+ if (ret < 0)
+ return ret;
+ fd = ret;
+ ret = upatch_open_fd(fd, &u);
close(fd);
- if (rc)
- return rc;
+ if (ret)
+ return ret;
memcpy(payload, u.hdr.payload_sha256, sizeof(payload));
upatch_close(&u);
/* As for unload: the event first, then the detach it describes. */
loaded = upatch_is_pinned(name);
if (loaded) {
- rc = upatch_chain_event("shirudo-unload", "upatch_unload",
- "purge", name, payload, reason, NULL,
- NULL);
- if (rc)
- return rc;
- rc = remove_pin_dir(name);
- if (rc) {
+ ret = upatch_chain_event("shirudo-unload", "upatch_unload",
+ "purge", name, payload, reason, NULL,
+ NULL);
+ if (ret)
+ return ret;
+ ret = remove_pin_dir(name);
+ if (ret) {
pr_err("upatch purge: measured, but failed to remove "
- "the pin for %s: %s", name, strerror(-rc));
- return rc;
+ "the pin for %s: %s", name, strerror(-ret));
+ return ret;
}
}
if (unlink(persisted) != 0 && errno != ENOENT) {
@@ -3145,18 +3145,18 @@ static int append_one_map_json(const char *path,
{
char *decoded = NULL;
size_t decoded_len = 0;
- int rc;
+ int ret;
- rc = upatch_decode_map_json(v, &decoded, &decoded_len);
- if (rc == 0) {
+ ret = upatch_decode_map_json(v, &decoded, &decoded_len);
+ if (ret == 0) {
while (decoded_len && (decoded[decoded_len - 1] == '\n' ||
decoded[decoded_len - 1] == '\r'))
decoded_len--;
- rc = emit_json_record(path, decoded, decoded_len);
+ ret = emit_json_record(path, decoded, decoded_len);
xfree(decoded, decoded_len + 1);
- return rc;
+ return ret;
}
- return rc;
+ return ret;
}
static int export_one_map(const char *upatch, const char *map,
@@ -3167,41 +3167,41 @@ static int export_one_map(const char *upatch, const char *map,
struct shirudo_map_view v = {};
__u32 cap = (show_full || json_output || otel) ? 0 :
MAP_ENTRIES_DEFAULT;
- int rc, ret = 0;
+ int err, ret = 0;
- rc = upatch_maps_read(upatch, map, cap,
- peek ? MAP_READ_PEEK : 0, &v);
- if (rc) {
+ err = upatch_maps_read(upatch, map, cap,
+ peek ? MAP_READ_PEEK : 0, &v);
+ if (err) {
pr_err("upatch map: read %s/%s: %s", upatch, map,
- strerror(-rc));
+ strerror(-err));
map_view_free(&v);
return 1;
}
if (json_output) {
- rc = append_one_map_json(json_path, &v);
- if (rc) {
+ err = append_one_map_json(json_path, &v);
+ if (err) {
if (json_path)
pr_err("upatch map: append JSON to %s: %s",
- json_path, strerror(-rc));
+ json_path, strerror(-err));
else
pr_err("upatch map: print JSON: %s",
- strerror(-rc));
+ strerror(-err));
ret = 1;
}
}
if (otel) {
__u32 decoder_signal;
- rc = upatch_decode_map_signal(&v, &decoder_signal);
- if (rc == -ENODATA)
- rc = shirudo_upatch_maps_otel_send(&v, SHIRUDO_OTEL_AUTO,
- otel_opts);
- else if (!rc)
- rc = shirudo_upatch_maps_otel_send_decoded(&v, decoder_signal,
- otel_opts);
- if (rc) {
+ err = upatch_decode_map_signal(&v, &decoder_signal);
+ if (err == -ENODATA)
+ err = shirudo_upatch_maps_otel_send(&v, SHIRUDO_OTEL_AUTO,
+ otel_opts);
+ else if (!err)
+ err = shirudo_upatch_maps_otel_send_decoded(&v, decoder_signal,
+ otel_opts);
+ if (err) {
pr_err("upatch map: OTLP export %s/%s: %s", upatch, map,
- strerror(-rc));
+ strerror(-err));
ret = 1;
}
}
@@ -3324,11 +3324,11 @@ static int cmd_upatch_map(int argc, const char **argv)
}
}
if (all) {
- int rc = config_load(&export_cfg);
+ int err = config_load(&export_cfg);
- if (rc) {
+ if (err) {
pr_err("upatch map: load export configuration: %s",
- strerror(-rc));
+ strerror(-err));
return 1;
}
if (!export_cfg.map_export_valid) {
@@ -3451,15 +3451,15 @@ static int cmd_upatch_map(int argc, const char **argv)
if (e.err) {
ret = 1;
} else {
- int rc = emit_json_record(json_path, buf, e.len);
+ int err = emit_json_record(json_path, buf, e.len);
- if (rc) {
+ if (err) {
if (json_path)
pr_err("upatch map: append JSON to %s: %s",
- json_path, strerror(-rc));
+ json_path, strerror(-err));
else
pr_err("upatch map: print JSON: %s",
- strerror(-rc));
+ strerror(-err));
ret = 1;
}
}
@@ -3502,7 +3502,7 @@ static int upatch_get_collect(const char *want, struct upatch_get_ctx *c)
void *recs = NULL;
size_t recs_sz = 0;
__u32 len, nr, rec_size, btf_id;
- int link_fd = -1, prog_fd = -1, rc = 0;
+ int link_fd = -1, prog_fd = -1, ret = 0;
c->upatch = want;
c->ents = NULL;
@@ -3519,9 +3519,9 @@ static int upatch_get_collect(const char *want, struct upatch_get_ctx *c)
return link_fd;
len = sizeof(linfo);
if (bpf_link_get_info_by_fd(link_fd, &linfo, &len) != 0) {
- rc = -errno;
+ ret = -errno;
close(link_fd);
- return rc;
+ return ret;
}
close(link_fd);
if (linfo.prog_id == 0)
@@ -3541,9 +3541,9 @@ static int upatch_get_collect(const char *want, struct upatch_get_ctx *c)
return -errno;
len = sizeof(info);
if (bpf_prog_get_info_by_fd(prog_fd, &info, &len) != 0) {
- rc = -errno;
+ ret = -errno;
close(prog_fd);
- return rc;
+ return ret;
}
nr = info.nr_line_info;
rec_size = info.line_info_rec_size;
@@ -3564,10 +3564,10 @@ static int upatch_get_collect(const char *want, struct upatch_get_ctx *c)
info.line_info = ptr_to_u64(recs);
len = sizeof(info);
if (bpf_prog_get_info_by_fd(prog_fd, &info, &len) != 0) {
- rc = -errno;
+ ret = -errno;
xfree(recs, recs_sz);
close(prog_fd);
- return rc;
+ return ret;
}
close(prog_fd);
c->btf = btf__load_from_kernel_by_id(btf_id);
@@ -3597,12 +3597,12 @@ static void render_one_map_text(const char *upatch, const char *map,
__u32 cap)
{
struct shirudo_map_view v = {};
- int rc = upatch_maps_read(upatch, map, cap, MAP_READ_PEEK,
- &v);
+ int ret = upatch_maps_read(upatch, map, cap, MAP_READ_PEEK,
+ &v);
printf("\n== Map: %s ==\n", map);
- if (rc != 0) {
- printf(" (read failed: %s)\n", strerror(-rc));
+ if (ret != 0) {
+ printf(" (read failed: %s)\n", strerror(-ret));
map_view_free(&v);
return;
}
@@ -3684,18 +3684,18 @@ static int render_get_json(const struct upatch_get_ctx *c,
json_arr_open(&e, "maps");
for (k = 0; k < nm; k++) {
struct shirudo_map_view v = {};
- int rc;
+ int err;
- rc = upatch_maps_read(c->upatch, maps[k].name, map_cap,
- MAP_READ_PEEK, &v);
- if (rc != 0) {
+ err = upatch_maps_read(c->upatch, maps[k].name, map_cap,
+ MAP_READ_PEEK, &v);
+ if (err != 0) {
json_obj_open(&e);
json_kv_string(&e, "name", maps[k].name);
json_kv_string(&e, "type",
maps[k].type_name);
json_kv_int(&e, "max_entries",
maps[k].max_entries);
- json_kv_string(&e, "error", strerror(-rc));
+ json_kv_string(&e, "error", strerror(-err));
json_obj_close(&e);
} else {
upatch_maps_emit_json_object(&e, &v);
@@ -3724,7 +3724,7 @@ static int cmd_upatch_get(int argc, const char **argv)
bool json = false, show_full = false;
size_t nm = 0;
__u32 map_cap;
- int rc, i;
+ int ret, i;
for (i = 1; i < argc; i++) {
const char *a = argv[i];
@@ -3757,9 +3757,9 @@ static int cmd_upatch_get(int argc, const char **argv)
return 2;
}
- rc = upatch_get_collect(want, &ctx);
- if (rc != 0) {
- pr_err("upatch get: '%s': %s", want, strerror(-rc));
+ ret = upatch_get_collect(want, &ctx);
+ if (ret != 0) {
+ pr_err("upatch get: '%s': %s", want, strerror(-ret));
upatch_get_ctx_free(&ctx);
return 1;
}
@@ -3767,13 +3767,13 @@ static int cmd_upatch_get(int argc, const char **argv)
map_cap = show_full ? 0 : MAP_ENTRIES_DEFAULT;
if (json)
- rc = render_get_json(&ctx, maps, nm, map_cap);
+ ret = render_get_json(&ctx, maps, nm, map_cap);
else
- render_get_text(&ctx, maps, nm, map_cap), rc = 0;
+ render_get_text(&ctx, maps, nm, map_cap), ret = 0;
map_summary_free(maps, nm);
upatch_get_ctx_free(&ctx);
- return rc;
+ return ret;
}
static const struct shirudo_help_item upatch_subcmds[] = {
diff --git a/shirudo.c b/shirudo.c
index 9e9b3022..ac31f326 100644
--- a/shirudo.c
+++ b/shirudo.c
@@ -106,7 +106,7 @@ int main(int argc, const char **argv)
const char *names[ARRAY_SIZE(commands)];
size_t matches[ARRAY_SIZE(commands)];
size_t i, n_match;
- int rc;
+ int ret;
harden_stdio();
log_init();
@@ -169,14 +169,14 @@ int main(int argc, const char **argv)
return 1;
}
- rc = shirudo_image_enter(c->name, argc - 1, argv + 1);
+ ret = shirudo_image_enter(c->name, argc - 1, argv + 1);
- if (rc) {
- fprintf(stderr, "shirudo: image state: %s\n", strerror(-rc));
+ if (ret) {
+ fprintf(stderr, "shirudo: image state: %s\n", strerror(-ret));
shirudo_image_leave();
return 1;
}
- rc = c->fn(argc - 1, argv + 1);
+ ret = c->fn(argc - 1, argv + 1);
shirudo_image_leave();
- return rc;
+ return ret;
}
diff --git a/testing/fixtures/arena-tree-serializer.bpf.c b/testing/fixtures/arena-tree-serializer.bpf.c
index d57bff0f..e5bc7f08 100644
--- a/testing/fixtures/arena-tree-serializer.bpf.c
+++ b/testing/fixtures/arena-tree-serializer.bpf.c
@@ -215,7 +215,7 @@ int shirudo_serialize__tree_arena(struct shirudo_serialize_ctx *ctx)
{
__u32 start, records, emitted, flags = 0;
__u64 next_cursor;
- int rc;
+ int ret;
if (!ctx || ctx->magic != SERIAL_MAGIC ||
ctx->version != SERIAL_VERSION ||
@@ -231,10 +231,10 @@ int shirudo_serialize__tree_arena(struct shirudo_serialize_ctx *ctx)
return -EINVAL;
}
- rc = build_tree();
- if (rc) {
- set_error(ctx, rc);
- return rc;
+ ret = build_tree();
+ if (ret) {
+ set_error(ctx, ret);
+ return ret;
}
start = (__u32)ctx->cursor;
@@ -246,11 +246,11 @@ int shirudo_serialize__tree_arena(struct shirudo_serialize_ctx *ctx)
if (next_cursor >= TREE_NODES)
flags = SERIAL_F_DONE;
- rc = init_page_chunks(records, flags, ctx->page_index, ctx->cursor,
- next_cursor, ctx->invocation_id);
- if (rc) {
- set_error(ctx, rc);
- return rc;
+ ret = init_page_chunks(records, flags, ctx->page_index, ctx->cursor,
+ next_cursor, ctx->invocation_id);
+ if (ret) {
+ set_error(ctx, ret);
+ return ret;
}
for (emitted = 0; emitted < TREE_RECORDS_PER_PAGE; emitted++) {
@@ -268,10 +268,10 @@ int shirudo_serialize__tree_arena(struct shirudo_serialize_ctx *ctx)
set_error(ctx, -EINVAL);
return -EINVAL;
}
- rc = emit_record(cur, absolute, emitted);
- if (rc) {
- set_error(ctx, rc);
- return rc;
+ ret = emit_record(cur, absolute, emitted);
+ if (ret) {
+ set_error(ctx, ret);
+ return ret;
}
}
return 0;
diff --git a/testing/helper/image-fault.c b/testing/helper/image-fault.c
index 0a4dfb76..fe71a2a1 100644
--- a/testing/helper/image-fault.c
+++ b/testing/helper/image-fault.c
@@ -55,42 +55,42 @@ int __wrap_shirudo_config_root_begin(const __u8 root[32],
int __wrap_shirudo_config_root_end(struct shirudo_config_root_guard *guard)
{
struct shirudo_expected_root expected = {};
- int rc = 0, cleanup;
+ int ret = 0, cleanup;
if (root_mode != ROOT_NORMAL) {
end_calls++;
if (guard->map_fd >= 0 &&
bpf_map_lookup_elem(guard->map_fd, &guard->task_fd,
&expected))
- rc = -errno;
+ ret = -errno;
consumed_valid = expected.valid;
}
cleanup = __real_shirudo_config_root_end(guard);
- return rc ? rc : cleanup;
+ return ret ? ret : cleanup;
}
static int check_root_cleared(void)
{
struct shirudo_expected_root expected = {}, empty = {};
- int map, task, rc;
+ int map, task, ret;
map = bpf_obj_get(BPFFS_DIR "/config_roots");
if (map < 0)
return -errno;
task = syscall(SYS_pidfd_open, getpid(), 0);
if (task < 0) {
- rc = -errno;
+ ret = -errno;
goto out;
}
- rc = bpf_map_lookup_elem(map, &task, &expected) ? -errno : 0;
- if (root_mode == ROOT_MISSING && rc == -ENOENT)
- rc = 0;
- if (!rc && memcmp(&expected, &empty, sizeof(empty)))
- rc = -EUCLEAN;
+ ret = bpf_map_lookup_elem(map, &task, &expected) ? -errno : 0;
+ if (root_mode == ROOT_MISSING && ret == -ENOENT)
+ ret = 0;
+ if (!ret && memcmp(&expected, &empty, sizeof(empty)))
+ ret = -EUCLEAN;
close(task);
out:
close(map);
- return rc;
+ return ret;
}
static int check_classification(const struct shirudo_dm_verity *device)
@@ -99,24 +99,24 @@ static int check_classification(const struct shirudo_dm_verity *device)
struct shirudo_device_authority entry;
__u64 key, next, diskseq;
__u32 matches = 0;
- int map, block, rc = 0;
+ int map, block, ret = 0;
void *cursor = NULL;
block = open(device->path, O_RDONLY | O_CLOEXEC | O_NOFOLLOW);
if (block < 0)
return -errno;
if (ioctl(block, BLKGETDISKSEQ, &diskseq)) {
- rc = -errno;
+ ret = -errno;
goto out_block;
}
map = bpf_obj_get(BPFFS_DIR "/devices");
if (map < 0) {
- rc = -errno;
+ ret = -errno;
goto out_block;
}
while (!bpf_map_get_next_key(map, cursor, &next)) {
if (bpf_map_lookup_elem(map, &next, &entry)) {
- rc = -errno;
+ ret = -errno;
break;
}
if (entry.dev == dev)
@@ -130,22 +130,22 @@ static int check_classification(const struct shirudo_dm_verity *device)
matches++;
if (entry.kind != DEVICE_CONFIG ||
memcmp(entry.root, device->image.root_hash, 32)) {
- rc = -EUCLEAN;
+ ret = -EUCLEAN;
break;
}
}
key = next;
cursor = &key;
}
- if (!rc && errno != ENOENT)
- rc = -errno;
- if (!rc && matches != (root_mode == ROOT_MATCH ? 1u : 0u))
- rc = -EACCES;
+ if (!ret && errno != ENOENT)
+ ret = -errno;
+ if (!ret && matches != (root_mode == ROOT_MATCH ? 1u : 0u))
+ ret = -EACCES;
printf("classified=%u consumed_valid=%d\n", matches, consumed_valid);
close(map);
out_block:
close(block);
- return rc;
+ return ret;
}
static int config_root_test(const char *mode, const char *prefix)
@@ -153,7 +153,7 @@ static int config_root_test(const char *mode, const char *prefix)
struct shirudo_config_image_open opened;
struct shirudo_dm_verity device;
bool created = false;
- int rc, cleanup;
+ int ret, cleanup;
char name[128];
if (!strcmp(mode, "missing"))
@@ -164,33 +164,33 @@ static int config_root_test(const char *mode, const char *prefix)
root_mode = ROOT_MATCH;
else
return 2;
- rc = shirudo_config_image_open(prefix, &opened);
- if (rc)
+ ret = shirudo_config_image_open(prefix, &opened);
+ if (ret)
goto done;
snprintf(name, sizeof(name), "shirudo-verify-root-test-%ld",
(long)getpid());
- rc = shirudo_dm_verity_create(&opened, name, &device);
- created = !rc;
- if (!rc && (begin_calls != 1 || end_calls != 1 ||
- consumed_valid != (root_mode == ROOT_WRONG ? 1 : 0)))
- rc = -EUCLEAN;
- if (!rc)
- rc = check_root_cleared();
- if (!rc)
- rc = shirudo_dm_verity_verify(&device, &opened);
- if (!rc)
- rc = check_classification(&device);
+ ret = shirudo_dm_verity_create(&opened, name, &device);
+ created = !ret;
+ if (!ret && (begin_calls != 1 || end_calls != 1 ||
+ consumed_valid != (root_mode == ROOT_WRONG ? 1 : 0)))
+ ret = -EUCLEAN;
+ if (!ret)
+ ret = check_root_cleared();
+ if (!ret)
+ ret = shirudo_dm_verity_verify(&device, &opened);
+ if (!ret)
+ ret = check_classification(&device);
if (created) {
cleanup = shirudo_dm_verity_remove(&device, true);
shirudo_dm_verity_close(&device);
- if (!rc)
- rc = cleanup;
+ if (!ret)
+ ret = cleanup;
}
shirudo_config_image_close(&opened);
done:
- if (rc)
- fprintf(stderr, "config root test: %s\n", strerror(-rc));
- return rc ? 1 : 0;
+ if (ret)
+ fprintf(stderr, "config root test: %s\n", strerror(-ret));
+ return ret ? 1 : 0;
}
int __wrap_main(int argc, const char **argv)
@@ -210,11 +210,11 @@ TSS2_RC __wrap_Esys_PCR_Extend(ESYS_CONTEXT *context, ESYS_TR pcr,
ESYS_TR first, ESYS_TR second, ESYS_TR third,
const TPML_DIGEST_VALUES *digests)
{
- TSS2_RC rc;
+ TSS2_RC ret;
- rc = __real_Esys_PCR_Extend(context, pcr, first, second, third,
- digests);
- if (!rc)
+ ret = __real_Esys_PCR_Extend(context, pcr, first, second, third,
+ digests);
+ if (!ret)
_exit(99);
- return rc;
+ return ret;
}
diff --git a/testing/helper/policy-probe.c b/testing/helper/policy-probe.c
index eb9a6587..b297a2b8 100644
--- a/testing/helper/policy-probe.c
+++ b/testing/helper/policy-probe.c
@@ -26,7 +26,7 @@ static int check_mark(const char *pin, int expected)
{
struct shirudo_task_authority authority = {};
union bpf_attr attr = {};
- int fd, pidfd, rc;
+ int fd, pidfd, ret;
pidfd = syscall(SYS_pidfd_open, getpid(), 0);
if (pidfd < 0)
@@ -36,22 +36,22 @@ static int check_mark(const char *pin, int expected)
fd = syscall(SYS_bpf, BPF_OBJ_GET, &attr, sizeof(attr));
if (fd < 0) {
/* Only a task with authority may open the pin at all. */
- rc = errno == EACCES && !expected ? 0 : 1;
+ ret = errno == EACCES && !expected ? 0 : 1;
close(pidfd);
- return rc;
+ return ret;
}
memset(&attr, 0, sizeof(attr));
attr.map_fd = fd;
attr.key = (uintptr_t)&pidfd;
attr.value = (uintptr_t)&authority;
- rc = syscall(SYS_bpf, BPF_MAP_LOOKUP_ELEM, &attr, sizeof(attr));
- if (rc && errno != ENOENT)
- rc = 1;
+ ret = syscall(SYS_bpf, BPF_MAP_LOOKUP_ELEM, &attr, sizeof(attr));
+ if (ret && errno != ENOENT)
+ ret = 1;
else
- rc = !!authority.trusted != expected;
+ ret = !!authority.trusted != expected;
close(pidfd);
close(fd);
- return rc;
+ return ret;
}
static void print_hex(const __u8 *bytes, size_t n)
@@ -68,7 +68,7 @@ static int print_identity(const char *pin, const char *field)
struct shirudo_identity id = {};
union bpf_attr attr = {};
__u32 zero = 0;
- int fd, rc;
+ int fd, ret;
attr.pathname = (uintptr_t)pin;
attr.file_flags = BPF_F_RDONLY;
@@ -79,9 +79,9 @@ static int print_identity(const char *pin, const char *field)
attr.map_fd = fd;
attr.key = (uintptr_t)&zero;
attr.value = (uintptr_t)&id;
- rc = syscall(SYS_bpf, BPF_MAP_LOOKUP_ELEM, &attr, sizeof(attr));
+ ret = syscall(SYS_bpf, BPF_MAP_LOOKUP_ELEM, &attr, sizeof(attr));
close(fd);
- if (rc)
+ if (ret)
return 1;
if (!strcmp(field, "runtime_root"))
print_hex(id.runtime_root, sizeof(id.runtime_root));
diff --git a/testing/helper/test-config-attest.c b/testing/helper/test-config-attest.c
index 20ee06a0..5878d096 100644
--- a/testing/helper/test-config-attest.c
+++ b/testing/helper/test-config-attest.c
@@ -23,27 +23,27 @@
static int boot_identity(void *ctx, __u32 *reset, __u32 *restart)
{
struct shirudo_tpm *tpm = NULL;
- int rc;
+ int ret;
(void)ctx;
- rc = tpm_open(&tpm);
- if (!rc)
- rc = shirudo_tpm_boot_identity(tpm, reset, restart);
+ ret = tpm_open(&tpm);
+ if (!ret)
+ ret = shirudo_tpm_boot_identity(tpm, reset, restart);
tpm_close(tpm);
- return rc;
+ return ret;
}
static int pcr_read(void *ctx, __u32 pcr, __u8 out[32])
{
struct shirudo_tpm *tpm = NULL;
- int rc;
+ int ret;
(void)ctx;
- rc = tpm_open(&tpm);
- if (!rc)
- rc = tpm_pcr_read(tpm, pcr, out);
+ ret = tpm_open(&tpm);
+ if (!ret)
+ ret = tpm_pcr_read(tpm, pcr, out);
tpm_close(tpm);
- return rc;
+ return ret;
}
static int no_extend(void *ctx, __u32 pcr, const __u8 event[32])
@@ -84,23 +84,23 @@ static int render(const char *directory, const char *nonce)
__u8 bytes[ATTEST_NONCE_MAX];
char *document = NULL;
size_t length = 0, capacity = 0, nonce_length;
- int rc;
+ int ret;
nonce_length = strlen(nonce) / 2;
if (strlen(nonce) % 2 || nonce_length > sizeof(bytes) ||
hex_decode(nonce, bytes, nonce_length))
return -EINVAL;
- rc = shirudo_config_update_open(directory, &ops, NULL, &update);
- if (!rc)
- rc = shirudo_attest_evidence_config(bytes, nonce_length,
- CHAIN_PCR_MASK,
- NULL, &update, &document,
- &length, &capacity);
- if (!rc)
- rc = write_complete(STDOUT_FILENO, document, length);
+ ret = shirudo_config_update_open(directory, &ops, NULL, &update);
+ if (!ret)
+ ret = shirudo_attest_evidence_config(bytes, nonce_length,
+ CHAIN_PCR_MASK,
+ NULL, &update, &document,
+ &length, &capacity);
+ if (!ret)
+ ret = write_complete(STDOUT_FILENO, document, length);
xfree(document, capacity);
shirudo_config_update_close(&update);
- return rc;
+ return ret;
}
static int read_document(const char *path, char **out, size_t *length)
@@ -143,20 +143,20 @@ int main(int argc, char **argv)
__u32 mask, reset, restart;
char *document = NULL;
size_t length = 0;
- int pcr, rc;
+ int pcr, ret;
if (argc == 4 && !strcmp(argv[1], "render")) {
- rc = render(argv[2], argv[3]);
- if (rc)
- fprintf(stderr, "render failed: %d\n", rc);
- return rc ? 1 : 0;
+ ret = render(argv[2], argv[3]);
+ if (ret)
+ fprintf(stderr, "render failed: %d\n", ret);
+ return ret ? 1 : 0;
}
if (argc != 3 && argc != 8)
return 2;
- rc = read_document(argv[2], &document, &length);
- if (!rc)
- rc = shirudo_config_evidence_parse(document, length, &config);
- if (rc)
+ ret = read_document(argv[2], &document, &length);
+ if (!ret)
+ ret = shirudo_config_evidence_parse(document, length, &config);
+ if (ret)
goto out;
if (argc == 8 && !strcmp(argv[1], "replay")) {
pcr = !strcmp(argv[4], "-") ? -1 : atoi(argv[4]);
@@ -165,24 +165,24 @@ int main(int argc, char **argv)
0 :
hex_decode(argv[3], root, 32)) ||
hex_decode(argv[7], pcrs[config.pcr], 32)) {
- rc = -EINVAL;
+ ret = -EINVAL;
goto out;
}
mask = 1u << (pcr < 0 ? config.pcr : (__u32)pcr);
reset = strtoul(argv[5], NULL, 10);
restart = strtoul(argv[6], NULL, 10);
expected = !strcmp(argv[3], "-") ? NULL : root;
- rc = shirudo_config_evidence_verify(&config, mask, reset,
- restart, pcrs, expected,
- pcr, &reason);
+ ret = shirudo_config_evidence_verify(&config, mask, reset,
+ restart, pcrs, expected,
+ pcr, &reason);
} else if (strcmp(argv[1], "parse")) {
- rc = -EINVAL;
+ ret = -EINVAL;
}
out:
if (reason)
printf("reason=%s\n", reason);
- printf("rc=%d\n", rc);
+ printf("rc=%d\n", ret);
shirudo_config_evidence_clear(&config);
xfree(document, document ? length + 1 : 0);
- return rc ? 1 : 0;
+ return ret ? 1 : 0;
}
diff --git a/testing/helper/test-config-image.c b/testing/helper/test-config-image.c
index 6c112ef2..55c6934d 100644
--- a/testing/helper/test-config-image.c
+++ b/testing/helper/test-config-image.c
@@ -14,14 +14,14 @@
static int header_read(const char *path, struct shirudo_config_image *image)
{
- int fd, rc;
+ int fd, ret;
fd = open(path, O_RDONLY | O_CLOEXEC);
if (fd < 0)
return -errno;
- rc = shirudo_config_image_read_header(fd, image);
+ ret = shirudo_config_image_read_header(fd, image);
close(fd);
- return rc;
+ return ret;
}
int main(int argc, char **argv)
@@ -33,23 +33,23 @@ int main(int argc, char **argv)
};
struct shirudo_config_image image;
__u8 root[32];
- int rc = -EINVAL;
+ int ret = -EINVAL;
if (argc == 4 && !strcmp(argv[1], "root")) {
- rc = hex_decode(argv[3], root, sizeof(root));
- if (!rc)
- rc = shirudo_config_image_open_root(argv[2], root,
- &op);
+ ret = hex_decode(argv[3], root, sizeof(root));
+ if (!ret)
+ ret = shirudo_config_image_open_root(argv[2], root,
+ &op);
shirudo_config_image_close(&op);
} else if (argc == 3 && !strcmp(argv[1], "decode")) {
- rc = header_read(argv[2], &image);
- if (!rc) {
+ ret = header_read(argv[2], &image);
+ if (!ret) {
printf("%llu %llu\n",
(__u64)image.data_blocks,
(__u64)image.hash_blocks);
}
}
- if (rc)
- fprintf(stderr, "config image: %s (%d)\n", strerror(-rc), rc);
- return rc ? 1 : 0;
+ if (ret)
+ fprintf(stderr, "config image: %s (%d)\n", strerror(-ret), ret);
+ return ret ? 1 : 0;
}
diff --git a/testing/helper/test-config-update.c b/testing/helper/test-config-update.c
index a73c4238..a361e25c 100644
--- a/testing/helper/test-config-update.c
+++ b/testing/helper/test-config-update.c
@@ -42,7 +42,7 @@ struct test_context {
static int simulator_save(struct test_context *ctx)
{
char path[PATH_MAX], temporary[PATH_MAX];
- int fd, dir, rc;
+ int fd, dir, ret;
if (snprintf(path, sizeof(path), "%s/simulator", ctx->directory) >=
(int)sizeof(path) ||
@@ -53,21 +53,21 @@ static int simulator_save(struct test_context *ctx)
O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC | O_NOFOLLOW, 0600);
if (fd < 0)
return -errno;
- rc = write_complete(fd, &ctx->sim, sizeof(ctx->sim));
- if (!rc && fsync(fd))
- rc = -errno;
- if (close(fd) && !rc)
- rc = -errno;
- if (!rc && rename(temporary, path))
- rc = -errno;
- if (rc)
- return rc;
+ ret = write_complete(fd, &ctx->sim, sizeof(ctx->sim));
+ if (!ret && fsync(fd))
+ ret = -errno;
+ if (close(fd) && !ret)
+ ret = -errno;
+ if (!ret && rename(temporary, path))
+ ret = -errno;
+ if (ret)
+ return ret;
dir = open(ctx->directory, O_RDONLY | O_DIRECTORY | O_CLOEXEC);
if (dir < 0)
return -errno;
- rc = fsync(dir) ? -errno : 0;
+ ret = fsync(dir) ? -errno : 0;
close(dir);
- return rc;
+ return ret;
}
static int simulator_load(struct test_context *ctx)
@@ -120,25 +120,25 @@ static int test_pcr_extend(void *opaque, __u32 pcr,
const char *mode = getenv("SHIRUDO_TEST_CONFIG_EXTEND");
struct test_context *ctx = opaque;
__u8 wrong[32] = { 1 };
- int rc;
+ int ret;
ctx->sim.extends++;
- rc = simulator_save(ctx);
- if (rc)
- return rc;
+ ret = simulator_save(ctx);
+ if (ret)
+ return ret;
if (mode && !strcmp(mode, "before"))
return -EIO;
if (mode && !strcmp(mode, "drift"))
event = wrong;
if (ctx->tpm)
- rc = tpm_pcr_extend(ctx->tpm, pcr, event);
+ ret = tpm_pcr_extend(ctx->tpm, pcr, event);
else
- rc = shirudo_chain_fold_checked(ctx->sim.value, event);
- if (!rc)
- rc = simulator_save(ctx);
- if (!rc && mode && !strcmp(mode, "ambiguous"))
+ ret = shirudo_chain_fold_checked(ctx->sim.value, event);
+ if (!ret)
+ ret = simulator_save(ctx);
+ if (!ret && mode && !strcmp(mode, "ambiguous"))
return -ETIMEDOUT;
- return rc;
+ return ret;
}
static int test_prepare(void *opaque,
@@ -146,12 +146,12 @@ static int test_prepare(void *opaque,
{
struct test_context *ctx = opaque;
size_t i;
- int rc;
+ int ret;
ctx->sim.prepares++;
- rc = simulator_save(ctx);
- if (rc)
- return rc;
+ ret = simulator_save(ctx);
+ if (ret)
+ return ret;
if (getenv("SHIRUDO_TEST_CONFIG_PREPARE_FAIL"))
return -EKEYREJECTED;
if (strlen(target->prefix) != sizeof("/verified/config-A") - 1 ||
@@ -171,21 +171,21 @@ static int test_activate(void *opaque,
struct shirudo_config_update_record record;
struct test_context *ctx = opaque;
__u8 live[32];
- int rc;
+ int ret;
- rc = shirudo_config_update_read(ctx->update, &record);
- if (!rc)
- rc = test_pcr_read(ctx, record.pcr, live);
- if (rc)
- return rc;
+ ret = shirudo_config_update_read(ctx->update, &record);
+ if (!ret)
+ ret = test_pcr_read(ctx, record.pcr, live);
+ if (ret)
+ return ret;
if (!record.pending ||
memcmp(target->root_hash, record.target.root_hash, 32))
return -EUCLEAN;
ctx->sim.activations++;
ctx->sim.partial = target->prefix[strlen(target->prefix) - 1];
- rc = simulator_save(ctx);
- if (rc)
- return rc;
+ ret = simulator_save(ctx);
+ if (ret)
+ return ret;
if (getenv("SHIRUDO_TEST_CONFIG_ACTIVATE_FAIL"))
return -EIO;
memcpy(ctx->sim.active, target->root_hash, sizeof(ctx->sim.active));
@@ -252,7 +252,7 @@ static void inspect(struct test_context *ctx)
__u8 value[32];
__u32 count = 0;
char hex[65];
- int rc;
+ int ret;
printf("extends=%u\nprepares=%u\nactivations=%u\npartial=%u\n",
ctx->sim.extends, ctx->sim.prepares, ctx->sim.activations,
@@ -261,9 +261,9 @@ static void inspect(struct test_context *ctx)
hex_encode(value, 32, hex);
printf("pcr_value=%s\n", hex);
}
- rc = shirudo_config_update_read(ctx->update, &record);
- printf("state_rc=%d\n", rc);
- if (!rc) {
+ ret = shirudo_config_update_read(ctx->update, &record);
+ printf("state_rc=%d\n", ret);
+ if (!ret) {
printf("sequence=%llu\npending=%u\nkind=%u\npcr=%u\nreset=%u\n",
(__u64)record.sequence, record.pending,
record.kind, record.pcr, record.reset_count);
@@ -274,8 +274,8 @@ static void inspect(struct test_context *ctx)
hex_encode(record.target.root_hash, 32, hex);
printf("root_hash=%s\n", hex);
}
- rc = shirudo_config_update_events(ctx->update, show_event, &count);
- printf("events_rc=%d\nevents=%u\n", rc, count);
+ ret = shirudo_config_update_events(ctx->update, show_event, &count);
+ printf("events_rc=%d\nevents=%u\n", ret, count);
}
int main(int argc, char **argv)
@@ -288,7 +288,7 @@ int main(int argc, char **argv)
char hex[65];
__u32 pcr = 15;
__u8 event[32];
- int rc;
+ int ret;
if (argc < 3 || argc > 5)
return 2;
@@ -298,71 +298,71 @@ int main(int argc, char **argv)
return 2;
if (argc == 5)
pcr = strtoul(argv[4], NULL, 10);
- rc = make_target(argc > 3 ? argv[3][0] : 'A', &target);
- if (rc)
+ ret = make_target(argc > 3 ? argv[3][0] : 'A', &target);
+ if (ret)
return 1;
if (!strcmp(argv[2], "describe")) {
hex_encode(target.root_hash, sizeof(target.root_hash),
hex);
printf("root_hash=%s\n", hex);
- rc = shirudo_config_measure_event(SHIRUDO_CONFIG_EVENT_BOOT,
- target.root_hash, event);
- if (!rc) {
+ ret = shirudo_config_measure_event(SHIRUDO_CONFIG_EVENT_BOOT,
+ target.root_hash, event);
+ if (!ret) {
hex_encode(event, sizeof(event), hex);
printf("boot_event=%s\n", hex);
}
- return rc ? 1 : 0;
+ return ret ? 1 : 0;
}
- rc = simulator_load(&ctx);
- if (rc)
+ ret = simulator_load(&ctx);
+ if (ret)
goto out;
if (getenv("SHIRUDO_TEST_CONFIG_TPM")) {
- rc = tpm_open(&ctx.tpm);
- if (rc)
+ ret = tpm_open(&ctx.tpm);
+ if (ret)
goto out;
}
ops = test_ops;
if (getenv("SHIRUDO_TEST_CONFIG_LOCK_WAIT_MS"))
ops.lock_wait_ms = strtoul(getenv("SHIRUDO_TEST_CONFIG_LOCK_WAIT_MS"),
NULL, 10);
- rc = shirudo_config_update_open(argv[1], &ops, &ctx, &update);
- if (rc)
+ ret = shirudo_config_update_open(argv[1], &ops, &ctx, &update);
+ if (ret)
goto out;
if (!strcmp(argv[2], "boot")) {
- rc = shirudo_config_update_boot(&update, &target, pcr);
- if (!rc && !getenv("SHIRUDO_TEST_CONFIG_BOOT_PENDING"))
- rc = shirudo_config_update_complete_boot(&update);
+ ret = shirudo_config_update_boot(&update, &target, pcr);
+ if (!ret && !getenv("SHIRUDO_TEST_CONFIG_BOOT_PENDING"))
+ ret = shirudo_config_update_complete_boot(&update);
} else if (!strcmp(argv[2], "update")) {
- rc = shirudo_config_update_begin(&update, &target, pcr);
+ ret = shirudo_config_update_begin(&update, &target, pcr);
} else if (!strcmp(argv[2], "complete")) {
- rc = shirudo_config_update_complete_boot(&update);
+ ret = shirudo_config_update_complete_boot(&update);
} else if (!strcmp(argv[2], "check")) {
- rc = shirudo_config_update_check(&update, NULL);
+ ret = shirudo_config_update_check(&update, NULL);
} else if (!strcmp(argv[2], "inspect")) {
- rc = 0;
+ ret = 0;
} else if (!strcmp(argv[2], "reset")) {
ctx.sim.reset_count++;
memset(ctx.sim.value, 0, sizeof(ctx.sim.value));
- rc = simulator_save(&ctx);
+ ret = simulator_save(&ctx);
} else if (!strcmp(argv[2], "restart")) {
ctx.sim.restart_count++;
memset(ctx.sim.value, 0, sizeof(ctx.sim.value));
- rc = simulator_save(&ctx);
+ ret = simulator_save(&ctx);
} else if (!strcmp(argv[2], "drift")) {
memset(ctx.sim.value, 0x55, sizeof(ctx.sim.value));
- rc = simulator_save(&ctx);
+ ret = simulator_save(&ctx);
} else if (!strcmp(argv[2], "lock")) {
- rc = shirudo_config_update_open(argv[1], &test_ops, &ctx,
- &second);
+ ret = shirudo_config_update_open(argv[1], &test_ops, &ctx,
+ &second);
shirudo_config_update_close(&second);
} else {
- rc = -EINVAL;
+ ret = -EINVAL;
}
inspect(&ctx);
shirudo_config_update_close(&update);
out:
if (ctx.tpm)
tpm_close(ctx.tpm);
- printf("rc=%d\n", rc);
- return rc ? 1 : 0;
+ printf("rc=%d\n", ret);
+ return ret ? 1 : 0;
}
diff --git a/testing/helper/test-config.c b/testing/helper/test-config.c
index 6689a527..35f91a78 100644
--- a/testing/helper/test-config.c
+++ b/testing/helper/test-config.c
@@ -18,15 +18,15 @@
static int write_config(const char *path, const char *contents)
{
- int fd, rc;
+ int fd, ret;
fd = open(path, O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC, 0600);
if (fd < 0)
return -errno;
- rc = write_complete(fd, contents, strlen(contents));
- if (rc) {
+ ret = write_complete(fd, contents, strlen(contents));
+ if (ret) {
close(fd);
- return rc;
+ return ret;
}
return close(fd) == 0 ? 0 : -errno;
}
diff --git a/testing/helper/test-eventlog.c b/testing/helper/test-eventlog.c
index 03549849..d57e38ab 100644
--- a/testing/helper/test-eventlog.c
+++ b/testing/helper/test-eventlog.c
@@ -86,21 +86,21 @@ int main(int argc, char **argv)
eventlog_pending_path() :
eventlog_path();
__u32 reset = 1;
- int rc;
+ int ret;
if (argc == 5)
reset = (__u32)strtoul(argv[4], NULL, 10);
- rc = append_init(path, argv[3], reset);
+ ret = append_init(path, argv[3], reset);
- printf("rc=%d\n", rc);
- return rc ? 1 : 0;
+ printf("rc=%d\n", ret);
+ return ret ? 1 : 0;
}
if (strcmp(argv[1], "boot-init") == 0) {
struct shirudo_eventlog_init rec;
- int rc = eventlog_boot_init(&rec);
+ int ret = eventlog_boot_init(&rec);
- printf("rc=%d\n", rc);
- if (rc)
+ printf("rc=%d\n", ret);
+ if (ret)
return 1;
printf("bound_in=%s\nrecords=%u\nreset_count=%u\n",
rec.initrd ? "initrd" : "root", rec.records,
@@ -109,18 +109,18 @@ int main(int argc, char **argv)
}
if (strcmp(argv[1], "lines") == 0) {
__u32 n = 0;
- int rc = eventlog_boot_lines(count_lines, &n);
+ int ret = eventlog_boot_lines(count_lines, &n);
- printf("rc=%d\nlines=%u\n", rc, n);
- return rc ? 1 : 0;
+ printf("rc=%d\nlines=%u\n", ret, n);
+ return ret ? 1 : 0;
}
if (strcmp(argv[1], "adopt") == 0) {
- int rc = eventlog_adopt_pending();
+ int ret = eventlog_adopt_pending();
- printf("rc=%d\npending=%s\n", rc,
+ printf("rc=%d\npending=%s\n", ret,
access(eventlog_pending_path(), F_OK) == 0 ?
"present" : "absent");
- return rc ? 1 : 0;
+ return ret ? 1 : 0;
}
fprintf(stderr, "unknown subcommand\n");
return 2;
diff --git a/testing/helper/test-harden.c b/testing/helper/test-harden.c
index 8ff9cc7d..e459abe1 100644
--- a/testing/helper/test-harden.c
+++ b/testing/helper/test-harden.c
@@ -27,7 +27,7 @@ int mlockall(int flags)
int main(int argc, char **argv)
{
struct rlimit core = {};
- int rc;
+ int ret;
if (argc != 2)
goto usage;
@@ -40,8 +40,8 @@ int main(int argc, char **argv)
else
goto usage;
- rc = harden_self();
- if (lock_flags != (MCL_CURRENT | MCL_FUTURE) || rc != -lock_error) {
+ ret = harden_self();
+ if (lock_flags != (MCL_CURRENT | MCL_FUTURE) || ret != -lock_error) {
fprintf(stderr, "unexpected lock flags or result\n");
return 2;
}
@@ -51,8 +51,8 @@ int main(int argc, char **argv)
fprintf(stderr, "existing startup hardening changed\n");
return 2;
}
- printf("rc=%d\n", rc);
- return rc ? 1 : 0;
+ printf("rc=%d\n", ret);
+ return ret ? 1 : 0;
usage:
fprintf(stderr, "usage: %s success|denied|limit\n", argv[0]);
return 2;
diff --git a/testing/helper/test-image-cleanup.c b/testing/helper/test-image-cleanup.c
index 3e6a4087..f419ec22 100644
--- a/testing/helper/test-image-cleanup.c
+++ b/testing/helper/test-image-cleanup.c
@@ -32,7 +32,7 @@ int main(int argc, char **argv)
{
__u32 expected_calls = 1;
int expected_result = 0;
- int rc;
+ int ret;
if (argc != 2)
return 2;
@@ -54,9 +54,9 @@ int main(int argc, char **argv)
} else {
return 2;
}
- rc = remove_candidate(&candidate);
- printf("rc=%d removes=%u sleeps=%u invalid=%d\n", rc,
+ ret = remove_candidate(&candidate);
+ printf("rc=%d removes=%u sleeps=%u invalid=%d\n", ret,
remove_calls, sleep_calls, invalid_call);
- return rc != expected_result || remove_calls != expected_calls ||
+ return ret != expected_result || remove_calls != expected_calls ||
sleep_calls != expected_calls - 1 || invalid_call;
}
diff --git a/testing/helper/test-image-cli.c b/testing/helper/test-image-cli.c
index 24d6ba79..17dd1dcb 100644
--- a/testing/helper/test-image-cli.c
+++ b/testing/helper/test-image-cli.c
@@ -31,46 +31,46 @@ int __wrap_bpm_tree_fetch_publication(struct bpm_oci_client *client,
int main(int argc, const char **argv)
{
struct shirudo_config bootstrap;
- int fd, rc;
+ int fd, ret;
if (argc < 3)
return 2;
fd = open(argv[1], O_RDONLY | O_DIRECTORY | O_CLOEXEC | O_NOFOLLOW);
if (fd < 0)
return 1;
- rc = config_load_path(&bootstrap, "/dev/null");
- if (!rc) {
+ ret = config_load_path(&bootstrap, "/dev/null");
+ if (!ret) {
memcpy(bootstrap.tpm_owner_auth, "bootstrap-owner", 15);
bootstrap.tpm_owner_auth_len = 15;
strscpy(bootstrap.tpm_tcti, "bootstrap-tcti", sizeof(bootstrap.tpm_tcti));
- rc = shirudo_image_config_set(&bootstrap, fd);
+ ret = shirudo_image_config_set(&bootstrap, fd);
}
close(fd);
- if (rc)
+ if (ret)
return 1;
if (!strcmp(argv[2], "bpm")) {
- rc = cmd_bpm(argc - 2, argv + 2);
+ ret = cmd_bpm(argc - 2, argv + 2);
} else if (!strcmp(argv[2], "keys")) {
- rc = cmd_keys(argc - 2, argv + 2);
+ ret = cmd_keys(argc - 2, argv + 2);
} else if (!strcmp(argv[2], "config")) {
- rc = cmd_config(argc - 2, argv + 2);
+ ret = cmd_config(argc - 2, argv + 2);
} else if (!strcmp(argv[2], "source") && argc == 4) {
struct bpm_source source;
- rc = load_source(argv[3], &source);
- if (!rc) {
+ ret = load_source(argv[3], &source);
+ if (!ret) {
char content[64];
int kfd = shirudo_image_open_relative(source.key_file,
O_RDONLY);
FILE *file = kfd < 0 ? NULL : fdopen(kfd, "r");
if (!file) {
- rc = kfd < 0 ? kfd : -errno;
+ ret = kfd < 0 ? kfd : -errno;
if (kfd >= 0)
close(kfd);
} else {
if (!fgets(content, sizeof(content), file))
- rc = -EIO;
+ ret = -EIO;
else
fputs(content, stdout);
fclose(file);
@@ -83,11 +83,11 @@ int main(int argc, const char **argv)
strscpy(config.endpoint, "oci://example.invalid/tree", sizeof(config.endpoint));
strscpy(config.reference, "latest", sizeof(config.reference));
- rc = tree_fetch_publication(&config, &publication, digest,
- sizeof(digest));
+ ret = tree_fetch_publication(&config, &publication, digest,
+ sizeof(digest));
} else {
- rc = 2;
+ ret = 2;
}
shirudo_image_config_clear();
- return rc ? 1 : 0;
+ return ret ? 1 : 0;
}
diff --git a/testing/helper/test-image-config.c b/testing/helper/test-image-config.c
index b6bc5b7f..4348a81a 100644
--- a/testing/helper/test-image-config.c
+++ b/testing/helper/test-image-config.c
@@ -16,25 +16,25 @@ static int read_bootstrap(int argc, char **argv)
{
struct shirudo_image_bootstrap boot = {};
char root[65];
- int rc;
+ int ret;
- rc = shirudo_image_bootstrap_read(argv[2], &boot, true);
- if (!rc && argc == 4)
- rc = shirudo_image_bootstrap_read(argv[3], &boot, false);
- if (!rc) {
+ ret = shirudo_image_bootstrap_read(argv[2], &boot, true);
+ if (!ret && argc == 4)
+ ret = shirudo_image_bootstrap_read(argv[3], &boot, false);
+ if (!ret) {
hex_encode(boot.runtime_root, 32, root);
printf("runtime=%s\nroot=%s\nconfig=%s\ncertificate=%s\npcr=%u\n",
boot.runtime, root, boot.config, boot.certificate,
boot.pcr);
}
- printf("rc=%d\n", rc);
- return rc ? 1 : 0;
+ printf("rc=%d\n", ret);
+ return ret ? 1 : 0;
}
int main(int argc, char **argv)
{
struct shirudo_config bootstrap, effective;
- int fd, rc;
+ int fd, ret;
if (argc < 3 || argc > 4)
return 2;
@@ -43,46 +43,46 @@ int main(int argc, char **argv)
fd = open(argv[2], O_RDONLY | O_DIRECTORY | O_CLOEXEC | O_NOFOLLOW);
if (fd < 0)
return 1;
- rc = config_load_path(&bootstrap, "/dev/null");
- if (rc)
+ ret = config_load_path(&bootstrap, "/dev/null");
+ if (ret)
goto out;
memcpy(bootstrap.tpm_owner_auth, "bootstrap-owner", 15);
bootstrap.tpm_owner_auth_len = 15;
snprintf(bootstrap.tpm_tcti, sizeof(bootstrap.tpm_tcti),
"bootstrap-tcti");
if (!strcmp(argv[1], "validate")) {
- rc = shirudo_image_config_validate(fd);
+ ret = shirudo_image_config_validate(fd);
} else if (!strcmp(argv[1], "effective")) {
- rc = shirudo_image_config_set(&bootstrap, fd);
- if (!rc && !shirudo_image_config_get(&effective))
- rc = -EIO;
- if (!rc) {
+ ret = shirudo_image_config_set(&bootstrap, fd);
+ if (!ret && !shirudo_image_config_get(&effective))
+ ret = -EIO;
+ if (!ret) {
printf("owner=%.*s\ntcti=%s\nlimit=%llu\n",
(int)effective.tpm_owner_auth_len,
effective.tpm_owner_auth, effective.tpm_tcti,
effective.eventlog_max_bytes);
- rc = shirudo_image_open(SHIRUDO_IMAGE_REGISTRIES,
- O_RDONLY | O_DIRECTORY);
- printf("registries=%s\n", rc >= 0 ? "open" : "missing");
- if (rc >= 0)
- close(rc);
- rc = 0;
+ ret = shirudo_image_open(SHIRUDO_IMAGE_REGISTRIES,
+ O_RDONLY | O_DIRECTORY);
+ printf("registries=%s\n", ret >= 0 ? "open" : "missing");
+ if (ret >= 0)
+ close(ret);
+ ret = 0;
}
} else if (!strcmp(argv[1], "relative") && argc == 4) {
- rc = shirudo_image_config_set(&bootstrap, fd);
- if (!rc)
- rc = shirudo_image_open_relative(argv[3], O_RDONLY);
- if (rc >= 0) {
+ ret = shirudo_image_config_set(&bootstrap, fd);
+ if (!ret)
+ ret = shirudo_image_open_relative(argv[3], O_RDONLY);
+ if (ret >= 0) {
printf("resolved=open\n");
- close(rc);
- rc = 0;
+ close(ret);
+ ret = 0;
}
} else {
- rc = -EINVAL;
+ ret = -EINVAL;
}
out:
shirudo_image_config_clear();
close(fd);
- printf("rc=%d\n", rc);
- return rc ? 1 : 0;
+ printf("rc=%d\n", ret);
+ return ret ? 1 : 0;
}
diff --git a/testing/helper/test-image-keys.c b/testing/helper/test-image-keys.c
index a066a764..0e6e1da5 100644
--- a/testing/helper/test-image-keys.c
+++ b/testing/helper/test-image-keys.c
@@ -44,14 +44,14 @@ int keyring_holds_cert(key_serial_t ring, const __u8 *der,
for (i = 0; i < held_count; i++) {
__u8 *candidate = NULL;
size_t length = 0;
- int rc;
+ int ret;
- rc = keys_read_der(held[i], &candidate, &length);
- if (rc)
- return rc;
- rc = size == length && !memcmp(der, candidate, size);
+ ret = keys_read_der(held[i], &candidate, &length);
+ if (ret)
+ return ret;
+ ret = size == length && !memcmp(der, candidate, size);
xfree(candidate, length);
- if (rc)
+ if (ret)
return 1;
}
return 0;
@@ -136,47 +136,47 @@ static int live_update(const char *directory, struct shirudo_trusted_set *set)
struct shirudo_config_update_target target = {};
struct shirudo_config_update update;
struct test_context ctx = { .set = set };
- int rc;
+ int ret;
- rc = shirudo_config_update_open(directory, &ops, &ctx, &update);
- if (rc)
- return rc;
+ ret = shirudo_config_update_open(directory, &ops, &ctx, &update);
+ if (ret)
+ return ret;
strcpy(target.prefix, "/verified/boot");
memset(target.root_hash, 1, 32);
- rc = shirudo_config_update_boot(&update, &target, 15);
- if (!rc)
- rc = shirudo_config_update_complete_boot(&update);
+ ret = shirudo_config_update_boot(&update, &target, 15);
+ if (!ret)
+ ret = shirudo_config_update_complete_boot(&update);
ctx.live = true;
ctx.interrupt = !!getenv("SHIRUDO_TEST_IMAGE_INTERRUPT");
ctx.extends = 0;
ctx.activations = 0;
strcpy(target.prefix, "/verified/live");
memset(target.root_hash, 2, 32);
- if (!rc)
- rc = shirudo_config_update_begin(&update, &target, 15);
+ if (!ret)
+ ret = shirudo_config_update_begin(&update, &target, 15);
printf("extends=%u activations=%u\n", ctx.extends, ctx.activations);
shirudo_config_update_close(&update);
- return rc;
+ return ret;
}
int main(int argc, char **argv)
{
struct shirudo_trusted_set set = {};
- int fd, rc;
+ int fd, ret;
if (argc != 3 && argc < 5)
return 2;
fd = open(argv[2], O_RDONLY | O_DIRECTORY | O_CLOEXEC | O_NOFOLLOW);
if (fd < 0)
return 2;
- rc = shirudo_keys_validate_image_set(argv[1], fd, &set);
- if (!rc && argc >= 5) {
+ ret = shirudo_keys_validate_image_set(argv[1], fd, &set);
+ if (!ret && argc >= 5) {
held = argv + 4;
held_count = argc - 4;
- rc = live_update(argv[3], &set);
+ ret = live_update(argv[3], &set);
}
close(fd);
- printf("rc=%d mutations=%u signers=%zu\n", rc, mutations, set.n);
- return rc || mutations ? 1 : 0;
+ printf("rc=%d mutations=%u signers=%zu\n", ret, mutations, set.n);
+ return ret || mutations ? 1 : 0;
}
diff --git a/testing/helper/test-keyring-seal.c b/testing/helper/test-keyring-seal.c
index 81fcd022..675ca654 100644
--- a/testing/helper/test-keyring-seal.c
+++ b/testing/helper/test-keyring-seal.c
@@ -38,11 +38,11 @@ static int read_cert(const char *path, struct keyring_cert *cert)
{
__u8 *der = NULL;
size_t len = 0;
- int rc;
+ int ret;
- rc = keys_read_der(path, &der, &len);
- if (rc)
- return rc;
+ ret = keys_read_der(path, &der, &len);
+ if (ret)
+ return ret;
cert->der = der;
cert->len = len;
return 0;
@@ -112,7 +112,7 @@ static int seal_case(const char *mode,
const struct keyring_cert *own,
const struct keyring_cert *other)
{
- int rc, fails = 0;
+ int ret, fails = 0;
test_ring = add("keyring", "shirudo-test-seal", NULL, 0,
KEY_SPEC_THREAD_KEYRING);
@@ -142,9 +142,9 @@ static int seal_case(const char *mode,
syscall(__NR_keyctl, KEYCTL_RESTRICT_KEYRING, test_ring,
"asymmetric", "key_or_keyring:0:chain", 0) < 0)
return -EIO;
- rc = init_bpf_keyring(test_ring, set);
+ ret = init_bpf_keyring(test_ring, set);
fails += expect("restriction init did not install",
- rc == 0 || rc == -EEXIST, 0);
+ ret == 0 || ret == -EEXIST, 0);
} else if (!strcmp(mode, "empty")) {
if (__wrap_keyring_bpf_seal())
return -EIO;
@@ -162,7 +162,7 @@ int main(int argc, char **argv)
struct keyring_cert own = {}, other = {};
struct shirudo_trusted_set set = {};
char keys[PATH_MAX];
- int rc;
+ int ret;
if (argc != 5) {
fprintf(stderr, "usage: %s exact|fresh|foreign|nested|"
@@ -173,21 +173,21 @@ int main(int argc, char **argv)
if (strsprintf(keys, sizeof(keys), "%s/%s", argv[2],
CERT_FILE) < 0)
return 2;
- rc = read_cert(keys, &own);
- if (!rc)
- rc = read_cert(argv[4], &other);
- if (!rc && strcmp(argv[1], "exact"))
- rc = keys_load(argv[2], argv[3], false, &set);
- if (!rc)
- rc = strcmp(argv[1], "exact") ?
+ ret = read_cert(keys, &own);
+ if (!ret)
+ ret = read_cert(argv[4], &other);
+ if (!ret && strcmp(argv[1], "exact"))
+ ret = keys_load(argv[2], argv[3], false, &set);
+ if (!ret)
+ ret = strcmp(argv[1], "exact") ?
seal_case(argv[1], &set, &own, &other) :
exact_case(&own, &other);
- if (rc)
+ if (ret)
fprintf(stderr, "keyring seal test %s: %s\n", argv[1],
- strerror(-rc));
+ strerror(-ret));
if (own.der)
xfree((void *)own.der, own.len);
if (other.der)
xfree((void *)other.der, other.len);
- return rc ? 1 : 0;
+ return ret ? 1 : 0;
}
diff --git a/testing/helper/test-keys.c b/testing/helper/test-keys.c
index 55f3a8df..127da140 100644
--- a/testing/helper/test-keys.c
+++ b/testing/helper/test-keys.c
@@ -34,7 +34,7 @@ int main(int argc, char **argv)
struct shirudo_trusted_set set;
__u8 digest[32];
size_t i;
- int rc;
+ int ret;
if (argc < 3) {
fprintf(stderr, "usage: %s load|digest|reject <keys-dir>"
@@ -54,12 +54,12 @@ int main(int argc, char **argv)
upatch_close(&u);
return 2;
}
- rc = cms_signed_by(upatch_signature(&u),
- u.hdr.signature_len, &cert);
+ ret = cms_signed_by(upatch_signature(&u),
+ u.hdr.signature_len, &cert);
cert_free(&cert);
upatch_close(&u);
- printf("%s\n", rc == 1 ? "yes" : rc == 0 ? "no" : "error");
- return rc < 0 ? 1 : 0;
+ printf("%s\n", ret == 1 ? "yes" : ret == 0 ? "no" : "error");
+ return ret < 0 ? 1 : 0;
}
if (!strcmp(argv[1], "image")) {
char primary[PATH_MAX];
@@ -69,17 +69,17 @@ int main(int argc, char **argv)
root = open(argv[2], O_RDONLY | O_DIRECTORY | O_CLOEXEC);
if (root < 0)
return 1;
- rc = shirudo_keys_load_image_at(primary, root, true, &set);
+ ret = shirudo_keys_load_image_at(primary, root, true, &set);
close(root);
} else {
- rc = keys_load(argv[2], NULL,
- argc < 4 || strcmp(argv[3], "primary"),
+ ret = keys_load(argv[2], NULL,
+ argc < 4 || strcmp(argv[3], "primary"),
&set);
}
if (!strcmp(argv[1], "reject"))
- return rc == -EINVAL ? 0 : 1;
- if (rc) {
- printf("rc=%d\n", rc);
+ return ret == -EINVAL ? 0 : 1;
+ if (ret) {
+ printf("rc=%d\n", ret);
return 1;
}
if (!strcmp(argv[1], "load") || !strcmp(argv[1], "image")) {
diff --git a/testing/helper/test-mode-objects.c b/testing/helper/test-mode-objects.c
index fdc2f28d..8752edb4 100644
--- a/testing/helper/test-mode-objects.c
+++ b/testing/helper/test-mode-objects.c
@@ -14,7 +14,7 @@ static int symbols(const char *selection,
{
Elf_Scn *section = NULL;
Elf *elf;
- int rc = 0;
+ int ret = 0;
if (elf_version(EV_CURRENT) == EV_NONE)
return 1;
@@ -27,14 +27,14 @@ static int symbols(const char *selection,
size_t i;
if (!gelf_getshdr(section, &header)) {
- rc = 1;
+ ret = 1;
break;
}
if (header.sh_type != SHT_SYMTAB)
continue;
data = elf_getdata(section, NULL);
if (!data || !header.sh_entsize) {
- rc = 1;
+ ret = 1;
break;
}
for (i = 1; i < header.sh_size / header.sh_entsize; i++) {
@@ -42,21 +42,21 @@ static int symbols(const char *selection,
const char *name;
if (!gelf_getsym(data, i, &symbol)) {
- rc = 1;
+ ret = 1;
break;
}
if (symbol.st_shndx != SHN_UNDEF)
continue;
name = elf_strptr(elf, header.sh_link, symbol.st_name);
if (!name) {
- rc = 1;
+ ret = 1;
break;
}
printf("extern %s %s\n", selection, name);
}
}
elf_end(elf);
- return rc;
+ return ret;
}
static int inspect(const char *selection,
diff --git a/testing/helper/test-nv-cphash.c b/testing/helper/test-nv-cphash.c
index 0b1aed4b..3e519c6f 100644
--- a/testing/helper/test-nv-cphash.c
+++ b/testing/helper/test-nv-cphash.c
@@ -18,11 +18,11 @@ enum signature_fault {
SIGNATURE_CORRUPT,
};
-static int tpm_failed(TSS2_RC rc, const char *operation)
+static int tpm_failed(TSS2_RC ret, const char *operation)
{
- if (rc == TSS2_RC_SUCCESS)
+ if (ret == TSS2_RC_SUCCESS)
return 0;
- fprintf(stderr, "%s: rc=0x%08x\n", operation, (__u32)rc);
+ fprintf(stderr, "%s: rc=0x%08x\n", operation, (__u32)ret);
return 1;
}
@@ -39,7 +39,7 @@ static int flush(ESYS_CONTEXT *esys, ESYS_TR *session)
static int read_value(ESYS_CONTEXT *esys, ESYS_TR nv, __u8 out[32])
{
TPM2B_MAX_NV_BUFFER *data = NULL;
- int rc = 1;
+ int ret = 1;
if (tpm_failed(Esys_NV_Read(esys, nv, nv, ESYS_TR_PASSWORD,
ESYS_TR_NONE, ESYS_TR_NONE, 32, 0, &data),
@@ -50,10 +50,10 @@ static int read_value(ESYS_CONTEXT *esys, ESYS_TR nv, __u8 out[32])
goto out;
}
memcpy(out, data->buffer, 32);
- rc = 0;
+ ret = 0;
out:
Esys_Free(data);
- return rc;
+ return ret;
}
static int sign_digest(ESYS_CONTEXT *esys, ESYS_TR writer,
@@ -67,7 +67,7 @@ static int sign_digest(ESYS_CONTEXT *esys, ESYS_TR writer,
TPMT_SIG_SCHEME scheme = { .scheme = TPM2_ALG_RSASSA };
TPMT_SIGNATURE *signed_digest = NULL;
TPM2B_DIGEST input = { .size = 32 };
- int rc = 1;
+ int ret = 1;
scheme.details.rsassa.hashAlg = TPM2_ALG_SHA256;
memcpy(input.buffer, digest, input.size);
@@ -83,10 +83,10 @@ static int sign_digest(ESYS_CONTEXT *esys, ESYS_TR writer,
}
memcpy(signature, signed_digest->signature.rsassa.sig.buffer,
TPM_NV_RSA_BYTES);
- rc = 0;
+ ret = 0;
out:
Esys_Free(signed_digest);
- return rc;
+ return ret;
}
static int authorize(struct shirudo_tpm *t, ESYS_TR writer, ESYS_TR nv,
@@ -98,7 +98,7 @@ static int authorize(struct shirudo_tpm *t, ESYS_TR writer, ESYS_TR nv,
__u8 signature[TPM_NV_RSA_BYTES];
TPM2B_NAME *name = NULL;
TSS2_RC trc;
- int rc = 1;
+ int ret = 1;
if (tpm_policy_session_start(t, session) ||
tpm_failed(Esys_TRSess_SetAttributes(t->esys, *session,
@@ -128,16 +128,16 @@ static int authorize(struct shirudo_tpm *t, ESYS_TR writer, ESYS_TR nv,
(__u32)trc);
goto out;
}
- rc = 0;
+ ret = 0;
goto out;
}
if (tpm_failed(trc, "PolicySigned") || tpm_policy_session_finish(t, *session, policy))
goto out;
memcpy(saved, signature, sizeof(signature));
- rc = 0;
+ ret = 0;
out:
Esys_Free(name);
- return rc;
+ return ret;
}
int main(void)
@@ -157,7 +157,7 @@ int main(void)
__u8 policy[32], zero[32] = {};
bool defined = false;
ssize_t got;
- int rc = 1, err;
+ int ret = 1, err;
TSS2_RC trc;
if (tpm_open(&t))
@@ -235,20 +235,20 @@ int main(void)
fprintf(stderr, "authorized NV_Extend did not produce SHA256(before || A)\n");
goto out;
}
- rc = 0;
+ ret = 0;
out:
if (esys) {
if (flush(esys, &session))
- rc = 1;
+ ret = 1;
if (defined && tpm_nv_undefine(t, TEST_NV_INDEX, NULL, 0))
- rc = 1;
+ ret = 1;
if (flush(esys, &writer))
- rc = 1;
+ ret = 1;
}
tpm_close(t);
- if (!rc) {
+ if (!ret) {
puts("PolicySigned: replay and corruption rejected; value unchanged");
puts("cpHash: authorized A; rejected B unchanged; extended A; scratch index removed");
}
- return rc;
+ return ret;
}
diff --git a/testing/helper/test-nv-writer.c b/testing/helper/test-nv-writer.c
index 0106c32e..23968919 100644
--- a/testing/helper/test-nv-writer.c
+++ b/testing/helper/test-nv-writer.c
@@ -42,18 +42,18 @@ static int sign_once(ESYS_CONTEXT *esys, ESYS_TR key)
TPMT_SIG_SCHEME scheme = { .scheme = TPM2_ALG_ECDSA };
TPMT_SIGNATURE *signature = NULL;
TPM2B_DIGEST digest = { .size = 32 };
- TSS2_RC rc;
+ TSS2_RC ret;
scheme.details.ecdsa.hashAlg = TPM2_ALG_SHA256;
memset(digest.buffer, 0x5a, digest.size);
- rc = Esys_Sign(esys, key, ESYS_TR_PASSWORD, ESYS_TR_NONE,
- ESYS_TR_NONE, &digest, &scheme, &validation, &signature);
- if (rc == TSS2_RC_SUCCESS && signature) {
+ ret = Esys_Sign(esys, key, ESYS_TR_PASSWORD, ESYS_TR_NONE,
+ ESYS_TR_NONE, &digest, &scheme, &validation, &signature);
+ if (ret == TSS2_RC_SUCCESS && signature) {
Esys_Free(signature);
return 0;
}
Esys_Free(signature);
- fprintf(stderr, "unrelated TPM2_Sign failed: rc=0x%08x\n", (__u32)rc);
+ fprintf(stderr, "unrelated TPM2_Sign failed: rc=0x%08x\n", (__u32)ret);
return 1;
}
@@ -68,7 +68,7 @@ static int sign_check(const char *device, bool inherited)
ESYS_CONTEXT *esys = NULL;
ESYS_TR key = ESYS_TR_NONE;
TSS2_RC trc;
- int status, rc = 1;
+ int status, ret = 1;
pid_t pid;
trc = Tss2_TctiLdr_Initialize(device, &tcti);
@@ -98,7 +98,7 @@ static int sign_check(const char *device, bool inherited)
if (trc)
goto tpm_error;
if (!inherited) {
- rc = sign_once(esys, key);
+ ret = sign_once(esys, key);
goto out;
}
pid = fork();
@@ -107,9 +107,9 @@ static int sign_check(const char *device, bool inherited)
goto out;
}
if (!pid) {
- rc = sign_once(esys, key);
+ ret = sign_once(esys, key);
fflush(stderr);
- _exit(rc);
+ _exit(ret);
}
if (waitpid(pid, &status, 0) != pid) {
perror("waitpid");
@@ -117,7 +117,7 @@ static int sign_check(const char *device, bool inherited)
}
if (!WIFEXITED(status) || WEXITSTATUS(status))
goto out;
- rc = 0;
+ ret = 0;
goto out;
tpm_error:
fprintf(stderr, "prepare TPM signing request on %s: rc=0x%08x\n",
@@ -128,7 +128,7 @@ out:
Esys_FlushContext(esys, key);
Esys_Finalize(&esys);
Tss2_TctiLdr_Finalize(&tcti);
- return rc;
+ return ret;
}
enum extend_probe {
@@ -170,7 +170,7 @@ static int raw_extend_check(const char *device, enum extend_probe probe,
bool nonblock, bool inherited)
{
int flags = O_RDWR | O_CLOEXEC;
- int status, rc;
+ int status, ret;
pid_t pid;
int fd;
@@ -184,9 +184,9 @@ static int raw_extend_check(const char *device, enum extend_probe probe,
return 1;
}
if (!inherited) {
- rc = write_extend(fd, device, probe);
+ ret = write_extend(fd, device, probe);
close(fd);
- return rc;
+ return ret;
}
pid = fork();
if (pid < 0) {
@@ -195,13 +195,13 @@ static int raw_extend_check(const char *device, enum extend_probe probe,
return 1;
}
if (!pid) {
- rc = write_extend(fd, device, probe);
- _exit(rc);
+ ret = write_extend(fd, device, probe);
+ _exit(ret);
}
- rc = waitpid(pid, &status, 0) == pid &&
+ ret = waitpid(pid, &status, 0) == pid &&
WIFEXITED(status) && WEXITSTATUS(status) == 0 ? 0 : 1;
close(fd);
- return rc;
+ return ret;
}
int main(int argc, char **argv)
diff --git a/testing/helper/test-otel-map.c b/testing/helper/test-otel-map.c
index dfa4652d..83561ca4 100644
--- a/testing/helper/test-otel-map.c
+++ b/testing/helper/test-otel-map.c
@@ -86,7 +86,7 @@ static int make_decoder(bool metric, bool counter, bool snapshot,
struct shirudo_upatch_header header = {};
__u8 *file;
char template[] = "/tmp/test-otel-map-decoder-XXXXXX";
- int fd, rc;
+ int fd, ret;
if (file_len > UINT32_MAX || decoder_len > UINT32_MAX ||
source_len > UINT32_MAX || snprintf(path, path_sz, "%s", template) >=
@@ -97,9 +97,9 @@ static int make_decoder(bool metric, bool counter, bool snapshot,
return -ENOMEM;
fd = mkstemp(path);
if (fd < 0) {
- rc = -errno;
+ ret = -errno;
xfree(file, file_len);
- return rc;
+ return ret;
}
header.magic = cpu_to_le64(UPATCH_MAGIC);
@@ -145,13 +145,13 @@ static int make_decoder(bool metric, bool counter, bool snapshot,
memcpy(file + data_off + dir_off + sizeof(section), &trailer,
sizeof(trailer));
- rc = write_complete(fd, file, file_len);
- if (close(fd) != 0 && rc == 0)
- rc = -errno;
+ ret = write_complete(fd, file, file_len);
+ if (close(fd) != 0 && ret == 0)
+ ret = -errno;
xfree(file, file_len);
- if (rc) {
+ if (ret) {
unlink(path);
- return rc;
+ return ret;
}
return 0;
}
@@ -217,18 +217,18 @@ static int print_classification(__u32 type, bool is_signed, bool with_btf,
struct fixture f;
enum shirudo_otel_signal signal;
char reason[160];
- int rc = fixture_init(&f, type, is_signed, with_btf);
+ int ret = fixture_init(&f, type, is_signed, with_btf);
- if (rc)
+ if (ret)
return 1;
f.view.serialized = serialized;
- rc = shirudo_upatch_maps_otel_classify(&f.view, &signal, reason,
- sizeof(reason));
- if (!rc)
+ ret = shirudo_upatch_maps_otel_classify(&f.view, &signal, reason,
+ sizeof(reason));
+ if (!ret)
printf("%s:%s\n", signal == SHIRUDO_OTEL_METRIC ?
"metric" : "log", reason);
fixture_destroy(&f);
- return rc != 0;
+ return ret != 0;
}
static int print_payload(bool metric, bool counter, bool with_location)
@@ -237,30 +237,30 @@ static int print_payload(bool metric, bool counter, bool with_location)
char decoder_path[128] = {};
char *buf = NULL;
size_t len = 0;
- int rc = fixture_init(&f, BPF_MAP_TYPE_PERCPU_ARRAY, false, true);
+ int ret = fixture_init(&f, BPF_MAP_TYPE_PERCPU_ARRAY, false, true);
- if (rc)
+ if (ret)
return 1;
if (!with_location)
f.view.location[0] = '\0';
- rc = make_decoder(metric, counter, false, decoder_path,
- sizeof(decoder_path));
- if (!rc && metric)
- rc = shirudo_upatch_maps_otel_build_metric_file(decoder_path,
- &f.view,
- &buf, &len);
- else if (!rc)
- rc = shirudo_upatch_maps_otel_build_log_file(decoder_path,
- &f.view, &buf,
- &len);
- if (!rc && buf)
+ ret = make_decoder(metric, counter, false, decoder_path,
+ sizeof(decoder_path));
+ if (!ret && metric)
+ ret = shirudo_upatch_maps_otel_build_metric_file(decoder_path,
+ &f.view,
+ &buf, &len);
+ else if (!ret)
+ ret = shirudo_upatch_maps_otel_build_log_file(decoder_path,
+ &f.view, &buf,
+ &len);
+ if (!ret && buf)
fwrite(buf, 1, len, stdout);
if (buf)
xfree(buf, JSON_MAX_BYTES);
if (decoder_path[0])
unlink(decoder_path);
fixture_destroy(&f);
- return rc != 0;
+ return ret != 0;
}
static int print_local_json(void)
@@ -293,20 +293,20 @@ static int send_log_limits(const char *url, __u32 retries, __u32 record_max,
};
struct fixture f;
char decoder_path[128] = {};
- int rc;
+ int ret;
- rc = fixture_init(&f, BPF_MAP_TYPE_PERCPU_ARRAY, false, true);
- if (rc)
+ ret = fixture_init(&f, BPF_MAP_TYPE_PERCPU_ARRAY, false, true);
+ if (ret)
return 1;
- rc = make_decoder(false, false, false, decoder_path,
- sizeof(decoder_path));
- if (!rc)
- rc = shirudo_upatch_maps_otel_send_file(decoder_path, &f.view,
- SHIRUDO_OTEL_FORCE_LOG, &opts);
+ ret = make_decoder(false, false, false, decoder_path,
+ sizeof(decoder_path));
+ if (!ret)
+ ret = shirudo_upatch_maps_otel_send_file(decoder_path, &f.view,
+ SHIRUDO_OTEL_FORCE_LOG, &opts);
if (decoder_path[0])
unlink(decoder_path);
fixture_destroy(&f);
- return rc ? 1 : 0;
+ return ret ? 1 : 0;
}
static int send_log(const char *url, __u32 retries, bool insecure)
@@ -318,20 +318,20 @@ static int send_log(const char *url, __u32 retries, bool insecure)
};
struct fixture f;
char decoder_path[128] = {};
- int rc;
+ int ret;
- rc = fixture_init(&f, BPF_MAP_TYPE_PERCPU_ARRAY, false, true);
- if (rc)
+ ret = fixture_init(&f, BPF_MAP_TYPE_PERCPU_ARRAY, false, true);
+ if (ret)
return 1;
- rc = make_decoder(false, false, false, decoder_path,
- sizeof(decoder_path));
- if (!rc)
- rc = shirudo_upatch_maps_otel_send_file(decoder_path, &f.view,
- SHIRUDO_OTEL_FORCE_LOG, &opts);
+ ret = make_decoder(false, false, false, decoder_path,
+ sizeof(decoder_path));
+ if (!ret)
+ ret = shirudo_upatch_maps_otel_send_file(decoder_path, &f.view,
+ SHIRUDO_OTEL_FORCE_LOG, &opts);
if (decoder_path[0])
unlink(decoder_path);
fixture_destroy(&f);
- return rc ? 1 : 0;
+ return ret ? 1 : 0;
}
static int print_record_size(void)
@@ -340,24 +340,24 @@ static int print_record_size(void)
char decoder_path[128] = {};
char *decoded = NULL;
size_t decoded_len = 0;
- int rc;
+ int ret;
- rc = fixture_init(&f, BPF_MAP_TYPE_PERCPU_ARRAY, false, true);
- if (rc)
+ ret = fixture_init(&f, BPF_MAP_TYPE_PERCPU_ARRAY, false, true);
+ if (ret)
return 1;
- rc = make_decoder(false, false, false, decoder_path,
- sizeof(decoder_path));
- if (!rc)
- rc = upatch_decode_map_file_otel(decoder_path, &f.view,
- &decoded, &decoded_len);
- if (!rc)
+ ret = make_decoder(false, false, false, decoder_path,
+ sizeof(decoder_path));
+ if (!ret)
+ ret = upatch_decode_map_file_otel(decoder_path, &f.view,
+ &decoded, &decoded_len);
+ if (!ret)
printf("%zu\n", decoded_len);
if (decoded)
xfree(decoded, decoded_len + 1);
if (decoder_path[0])
unlink(decoder_path);
fixture_destroy(&f);
- return rc != 0;
+ return ret != 0;
}
static int send_auto(const char *base, bool is_signed)
@@ -365,19 +365,19 @@ static int send_auto(const char *base, bool is_signed)
struct shirudo_otel_opts opts = { .endpoint = base, .retries = 0 };
struct fixture f;
char decoder_path[128] = {};
- int rc;
+ int ret;
if (fixture_init(&f, BPF_MAP_TYPE_PERCPU_ARRAY, is_signed, true))
return 1;
- rc = make_decoder(!is_signed, !is_signed, false, decoder_path,
- sizeof(decoder_path));
- if (!rc)
- rc = shirudo_upatch_maps_otel_send_file(decoder_path, &f.view,
- SHIRUDO_OTEL_AUTO, &opts);
+ ret = make_decoder(!is_signed, !is_signed, false, decoder_path,
+ sizeof(decoder_path));
+ if (!ret)
+ ret = shirudo_upatch_maps_otel_send_file(decoder_path, &f.view,
+ SHIRUDO_OTEL_AUTO, &opts);
if (decoder_path[0])
unlink(decoder_path);
fixture_destroy(&f);
- return rc ? 1 : 0;
+ return ret ? 1 : 0;
}
static int send_metric(const char *url)
@@ -388,19 +388,19 @@ static int send_metric(const char *url)
};
struct fixture f;
char decoder_path[128] = {};
- int rc;
+ int ret;
if (fixture_init(&f, BPF_MAP_TYPE_PERCPU_ARRAY, false, true))
return 1;
- rc = make_decoder(true, false, false, decoder_path,
- sizeof(decoder_path));
- if (!rc)
- rc = shirudo_upatch_maps_otel_send_file(decoder_path, &f.view,
- SHIRUDO_OTEL_FORCE_METRIC, &opts);
+ ret = make_decoder(true, false, false, decoder_path,
+ sizeof(decoder_path));
+ if (!ret)
+ ret = shirudo_upatch_maps_otel_send_file(decoder_path, &f.view,
+ SHIRUDO_OTEL_FORCE_METRIC, &opts);
if (decoder_path[0])
unlink(decoder_path);
fixture_destroy(&f);
- return rc ? 1 : 0;
+ return ret ? 1 : 0;
}
static int send_status(const char *url, const char *status)
@@ -432,20 +432,20 @@ static int send_metric_env(void)
};
struct fixture f;
char decoder_path[128] = {};
- int rc;
+ int ret;
- rc = fixture_init(&f, BPF_MAP_TYPE_PERCPU_ARRAY, false, true);
- if (rc)
+ ret = fixture_init(&f, BPF_MAP_TYPE_PERCPU_ARRAY, false, true);
+ if (ret)
return 1;
- rc = make_decoder(true, false, false, decoder_path,
- sizeof(decoder_path));
- if (!rc)
- rc = shirudo_upatch_maps_otel_send_file(decoder_path, &f.view,
- SHIRUDO_OTEL_FORCE_METRIC, &opts);
+ ret = make_decoder(true, false, false, decoder_path,
+ sizeof(decoder_path));
+ if (!ret)
+ ret = shirudo_upatch_maps_otel_send_file(decoder_path, &f.view,
+ SHIRUDO_OTEL_FORCE_METRIC, &opts);
if (decoder_path[0])
unlink(decoder_path);
fixture_destroy(&f);
- return rc != 0;
+ return ret != 0;
}
static bool large_serialized_fixture(struct fixture *f)
@@ -501,12 +501,12 @@ static int send_s3(const char *endpoint, __u32 retries, bool large)
};
struct fixture f;
char decoder_path[128] = {};
- int rc;
+ int ret;
if (setenv("AWS_ENDPOINT_URL_S3", endpoint, 1) != 0)
return 1;
- rc = fixture_init(&f, BPF_MAP_TYPE_PERCPU_ARRAY, false, true);
- if (rc)
+ ret = fixture_init(&f, BPF_MAP_TYPE_PERCPU_ARRAY, false, true);
+ if (ret)
return 1;
if (large) {
if (!large_serialized_fixture(&f)) {
@@ -515,16 +515,16 @@ static int send_s3(const char *endpoint, __u32 retries, bool large)
return 1;
}
}
- rc = make_decoder(false, false, true, decoder_path,
- sizeof(decoder_path));
- if (!rc)
- rc = shirudo_upatch_maps_otel_send_file(decoder_path, &f.view,
- SHIRUDO_OTEL_S3, &opts);
+ ret = make_decoder(false, false, true, decoder_path,
+ sizeof(decoder_path));
+ if (!ret)
+ ret = shirudo_upatch_maps_otel_send_file(decoder_path, &f.view,
+ SHIRUDO_OTEL_S3, &opts);
if (decoder_path[0])
unlink(decoder_path);
large_serialized_destroy(&f);
fixture_destroy(&f);
- return rc ? 1 : 0;
+ return ret ? 1 : 0;
}
static int tenant_validation(void)
@@ -534,31 +534,31 @@ static int tenant_validation(void)
.retries = 0,
};
struct fixture f;
- int rc, failed = 0;
+ int ret, failed = 0;
if (fixture_init(&f, BPF_MAP_TYPE_PERCPU_ARRAY, false, true))
return 1;
opts.tenant_id = "bad tenant";
- rc = shirudo_upatch_maps_otel_send(&f.view, SHIRUDO_OTEL_FORCE_LOG,
- &opts);
- failed += rc != -EINVAL;
+ ret = shirudo_upatch_maps_otel_send(&f.view, SHIRUDO_OTEL_FORCE_LOG,
+ &opts);
+ failed += ret != -EINVAL;
opts.tenant_id = NULL;
setenv("OTEL_EXPORTER_OTLP_LOGS_HEADERS",
"X-Tenant-ID=bad%20tenant", 1);
- rc = shirudo_upatch_maps_otel_send(&f.view, SHIRUDO_OTEL_FORCE_LOG,
- &opts);
- failed += rc != -EINVAL;
+ ret = shirudo_upatch_maps_otel_send(&f.view, SHIRUDO_OTEL_FORCE_LOG,
+ &opts);
+ failed += ret != -EINVAL;
setenv("OTEL_EXPORTER_OTLP_LOGS_HEADERS",
"X-Tenant-ID=one,x-tenant-id=two", 1);
- rc = shirudo_upatch_maps_otel_send(&f.view, SHIRUDO_OTEL_FORCE_LOG,
- &opts);
- failed += rc != -EINVAL;
+ ret = shirudo_upatch_maps_otel_send(&f.view, SHIRUDO_OTEL_FORCE_LOG,
+ &opts);
+ failed += ret != -EINVAL;
opts.tenant_id = "tenant-cli-1234";
setenv("OTEL_EXPORTER_OTLP_LOGS_HEADERS",
"X-Tenant-ID=ignored%20invalid", 1);
- rc = shirudo_upatch_maps_otel_send(&f.view, SHIRUDO_OTEL_FORCE_LOG,
- &opts);
- failed += rc == -EINVAL;
+ ret = shirudo_upatch_maps_otel_send(&f.view, SHIRUDO_OTEL_FORCE_LOG,
+ &opts);
+ failed += ret == -EINVAL;
unsetenv("OTEL_EXPORTER_OTLP_LOGS_HEADERS");
fixture_destroy(&f);
return failed ? 1 : 0;
@@ -571,7 +571,7 @@ static int s3_validation(void)
.retries = 0,
};
struct fixture f;
- int rc;
+ int ret;
if (fixture_init(&f, BPF_MAP_TYPE_PERCPU_ARRAY, false, true))
return 1;
@@ -582,51 +582,51 @@ static int s3_validation(void)
unsetenv("AWS_SECRET_ACCESS_KEY");
unsetenv("AWS_SESSION_TOKEN");
unsetenv("AWS_CA_BUNDLE");
- rc = shirudo_upatch_maps_otel_send(&f.view, SHIRUDO_OTEL_S3, &opts);
- if (rc != -EACCES)
+ ret = shirudo_upatch_maps_otel_send(&f.view, SHIRUDO_OTEL_S3, &opts);
+ if (ret != -EACCES)
goto fail;
setenv("AWS_ACCESS_KEY_ID", "test", 1);
setenv("AWS_SECRET_ACCESS_KEY", "bad\nsecret", 1);
- rc = shirudo_upatch_maps_otel_send(&f.view, SHIRUDO_OTEL_S3, &opts);
- if (rc != -EACCES)
+ ret = shirudo_upatch_maps_otel_send(&f.view, SHIRUDO_OTEL_S3, &opts);
+ if (ret != -EACCES)
goto fail;
setenv("AWS_SECRET_ACCESS_KEY", "secret", 1);
setenv("AWS_ACCESS_KEY_ID", "bad:key", 1);
- rc = shirudo_upatch_maps_otel_send(&f.view, SHIRUDO_OTEL_S3, &opts);
- if (rc != -EACCES)
+ ret = shirudo_upatch_maps_otel_send(&f.view, SHIRUDO_OTEL_S3, &opts);
+ if (ret != -EACCES)
goto fail;
setenv("AWS_ACCESS_KEY_ID", "test", 1);
setenv("AWS_REGION", "not_a_region", 1);
- rc = shirudo_upatch_maps_otel_send(&f.view, SHIRUDO_OTEL_S3, &opts);
- if (rc != -EINVAL)
+ ret = shirudo_upatch_maps_otel_send(&f.view, SHIRUDO_OTEL_S3, &opts);
+ if (ret != -EINVAL)
goto fail;
unsetenv("AWS_REGION");
opts.s3_uri = "s3://test-bucket/../escape";
- rc = shirudo_upatch_maps_otel_send(&f.view, SHIRUDO_OTEL_S3, &opts);
- if (rc != -EINVAL)
+ ret = shirudo_upatch_maps_otel_send(&f.view, SHIRUDO_OTEL_S3, &opts);
+ if (ret != -EINVAL)
goto fail;
opts.s3_uri = "s3://test-bucket/prefix?query";
- rc = shirudo_upatch_maps_otel_send(&f.view, SHIRUDO_OTEL_S3, &opts);
- if (rc != -EINVAL)
+ ret = shirudo_upatch_maps_otel_send(&f.view, SHIRUDO_OTEL_S3, &opts);
+ if (ret != -EINVAL)
goto fail;
opts.s3_uri = "s3://BAD_BUCKET/prefix";
- rc = shirudo_upatch_maps_otel_send(&f.view, SHIRUDO_OTEL_S3, &opts);
- if (rc != -EINVAL)
+ ret = shirudo_upatch_maps_otel_send(&f.view, SHIRUDO_OTEL_S3, &opts);
+ if (ret != -EINVAL)
goto fail;
opts.s3_uri = "s3://test-bucket/prefix";
f.view.truncated = true;
- rc = shirudo_upatch_maps_otel_send(&f.view, SHIRUDO_OTEL_S3, &opts);
+ ret = shirudo_upatch_maps_otel_send(&f.view, SHIRUDO_OTEL_S3, &opts);
f.view.truncated = false;
- if (rc != -E2BIG)
+ if (ret != -E2BIG)
goto fail;
f.view.skipped = true;
- rc = shirudo_upatch_maps_otel_send(&f.view, SHIRUDO_OTEL_S3, &opts);
+ ret = shirudo_upatch_maps_otel_send(&f.view, SHIRUDO_OTEL_S3, &opts);
f.view.skipped = false;
- if (rc != -EOPNOTSUPP)
+ if (ret != -EOPNOTSUPP)
goto fail;
setenv("AWS_ENDPOINT_URL_S3", "http://storage.example", 1);
- rc = shirudo_upatch_maps_otel_send(&f.view, SHIRUDO_OTEL_S3, &opts);
- if (rc != -EPERM)
+ ret = shirudo_upatch_maps_otel_send(&f.view, SHIRUDO_OTEL_S3, &opts);
+ if (ret != -EPERM)
goto fail;
fixture_destroy(&f);
return 0;
@@ -642,14 +642,14 @@ static int security_check(void)
.retries = 0,
};
struct fixture f;
- int rc;
+ int ret;
if (fixture_init(&f, BPF_MAP_TYPE_PERCPU_ARRAY, false, true))
return 1;
- rc = shirudo_upatch_maps_otel_send(&f.view, SHIRUDO_OTEL_FORCE_LOG,
- &opts);
+ ret = shirudo_upatch_maps_otel_send(&f.view, SHIRUDO_OTEL_FORCE_LOG,
+ &opts);
fixture_destroy(&f);
- return rc != -EPERM;
+ return ret != -EPERM;
}
int main(int argc, char **argv)
@@ -670,11 +670,11 @@ int main(int argc, char **argv)
if (argc == 4 && strcmp(argv[1], "retry-after") == 0) {
__u64 seconds;
time_t now = (time_t)strtoll(argv[3], NULL, 10);
- int rc = shirudo_otel_retry_after(argv[2], now, &seconds);
+ int ret = shirudo_otel_retry_after(argv[2], now, &seconds);
- if (!rc)
+ if (!ret)
printf("%llu\n", seconds);
- return rc != 0;
+ return ret != 0;
}
if (argc < 2)
return 2;
diff --git a/testing/helper/test-register.c b/testing/helper/test-register.c
index 475d1042..b8157985 100644
--- a/testing/helper/test-register.c
+++ b/testing/helper/test-register.c
@@ -35,26 +35,26 @@ static int writer_create(void)
{
struct bpf_map_create_opts opts = { .sz = sizeof(opts) };
struct shirudo_identity id = {};
- int fd, rc;
+ int fd, ret;
__u32 zero = 0;
- rc = nv_writer_create(id.nv_writer_seed, id.nv_writer_public);
- if (rc)
+ ret = nv_writer_create(id.nv_writer_seed, id.nv_writer_public);
+ if (ret)
goto out;
fd = bpf_map_create(BPF_MAP_TYPE_ARRAY, "shirudo_test_id", sizeof(zero),
sizeof(id), 1, &opts);
if (fd < 0) {
- rc = -errno;
+ ret = -errno;
goto out;
}
if (bpf_map_update_elem(fd, &zero, &id, BPF_ANY) ||
bpf_map_freeze(fd) || bpf_obj_pin(fd, IDENTITY_PIN))
- rc = -errno;
+ ret = -errno;
close(fd);
- if (!rc)
+ if (!ret)
return 0;
out:
- fprintf(stderr, "TPM writer setup: %s\n", strerror(-rc));
+ fprintf(stderr, "TPM writer setup: %s\n", strerror(-ret));
return 1;
}
@@ -188,7 +188,7 @@ static int append_tree(__s64 seq, const char *op, const char *id,
int main(int argc, char **argv)
{
__u8 event[32], chain[32];
- int rc;
+ int ret;
if (argc < 2)
return 2;
@@ -212,9 +212,9 @@ int main(int argc, char **argv)
if (hex_decode(argv[2], event, 32))
return 2;
- rc = chain_init(event, &info);
- printf("rc=%d\n", rc);
- if (rc)
+ ret = chain_init(event, &info);
+ printf("rc=%d\n", ret);
+ if (ret)
return 1;
printf("reused=%d\n", info.reused);
printf("reset_count=%u\n", info.reset_count);
@@ -239,9 +239,9 @@ int main(int argc, char **argv)
return 2;
chain_upatch_event("shirudo-upatch", argv[2], payload,
event);
- rc = chain_extend(event, chain);
- printf("rc=%d\n", rc);
- if (rc)
+ ret = chain_extend(event, chain);
+ printf("rc=%d\n", ret);
+ if (ret)
return 1;
printf("value=");
puthex(chain, 32);
@@ -257,9 +257,9 @@ int main(int argc, char **argv)
hex_decode(argv[5] + 7, operation, 32))
return 2;
chain_tree_event(seq, operation, event);
- rc = chain_extend(event, chain);
- printf("rc=%d\n", rc);
- if (rc)
+ ret = chain_extend(event, chain);
+ printf("rc=%d\n", ret);
+ if (ret)
return 1;
printf("value=");
puthex(chain, 32);
@@ -269,18 +269,18 @@ int main(int argc, char **argv)
if (strcmp(argv[1], "extend-raw") == 0 && argc == 3) {
if (hex_decode(argv[2], event, 32))
return 2;
- rc = chain_extend(event, chain);
- printf("rc=%d\n", rc);
- if (rc)
+ ret = chain_extend(event, chain);
+ printf("rc=%d\n", ret);
+ if (ret)
return 1;
printf("value=");
puthex(chain, 32);
return 0;
}
if (strcmp(argv[1], "read") == 0) {
- rc = chain_read(chain);
- printf("rc=%d\n", rc);
- if (rc)
+ ret = chain_read(chain);
+ printf("rc=%d\n", ret);
+ if (ret)
return 1;
printf("value=");
puthex(chain, 32);
@@ -289,8 +289,8 @@ int main(int argc, char **argv)
if (strcmp(argv[1], "status") == 0) {
struct chain_status st;
- rc = chain_status(&st);
- printf("rc=%d\n", rc);
+ ret = chain_status(&st);
+ printf("rc=%d\n", ret);
printf("tpm=%d defined=%d written=%d logged=%d anchored=%d\n",
st.tpm, st.defined, st.written, st.logged, st.anchored);
printf("rebound=%d\n", st.rebound);
@@ -298,7 +298,7 @@ int main(int argc, char **argv)
printf("value=");
puthex(st.value, 32);
}
- return rc ? 1 : 0;
+ return ret ? 1 : 0;
}
/* A measurement into a PCR, as systemd's boot phases make them. */
if (strcmp(argv[1], "pcr-extend") == 0 && argc == 4) {
@@ -307,10 +307,10 @@ int main(int argc, char **argv)
if (hex_decode(argv[3], d, 32) || tpm_open(&tpm))
return 2;
- rc = tpm_pcr_extend(tpm, (__u32)atoi(argv[2]), d);
+ ret = tpm_pcr_extend(tpm, (__u32)atoi(argv[2]), d);
tpm_close(tpm);
- printf("rc=%d\n", rc);
- return rc ? 1 : 0;
+ printf("rc=%d\n", ret);
+ return ret ? 1 : 0;
}
if (strcmp(argv[1], "pcr") == 0 && argc == 3) {
struct shirudo_tpm *tpm = NULL;
@@ -318,9 +318,9 @@ int main(int argc, char **argv)
if (tpm_open(&tpm))
return 1;
- rc = tpm_pcr_read(tpm, (__u32)atoi(argv[2]), v);
+ ret = tpm_pcr_read(tpm, (__u32)atoi(argv[2]), v);
tpm_close(tpm);
- if (rc)
+ if (ret)
return 1;
puthex(v, 32);
return 0;
@@ -335,9 +335,9 @@ int main(int argc, char **argv)
if (tpm_open(&tpm))
return 1;
- rc = tpm_ek_create(tpm, strcmp(argv[2], "rsa") == 0,
- &ek);
- if (!rc) {
+ ret = tpm_ek_create(tpm, strcmp(argv[2], "rsa") == 0,
+ &ek);
+ if (!ret) {
printf("public=");
puthex(ek.public, ek.public_len);
printf("name=");
@@ -345,8 +345,8 @@ int main(int argc, char **argv)
tpm_key_flush(tpm, &ek);
}
tpm_close(tpm);
- printf("rc=%d\n", rc);
- return rc ? 1 : 0;
+ printf("rc=%d\n", ret);
+ return ret ? 1 : 0;
}
/* The attack: recreate the index with the same public area. */
if (strcmp(argv[1], "recreate") == 0) {
@@ -355,18 +355,18 @@ int main(int argc, char **argv)
if (tpm_open(&tpm))
return 1;
- rc = tpm_nv_info(tpm, NV_INDEX, &nv);
- if (!rc && nv.defined)
- rc = tpm_nv_undefine(tpm, NV_INDEX,
- NULL, 0);
- if (!rc)
- rc = tpm_nv_define(tpm, NV_INDEX,
- nv.policy, NULL, 0);
- if (!rc)
- rc = tpm_nv_info(tpm, NV_INDEX, &nv);
+ ret = tpm_nv_info(tpm, NV_INDEX, &nv);
+ if (!ret && nv.defined)
+ ret = tpm_nv_undefine(tpm, NV_INDEX,
+ NULL, 0);
+ if (!ret)
+ ret = tpm_nv_define(tpm, NV_INDEX,
+ nv.policy, NULL, 0);
+ if (!ret)
+ ret = tpm_nv_info(tpm, NV_INDEX, &nv);
tpm_close(tpm);
- printf("rc=%d\n", rc);
- if (rc)
+ printf("rc=%d\n", ret);
+ if (ret)
return 1;
printf("written=%d\nname=", nv.written);
puthex(nv.name, nv.name_len);
@@ -387,23 +387,23 @@ int main(int argc, char **argv)
return 2;
memcpy(values, rec.pcr_before, 32);
memcpy(values + 32, rec.phase_before, 32);
- rc = tpm_register_policy(CHAIN_PCR_MASK, values, 2,
- rec.writer_public, branch_written, branch_init, policy);
- if (rc) {
- fprintf(stderr, "register policy: %s\n", strerror(-rc));
+ ret = tpm_register_policy(CHAIN_PCR_MASK, values, 2,
+ rec.writer_public, branch_written, branch_init, policy);
+ if (ret) {
+ fprintf(stderr, "register policy: %s\n", strerror(-ret));
return 1;
}
if (tpm_open(&tpm))
return 1;
- rc = tpm_nv_set_writer(tpm, writer_seed, writer_public);
- if (!rc)
- rc = tpm_nv_extend_first(tpm, NV_INDEX,
- CHAIN_PCR_MASK,
- branch_written, branch_init,
- event);
+ ret = tpm_nv_set_writer(tpm, writer_seed, writer_public);
+ if (!ret)
+ ret = tpm_nv_extend_first(tpm, NV_INDEX,
+ CHAIN_PCR_MASK,
+ branch_written, branch_init,
+ event);
tpm_close(tpm);
- printf("rc=%d\n", rc);
- return rc ? 1 : 0;
+ printf("rc=%d\n", ret);
+ return ret ? 1 : 0;
}
/*
* The attack: a register of the target's own at another handle,
@@ -444,54 +444,54 @@ int main(int argc, char **argv)
return 1;
if (tpm_open(&tpm))
return 1;
- rc = tpm_nv_set_writer(tpm, writer_seed, writer_public);
- if (!rc)
- rc = tpm_reset_count(tpm, &reset);
- if (!rc)
- rc = tpm_pcr_read(tpm, pcr, before);
- if (!rc)
- rc = tpm_pcr_read(tpm, phase, before + 32);
- if (!rc)
- rc = tpm_register_policy(mask, before, 2, writer_public,
- branch_written, branch_init, policy);
- if (!rc)
- rc = tpm_nv_define(tpm, index, policy, NULL, 0);
- if (!rc)
- rc = tpm_nv_extend_first(tpm, index, mask,
- branch_written, branch_init,
- event);
- if (!rc)
- rc = tpm_nv_info(tpm, index, &nv);
- if (!rc)
- rc = chain_anchor(nv.name, anchor, sizeof(anchor));
- if (!rc) {
+ ret = tpm_nv_set_writer(tpm, writer_seed, writer_public);
+ if (!ret)
+ ret = tpm_reset_count(tpm, &reset);
+ if (!ret)
+ ret = tpm_pcr_read(tpm, pcr, before);
+ if (!ret)
+ ret = tpm_pcr_read(tpm, phase, before + 32);
+ if (!ret)
+ ret = tpm_register_policy(mask, before, 2, writer_public,
+ branch_written, branch_init, policy);
+ if (!ret)
+ ret = tpm_nv_define(tpm, index, policy, NULL, 0);
+ if (!ret)
+ ret = tpm_nv_extend_first(tpm, index, mask,
+ branch_written, branch_init,
+ event);
+ if (!ret)
+ ret = tpm_nv_info(tpm, index, &nv);
+ if (!ret)
+ ret = chain_anchor(nv.name, anchor, sizeof(anchor));
+ if (!ret) {
shirudo_sha256(anchor, strlen(anchor), anchor_digest);
- rc = tpm_pcr_extend(tpm, pcr, anchor_digest);
+ ret = tpm_pcr_extend(tpm, pcr, anchor_digest);
}
- if (!rc)
- rc = tpm_nv_read(tpm, index, value);
- if (!rc)
- rc = tpm_ak_create(tpm, &ak);
- if (!rc)
- rc = tpm_ek_create(tpm, false, &ek);
- for (i = 0; !rc && i < 24; i++) {
+ if (!ret)
+ ret = tpm_nv_read(tpm, index, value);
+ if (!ret)
+ ret = tpm_ak_create(tpm, &ak);
+ if (!ret)
+ ret = tpm_ek_create(tpm, false, &ek);
+ for (i = 0; !ret && i < 24; i++) {
if (quoted & (1u << i))
- rc = tpm_pcr_read(tpm, i, values[i]);
+ ret = tpm_pcr_read(tpm, i, values[i]);
}
- if (!rc)
- rc = tpm_quote(tpm, &ak, nonce, nonce_len, quoted,
- &quote);
- if (!rc)
- rc = tpm_nv_certify(tpm, &ak, index, nonce, nonce_len,
- &certify);
+ if (!ret)
+ ret = tpm_quote(tpm, &ak, nonce, nonce_len, quoted,
+ &quote);
+ if (!ret)
+ ret = tpm_nv_certify(tpm, &ak, index, nonce, nonce_len,
+ &certify);
/* Flushing scrubs the key; keep the public parts. */
memcpy(&ak_copy, &ak, sizeof(ak_copy));
memcpy(&ek_copy, &ek, sizeof(ek_copy));
tpm_key_flush(tpm, &ek);
tpm_key_flush(tpm, &ak);
tpm_close(tpm);
- if (rc) {
- printf("rc=%d\n", rc);
+ if (ret) {
+ printf("rc=%d\n", ret);
return 1;
}
@@ -606,12 +606,12 @@ int main(int argc, char **argv)
fprintf(stderr, "evidence: bad challenge\n");
return 2;
}
- rc = shirudo_attest_evidence_config(nonce, nonce_len,
- ATTEST_PCR_DEFAULT,
- argc == 4 ? &challenge : NULL,
- NULL, &doc, &len, &cap);
- if (rc) {
- fprintf(stderr, "evidence: %s\n", strerror(-rc));
+ ret = shirudo_attest_evidence_config(nonce, nonce_len,
+ ATTEST_PCR_DEFAULT,
+ argc == 4 ? &challenge : NULL,
+ NULL, &doc, &len, &cap);
+ if (ret) {
+ fprintf(stderr, "evidence: %s\n", strerror(-ret));
return 1;
}
fwrite(doc, 1, len, stdout);
diff --git a/testing/helper/test-seal.c b/testing/helper/test-seal.c
index f4277ae1..188def62 100644
--- a/testing/helper/test-seal.c
+++ b/testing/helper/test-seal.c
@@ -19,15 +19,15 @@
static int append(const char *path, const char *text)
{
- int fd, rc;
+ int fd, ret;
fd = seal_open(path, O_WRONLY | O_CREAT | O_APPEND, 0600);
if (fd < 0)
return fd;
- rc = write_complete(fd, text, strlen(text));
- if (close(fd) && !rc)
- rc = -errno;
- return rc;
+ ret = write_complete(fd, text, strlen(text));
+ if (close(fd) && !ret)
+ ret = -errno;
+ return ret;
}
/* The label an inode carries, or none, without following a link. */
@@ -47,7 +47,7 @@ static void show_label(const char *path)
int main(int argc, char **argv)
{
- int rc;
+ int ret;
if (argc < 3) {
fprintf(stderr, "usage: %s label|mkdir|open|write|inherit|get "
@@ -59,20 +59,20 @@ int main(int argc, char **argv)
return 0;
}
if (strcmp(argv[1], "label") == 0) {
- rc = seal_label(argv[2]);
+ ret = seal_label(argv[2]);
} else if (strcmp(argv[1], "mkdir") == 0) {
- rc = seal_mkdir_p(argv[2], 0700);
+ ret = seal_mkdir_p(argv[2], 0700);
} else if (strcmp(argv[1], "open") == 0 && argc == 4) {
- rc = append(argv[2], argv[3]);
+ ret = append(argv[2], argv[3]);
} else if (strcmp(argv[1], "write") == 0 && argc == 4) {
- rc = seal_write_file(argv[2], argv[3], strlen(argv[3]),
- 0600);
+ ret = seal_write_file(argv[2], argv[3], strlen(argv[3]),
+ 0600);
} else if (strcmp(argv[1], "inherit") == 0) {
- rc = seal_inherit_path(argv[2]);
+ ret = seal_inherit_path(argv[2]);
} else {
fprintf(stderr, "unknown subcommand\n");
return 2;
}
- printf("rc=%d\n", rc);
- return rc ? 1 : 0;
+ printf("rc=%d\n", ret);
+ return ret ? 1 : 0;
}
diff --git a/testing/helper/test-tpm-preopened.c b/testing/helper/test-tpm-preopened.c
index 1058e7dc..30ebfbed 100644
--- a/testing/helper/test-tpm-preopened.c
+++ b/testing/helper/test-tpm-preopened.c
@@ -14,13 +14,13 @@
static int read_register(__u8 out[TPM_DIGEST_LEN])
{
struct shirudo_tpm *tpm = NULL;
- int rc;
+ int ret;
if (tpm_open(&tpm))
return 1;
- rc = tpm_nv_read(tpm, NV_INDEX, out);
+ ret = tpm_nv_read(tpm, NV_INDEX, out);
tpm_close(tpm);
- return rc != 0;
+ return ret != 0;
}
static int write_extend(int fd)
@@ -64,10 +64,10 @@ int main(void)
return 1;
}
if (!pid) {
- int rc = write_extend(fd);
+ int ret = write_extend(fd);
close(fd);
- _exit(rc);
+ _exit(ret);
}
close(fd);
if (waitpid(pid, &status, 0) != pid || !WIFEXITED(status) ||
diff --git a/testing/helper/test-tpm-wire.c b/testing/helper/test-tpm-wire.c
index 7fc8fe42..a639036b 100644
--- a/testing/helper/test-tpm-wire.c
+++ b/testing/helper/test-tpm-wire.c
@@ -158,13 +158,13 @@ int main(int argc, char **argv)
}
if (strcmp(argv[1], "ecc-public") == 0 && argc == 3) {
struct shirudo_tpm_ecc_public pub;
- int rc;
+ int ret;
if (gethex(argv[2], buf, sizeof(buf), &len))
return 2;
- rc = tpm_ecc_public_parse(buf, len, &pub);
- printf("rc=%d\n", rc);
- if (rc)
+ ret = tpm_ecc_public_parse(buf, len, &pub);
+ printf("rc=%d\n", ret);
+ if (ret)
return 0;
printf("attrs=0x%08x scheme=0x%04x hash=0x%04x curve=0x%04x\n",
pub.attrs, pub.scheme, pub.hash, pub.curve);
@@ -176,13 +176,13 @@ int main(int argc, char **argv)
struct shirudo_tpm_public pub;
__u8 again[512];
size_t again_len = 0;
- int rc;
+ int ret;
if (gethex(argv[2], buf, sizeof(buf), &len))
return 2;
- rc = tpm_public_parse(buf, len, &pub);
- printf("rc=%d\n", rc);
- if (rc)
+ ret = tpm_public_parse(buf, len, &pub);
+ printf("rc=%d\n", ret);
+ if (ret)
return 0;
printf("type=0x%04x attrs=0x%08x policy_len=%zu sym=0x%04x/%u/0x%04x "
"scheme=0x%04x/0x%04x curve=0x%04x rsa_bits=%u exponent=%u "
@@ -190,10 +190,10 @@ int main(int argc, char **argv)
pub.sym_alg, pub.sym_bits, pub.sym_mode, pub.scheme,
pub.scheme_hash, pub.curve, pub.rsa_bits,
pub.rsa_exponent, pub.n_len);
- rc = tpm_public_marshal(&pub, again, sizeof(again),
- &again_len);
- printf("marshal_rc=%d same=%d\n", rc,
- rc == 0 && again_len == len && !memcmp(again, buf, len));
+ ret = tpm_public_marshal(&pub, again, sizeof(again),
+ &again_len);
+ printf("marshal_rc=%d same=%d\n", ret,
+ ret == 0 && again_len == len && !memcmp(again, buf, len));
return 0;
}
if (strcmp(argv[1], "kdfa") == 0 && argc == 6) {
@@ -243,13 +243,13 @@ int main(int argc, char **argv)
}
if (strcmp(argv[1], "signature") == 0 && argc == 3) {
__u8 r[32], s[32];
- int rc;
+ int ret;
if (gethex(argv[2], buf, sizeof(buf), &len))
return 2;
- rc = tpm_ecdsa_signature_parse(buf, len, r, s);
- printf("rc=%d\n", rc);
- if (rc)
+ ret = tpm_ecdsa_signature_parse(buf, len, r, s);
+ printf("rc=%d\n", ret);
+ if (ret)
return 0;
puthex(r, 32);
puthex(s, 32);
@@ -257,13 +257,13 @@ int main(int argc, char **argv)
}
if (strcmp(argv[1], "attest") == 0 && argc == 3) {
struct shirudo_tpm_attest at;
- int rc;
+ int ret;
if (gethex(argv[2], buf, sizeof(buf), &len))
return 2;
- rc = tpm_attest_parse(buf, len, &at);
- printf("rc=%d\n", rc);
- if (rc)
+ ret = tpm_attest_parse(buf, len, &at);
+ printf("rc=%d\n", ret);
+ if (ret)
return 0;
printf("type=0x%04x reset=%u restart=%u safe=%d\n", at.type,
at.reset_count, at.restart_count, at.safe);
diff --git a/testing/helper/test-upatch-decode.c b/testing/helper/test-upatch-decode.c
index 294b8398..f33b5c38 100644
--- a/testing/helper/test-upatch-decode.c
+++ b/testing/helper/test-upatch-decode.c
@@ -21,14 +21,14 @@ static int dump_chunk(lua_State *L, const void *p, size_t sz, void *ud)
static int dump(const char *source)
{
lua_State *L = luaL_newstate();
- int rc = 1;
+ int ret = 1;
if (!L)
return 1;
if (!luaL_loadfile(L, source))
- rc = lua_dump(L, dump_chunk, stdout);
+ ret = lua_dump(L, dump_chunk, stdout);
lua_close(L);
- return rc ? 1 : 0;
+ return ret ? 1 : 0;
}
int main(int argc, char **argv)
@@ -40,7 +40,7 @@ int main(int argc, char **argv)
};
char *out = NULL;
size_t out_len = 0;
- int rc;
+ int ret;
if (argc == 3 && strcmp(argv[1], "dump") == 0)
return dump(argv[2]);
@@ -64,13 +64,13 @@ int main(int argc, char **argv)
else if (strcmp(argv[1], "loop") == 0)
view.serial_bytes_total = 999;
if (strcmp(argv[1], "otel") == 0)
- rc = upatch_decode_map_file_otel(argv[2], &view,
- &out, &out_len);
+ ret = upatch_decode_map_file_otel(argv[2], &view,
+ &out, &out_len);
else
- rc = upatch_decode_map_file_json(argv[2], &view,
- &out, &out_len);
- if (rc) {
- fprintf(stderr, "decode: %d\n", rc);
+ ret = upatch_decode_map_file_json(argv[2], &view,
+ &out, &out_len);
+ if (ret) {
+ fprintf(stderr, "decode: %d\n", ret);
return 1;
}
if (fwrite(out, 1, out_len, stdout) != out_len) {
diff --git a/testing/helper/test-upatch-prog-metadata.c b/testing/helper/test-upatch-prog-metadata.c
index 8c1d9a68..0a595688 100644
--- a/testing/helper/test-upatch-prog-metadata.c
+++ b/testing/helper/test-upatch-prog-metadata.c
@@ -164,53 +164,53 @@ int main(int argc, char **argv)
{
struct shirudo_upatch u;
const char *mode = "serializer";
- int rc;
+ int ret;
if (argc != 2 && argc != 3 && argc != 6)
return fail("usage: test-upatch-prog-metadata <file.upatch> [mode [path pattern count]]");
if (argc >= 3)
mode = argv[2];
- rc = upatch_open(argv[1], &u);
- if (rc)
+ ret = upatch_open(argv[1], &u);
+ if (ret)
return fail("open upatch failed");
if (strcmp(mode, "serializer") == 0) {
- rc = expect_serializer(&u);
+ ret = expect_serializer(&u);
} else if (strcmp(mode, "cgroup-ingress") == 0) {
- rc = expect_attach(&u,
- SHIRUDO_UPATCH_ATTACH_CGROUP_SKB_INGRESS,
- NULL, 0);
+ ret = expect_attach(&u,
+ SHIRUDO_UPATCH_ATTACH_CGROUP_SKB_INGRESS,
+ NULL, 0);
} else if (strcmp(mode, "cgroup-egress") == 0) {
- rc = expect_attach(&u,
- SHIRUDO_UPATCH_ATTACH_CGROUP_SKB_EGRESS,
- NULL, 0);
+ ret = expect_attach(&u,
+ SHIRUDO_UPATCH_ATTACH_CGROUP_SKB_EGRESS,
+ NULL, 0);
} else if (strcmp(mode, "kprobe-override") == 0) {
- rc = expect_attach(&u, SHIRUDO_UPATCH_ATTACH_KPROBE,
- "bpf_modify_return_test", 0);
+ ret = expect_attach(&u, SHIRUDO_UPATCH_ATTACH_KPROBE,
+ "bpf_modify_return_test", 0);
} else if (strcmp(mode, "fmod-ret") == 0) {
- rc = expect_attach(&u, SHIRUDO_UPATCH_ATTACH_FMOD_RET,
- NULL, 0);
+ ret = expect_attach(&u, SHIRUDO_UPATCH_ATTACH_FMOD_RET,
+ NULL, 0);
} else if (strcmp(mode, "netfilter-ipv6-pre-routing") == 0) {
- rc = expect_attach(&u,
- SHIRUDO_UPATCH_ATTACH_NETFILTER_IPV6_PRE_ROUTING,
- NULL, 0);
+ ret = expect_attach(&u,
+ SHIRUDO_UPATCH_ATTACH_NETFILTER_IPV6_PRE_ROUTING,
+ NULL, 0);
} else if (strcmp(mode, "uprobe-multi") == 0 && argc == 6) {
char *end = NULL;
__u64 count = strtoul(argv[5], &end, 10);
if (!end || *end || count > UINT32_MAX)
- rc = fail("invalid expected uprobe offset count");
+ ret = fail("invalid expected uprobe offset count");
else
- rc = expect_uprobe_multi(&u, argv[3], argv[4],
- (__u32)count);
+ ret = expect_uprobe_multi(&u, argv[3], argv[4],
+ (__u32)count);
} else {
- rc = fail("unknown metadata check mode");
+ ret = fail("unknown metadata check mode");
}
upatch_close(&u);
- if (rc)
- return rc;
+ if (ret)
+ return ret;
puts("ok");
return 0;
}
diff --git a/testing/helper/test-upatch-rodata.c b/testing/helper/test-upatch-rodata.c
index 34edb04e..a8c360a7 100644
--- a/testing/helper/test-upatch-rodata.c
+++ b/testing/helper/test-upatch-rodata.c
@@ -14,7 +14,7 @@ static int name_into(size_t len, int ptrs, size_t cap)
char name[512], buf[512];
struct btf *btf;
size_t off = 0;
- int id, rc;
+ int id, ret;
if (len >= sizeof(name) || cap > sizeof(buf))
return 2;
@@ -33,13 +33,13 @@ static int name_into(size_t len, int ptrs, size_t cap)
btf__free(btf);
return 2;
}
- rc = append_type_name(btf, (__u32)id, buf, cap, &off, 0);
+ ret = append_type_name(btf, (__u32)id, buf, cap, &off, 0);
btf__free(btf);
- printf("rc=%d off=%zu terminated=%d\n", rc, off,
+ printf("rc=%d off=%zu terminated=%d\n", ret, off,
!!memchr(buf, '\0', cap));
if (!memchr(buf, '\0', cap))
return 1;
- return rc ? 3 : 0;
+ return ret ? 3 : 0;
}
int main(int argc, char **argv)
diff --git a/testing/helper/test-upatch-serializer-pages.c b/testing/helper/test-upatch-serializer-pages.c
index f232bc6f..75757d27 100644
--- a/testing/helper/test-upatch-serializer-pages.c
+++ b/testing/helper/test-upatch-serializer-pages.c
@@ -63,7 +63,7 @@ static int check_map_locks(void)
{
char dir[] = "/tmp/shirudo-serializer-lock-XXXXXX";
char path1[256], path2[256];
- int first = -1, busy = -1, other = -1, again = -1, rc = 1;
+ int first = -1, busy = -1, other = -1, again = -1, ret = 1;
if (!mkdtemp(dir))
return fail("mkdtemp failed");
@@ -89,7 +89,7 @@ static int check_map_locks(void)
fail("released serializer lock could not be reacquired");
goto out;
}
- rc = 0;
+ ret = 0;
out:
if (first >= 0)
close(first);
@@ -104,7 +104,7 @@ out:
unlink(path1);
unlink(path2);
rmdir(dir);
- return rc;
+ return ret;
}
int main(void)
diff --git a/testing/helper/tpmsim-cmd.c b/testing/helper/tpmsim-cmd.c
index a44dfad2..a2220c72 100644
--- a/testing/helper/tpmsim-cmd.c
+++ b/testing/helper/tpmsim-cmd.c
@@ -92,18 +92,18 @@ static int store_blob(const char *path, const __u8 *buf,
__u32 len)
{
char tmp[4096 + 8];
- int fd, rc;
+ int fd, ret;
snprintf(tmp, sizeof(tmp), "%s.tmp", path);
fd = open(tmp, O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC, 0600);
if (fd < 0)
return -1;
- rc = write_full(fd, buf, len);
+ ret = write_full(fd, buf, len);
if (close(fd) != 0)
- rc = -1;
- if (rc == 0)
- rc = rename(tmp, path);
- return rc;
+ ret = -1;
+ if (ret == 0)
+ ret = rename(tmp, path);
+ return ret;
}
static int process(__u8 **resp, __u32 *resp_size,
@@ -126,7 +126,7 @@ static int save_state(const char *dir)
};
char path[4096];
size_t i;
- int rc = 0;
+ int ret = 0;
for (i = 0; i < ARRAY_SIZE(blobs); i++) {
__u32 blob_len = 0;
@@ -134,15 +134,15 @@ static int save_state(const char *dir)
if (TPMLIB_GetState(blobs[i].type, &blob, &blob_len) !=
TPM_SUCCESS || !blob) {
- rc = -1;
+ ret = -1;
continue;
}
snprintf(path, sizeof(path), "%s/%s", dir, blobs[i].name);
if (store_blob(path, blob, blob_len) != 0)
- rc = -1;
+ ret = -1;
free(blob);
}
- return rc;
+ return ret;
}
int main(int argc, char **argv)
@@ -150,7 +150,7 @@ int main(int argc, char **argv)
__u8 *resp = NULL, *permanent = NULL, *vol = NULL;
__u32 resp_size = 0, resp_cap = 0, permanent_len, vol_len;
char path[4096];
- int rc = 0;
+ int ret = 0;
if (argc != 2) {
fprintf(stderr, "usage: tpmsim-cmd <state-dir>\n");
@@ -202,22 +202,22 @@ int main(int argc, char **argv)
if (len < 10 || len > sizeof(cmd) ||
(len > 10 && read_full(STDIN_FILENO, cmd + 10,
len - 10) != 0)) {
- rc = 1;
+ ret = 1;
break;
}
if (process(&resp, &resp_size, &resp_cap, cmd, len) != 0 ||
write_full(STDOUT_FILENO, resp, resp_size) != 0) {
- rc = 1;
+ ret = 1;
break;
}
}
if (save_state(".") != 0) {
fprintf(stderr, "tpmsim-cmd: saving TPM state failed\n");
- rc = 1;
+ ret = 1;
}
TPMLIB_Terminate();
free(resp);
free(permanent);
free(vol);
- return rc;
+ return ret;
}
diff --git a/testing/unit/kernel_abi.c b/testing/unit/kernel_abi.c
index f7130cef..e978f69f 100644
--- a/testing/unit/kernel_abi.c
+++ b/testing/unit/kernel_abi.c
@@ -37,7 +37,7 @@ static struct btf *make_fixture(enum fixture fixture)
int raw_u8, raw_u32, u8, u16, u32, s8, s32, index;
int sha32, sha31, sha_u16, sha_s8, byte_ptr, u32_ptr;
int sig_struct = -1;
- int rc;
+ int ret;
btf = btf__new_empty();
if (libbpf_get_error(btf))
@@ -62,8 +62,8 @@ static struct btf *make_fixture(enum fixture fixture)
goto err;
if (fixture != NO_MAP) {
- rc = btf__add_struct(btf, "bpf_map", 64);
- if (rc < 0)
+ ret = btf__add_struct(btf, "bpf_map", 64);
+ if (ret < 0)
goto err;
if (fixture != NO_SHA) {
int sha_type = sha32;
@@ -115,8 +115,8 @@ static struct btf *make_fixture(enum fixture fixture)
40, 0) < 0)
goto err;
}
- rc = btf__add_struct(btf, "bpf_prog_aux", 32);
- if (rc < 0)
+ ret = btf__add_struct(btf, "bpf_prog_aux", 32);
+ if (ret < 0)
goto err;
if (fixture != NO_SIG &&
btf__add_field(btf, "sig",
@@ -137,16 +137,16 @@ static void check(enum fixture fixture, int want_ok, const char *want)
{
char detail[KERNEL_ABI_DETAIL_MAX] = {};
struct btf *btf = make_fixture(fixture);
- int rc;
+ int ret;
ASSERT_TRUE(btf);
- rc = kernel_abi_validate_btf(btf, detail, sizeof(detail));
+ ret = kernel_abi_validate_btf(btf, detail, sizeof(detail));
btf__free(btf);
if (want_ok) {
- EXPECT_EQ(rc, 0);
+ EXPECT_EQ(ret, 0);
return;
}
- EXPECT_NE(rc, 0);
+ EXPECT_NE(ret, 0);
UNIT_CHECK(0, strstr(detail, want), "detail \"%s\" lacks \"%s\"",
detail, want);
}
diff --git a/testing/unit/string.c b/testing/unit/string.c
index 5b8f9d5f..8e5bae05 100644
--- a/testing/unit/string.c
+++ b/testing/unit/string.c
@@ -25,36 +25,36 @@ static char *span(const char *text, size_t len)
static int u64_of(const char *text, size_t len, __u64 max, __u64 *v)
{
char *buf = span(text, len);
- int rc;
+ int ret;
*v = 0;
- rc = parse_u64(buf, len, max, v);
+ ret = parse_u64(buf, len, max, v);
xfree(buf, len ? len : 1);
- return rc;
+ return ret;
}
static int x64_of(const char *text, __u64 max, __u64 *v)
{
size_t len = strlen(text);
char *buf = span(text, len);
- int rc;
+ int ret;
*v = 0;
- rc = parse_x64(buf, len, max, v);
+ ret = parse_x64(buf, len, max, v);
xfree(buf, len ? len : 1);
- return rc;
+ return ret;
}
static int s64_of(const char *text, __s64 min, __s64 max, __s64 *v)
{
size_t len = strlen(text);
char *buf = span(text, len);
- int rc;
+ int ret;
*v = 0;
- rc = parse_s64(buf, len, min, max, v);
+ ret = parse_s64(buf, len, min, max, v);
xfree(buf, len ? len : 1);
- return rc;
+ return ret;
}
static int u64_str(const char *text, __u64 max, __u64 *v)
@@ -62,11 +62,11 @@ static int u64_str(const char *text, __u64 max, __u64 *v)
return u64_of(text, strlen(text), max, v);
}
-#define EXPECT_U64(text, max, rc, value) \
+#define EXPECT_U64(text, max, ret, value) \
do { \
__u64 v_; \
\
- EXPECT_EQ(u64_str(text, max, &v_), rc); \
+ EXPECT_EQ(u64_str(text, max, &v_), ret); \
EXPECT_UEQ(v_, value); \
} while (0)
diff --git a/tools/shirudo-build/bpm-build.c b/tools/shirudo-build/bpm-build.c
index 34158588..0f2eaae8 100644
--- a/tools/shirudo-build/bpm-build.c
+++ b/tools/shirudo-build/bpm-build.c
@@ -104,10 +104,10 @@ static int build_read_file(const char *path, __u8 **out, size_t *len,
if (fd < 0)
return -errno;
if (fstat(fd, &st) || st.st_size < 0 || (uintmax_t)st.st_size > max) {
- int rc = errno ? -errno : -E2BIG;
+ int ret = errno ? -errno : -E2BIG;
close(fd);
- return rc;
+ return ret;
}
body = xmalloc((size_t)st.st_size + 1);
if (!body) {
@@ -119,11 +119,11 @@ static int build_read_file(const char *path, __u8 **out, size_t *len,
ssize_t got = read(fd, body + n, (size_t)st.st_size - (size_t)n);
if (got <= 0) {
- int rc = got < 0 ? -errno : -EIO;
+ int ret = got < 0 ? -errno : -EIO;
close(fd);
xfree(body, (size_t)st.st_size + 1);
- return rc;
+ return ret;
}
n += got;
}
@@ -623,7 +623,7 @@ int bpm_build_parse_beefile(const __u8 *body, size_t len,
struct bpm_build_spec *spec)
{
__u8 *scratch;
- int rc;
+ int ret;
if (!body || !spec || memchr(body, '\0', len))
return -EINVAL;
@@ -642,9 +642,9 @@ int bpm_build_parse_beefile(const __u8 *body, size_t len,
spec->build_file_len = len;
memcpy(scratch, body, len);
scratch[len] = '\0';
- rc = build_parse_spec(spec, (char *)scratch);
+ ret = build_parse_spec(spec, (char *)scratch);
xfree(scratch, len + 1);
- return rc;
+ return ret;
}
void bpm_build_spec_free(struct bpm_build_spec *spec)
@@ -810,15 +810,15 @@ static int build_rodata_apply(const struct bpm_build_spec *spec,
char input[PATH_MAX], generated[PATH_MAX], patched[PATH_MAX];
__u8 *value = NULL;
size_t value_len = 0;
- int rc;
+ int ret;
if (!selected)
return -EINVAL;
if (selected == rodata->input) {
- rc = build_resolve_source(spec, selected, input,
- sizeof(input), &(struct stat){});
- if (rc)
- return rc;
+ ret = build_resolve_source(spec, selected, input,
+ sizeof(input), &(struct stat){});
+ if (ret)
+ return ret;
} else if (strscpy(input, selected, sizeof(input)) < 0) {
return -ENAMETOOLONG;
}
@@ -829,29 +829,29 @@ static int build_rodata_apply(const struct bpm_build_spec *spec,
return -ENAMETOOLONG;
unlink(generated);
unlink(patched);
- rc = build_run_rodata_command(spec, rodata, update, input,
- generated);
- if (rc) {
+ ret = build_run_rodata_command(spec, rodata, update, input,
+ generated);
+ if (ret) {
pr_err("bpm %s: converter failed for .rodata symbol %s",
update ? "config update" : "build", rodata->symbol);
goto out;
}
- rc = build_read_file(generated, &value, &value_len,
- UPATCH_FILE_MAX);
- if (rc)
+ ret = build_read_file(generated, &value, &value_len,
+ UPATCH_FILE_MAX);
+ if (ret)
goto out;
- rc = shirudo_build_package_patch_rodata(load, patched,
- rodata->symbol, value,
- value_len, pkey, cert);
- if (!rc && rename(patched, load))
- rc = -errno;
+ ret = shirudo_build_package_patch_rodata(load, patched,
+ rodata->symbol, value,
+ value_len, pkey, cert);
+ if (!ret && rename(patched, load))
+ ret = -errno;
out:
if (value)
xfree(value, value_len + 1);
unlink(generated);
- if (rc) {
+ if (ret) {
unlink(patched);
- return rc;
+ return ret;
}
}
return 0;
@@ -1059,10 +1059,10 @@ static int build_stage_open(struct bpm_build_spec *spec)
if (!mkdtemp(spec->stage))
return -errno;
if (!realpath(spec->stage, resolved)) {
- int rc = -errno;
+ int ret = -errno;
rmdir(spec->stage);
- return rc;
+ return ret;
}
if (strscpy(spec->stage, resolved, sizeof(spec->stage)) < 0) {
rmdir(resolved);
@@ -1101,7 +1101,7 @@ static int build_remove_tree(const char *path)
struct dirent *entry;
struct stat st;
DIR *dir;
- int rc = 0;
+ int ret = 0;
if (lstat(path, &st))
return errno == ENOENT ? 0 : -errno;
@@ -1117,17 +1117,17 @@ static int build_remove_tree(const char *path)
continue;
if (strsprintf(child, sizeof(child), "%s/%s", path,
entry->d_name) < 0) {
- rc = -ENAMETOOLONG;
+ ret = -ENAMETOOLONG;
break;
}
- rc = build_remove_tree(child);
- if (rc)
+ ret = build_remove_tree(child);
+ if (ret)
break;
}
closedir(dir);
- if (!rc && rmdir(path))
- rc = -errno;
- return rc;
+ if (!ret && rmdir(path))
+ ret = -errno;
+ return ret;
}
static void build_stage_close(struct bpm_build_spec *spec)
@@ -1167,7 +1167,7 @@ static int build_upatches(struct bpm_build_spec *spec, const char *pkey,
const char *bpf_o = source, *src_path = NULL;
__u8 payload[CRYPTO_SHA256_LEN];
struct shirudo_upatch parsed = {};
- int rc;
+ int ret;
if (build_resolve_source(spec, u->source, source, sizeof(source),
&(struct stat){}))
@@ -1191,11 +1191,11 @@ static int build_upatches(struct bpm_build_spec *spec, const char *pkey,
}
if (strsprintf(object, sizeof(object), "%s.bpf.o", load) < 0)
return -ENAMETOOLONG;
- rc = shirudo_build_compile(source, object, vmlinux_h, NULL,
- shirudo_bpf_incdir);
- if (rc) {
+ ret = shirudo_build_compile(source, object, vmlinux_h, NULL,
+ shirudo_bpf_incdir);
+ if (ret) {
pr_err("bpm build: compile %s failed", u->source);
- return rc < 0 ? rc : -EIO;
+ return ret < 0 ? ret : -EIO;
}
bpf_o = object;
src_path = source;
@@ -1205,16 +1205,16 @@ static int build_upatches(struct bpm_build_spec *spec, const char *pkey,
return -EINVAL;
}
build_upatch_name(source, name, sizeof(name));
- rc = shirudo_build_package_load(bpf_o, src_path, load, name, pkey,
- cert);
+ ret = shirudo_build_package_load(bpf_o, src_path, load, name, pkey,
+ cert);
if (bpf_o == object)
unlink(object);
- if (rc)
- return rc < 0 ? rc : -EIO;
- rc = build_rodata_apply(spec, u, load, pkey, cert, overrides,
- n_overrides, update);
- if (rc)
- return rc;
+ if (ret)
+ return ret < 0 ? ret : -EIO;
+ ret = build_rodata_apply(spec, u, load, pkey, cert, overrides,
+ n_overrides, update);
+ if (ret)
+ return ret;
if (upatch_open(load, &parsed))
return -EINVAL;
if (upatch_is_unload(&parsed) || !parsed.hdr.name[0]) {
@@ -1228,10 +1228,10 @@ static int build_upatches(struct bpm_build_spec *spec, const char *pkey,
memcpy(payload, parsed.hdr.payload_sha256, sizeof(payload));
strscpy(u->type, upatch_type_str(&parsed), sizeof(u->type));
upatch_close(&parsed);
- rc = shirudo_build_package_unload(u->name, payload, unload, pkey,
- cert);
- if (rc)
- return rc < 0 ? rc : -EIO;
+ ret = shirudo_build_package_unload(u->name, payload, unload, pkey,
+ cert);
+ if (ret)
+ return ret < 0 ? ret : -EIO;
}
return 0;
}
@@ -1352,18 +1352,18 @@ static int tar_path(struct bpm_tar *tar, const char *name, const char *path)
__u8 *body;
size_t len;
struct stat st;
- int rc;
+ int ret;
if (stat(path, &st))
return -errno;
if (!S_ISREG(st.st_mode))
return -EINVAL;
- rc = build_read_file(path, &body, &len, BPM_BUILD_MAX_FILE);
- if (!rc) {
- rc = tar_entry(tar, name, body, len, st.st_mode, '0');
+ ret = build_read_file(path, &body, &len, BPM_BUILD_MAX_FILE);
+ if (!ret) {
+ ret = tar_entry(tar, name, body, len, st.st_mode, '0');
xfree(body, len + 1);
}
- return rc;
+ return ret;
}
static int build_archive(const struct bpm_build_spec *spec, const char *version,
@@ -1374,7 +1374,7 @@ static int build_archive(const struct bpm_build_spec *spec, const char *version,
size_t environment_len = 0, cert_len = 0;
__u8 *environment = NULL, *cert = NULL;
struct bpm_tar tar;
- int rc;
+ int ret;
if (strsprintf(top, sizeof(top), "%s-%s", spec->name, version) < 0 ||
strsprintf(output, sizeof(output), "%s/%s.bee", out_dir, top) < 0)
@@ -1392,82 +1392,82 @@ static int build_archive(const struct bpm_build_spec *spec, const char *version,
xfree(cert, cert_len + 1);
return -errno;
}
- rc = build_entry_name(name, sizeof(name), top, "");
- if (!rc)
- rc = tar_entry(&tar, name, NULL, 0, 0755, '5');
- if (!rc) {
- rc = build_entry_name(name, sizeof(name), top, "Beefile");
- if (!rc)
- rc = tar_entry(&tar, name, spec->build_file,
- spec->build_file_len, 0644, '0');
+ ret = build_entry_name(name, sizeof(name), top, "");
+ if (!ret)
+ ret = tar_entry(&tar, name, NULL, 0, 0755, '5');
+ if (!ret) {
+ ret = build_entry_name(name, sizeof(name), top, "Beefile");
+ if (!ret)
+ ret = tar_entry(&tar, name, spec->build_file,
+ spec->build_file_len, 0644, '0');
}
- for (size_t i = 0; !rc && i < spec->n_files; i++) {
+ for (size_t i = 0; !ret && i < spec->n_files; i++) {
char resolved[PATH_MAX];
struct stat st;
- rc = build_resolve_source(spec, spec->files[i].source, resolved,
- sizeof(resolved), &st);
- if (!rc)
- rc = build_entry_name(name, sizeof(name), top,
- spec->files[i].target);
- if (!rc)
- rc = tar_path(&tar, name, resolved);
+ ret = build_resolve_source(spec, spec->files[i].source, resolved,
+ sizeof(resolved), &st);
+ if (!ret)
+ ret = build_entry_name(name, sizeof(name), top,
+ spec->files[i].target);
+ if (!ret)
+ ret = tar_path(&tar, name, resolved);
}
- for (size_t i = 0; !rc && i < spec->n_upatches; i++) {
+ for (size_t i = 0; !ret && i < spec->n_upatches; i++) {
const struct bpm_build_upatch *u = &spec->upatches[i];
- rc = build_entry_name(name, sizeof(name), top, u->load_target);
- if (!rc)
- rc = tar_path(&tar, name, u->load_path);
- if (!rc)
- rc = build_entry_name(name, sizeof(name), top, u->unload_target);
- if (!rc)
- rc = tar_path(&tar, name, u->unload_path);
+ ret = build_entry_name(name, sizeof(name), top, u->load_target);
+ if (!ret)
+ ret = tar_path(&tar, name, u->load_path);
+ if (!ret)
+ ret = build_entry_name(name, sizeof(name), top, u->unload_target);
+ if (!ret)
+ ret = tar_path(&tar, name, u->unload_path);
}
- if (!rc) {
+ if (!ret) {
char readme[PATH_MAX];
struct stat st;
- rc = build_join(readme, sizeof(readme), spec->scope, "README.md");
- if (!rc) {
+ ret = build_join(readme, sizeof(readme), spec->scope, "README.md");
+ if (!ret) {
if (!stat(readme, &st)) {
if (!build_within(spec->scope, readme))
- rc = -EINVAL;
+ ret = -EINVAL;
} else if (errno != ENOENT) {
- rc = -errno;
+ ret = -errno;
}
}
- if (!rc && !access(readme, R_OK)) {
- rc = build_entry_name(name, sizeof(name), top, "README.md");
- if (!rc)
- rc = tar_path(&tar, name, readme);
+ if (!ret && !access(readme, R_OK)) {
+ ret = build_entry_name(name, sizeof(name), top, "README.md");
+ if (!ret)
+ ret = tar_path(&tar, name, readme);
}
}
- if (!rc) {
- rc = build_entry_name(name, sizeof(name), top, "cert.der");
- if (!rc)
- rc = tar_entry(&tar, name, cert, cert_len, 0644, '0');
+ if (!ret) {
+ ret = build_entry_name(name, sizeof(name), top, "cert.der");
+ if (!ret)
+ ret = tar_entry(&tar, name, cert, cert_len, 0644, '0');
}
- if (!rc) {
- rc = build_entry_name(name, sizeof(name), top,
- "build-environment.json");
- if (!rc)
- rc = tar_entry(&tar, name, environment, environment_len, 0644, '0');
+ if (!ret) {
+ ret = build_entry_name(name, sizeof(name), top,
+ "build-environment.json");
+ if (!ret)
+ ret = tar_entry(&tar, name, environment, environment_len, 0644, '0');
}
- if (!rc) {
+ if (!ret) {
__u8 end[1024] = {};
- rc = tar_write(&tar, end, sizeof(end));
+ ret = tar_write(&tar, end, sizeof(end));
}
if (gzclose(tar.gz) != Z_OK)
- rc = rc ? rc : -EIO;
+ ret = ret ? ret : -EIO;
xfree(environment, BPM_BUILD_MAX_JSON);
xfree(cert, cert_len + 1);
- if (rc)
+ if (ret)
unlink(output);
else
printf("%s\n", output);
- return rc;
+ return ret;
}
static const char *build_resolve_keys_dir(const char *arg, char *out, size_t cap)
@@ -1516,7 +1516,7 @@ static int shirudo_build_bpm_build(int argc, char **argv)
__u8 digest[CRYPTO_SHA256_LEN];
struct shirudo_cert cert = {};
struct bpm_build_spec *spec;
- int positional = 0, rc;
+ int positional = 0, ret;
char out_dir[PATH_MAX];
size_t body_len = 0;
__u8 *body = NULL;
@@ -1552,13 +1552,13 @@ static int shirudo_build_bpm_build(int argc, char **argv)
} else if (!strcmp(argv[i], "--rodata-input")) {
if (++i >= argc)
goto usage;
- rc = parse_rodata_input(argv[i], overrides,
- &n_overrides,
- ARRAY_SIZE(overrides));
- if (rc > 0)
+ ret = parse_rodata_input(argv[i], overrides,
+ &n_overrides,
+ ARRAY_SIZE(overrides));
+ if (ret > 0)
goto usage;
- if (rc)
- return rc;
+ if (ret)
+ return ret;
} else if (argv[i][0] == '-') {
goto usage;
} else if (++positional == 1) {
@@ -1576,10 +1576,10 @@ static int shirudo_build_bpm_build(int argc, char **argv)
pr_err("bpm build: keys directory %s is not usable", keys_dir);
return -ENOENT;
}
- rc = key_paths(keys_abs, pkey, sizeof(pkey), cert_path,
- sizeof(cert_path));
- if (rc)
- return rc;
+ ret = key_paths(keys_abs, pkey, sizeof(pkey), cert_path,
+ sizeof(cert_path));
+ if (ret)
+ return ret;
if (shirudo_build_check_keys(pkey, cert_path))
return -EACCES;
if (vmlinux_arg && !realpath(vmlinux_arg, vmlinux_abs)) {
@@ -1612,30 +1612,30 @@ static int shirudo_build_bpm_build(int argc, char **argv)
char *slash = strrchr(spec->scope, '/');
if (!slash) {
- rc = -EINVAL;
+ ret = -EINVAL;
goto out;
}
*slash = '\0';
}
- rc = build_read_file(resolved_file, &body, &body_len, BPM_BUILD_MAX_FILE);
- if (rc)
+ ret = build_read_file(resolved_file, &body, &body_len, BPM_BUILD_MAX_FILE);
+ if (ret)
goto out;
- rc = bpm_build_parse_beefile(body, body_len, spec);
- if (!rc)
- rc = build_validate(spec, false);
- if (rc) {
+ ret = bpm_build_parse_beefile(body, body_len, spec);
+ if (!ret)
+ ret = build_validate(spec, false);
+ if (ret) {
pr_err("bpm build: %s is not a valid Beefile", resolved_file);
goto out;
}
- rc = build_rodata_overrides_known(spec, overrides, n_overrides);
- if (rc)
+ ret = build_rodata_overrides_known(spec, overrides, n_overrides);
+ if (ret)
goto out;
if (cert_read_file(cert_path, &cert)) {
- rc = -ENOENT;
+ ret = -ENOENT;
goto out;
}
- rc = cert_pubkey_digest(&cert, digest);
- if (rc)
+ ret = cert_pubkey_digest(&cert, digest);
+ if (ret)
goto out_cert;
hex_encode(digest, sizeof(digest), fingerprint);
/*
@@ -1643,16 +1643,16 @@ static int shirudo_build_bpm_build(int argc, char **argv)
* headers resolve the way they do for `shirudo build` run there.
*/
if (chdir(spec->scope)) {
- rc = -errno;
+ ret = -errno;
goto out_cert;
}
- rc = build_stage_open(spec);
- if (rc)
+ ret = build_stage_open(spec);
+ if (ret)
goto out_cert;
- rc = build_upatches(spec, pkey, cert_path, vmlinux_override,
- shirudo_bpf_incdir, overrides, n_overrides, false);
- if (!rc)
- rc = build_archive(spec, version, cert_path, fingerprint, out_dir);
+ ret = build_upatches(spec, pkey, cert_path, vmlinux_override,
+ shirudo_bpf_incdir, overrides, n_overrides, false);
+ if (!ret)
+ ret = build_archive(spec, version, cert_path, fingerprint, out_dir);
build_stage_close(spec);
out_cert:
cert_free(&cert);
@@ -1660,7 +1660,7 @@ out:
if (body)
xfree(body, body_len + 1);
bpm_build_spec_free(spec);
- return rc;
+ return ret;
usage:
build_usage();
return -EINVAL;
@@ -1674,14 +1674,14 @@ static int build_copy_package_member(const char *package, const char *member,
size_t len = 0;
char *slash;
int fd = -1;
- int rc;
+ int ret;
- rc = bpm_pkg_read_member(package, member, &body, &len,
- BPM_BUILD_MAX_FILE);
- if (rc)
- return rc;
+ ret = bpm_pkg_read_member(package, member, &body, &len,
+ BPM_BUILD_MAX_FILE);
+ if (ret)
+ return ret;
if (strscpy(parent, output, sizeof(parent)) < 0) {
- rc = -ENAMETOOLONG;
+ ret = -ENAMETOOLONG;
goto out;
}
slash = strrchr(parent, '/');
@@ -1698,15 +1698,15 @@ static int build_copy_package_member(const char *package, const char *member,
*p = '\0';
if (mkdir(parent, 0700) && errno != EEXIST) {
- rc = -errno;
+ ret = -errno;
goto out;
}
if (lstat(parent, &st)) {
- rc = -errno;
+ ret = -errno;
goto out;
}
if (!S_ISDIR(st.st_mode)) {
- rc = -ENOTDIR;
+ ret = -ENOTDIR;
goto out;
}
*p = saved;
@@ -1717,18 +1717,18 @@ static int build_copy_package_member(const char *package, const char *member,
}
fd = open(output, O_WRONLY | O_CREAT | O_EXCL | O_CLOEXEC, 0600);
if (fd < 0) {
- rc = -errno;
+ ret = -errno;
goto out;
}
- rc = write_complete(fd, body, len);
- if (!rc && fsync(fd))
- rc = -errno;
+ ret = write_complete(fd, body, len);
+ if (!ret && fsync(fd))
+ ret = -errno;
out:
if (fd >= 0)
close(fd);
if (body)
xfree(body, len + 1);
- return rc;
+ return ret;
}
static int build_download_package(const char *reference, char *path)
@@ -1740,61 +1740,61 @@ static int build_download_package(const char *reference, char *path)
char url[PATH_MAX], digest[BPM_MAX_DIGEST];
__u8 *body = NULL;
size_t body_len = 0;
- int n_layers = 0, fd = -1, rc;
-
- rc = bpm_oci_parse_pull_ref(reference, &client, repository,
- sizeof(repository), tag, sizeof(tag));
- if (rc)
- return rc;
- rc = bpm_oci_url(&client, repository, "manifests", tag, url,
- sizeof(url));
- if (rc)
- return rc;
- rc = bpm_oci_get_memory(&client, url, BPM_MANIFEST_MEDIA, &manifest);
- if (rc)
+ int n_layers = 0, fd = -1, ret;
+
+ ret = bpm_oci_parse_pull_ref(reference, &client, repository,
+ sizeof(repository), tag, sizeof(tag));
+ if (ret)
+ return ret;
+ ret = bpm_oci_url(&client, repository, "manifests", tag, url,
+ sizeof(url));
+ if (ret)
+ return ret;
+ ret = bpm_oci_get_memory(&client, url, BPM_MANIFEST_MEDIA, &manifest);
+ if (ret)
goto out;
- rc = bpm_oci_parse_manifest(manifest.data, manifest.len, layers,
- ARRAY_SIZE(layers), &n_layers, NULL, 0);
- if (rc)
+ ret = bpm_oci_parse_manifest(manifest.data, manifest.len, layers,
+ ARRAY_SIZE(layers), &n_layers, NULL, 0);
+ if (ret)
goto out;
for (int i = 0; i < n_layers; i++) {
if (strcmp(layers[i].media, BPM_PACKAGE_MEDIA))
continue;
- rc = bpm_oci_url(&client, repository, "blobs", layers[i].digest,
- url, sizeof(url));
- if (rc)
+ ret = bpm_oci_url(&client, repository, "blobs", layers[i].digest,
+ url, sizeof(url));
+ if (ret)
goto out;
fd = mkstemp(path);
if (fd < 0) {
- rc = -errno;
+ ret = -errno;
goto out;
}
- rc = bpm_oci_get_file(&client, url, BPM_PACKAGE_MEDIA, fd,
- layers[i].size);
- if (close(fd) && !rc)
- rc = -errno;
+ ret = bpm_oci_get_file(&client, url, BPM_PACKAGE_MEDIA, fd,
+ layers[i].size);
+ if (close(fd) && !ret)
+ ret = -errno;
fd = -1;
- if (rc)
+ if (ret)
goto out;
- rc = build_read_file(path, &body, &body_len, BPM_BUILD_MAX_FILE);
- if (rc)
+ ret = build_read_file(path, &body, &body_len, BPM_BUILD_MAX_FILE);
+ if (ret)
goto out;
- rc = bpm_sha256_hex(body, body_len, digest, sizeof(digest));
- if (!rc && !bpm_digest_matches(layers[i].digest, digest))
- rc = -EKEYREJECTED;
+ ret = bpm_sha256_hex(body, body_len, digest, sizeof(digest));
+ if (!ret && !bpm_digest_matches(layers[i].digest, digest))
+ ret = -EKEYREJECTED;
goto out;
}
- if (!rc)
- rc = -ENOENT;
+ if (!ret)
+ ret = -ENOENT;
out:
if (fd >= 0)
close(fd);
- if (rc)
+ if (ret)
unlink(path);
if (body)
xfree(body, body_len + 1);
bpm_buffer_free(&manifest);
- return rc;
+ return ret;
}
static int shirudo_build_bpm_config_update(int argc, char **argv)
@@ -1814,7 +1814,7 @@ static int shirudo_build_bpm_config_update(int argc, char **argv)
struct bpm_package_info base_info = {};
struct bpm_build_spec *spec;
size_t body_len = 0;
- int rc;
+ int ret;
bool has_rodata = false, package_source, stage_open = false;
bool downloaded_package = false;
@@ -1848,13 +1848,13 @@ static int shirudo_build_bpm_config_update(int argc, char **argv)
} else if (!strcmp(argv[i], "--rodata-input")) {
if (++i >= argc)
goto usage;
- rc = parse_rodata_input(argv[i], overrides,
- &n_overrides,
- ARRAY_SIZE(overrides));
- if (rc > 0)
+ ret = parse_rodata_input(argv[i], overrides,
+ &n_overrides,
+ ARRAY_SIZE(overrides));
+ if (ret > 0)
goto usage;
- if (rc)
- return rc;
+ if (ret)
+ return ret;
} else {
goto usage;
}
@@ -1862,9 +1862,9 @@ static int shirudo_build_bpm_config_update(int argc, char **argv)
if (!base_arg || !version || !build_version_ok(version))
goto usage;
if (!strncmp(base_arg, "oci://", 6)) {
- rc = build_download_package(base_arg, base_package_tmp);
- if (rc)
- return rc;
+ ret = build_download_package(base_arg, base_package_tmp);
+ if (ret)
+ return ret;
if (strscpy(base_package, base_package_tmp,
sizeof(base_package)) < 0) {
unlink(base_package_tmp);
@@ -1874,25 +1874,25 @@ static int shirudo_build_bpm_config_update(int argc, char **argv)
} else if (!realpath(base_arg, base_package)) {
goto usage;
}
- rc = bpm_pkg_load_info(base_package, &base_info);
- if (rc)
+ ret = bpm_pkg_load_info(base_package, &base_info);
+ if (ret)
goto out_base;
if (bpm_semver_compare(version, base_info.version) <= 0) {
- rc = -EINVAL;
+ ret = -EINVAL;
goto out_base;
}
if (!getcwd(out_dir, sizeof(out_dir))) {
- rc = -errno;
+ ret = -errno;
goto out_base;
}
if (!build_resolve_keys_dir(keys_arg, keys_dir, sizeof(keys_dir)) ||
!realpath(keys_dir, keys_abs)) {
- rc = -ENOENT;
+ ret = -ENOENT;
goto out_base;
}
- rc = key_paths(keys_abs, pkey, sizeof(pkey), cert_path,
- sizeof(cert_path));
- if (rc)
+ ret = key_paths(keys_abs, pkey, sizeof(pkey), cert_path,
+ sizeof(cert_path));
+ if (ret)
goto out_base;
if (shirudo_build_check_keys(pkey, cert_path))
goto key_error;
@@ -1901,39 +1901,39 @@ static int shirudo_build_bpm_config_update(int argc, char **argv)
if (!spec)
goto alloc_error;
if (package_source) {
- rc = build_stage_open(spec);
- if (rc)
+ ret = build_stage_open(spec);
+ if (ret)
goto out;
stage_open = true;
if (strsprintf(source_dir, sizeof(source_dir), "%s/source",
spec->stage) < 0) {
- rc = -ENAMETOOLONG;
+ ret = -ENAMETOOLONG;
goto out;
}
if (mkdir(source_dir, 0700)) {
- rc = -errno;
+ ret = -errno;
goto out;
}
if (strsprintf(build_file, sizeof(build_file), "%s/Beefile",
source_dir) < 0) {
- rc = -ENAMETOOLONG;
+ ret = -ENAMETOOLONG;
goto out;
}
- rc = build_copy_package_member(base_package, "Beefile", build_file);
- if (rc == -ENOENT) {
+ ret = build_copy_package_member(base_package, "Beefile", build_file);
+ if (ret == -ENOENT) {
pr_err("bpm config update: base package %s has no Beefile; "
"rebuild it with a Beefile or pass -f <name>.bee",
base_package);
- rc = -EINVAL;
+ ret = -EINVAL;
}
- if (rc)
+ if (ret)
goto out;
} else if (strscpy(build_file, file_arg, sizeof(build_file)) < 0) {
- rc = -ENAMETOOLONG;
+ ret = -ENAMETOOLONG;
goto out;
}
if (!realpath(build_file, resolved_file)) {
- rc = -errno;
+ ret = -errno;
goto out;
}
strscpy(spec->scope, resolved_file, sizeof(spec->scope));
@@ -1941,84 +1941,84 @@ static int shirudo_build_bpm_config_update(int argc, char **argv)
char *slash = strrchr(spec->scope, '/');
if (!slash) {
- rc = -EINVAL;
+ ret = -EINVAL;
goto out;
}
*slash = '\0';
}
- rc = build_read_file(resolved_file, &body, &body_len,
- BPM_BUILD_MAX_FILE);
- if (rc)
+ ret = build_read_file(resolved_file, &body, &body_len,
+ BPM_BUILD_MAX_FILE);
+ if (ret)
goto out;
- rc = bpm_build_parse_beefile(body, body_len, spec);
- if (!rc && package_source) {
- for (size_t i = 0; i < spec->n_files && !rc; i++) {
+ ret = bpm_build_parse_beefile(body, body_len, spec);
+ if (!ret && package_source) {
+ for (size_t i = 0; i < spec->n_files && !ret; i++) {
char output[PATH_MAX];
if (build_target_ok(spec->files[i].source) ||
build_target_ok(spec->files[i].target)) {
- rc = -EINVAL;
+ ret = -EINVAL;
break;
}
if (build_join(output, sizeof(output), spec->scope,
spec->files[i].source)) {
- rc = -ENAMETOOLONG;
+ ret = -ENAMETOOLONG;
break;
}
- rc = build_copy_package_member(base_package,
- spec->files[i].target,
- output);
+ ret = build_copy_package_member(base_package,
+ spec->files[i].target,
+ output);
}
- if (!rc) {
+ if (!ret) {
char readme[PATH_MAX];
if (build_join(readme, sizeof(readme), spec->scope,
"README.md")) {
- rc = -ENAMETOOLONG;
+ ret = -ENAMETOOLONG;
} else {
- rc = build_copy_package_member(base_package,
- "README.md", readme);
- if (rc == -ENOENT)
- rc = 0;
+ ret = build_copy_package_member(base_package,
+ "README.md", readme);
+ if (ret == -ENOENT)
+ ret = 0;
}
}
}
- if (!rc)
- rc = build_validate(spec, package_source);
- if (!rc)
- rc = build_rodata_overrides_known(spec, overrides, n_overrides);
- if (!rc && strcmp(spec->name, base_info.name))
- rc = -EINVAL;
- for (size_t i = 0; !rc && i < spec->n_upatches; i++)
+ if (!ret)
+ ret = build_validate(spec, package_source);
+ if (!ret)
+ ret = build_rodata_overrides_known(spec, overrides, n_overrides);
+ if (!ret && strcmp(spec->name, base_info.name))
+ ret = -EINVAL;
+ for (size_t i = 0; !ret && i < spec->n_upatches; i++)
if (spec->upatches[i].n_rodata)
has_rodata = true;
- if (!rc && !has_rodata)
- rc = -EINVAL;
- if (rc)
+ if (!ret && !has_rodata)
+ ret = -EINVAL;
+ if (ret)
goto out;
if (cert_read_file(cert_path, &cert)) {
- rc = -ENOENT;
+ ret = -ENOENT;
goto out_cert;
}
- rc = cert_pubkey_digest(&cert, digest);
- if (rc)
+ ret = cert_pubkey_digest(&cert, digest);
+ if (ret)
goto out_cert;
hex_encode(digest, sizeof(digest), fingerprint);
if (strcmp(fingerprint, base_info.signer)) {
- rc = -EKEYREJECTED;
+ ret = -EKEYREJECTED;
goto out_cert;
}
if (chdir(spec->scope)) {
- rc = -errno;
+ ret = -errno;
goto out_cert;
}
if (!stage_open) {
- rc = build_stage_open(spec);
- if (rc)
+ ret = build_stage_open(spec);
+ if (ret)
goto out_cert;
stage_open = true;
}
- for (size_t i = 0; i < spec->n_upatches && !rc; i++) {
+ for (size_t i = 0; i < spec->n_upatches && !ret; i++) {
struct bpm_build_upatch *upatch = &spec->upatches[i];
char load[PATH_MAX], unload[PATH_MAX];
char expected_name[UPATCH_NAME_MAX];
@@ -2029,38 +2029,38 @@ static int shirudo_build_bpm_config_update(int argc, char **argv)
spec->stage, i) < 0 ||
strsprintf(unload, sizeof(unload), "%s/update-%zu.unload.upatch",
spec->stage, i) < 0) {
- rc = -ENAMETOOLONG;
+ ret = -ENAMETOOLONG;
break;
}
- rc = build_copy_package_member(base_package, upatch->load_target,
- load);
- if (rc)
+ ret = build_copy_package_member(base_package, upatch->load_target,
+ load);
+ if (ret)
break;
- rc = shirudo_build_package_verify(load, cert_path);
- if (rc)
+ ret = shirudo_build_package_verify(load, cert_path);
+ if (ret)
break;
build_upatch_name(upatch->source, expected_name,
sizeof(expected_name));
- rc = upatch_open(load, &parsed);
- if (rc)
+ ret = upatch_open(load, &parsed);
+ if (ret)
break;
if (upatch_is_unload(&parsed) ||
strncmp(parsed.hdr.name, expected_name,
sizeof(parsed.hdr.name))) {
- rc = -EINVAL;
+ ret = -EINVAL;
upatch_close(&parsed);
break;
}
upatch_close(&parsed);
- rc = build_rodata_apply(spec, upatch, load, pkey, cert_path,
- overrides, n_overrides, true);
- if (rc)
+ ret = build_rodata_apply(spec, upatch, load, pkey, cert_path,
+ overrides, n_overrides, true);
+ if (ret)
break;
- rc = upatch_open(load, &parsed);
- if (rc)
+ ret = upatch_open(load, &parsed);
+ if (ret)
break;
if (upatch_is_unload(&parsed)) {
- rc = -EINVAL;
+ ret = -EINVAL;
upatch_close(&parsed);
break;
}
@@ -2072,17 +2072,17 @@ static int shirudo_build_bpm_config_update(int argc, char **argv)
upatch_close(&parsed);
strscpy(upatch->load_path, load, sizeof(upatch->load_path));
strscpy(upatch->unload_path, unload, sizeof(upatch->unload_path));
- rc = shirudo_build_package_unload(upatch->name, payload, unload,
- pkey, cert_path);
+ ret = shirudo_build_package_unload(upatch->name, payload, unload,
+ pkey, cert_path);
}
- if (!rc)
- rc = build_archive(spec, version, cert_path, fingerprint, out_dir);
+ if (!ret)
+ ret = build_archive(spec, version, cert_path, fingerprint, out_dir);
out_cert:
cert_free(&cert);
out:
if (stage_open) {
- if (chdir(out_dir) && !rc)
- rc = -errno;
+ if (chdir(out_dir) && !ret)
+ ret = -errno;
build_stage_close(spec);
}
if (body)
@@ -2090,16 +2090,16 @@ out:
bpm_build_spec_free(spec);
goto out_base;
key_error:
- rc = -EACCES;
+ ret = -EACCES;
goto out_base;
alloc_error:
- rc = -ENOMEM;
+ ret = -ENOMEM;
out_base:
if (base_info.cert)
xfree(base_info.cert, base_info.cert_len + 1);
if (downloaded_package)
unlink(base_package);
- return rc;
+ return ret;
usage:
fprintf(stderr,
"usage: shirudo bpm config update --base-package "
@@ -2133,24 +2133,24 @@ bool shirudo_build_is_help(const char *arg)
int shirudo_build_bpm(int argc, char **argv)
{
- int rc;
+ int ret;
if (argc < 2 || shirudo_build_is_help(argv[1])) {
bpm_usage(argc < 2 ? stderr : stdout);
return argc < 2 ? 2 : 0;
}
if (!strcmp(argv[1], "build")) {
- rc = shirudo_build_bpm_build(argc - 1, argv + 1);
- if (rc < 0 && rc != -EINVAL)
- pr_err("bpm build: %s", strerror(-rc));
- return rc ? 1 : 0;
+ ret = shirudo_build_bpm_build(argc - 1, argv + 1);
+ if (ret < 0 && ret != -EINVAL)
+ pr_err("bpm build: %s", strerror(-ret));
+ return ret ? 1 : 0;
}
if (!strcmp(argv[1], "config") && argc >= 3 &&
!strcmp(argv[2], "update")) {
- rc = shirudo_build_bpm_config_update(argc - 2, argv + 2);
- if (rc < 0 && rc != -EINVAL)
- pr_err("bpm config update: %s", strerror(-rc));
- return rc ? 1 : 0;
+ ret = shirudo_build_bpm_config_update(argc - 2, argv + 2);
+ if (ret < 0 && ret != -EINVAL)
+ pr_err("bpm config update: %s", strerror(-ret));
+ return ret ? 1 : 0;
}
if (!strcmp(argv[1], "push"))
return shirudo_build_bpm_push(argc - 1, argv + 1);
diff --git a/tools/shirudo-build/bpm-publish.c b/tools/shirudo-build/bpm-publish.c
index abc07513..9cb20e45 100644
--- a/tools/shirudo-build/bpm-publish.c
+++ b/tools/shirudo-build/bpm-publish.c
@@ -51,10 +51,10 @@ static void tree_append_usage(void)
KEYS_DIR);
}
-static int publish_fail(const char *action, int rc)
+static int publish_fail(const char *action, int ret)
{
- if (rc < 0)
- pr_err("bpm %s: %s", action, strerror(-rc));
+ if (ret < 0)
+ pr_err("bpm %s: %s", action, strerror(-ret));
else
pr_err("bpm %s failed", action);
return 1;
@@ -71,15 +71,15 @@ static int sign_detached(const void *payload, size_t len,
struct shirudo_sign_io io = {
.insns = payload, .insns_sz = len, .signature_sz = BPM_SIGN_MAX,
};
- int rc;
+ int ret;
io.signature = xmalloc(io.signature_sz);
if (!io.signature)
return -ENOMEM;
- rc = cms_sign(&io, key, cert);
- if (rc) {
+ ret = cms_sign(&io, key, cert);
+ if (ret) {
xfree(io.signature, BPM_SIGN_MAX);
- return rc;
+ return ret;
}
*sig = io.signature;
*sig_len = io.signature_sz;
@@ -95,9 +95,9 @@ static void sig_free(__u8 *sig)
static int index_entry_compare(const void *left, const void *right)
{
const struct bpm_index_entry *a = left, *b = right;
- int rc = strcmp(a->name, b->name);
+ int ret = strcmp(a->name, b->name);
- return rc ? rc : strcmp(a->version, b->version);
+ return ret ? ret : strcmp(a->version, b->version);
}
/* A registry without an index yields an empty one. */
@@ -107,46 +107,46 @@ static int fetch_index(struct bpm_oci_client *c, const char *cert,
struct bpm_buffer manifest = {}, payload = {}, sig = {};
struct bpm_descriptor *layers = NULL;
char url[PATH_MAX];
- int nl = 0, rc;
+ int nl = 0, ret;
*n = 0;
- rc = bpm_oci_url(c, BPM_INDEX_REPOSITORY, "manifests", BPM_INDEX_TAG,
- url, sizeof(url));
- if (rc)
- return rc;
- rc = bpm_oci_get_memory(c, url, BPM_MANIFEST_MEDIA, &manifest);
- if (rc == -ENOENT)
+ ret = bpm_oci_url(c, BPM_INDEX_REPOSITORY, "manifests", BPM_INDEX_TAG,
+ url, sizeof(url));
+ if (ret)
+ return ret;
+ ret = bpm_oci_get_memory(c, url, BPM_MANIFEST_MEDIA, &manifest);
+ if (ret == -ENOENT)
return 0;
- if (rc)
- return rc;
+ if (ret)
+ return ret;
layers = xcalloc(BPM_MAX_ENTRIES, sizeof(*layers));
if (!layers) {
- rc = -ENOMEM;
+ ret = -ENOMEM;
goto out;
}
- rc = bpm_oci_parse_manifest(manifest.data, manifest.len, layers,
- BPM_MAX_ENTRIES, &nl, NULL, 0);
- if (rc)
+ ret = bpm_oci_parse_manifest(manifest.data, manifest.len, layers,
+ BPM_MAX_ENTRIES, &nl, NULL, 0);
+ if (ret)
goto out;
- rc = bpm_oci_get_signed(c, BPM_INDEX_REPOSITORY, layers, nl,
- BPM_INDEX_MEDIA, BPM_INDEX_SIG_MEDIA, &payload,
- &sig);
- if (rc)
+ ret = bpm_oci_get_signed(c, BPM_INDEX_REPOSITORY, layers, nl,
+ BPM_INDEX_MEDIA, BPM_INDEX_SIG_MEDIA, &payload,
+ &sig);
+ if (ret)
goto out;
if (bpm_verify_cms(payload.data, payload.len, sig.data, sig.len, cert)) {
pr_err("bpm push: the published repository index is not signed by %s",
cert);
- rc = -EKEYREJECTED;
+ ret = -EKEYREJECTED;
goto out;
}
- rc = bpm_index_parse(payload.data, payload.len, entries, n);
+ ret = bpm_index_parse(payload.data, payload.len, entries, n);
out:
if (layers)
xfree(layers, BPM_MAX_ENTRIES * sizeof(*layers));
bpm_buffer_free(&manifest);
bpm_buffer_free(&payload);
bpm_buffer_free(&sig);
- return rc;
+ return ret;
}
/*
@@ -170,13 +170,13 @@ static int push_index(struct bpm_oci_client *c, const char *repository,
size_t cap, sig_len = 0;
time_t now = time(NULL);
__u8 *sig = NULL;
- int n = 0, rc;
+ int n = 0, ret;
entries = xcalloc(BPM_MAX_ENTRIES, sizeof(*entries));
if (!entries)
return -ENOMEM;
- rc = fetch_index(c, cert, entries, &n);
- if (rc)
+ ret = fetch_index(c, cert, entries, &n);
+ if (ret)
goto out;
for (int i = 0; i < n; i++) {
if (strcmp(entries[i].name, info->name) ||
@@ -186,14 +186,14 @@ static int push_index(struct bpm_oci_client *c, const char *repository,
strcmp(entries[i].package_digest, layer->digest)) {
pr_err("bpm push: the repository index already lists %s %s "
"with different content", info->name, info->version);
- rc = -EEXIST;
+ ret = -EEXIST;
goto out;
}
entry = &entries[i];
}
if (!entry) {
if (n >= BPM_MAX_ENTRIES) {
- rc = -E2BIG;
+ ret = -E2BIG;
goto out;
}
entry = &entries[n++];
@@ -210,13 +210,13 @@ static int push_index(struct bpm_oci_client *c, const char *repository,
qsort(entries, (size_t)n, sizeof(*entries), index_entry_compare);
if (iso8601(now, timestamp, sizeof(timestamp))) {
- rc = -EIO;
+ ret = -EIO;
goto out;
}
cap = 4096 + (size_t)n * 4096;
body = xmalloc(cap);
if (!body) {
- rc = -ENOMEM;
+ ret = -ENOMEM;
goto out;
}
e = (struct shirudo_json_emit){ .buf = body, .cap = cap };
@@ -238,28 +238,28 @@ static int push_index(struct bpm_oci_client *c, const char *repository,
json_arr_close(&e);
json_obj_close(&e);
if (e.err) {
- rc = e.err;
+ ret = e.err;
goto out;
}
- rc = sign_detached(body, e.len, key, cert, &sig, &sig_len);
- if (rc)
+ ret = sign_detached(body, e.len, key, cert, &sig, &sig_len);
+ if (ret)
goto out;
- rc = bpm_oci_push_blob(c, BPM_INDEX_REPOSITORY, empty_config,
- strlen(empty_config), BPM_EMPTY_CONFIG_MEDIA,
- &config);
- if (rc)
+ ret = bpm_oci_push_blob(c, BPM_INDEX_REPOSITORY, empty_config,
+ strlen(empty_config), BPM_EMPTY_CONFIG_MEDIA,
+ &config);
+ if (ret)
goto out;
- rc = bpm_oci_push_blob(c, BPM_INDEX_REPOSITORY, body, e.len,
- BPM_INDEX_MEDIA, &payload_layer);
- if (rc)
+ ret = bpm_oci_push_blob(c, BPM_INDEX_REPOSITORY, body, e.len,
+ BPM_INDEX_MEDIA, &payload_layer);
+ if (ret)
goto out;
- rc = bpm_oci_push_blob(c, BPM_INDEX_REPOSITORY, sig, sig_len,
- BPM_INDEX_SIG_MEDIA, &sig_layer);
- if (rc)
+ ret = bpm_oci_push_blob(c, BPM_INDEX_REPOSITORY, sig, sig_len,
+ BPM_INDEX_SIG_MEDIA, &sig_layer);
+ if (ret)
goto out;
manifest = xmalloc(BPM_MANIFEST_CAP);
if (!manifest) {
- rc = -ENOMEM;
+ ret = -ENOMEM;
goto out;
}
e = (struct shirudo_json_emit){ .buf = manifest, .cap = BPM_MANIFEST_CAP };
@@ -274,12 +274,12 @@ static int push_index(struct bpm_oci_client *c, const char *repository,
json_arr_close(&e);
json_obj_close(&e);
if (e.err) {
- rc = e.err;
+ ret = e.err;
goto out;
}
- rc = bpm_oci_put_manifest(c, BPM_INDEX_REPOSITORY, BPM_INDEX_TAG,
- (const __u8 *)manifest, e.len, digest,
- sizeof(digest));
+ ret = bpm_oci_put_manifest(c, BPM_INDEX_REPOSITORY, BPM_INDEX_TAG,
+ (const __u8 *)manifest, e.len, digest,
+ sizeof(digest));
out:
if (manifest)
xfree(manifest, BPM_MANIFEST_CAP);
@@ -287,7 +287,7 @@ out:
if (body)
xfree(body, cap);
xfree(entries, BPM_MAX_ENTRIES * sizeof(*entries));
- return rc;
+ return ret;
}
static int push_package(const char *package_path, const char *raw_repository,
@@ -310,7 +310,7 @@ static int push_package(const char *package_path, const char *raw_repository,
char *key_manifest_body = NULL;
struct stat st;
size_t archive_len, manifest_len, key_manifest_len;
- int rc;
+ int ret;
if (!package_path || !*package_path)
return -EINVAL;
@@ -318,37 +318,37 @@ static int push_package(const char *package_path, const char *raw_repository,
return -errno;
if (!S_ISREG(st.st_mode))
return -EINVAL;
- rc = read_file(package_path, BPM_MAX_HTTP_BODY, &archive,
- &archive_len);
- if (rc)
- return rc;
- rc = bpm_pkg_load_info(package_path, &info);
- if (rc)
+ ret = read_file(package_path, BPM_MAX_HTTP_BODY, &archive,
+ &archive_len);
+ if (ret)
+ return ret;
+ ret = bpm_pkg_load_info(package_path, &info);
+ if (ret)
goto out;
- rc = bpm_oci_parse_push_repo(raw_repository, &c, repository,
- sizeof(repository));
- if (rc)
+ ret = bpm_oci_parse_push_repo(raw_repository, &c, repository,
+ sizeof(repository));
+ if (ret)
goto out;
base = strrchr(package_path, '/');
base = base ? base + 1 : package_path;
if (!*base || strlen(base) >= sizeof(package_title)) {
- rc = -ENAMETOOLONG;
+ ret = -ENAMETOOLONG;
goto out;
}
bpm_copy_string(package_title, sizeof(package_title), base);
- rc = bpm_oci_push_blob(&c, repository, config_body, strlen(config_body),
- BPM_CONFIG_MEDIA, &config);
- if (rc)
+ ret = bpm_oci_push_blob(&c, repository, config_body, strlen(config_body),
+ BPM_CONFIG_MEDIA, &config);
+ if (ret)
goto out;
- rc = bpm_oci_push_blob(&c, repository, archive, archive_len,
- BPM_PACKAGE_MEDIA, &layer);
- if (rc)
+ ret = bpm_oci_push_blob(&c, repository, archive, archive_len,
+ BPM_PACKAGE_MEDIA, &layer);
+ if (ret)
goto out;
manifest_body = xmalloc(BPM_MANIFEST_CAP);
if (!manifest_body) {
- rc = -ENOMEM;
+ ret = -ENOMEM;
goto out;
}
e.buf = manifest_body;
@@ -369,37 +369,37 @@ static int push_package(const char *package_path, const char *raw_repository,
json_obj_close(&e);
if (e.err) {
xfree(manifest_body, BPM_MANIFEST_CAP);
- rc = e.err;
+ ret = e.err;
goto out;
}
manifest_len = e.len;
manifest = (__u8 *)manifest_body;
if (bpm_sha256_hex(manifest, manifest_len, hex, sizeof(hex)) ||
strsprintf(package_digest, sizeof(package_digest), "sha256:%s", hex) < 0) {
- rc = -EINVAL;
+ ret = -EINVAL;
goto out;
}
/*
* By digest until the index takes the version, so a refused re-push
* leaves the tag on the package already published.
*/
- rc = bpm_oci_put_manifest(&c, repository, package_digest, manifest,
- manifest_len, key_digest, sizeof(key_digest));
- if (rc)
+ ret = bpm_oci_put_manifest(&c, repository, package_digest, manifest,
+ manifest_len, key_digest, sizeof(key_digest));
+ if (ret)
goto out;
/*
* Publish the package certificate as an OCI referrer so `bpm key add`
* can fetch it without downloading the package.
*/
- rc = bpm_oci_push_blob(&c, repository, empty_config,
- strlen(empty_config), BPM_EMPTY_CONFIG_MEDIA,
- &key_config);
- if (rc)
+ ret = bpm_oci_push_blob(&c, repository, empty_config,
+ strlen(empty_config), BPM_EMPTY_CONFIG_MEDIA,
+ &key_config);
+ if (ret)
goto out;
- rc = bpm_oci_push_blob(&c, repository, info.cert, info.cert_len,
- BPM_PUBLIC_KEY_MEDIA, &key_layer);
- if (rc)
+ ret = bpm_oci_push_blob(&c, repository, info.cert, info.cert_len,
+ BPM_PUBLIC_KEY_MEDIA, &key_layer);
+ if (ret)
goto out;
subject = (struct bpm_descriptor){
.media = "application/vnd.oci.image.manifest.v1+json",
@@ -408,7 +408,7 @@ static int push_package(const char *package_path, const char *raw_repository,
subject.size = (__s64)manifest_len;
key_manifest_body = xmalloc(BPM_MANIFEST_CAP);
if (!key_manifest_body) {
- rc = -ENOMEM;
+ ret = -ENOMEM;
goto out;
}
e = (struct shirudo_json_emit){ .buf = key_manifest_body, .cap = BPM_MANIFEST_CAP };
@@ -427,40 +427,40 @@ static int push_package(const char *package_path, const char *raw_repository,
json_obj_close(&e);
json_obj_close(&e);
if (e.err) {
- rc = e.err;
+ ret = e.err;
goto out;
}
key_manifest_len = e.len;
if (bpm_sha256_hex(key_manifest_body, key_manifest_len, hex,
sizeof(hex)) ||
strsprintf(key_digest, sizeof(key_digest), "sha256:%s", hex) < 0) {
- rc = -EINVAL;
+ ret = -EINVAL;
goto out;
}
- rc = bpm_oci_put_manifest(&c, repository, key_digest,
- (const __u8 *)key_manifest_body,
- key_manifest_len, key_digest,
- sizeof(key_digest));
- if (rc)
+ ret = bpm_oci_put_manifest(&c, repository, key_digest,
+ (const __u8 *)key_manifest_body,
+ key_manifest_len, key_digest,
+ sizeof(key_digest));
+ if (ret)
goto out;
if (index_key && index_cert) {
- rc = push_index(&c, repository, &info, package_digest, &layer,
- index_key, index_cert);
- if (rc)
+ ret = push_index(&c, repository, &info, package_digest, &layer,
+ index_key, index_cert);
+ if (ret)
goto out;
}
- rc = bpm_oci_put_manifest(&c, repository, info.version, manifest,
- manifest_len, package_digest,
- sizeof(package_digest));
- if (rc)
+ ret = bpm_oci_put_manifest(&c, repository, info.version, manifest,
+ manifest_len, package_digest,
+ sizeof(package_digest));
+ if (ret)
goto out;
if (strsprintf(reference, sizeof(reference), "oci://%s/%s:%s",
c.registry, repository, info.version) < 0) {
- rc = -ENAMETOOLONG;
+ ret = -ENAMETOOLONG;
goto out;
}
*reference_out = xstrdup(reference);
- rc = *reference_out ? 0 : -ENOMEM;
+ ret = *reference_out ? 0 : -ENOMEM;
out:
if (key_manifest_body)
xfree(key_manifest_body, BPM_MANIFEST_CAP);
@@ -469,7 +469,7 @@ out:
if (info.cert)
xfree(info.cert, info.cert_len + 1);
xfree(archive, archive_len + 1);
- return rc;
+ return ret;
}
static int tree_string_compare(const void *left, const void *right)
@@ -514,45 +514,45 @@ static int tree_push_artifact(struct bpm_oci_client *c, const char *repository,
struct shirudo_upatch u;
char hex[65], tag[160];
char *manifest;
- int fd, rc;
+ int fd, ret;
fd = mkstemp(temporary);
if (fd < 0)
return -errno;
- rc = write_complete(fd, body, len);
+ ret = write_complete(fd, body, len);
close(fd);
- if (!rc)
- rc = upatch_open(temporary, &u);
+ if (!ret)
+ ret = upatch_open(temporary, &u);
unlink(temporary);
- if (rc) {
+ if (ret) {
pr_err("bpm tree append: %s is not a valid upatch", id);
- return rc;
+ return ret;
}
memcpy(name, u.hdr.name, UPATCH_NAME_MAX);
name[UPATCH_NAME_MAX] = '\0';
hex_encode(u.hdr.payload_sha256, 32, hex);
if (strcmp(name, id) || upatch_is_unload(&u) != unload)
- rc = -EKEYREJECTED;
+ ret = -EKEYREJECTED;
upatch_close(&u);
- if (rc) {
+ if (ret) {
pr_err("bpm tree append: the %s artifact for %s is a %s directive named %s",
unload ? "unload" : "load", id,
unload ? "load" : "unload", name);
- return rc;
+ return ret;
}
if (strsprintf(tag, sizeof(tag), "upatch-%s-%.16s", id, hex) < 0 || strlen(tag) > 128)
return -ENAMETOOLONG;
if (strsprintf(title, sizeof(title), "%s.upatch", id) < 0)
return -ENAMETOOLONG;
- rc = bpm_oci_push_blob(c, repository, body, len, BPM_UPATCH_MEDIA,
- &layer);
- if (rc)
- return rc;
- rc = bpm_oci_push_blob(c, repository, empty_config,
- strlen(empty_config), BPM_EMPTY_CONFIG_MEDIA,
- &config);
- if (rc)
- return rc;
+ ret = bpm_oci_push_blob(c, repository, body, len, BPM_UPATCH_MEDIA,
+ &layer);
+ if (ret)
+ return ret;
+ ret = bpm_oci_push_blob(c, repository, empty_config,
+ strlen(empty_config), BPM_EMPTY_CONFIG_MEDIA,
+ &config);
+ if (ret)
+ return ret;
manifest = xmalloc(BPM_MANIFEST_CAP);
if (!manifest)
return -ENOMEM;
@@ -569,15 +569,15 @@ static int tree_push_artifact(struct bpm_oci_client *c, const char *repository,
json_kv_string(&e, "org.opencontainers.image.title", title);
json_obj_close(&e);
json_obj_close(&e);
- rc = e.err;
- if (!rc)
- rc = bpm_oci_put_manifest(c, repository, tag,
- (const __u8 *)manifest, e.len,
- out->manifest_digest,
- sizeof(out->manifest_digest));
+ ret = e.err;
+ if (!ret)
+ ret = bpm_oci_put_manifest(c, repository, tag,
+ (const __u8 *)manifest, e.len,
+ out->manifest_digest,
+ sizeof(out->manifest_digest));
xfree(manifest, BPM_MANIFEST_CAP);
- if (rc)
- return rc;
+ if (ret)
+ return ret;
bpm_copy_string(out->repository, sizeof(out->repository), raw_repository);
bpm_copy_string(out->layer_digest, sizeof(out->layer_digest), layer.digest);
if (strsprintf(out->payload_sha256, sizeof(out->payload_sha256),
@@ -606,7 +606,7 @@ static int cmd_bpm_tree_append(int argc, char **argv)
struct shirudo_json_emit e;
char empty_config[] = "{}";
char package_dir[101];
- int appended = 0, rc;
+ int appended = 0, ret;
bool unload;
for (int i = 2; i < argc; i++) {
@@ -682,40 +682,40 @@ static int cmd_bpm_tree_append(int argc, char **argv)
return -ENAMETOOLONG;
}
- rc = bpm_pkg_load_info(package, &info);
- if (rc)
- return rc;
- rc = bpm_pkg_read_member_in(package, "Beefile", NULL, package_dir,
- sizeof(package_dir), &beefile, &len,
- 4u * 1024u * 1024u);
- if (rc) {
+ ret = bpm_pkg_load_info(package, &info);
+ if (ret)
+ return ret;
+ ret = bpm_pkg_read_member_in(package, "Beefile", NULL, package_dir,
+ sizeof(package_dir), &beefile, &len,
+ 4u * 1024u * 1024u);
+ if (ret) {
pr_err("bpm tree append: package %s does not include Beefile", package);
goto out;
}
spec = xmalloc(sizeof(*spec));
if (!spec) {
- rc = -ENOMEM;
+ ret = -ENOMEM;
goto out;
}
- rc = bpm_build_parse_beefile(beefile, len, spec);
- if (rc) {
+ ret = bpm_build_parse_beefile(beefile, len, spec);
+ if (ret) {
pr_err("bpm tree append: cannot parse the Beefile of %s", package);
goto out;
}
- rc = bpm_oci_parse_push_repo(repo_ref, &c, repository, sizeof(repository));
- if (rc) {
+ ret = bpm_oci_parse_push_repo(repo_ref, &c, repository, sizeof(repository));
+ if (ret) {
pr_err("bpm tree append: the repository must be oci://registry/repository");
goto out;
}
- rc = bpm_tree_fetch_publication(&c, repository, reference, cert, &pub,
- parent, sizeof(parent));
- if (rc == -ENOENT) {
+ ret = bpm_tree_fetch_publication(&c, repository, reference, cert, &pub,
+ parent, sizeof(parent));
+ if (ret == -ENOENT) {
pub = (struct shirudo_tree_publication){ .schema = 1,
.generation = 1 };
parent[0] = '\0';
if (tree_id)
bpm_copy_string(pub.tree_id, sizeof(pub.tree_id), tree_id);
- } else if (rc) {
+ } else if (ret) {
pr_err("bpm tree append: cannot read the publication at %s:%s",
repo_ref, reference);
goto out;
@@ -723,7 +723,7 @@ static int cmd_bpm_tree_append(int argc, char **argv)
if (tree_id && strcmp(pub.tree_id, tree_id)) {
pr_err("bpm tree append: tree id mismatch: existing %s, requested %s",
pub.tree_id, tree_id);
- rc = -EINVAL;
+ ret = -EINVAL;
goto out;
}
pub.generation++;
@@ -736,7 +736,7 @@ static int cmd_bpm_tree_append(int argc, char **argv)
op = xmalloc(sizeof(*op));
if (!op) {
- rc = -ENOMEM;
+ ret = -ENOMEM;
goto out;
}
for (size_t i = 0; i < spec->n_upatches; i++) {
@@ -748,9 +748,9 @@ static int cmd_bpm_tree_append(int argc, char **argv)
if (!u->tree.present)
continue;
member = unload ? u->tree.unload_artifact : u->tree.load_artifact;
- rc = bpm_pkg_read_member_in(package, member, package_dir, NULL, 0,
- &body, &body_len, BPM_MAX_HTTP_BODY);
- if (rc) {
+ ret = bpm_pkg_read_member_in(package, member, package_dir, NULL, 0,
+ &body, &body_len, BPM_MAX_HTTP_BODY);
+ if (ret) {
pr_err("bpm tree append: package entry %s not found", member);
goto out;
}
@@ -760,46 +760,46 @@ static int cmd_bpm_tree_append(int argc, char **argv)
if (u->tree.selector)
op->selector = *u->tree.selector;
tree_selector_canonicalize(&op->selector);
- rc = tree_push_artifact(&c, repository, repo_ref, body, body_len,
- u->tree.id, unload, &op->artifact);
+ ret = tree_push_artifact(&c, repository, repo_ref, body, body_len,
+ u->tree.id, unload, &op->artifact);
xfree(body, body_len + 1);
- if (rc)
+ if (ret)
goto out;
- rc = tree_operation_digest(op, op->operation_digest);
- if (!rc)
- rc = tree_publication_append(&pub, op);
- if (rc)
+ ret = tree_operation_digest(op, op->operation_digest);
+ if (!ret)
+ ret = tree_publication_append(&pub, op);
+ if (ret)
goto out;
pub.head_seq = op->seq;
appended++;
}
if (!appended) {
pr_err("bpm tree append: %s has no [upatches.tree] entries", package);
- rc = -ENOENT;
+ ret = -ENOENT;
goto out;
}
- rc = tree_emit_publication(&pub, &payload, &payload_len);
- if (rc)
+ ret = tree_emit_publication(&pub, &payload, &payload_len);
+ if (ret)
goto out;
- rc = sign_detached(payload, payload_len, key, cert, &sig, &sig_len);
- if (rc)
+ ret = sign_detached(payload, payload_len, key, cert, &sig, &sig_len);
+ if (ret)
goto out;
- rc = bpm_oci_push_blob(&c, repository, empty_config,
- strlen(empty_config), BPM_EMPTY_CONFIG_MEDIA,
- &config);
- if (rc)
+ ret = bpm_oci_push_blob(&c, repository, empty_config,
+ strlen(empty_config), BPM_EMPTY_CONFIG_MEDIA,
+ &config);
+ if (ret)
goto out;
- rc = bpm_oci_push_blob(&c, repository, payload, payload_len,
- BPM_TREE_MEDIA, &payload_layer);
- if (rc)
+ ret = bpm_oci_push_blob(&c, repository, payload, payload_len,
+ BPM_TREE_MEDIA, &payload_layer);
+ if (ret)
goto out;
- rc = bpm_oci_push_blob(&c, repository, sig, sig_len, BPM_TREE_SIG_MEDIA,
- &sig_layer);
- if (rc)
+ ret = bpm_oci_push_blob(&c, repository, sig, sig_len, BPM_TREE_SIG_MEDIA,
+ &sig_layer);
+ if (ret)
goto out;
manifest = xmalloc(BPM_MANIFEST_CAP);
if (!manifest) {
- rc = -ENOMEM;
+ ret = -ENOMEM;
goto out;
}
e = (struct shirudo_json_emit){ .buf = manifest, .cap = BPM_MANIFEST_CAP };
@@ -813,12 +813,12 @@ static int cmd_bpm_tree_append(int argc, char **argv)
bpm_oci_emit_descriptor(&e, NULL, &sig_layer, NULL);
json_arr_close(&e);
json_obj_close(&e);
- rc = e.err;
- if (!rc)
- rc = bpm_oci_put_manifest(&c, repository, reference,
- (const __u8 *)manifest, e.len,
- digest, sizeof(digest));
- if (!rc)
+ ret = e.err;
+ if (!ret)
+ ret = bpm_oci_put_manifest(&c, repository, reference,
+ (const __u8 *)manifest, e.len,
+ digest, sizeof(digest));
+ if (!ret)
printf("oci://%s/%s:%s %s\n", c.registry, repository, reference,
digest);
out:
@@ -835,7 +835,7 @@ out:
xfree(beefile, len + 1);
if (info.cert)
xfree(info.cert, info.cert_len + 1);
- return rc;
+ return ret;
}
static void bpm_push_usage(void)
@@ -859,7 +859,7 @@ int shirudo_build_bpm_push(int argc, char **argv)
const char *package = NULL, *repository = NULL, *reference = NULL;
const char *keys_dir_arg = NULL, *index_cert = NULL, *index_key = NULL;
char cert_path[PATH_MAX], key_path[PATH_MAX];
- int rc;
+ int ret;
if (argc == 2 && shirudo_build_is_help(argv[1])) {
bpm_push_usage();
@@ -914,10 +914,10 @@ int shirudo_build_bpm_push(int argc, char **argv)
return 1;
if (curl_global_init(CURL_GLOBAL_DEFAULT) != CURLE_OK)
return publish_fail("initialize curl", -EIO);
- rc = push_package(package, repository, index_key, index_cert, &reference);
+ ret = push_package(package, repository, index_key, index_cert, &reference);
curl_global_cleanup();
- if (rc)
- return publish_fail("push", rc);
+ if (ret)
+ return publish_fail("push", ret);
printf("%s\n", reference);
xstrfree((char *)reference);
return 0;
@@ -925,7 +925,7 @@ int shirudo_build_bpm_push(int argc, char **argv)
int shirudo_build_bpm_tree(int argc, char **argv)
{
- int rc;
+ int ret;
if (argc < 2 || strcmp(argv[1], "append")) {
tree_append_usage();
@@ -937,7 +937,7 @@ int shirudo_build_bpm_tree(int argc, char **argv)
}
if (curl_global_init(CURL_GLOBAL_DEFAULT) != CURLE_OK)
return publish_fail("initialize curl", -EIO);
- rc = cmd_bpm_tree_append(argc, argv);
+ ret = cmd_bpm_tree_append(argc, argv);
curl_global_cleanup();
- return rc ? publish_fail("tree append", rc) : 0;
+ return ret ? publish_fail("tree append", ret) : 0;
}
diff --git a/tools/shirudo-build/compile.c b/tools/shirudo-build/compile.c
index 43078967..35f1fc6d 100644
--- a/tools/shirudo-build/compile.c
+++ b/tools/shirudo-build/compile.c
@@ -75,7 +75,7 @@ int shirudo_build_compile(const char *source, const char *output,
char inc_shirudo_bpf_buf[PATH_MAX + 8];
char vmlinux_dir[1024];
char *cf_copy = NULL;
- int rc = 0;
+ int ret = 0;
int status;
int n = 0;
pid_t pid;
@@ -152,10 +152,10 @@ int shirudo_build_compile(const char *source, const char *output,
return -ENOMEM;
for (tok = strtok(cf_copy, " \t\n"); tok;
tok = strtok(NULL, " \t\n")) {
- rc = push(argv, &n, tok);
- if (rc) {
+ ret = push(argv, &n, tok);
+ if (ret) {
xstrfree(cf_copy);
- return rc;
+ return ret;
}
}
}
@@ -163,7 +163,7 @@ int shirudo_build_compile(const char *source, const char *output,
pid = fork();
if (pid < 0) {
- rc = -errno;
+ ret = -errno;
pr_err("fork: %s", strerror(errno));
goto out;
}
@@ -175,7 +175,7 @@ int shirudo_build_compile(const char *source, const char *output,
}
while (waitpid(pid, &status, 0) < 0) {
if (errno != EINTR) {
- rc = -errno;
+ ret = -errno;
goto out;
}
}
@@ -183,18 +183,18 @@ int shirudo_build_compile(const char *source, const char *output,
int es = WEXITSTATUS(status);
if (es == 0) {
- rc = 0;
+ ret = 0;
} else {
pr_err("clang exited with status %d", es);
- rc = -EIO;
+ ret = -EIO;
}
} else if (WIFSIGNALED(status)) {
pr_err("clang killed by signal %d", WTERMSIG(status));
- rc = -EINTR;
+ ret = -EINTR;
} else {
- rc = -EIO;
+ ret = -EIO;
}
out:
xstrfree(cf_copy);
- return rc;
+ return ret;
}
diff --git a/tools/shirudo-build/image.c b/tools/shirudo-build/image.c
index f8ffd3c2..a851971b 100644
--- a/tools/shirudo-build/image.c
+++ b/tools/shirudo-build/image.c
@@ -117,21 +117,21 @@ static int verify_root_signature(const char root[65], const __u8 *signature,
{
struct shirudo_cert cert = {};
char algorithm[32];
- int rc;
+ int ret;
- rc = cert_read_file(path, &cert);
- if (!rc)
- rc = cert_key_algorithm(&cert, algorithm,
- sizeof(algorithm));
- if (!rc && strcmp(algorithm, "ML-DSA-87"))
- rc = -EKEYREJECTED;
- if (!rc && cms_signed_by(signature, size, &cert) != 1)
- rc = -EKEYREJECTED;
- if (!rc)
- rc = verify_detached((const __u8 *)root, 64,
- signature, size, &cert);
+ ret = cert_read_file(path, &cert);
+ if (!ret)
+ ret = cert_key_algorithm(&cert, algorithm,
+ sizeof(algorithm));
+ if (!ret && strcmp(algorithm, "ML-DSA-87"))
+ ret = -EKEYREJECTED;
+ if (!ret && cms_signed_by(signature, size, &cert) != 1)
+ ret = -EKEYREJECTED;
+ if (!ret)
+ ret = verify_detached((const __u8 *)root, 64,
+ signature, size, &cert);
cert_free(&cert);
- return rc;
+ return ret;
}
static int verify_image(const char *prefix, const char *cert)
@@ -143,18 +143,18 @@ static int verify_image(const char *prefix, const char *cert)
size_t size = 0;
char root[65];
ssize_t n;
- int rc;
+ int ret;
- rc = shirudo_config_image_open(prefix, &image);
- if (rc)
- return rc;
+ ret = shirudo_config_image_open(prefix, &image);
+ if (ret)
+ return ret;
while (size < sizeof(signature)) {
n = pread(image.signature_fd, signature + size,
sizeof(signature) - size, size);
if (n < 0) {
if (errno == EINTR)
continue;
- rc = -errno;
+ ret = -errno;
goto out;
}
if (!n)
@@ -162,19 +162,19 @@ static int verify_image(const char *prefix, const char *cert)
size += n;
}
if (!size || size > CONFIG_IMAGE_SIG_MAX) {
- rc = -EINVAL;
+ ret = -EINVAL;
goto out;
}
hex_encode(image.image.root_hash, sizeof(image.image.root_hash),
root);
- rc = verify_root_signature(root, signature, size, cert);
- if (!rc)
- rc = verify_verity(image.data_fd, image.hash_fd, root);
- if (!rc)
+ ret = verify_root_signature(root, signature, size, cert);
+ if (!ret)
+ ret = verify_verity(image.data_fd, image.hash_fd, root);
+ if (!ret)
puts(root);
out:
shirudo_config_image_close(&image);
- return rc;
+ return ret;
}
static int sign_root(const char *input, const char *output, const char *pkey,
@@ -186,30 +186,30 @@ static int sign_root(const char *input, const char *output, const char *pkey,
size_t done = 0;
struct stat st;
ssize_t size;
- int fd, rc;
+ int fd, ret;
if (shirudo_build_check_keys(pkey, cert))
return -EKEYREJECTED;
fd = open(input, O_RDONLY | O_NOFOLLOW | O_CLOEXEC | O_NONBLOCK);
if (fd < 0)
return -errno;
- rc = fstat(fd, &st) ? -errno : 0;
- if (!rc && (!S_ISREG(st.st_mode) || st.st_size != 64))
- rc = -EINVAL;
- while (!rc && done < 64) {
+ ret = fstat(fd, &st) ? -errno : 0;
+ if (!ret && (!S_ISREG(st.st_mode) || st.st_size != 64))
+ ret = -EINVAL;
+ while (!ret && done < 64) {
size = read(fd, root + done, 64 - done);
if (size < 0) {
if (errno != EINTR)
- rc = -errno;
+ ret = -errno;
} else if (!size) {
- rc = -EIO;
+ ret = -EIO;
} else {
done += size;
}
}
close(fd);
- if (rc)
- return rc;
+ if (ret)
+ return ret;
for (done = 0; done < 64; done++)
if (!((root[done] >= '0' && root[done] <= '9') ||
(root[done] >= 'a' && root[done] <= 'f')))
@@ -218,22 +218,22 @@ static int sign_root(const char *input, const char *output, const char *pkey,
sign.insns_sz = 64;
sign.signature = signature;
sign.signature_sz = sizeof(signature);
- rc = cms_sign(&sign, pkey, cert);
- if (!rc)
- rc = verify_root_signature(root, signature, sign.signature_sz,
- cert);
- if (rc)
- return rc;
+ ret = cms_sign(&sign, pkey, cert);
+ if (!ret)
+ ret = verify_root_signature(root, signature, sign.signature_sz,
+ cert);
+ if (ret)
+ return ret;
fd = open(output, O_WRONLY | O_CREAT | O_EXCL | O_CLOEXEC, 0644);
if (fd < 0)
return -errno;
- rc = write_complete(fd, signature, sign.signature_sz);
- if (!rc && fsync(fd))
- rc = -errno;
+ ret = write_complete(fd, signature, sign.signature_sz);
+ if (!ret && fsync(fd))
+ ret = -errno;
close(fd);
- if (rc)
+ if (ret)
unlink(output);
- return rc;
+ return ret;
}
int shirudo_build_image(int argc, char **argv)
@@ -244,7 +244,7 @@ int shirudo_build_image(int argc, char **argv)
const char *input = NULL, *prefix = NULL;
const char *cert = CERT_PATH;
const char *keys_dir = NULL;
- int i, rc;
+ int i, ret;
if (argc >= 2 && !strcmp(argv[1], "build"))
return build_image(argc, argv);
@@ -254,10 +254,10 @@ int shirudo_build_image(int argc, char **argv)
}
if (argc == 5 && !strcmp(argv[1], "verify") &&
!strcmp(argv[3], "--cert")) {
- rc = verify_image(argv[2], argv[4]);
- if (rc)
- pr_err("image verify: %s", strerror(-rc));
- return rc ? 1 : 0;
+ ret = verify_image(argv[2], argv[4]);
+ if (ret)
+ pr_err("image verify: %s", strerror(-ret));
+ return ret ? 1 : 0;
}
if (argc < 2 || strcmp(argv[1], "sign-root")) {
image_usage(stderr);
@@ -291,17 +291,17 @@ int shirudo_build_image(int argc, char **argv)
return 2;
keys_dir = keys_dir_resolve(keys_dir);
if (keys_dir) {
- rc = key_paths(keys_dir, pkey_path, sizeof(pkey_path),
- cert_path, sizeof(cert_path));
- if (rc)
+ ret = key_paths(keys_dir, pkey_path, sizeof(pkey_path),
+ cert_path, sizeof(cert_path));
+ if (ret)
return 2;
if (!explicit_key)
pkey = pkey_path;
if (!explicit_cert)
cert = cert_path;
}
- rc = sign_root(input, prefix, pkey, cert);
- if (rc)
- pr_err("image sign-root: %s", strerror(-rc));
- return rc ? 1 : 0;
+ ret = sign_root(input, prefix, pkey, cert);
+ if (ret)
+ pr_err("image sign-root: %s", strerror(-ret));
+ return ret ? 1 : 0;
}
diff --git a/tools/shirudo-build/package.c b/tools/shirudo-build/package.c
index ba18e95a..89589cd6 100644
--- a/tools/shirudo-build/package.c
+++ b/tools/shirudo-build/package.c
@@ -144,7 +144,7 @@ static int verify_payload(const struct shirudo_upatch *u,
__u8 digest[SHA256_LEN], *payload;
__u64 payload_len;
__u32 digest_len;
- int rc;
+ int ret;
payload_len = (__u64)u->hdr.loader_insns_len + u->hdr.data_len;
if (payload_len > SIZE_MAX)
@@ -155,16 +155,16 @@ static int verify_payload(const struct shirudo_upatch *u,
memcpy(payload, upatch_loader(u), u->hdr.loader_insns_len);
memcpy(payload + u->hdr.loader_insns_len, upatch_data(u),
u->hdr.data_len);
- rc = bpm_verify_cms(payload, (size_t)payload_len,
- upatch_signature(u), u->hdr.signature_len,
- cert_path);
- if (!rc && (EVP_Digest(payload, (size_t)payload_len, digest,
- &digest_len, EVP_sha256(), NULL) != 1 ||
- digest_len != sizeof(digest) ||
- memcmp(digest, u->hdr.payload_sha256, sizeof(digest))))
- rc = -EBADMSG;
+ ret = bpm_verify_cms(payload, (size_t)payload_len,
+ upatch_signature(u), u->hdr.signature_len,
+ cert_path);
+ if (!ret && (EVP_Digest(payload, (size_t)payload_len, digest,
+ &digest_len, EVP_sha256(), NULL) != 1 ||
+ digest_len != sizeof(digest) ||
+ memcmp(digest, u->hdr.payload_sha256, sizeof(digest))))
+ ret = -EBADMSG;
xfree(payload, (size_t)payload_len);
- return rc;
+ return ret;
}
static int package_resign_symbols(const char *original,
@@ -187,18 +187,18 @@ static int package_resign_symbols(const char *original,
__u64 total;
bool wrote = false;
int fd = -1;
- int rc;
+ int ret;
if (!original || !modified || !output || !ranges || !symbols ||
!nr_ranges || nr_ranges > ARRAY_SIZE(expected) ||
nr_symbols != nr_ranges || !strcmp(original, output) ||
!strcmp(modified, output))
return -EINVAL;
- rc = upatch_open(original, &src);
- if (rc)
- return rc;
- rc = upatch_open(modified, &mod);
- if (rc)
+ ret = upatch_open(original, &src);
+ if (ret)
+ return ret;
+ ret = upatch_open(modified, &mod);
+ if (ret)
goto out;
src_data = upatch_data(&src);
mod_data = upatch_data(&mod);
@@ -215,7 +215,7 @@ static int package_resign_symbols(const char *original,
(src.hdr.metadata_len &&
memcmp(upatch_metadata(&src), upatch_metadata(&mod),
src.hdr.metadata_len))) {
- rc = -EINVAL;
+ ret = -EINVAL;
goto out;
}
for (i = 0; i < nr_ranges; i++) {
@@ -223,7 +223,7 @@ static int package_resign_symbols(const char *original,
ranges[i].length > src.hdr.data_len - ranges[i].offset ||
(i && ranges[i].offset <
ranges[i - 1].offset + ranges[i - 1].length)) {
- rc = -EINVAL;
+ ret = -EINVAL;
goto out;
}
}
@@ -237,20 +237,20 @@ static int package_resign_symbols(const char *original,
break;
}
if (!allowed && src_data[i] != mod_data[i]) {
- rc = -EPERM;
+ ret = -EPERM;
goto out;
}
}
if (!memchr(src.hdr.name, '\0', sizeof(src.hdr.name))) {
- rc = -EINVAL;
+ ret = -EINVAL;
goto out;
}
- rc = verify_payload(&src, cert_path);
- if (rc)
+ ret = verify_payload(&src, cert_path);
+ if (ret)
goto out;
for (i = 0; i < nr_symbols; i++) {
- rc = upatch_rodata_symbol_range(&src, symbols[i], &expected[i]);
- if (rc)
+ ret = upatch_rodata_symbol_range(&src, symbols[i], &expected[i]);
+ if (ret)
goto out;
}
for (i = 0; i < nr_ranges; i++) {
@@ -262,13 +262,13 @@ static int package_resign_symbols(const char *original,
break;
}
if (j == nr_symbols) {
- rc = -EPERM;
+ ret = -EPERM;
goto out;
}
}
sig_buf = xmalloc(MAX_SIG_SIZE);
if (!sig_buf) {
- rc = -ENOMEM;
+ ret = -ENOMEM;
goto out;
}
sio.insns = upatch_loader(&mod);
@@ -277,28 +277,28 @@ static int package_resign_symbols(const char *original,
sio.data_sz = mod.hdr.data_len;
sio.signature = sig_buf;
sio.signature_sz = MAX_SIG_SIZE;
- rc = cms_sign(&sio, pkey_path, cert_path);
- if (rc)
+ ret = cms_sign(&sio, pkey_path, cert_path);
+ if (ret)
goto out;
loader_off = sizeof(hdr);
if ((__u64)loader_off + sio.insns_sz > UINT32_MAX) {
- rc = -EOVERFLOW;
+ ret = -EOVERFLOW;
goto out;
}
sig_off = loader_off + (__u32)sio.insns_sz;
if ((__u64)sig_off + sio.signature_sz > UINT32_MAX) {
- rc = -EOVERFLOW;
+ ret = -EOVERFLOW;
goto out;
}
data_off = sig_off + (__u32)sio.signature_sz;
if ((__u64)data_off + sio.data_sz > UINT32_MAX) {
- rc = -EOVERFLOW;
+ ret = -EOVERFLOW;
goto out;
}
meta_off = data_off + (__u32)sio.data_sz;
total = (__u64)meta_off + mod.hdr.metadata_len;
if (total > UPATCH_FILE_MAX) {
- rc = -E2BIG;
+ ret = -E2BIG;
goto out;
}
memcpy(name, mod.hdr.name, UPATCH_NAME_MAX);
@@ -313,35 +313,35 @@ static int package_resign_symbols(const char *original,
mod.hdr.nr_maps, mod.hdr.nr_progs);
fd = open(output, O_WRONLY | O_CREAT | O_CLOEXEC, 0644);
if (fd < 0) {
- rc = -errno;
+ ret = -errno;
goto out;
}
- rc = output_is_input(fd, original, modified) ? -EINVAL : 0;
- if (!rc && ftruncate(fd, 0))
- rc = -errno;
- wrote = !rc;
- if (!rc)
- rc = write_complete(fd, &hdr, sizeof(hdr));
- if (!rc)
- rc = write_complete(fd, sio.insns, sio.insns_sz);
- if (!rc)
- rc = write_complete(fd, sig_buf, sio.signature_sz);
- if (!rc && sio.data_sz)
- rc = write_complete(fd, sio.data, sio.data_sz);
- if (!rc && mod.hdr.metadata_len)
- rc = write_complete(fd, upatch_metadata(&mod), mod.hdr.metadata_len);
- if (!rc && fsync(fd) != 0)
- rc = -errno;
+ ret = output_is_input(fd, original, modified) ? -EINVAL : 0;
+ if (!ret && ftruncate(fd, 0))
+ ret = -errno;
+ wrote = !ret;
+ if (!ret)
+ ret = write_complete(fd, &hdr, sizeof(hdr));
+ if (!ret)
+ ret = write_complete(fd, sio.insns, sio.insns_sz);
+ if (!ret)
+ ret = write_complete(fd, sig_buf, sio.signature_sz);
+ if (!ret && sio.data_sz)
+ ret = write_complete(fd, sio.data, sio.data_sz);
+ if (!ret && mod.hdr.metadata_len)
+ ret = write_complete(fd, upatch_metadata(&mod), mod.hdr.metadata_len);
+ if (!ret && fsync(fd) != 0)
+ ret = -errno;
out:
if (fd >= 0)
close(fd);
- if (rc && wrote)
+ if (ret && wrote)
unlink(output);
if (sig_buf)
xfree(sig_buf, MAX_SIG_SIZE);
upatch_close(&mod);
upatch_close(&src);
- return rc;
+ return ret;
}
static int shirudo_build_package_resign(const char *original,
@@ -373,55 +373,55 @@ int shirudo_build_package_patch_rodata(const char *input, const char *output,
__u8 *candidate = NULL;
bool created = false;
int fd = -1;
- int rc;
+ int ret;
if (!input || !output || !symbol || !value || !value_len ||
!strcmp(input, output))
return -EINVAL;
- rc = upatch_open(input, &src);
- if (rc)
- return rc;
+ ret = upatch_open(input, &src);
+ if (ret)
+ return ret;
if (upatch_is_unload(&src)) {
- rc = -EINVAL;
+ ret = -EINVAL;
goto out;
}
- rc = verify_payload(&src, cert_path);
- if (rc)
+ ret = verify_payload(&src, cert_path);
+ if (ret)
goto out;
- rc = upatch_rodata_symbol_range(&src, symbol, &range);
- if (rc)
+ ret = upatch_rodata_symbol_range(&src, symbol, &range);
+ if (ret)
goto out;
if (value_len != range.size || range.offset > src.hdr.data_len ||
value_len > src.hdr.data_len - range.offset) {
- rc = -EINVAL;
+ ret = -EINVAL;
goto out;
}
candidate = xmalloc(src.map_size);
if (!candidate) {
- rc = -ENOMEM;
+ ret = -ENOMEM;
goto out;
}
memcpy(candidate, src.map, src.map_size);
memcpy(candidate + src.hdr.data_off + range.offset, value, value_len);
fd = mkstemp(modified);
if (fd < 0) {
- rc = -errno;
+ ret = -errno;
goto out;
}
created = true;
- rc = write_complete(fd, candidate, src.map_size);
- if (!rc && fsync(fd))
- rc = -errno;
- if (close(fd) && !rc)
- rc = -errno;
+ ret = write_complete(fd, candidate, src.map_size);
+ if (!ret && fsync(fd))
+ ret = -errno;
+ if (close(fd) && !ret)
+ ret = -errno;
fd = -1;
- if (rc)
+ if (ret)
goto out;
allowed.offset = range.offset;
allowed.length = range.size;
- rc = package_resign_symbols(input, modified, output, &allowed, 1,
- symbols, ARRAY_SIZE(symbols), pkey_path,
- cert_path);
+ ret = package_resign_symbols(input, modified, output, &allowed, 1,
+ symbols, ARRAY_SIZE(symbols), pkey_path,
+ cert_path);
out:
if (fd >= 0)
close(fd);
@@ -430,21 +430,21 @@ out:
if (candidate)
xfree(candidate, src.map_size);
upatch_close(&src);
- return rc;
+ return ret;
}
int shirudo_build_package_verify(const char *input, const char *cert_path)
{
struct shirudo_upatch upatch = {};
- int rc;
+ int ret;
- rc = upatch_open(input, &upatch);
- if (rc)
- return rc;
- rc = upatch_is_unload(&upatch) ? -EINVAL :
+ ret = upatch_open(input, &upatch);
+ if (ret)
+ return ret;
+ ret = upatch_is_unload(&upatch) ? -EINVAL :
verify_payload(&upatch, cert_path);
upatch_close(&upatch);
- return rc;
+ return ret;
}
int shirudo_build_upatch_cli(int argc, char **argv)
@@ -458,7 +458,7 @@ int shirudo_build_upatch_cli(int argc, char **argv)
int pkey_explicit = 0, cert_explicit = 0;
size_t nr_ranges = 0;
int i;
- int rc;
+ int ret;
if (argc < 2 || strcmp(argv[1], "rewrite-rodata")) {
fprintf(stderr,
@@ -519,25 +519,25 @@ int shirudo_build_upatch_cli(int argc, char **argv)
keys_dir = keys_dir_resolve(keys_dir);
if (keys_dir) {
if (!pkey_explicit) {
- rc = shirudo_key_path(pkey_buf, sizeof(pkey_buf), keys_dir,
- SIGNING_KEY_FILE);
- if (rc)
+ ret = shirudo_key_path(pkey_buf, sizeof(pkey_buf), keys_dir,
+ SIGNING_KEY_FILE);
+ if (ret)
return 2;
pkey = pkey_buf;
}
if (!cert_explicit) {
- rc = shirudo_key_path(cert_buf, sizeof(cert_buf), keys_dir,
- CERT_FILE);
- if (rc)
+ ret = shirudo_key_path(cert_buf, sizeof(cert_buf), keys_dir,
+ CERT_FILE);
+ if (ret)
return 2;
cert = cert_buf;
}
}
- rc = shirudo_build_package_resign(original, modified, output,
- ranges, nr_ranges, pkey, cert);
- if (rc)
- pr_err("upatch rewrite-rodata: %s", strerror(-rc));
- return rc ? 1 : 0;
+ ret = shirudo_build_package_resign(original, modified, output,
+ ranges, nr_ranges, pkey, cert);
+ if (ret)
+ pr_err("upatch rewrite-rodata: %s", strerror(-ret));
+ return ret ? 1 : 0;
}
static bool unsupported_kprobe_section(const char *sec)
@@ -716,17 +716,17 @@ static int split_probe_target(const char *src, char *target,
if (plus) {
const char *num = plus + 1;
size_t n = strlen(num);
- int rc;
+ int ret;
if (plus == src)
return -EINVAL;
if (n > 2 && num[0] == '0' && (num[1] == 'x' || num[1] == 'X'))
- rc = parse_x64(num + 2, n - 2, UINT64_MAX, offset);
+ ret = parse_x64(num + 2, n - 2, UINT64_MAX, offset);
else if (n > 1 && num[0] == '0')
- rc = -EINVAL;
+ ret = -EINVAL;
else
- rc = parse_u64(num, n, UINT64_MAX, offset);
- if (rc)
+ ret = parse_u64(num, n, UINT64_MAX, offset);
+ if (ret)
return -EINVAL;
len = (size_t)(plus - src);
} else {
diff --git a/tools/shirudo-build/shirudo-build.c b/tools/shirudo-build/shirudo-build.c
index c2e68928..bfab754c 100644
--- a/tools/shirudo-build/shirudo-build.c
+++ b/tools/shirudo-build/shirudo-build.c
@@ -138,17 +138,17 @@ static int compile_to_temp(const char *source, const char *vmlinux_h,
{
char tmpl[] = "/tmp/shirudo-build-XXXXXX.bpf.o";
int fd;
- int rc;
+ int ret;
fd = mkstemps(tmpl, strlen(".bpf.o"));
if (fd < 0)
return -errno;
close(fd);
- rc = shirudo_build_compile(source, tmpl, vmlinux_h, extra_cflags, NULL);
- if (rc) {
+ ret = shirudo_build_compile(source, tmpl, vmlinux_h, extra_cflags, NULL);
+ if (ret) {
unlink(tmpl);
- return rc;
+ return ret;
}
*out_path = xstrdup(tmpl);
if (!*out_path) {
@@ -203,7 +203,7 @@ int main(int argc, char **argv)
int emit_artifacts = 0;
int pkey_explicit = 0;
int cert_explicit = 0;
- int rc;
+ int ret;
int i;
harden_stdio();
@@ -267,22 +267,22 @@ int main(int argc, char **argv)
if (keys_dir) {
if (!pkey_explicit) {
- rc = shirudo_key_path(pkey_path, sizeof(pkey_path),
- keys_dir,
- SIGNING_KEY_FILE);
- if (rc) {
+ ret = shirudo_key_path(pkey_path, sizeof(pkey_path),
+ keys_dir,
+ SIGNING_KEY_FILE);
+ if (ret) {
pr_err("invalid keys dir %s: %s",
- keys_dir, strerror(-rc));
+ keys_dir, strerror(-ret));
return 2;
}
pkey = pkey_path;
}
if (!cert_explicit) {
- rc = shirudo_key_path(cert_path, sizeof(cert_path),
- keys_dir, CERT_FILE);
- if (rc) {
+ ret = shirudo_key_path(cert_path, sizeof(cert_path),
+ keys_dir, CERT_FILE);
+ if (ret) {
pr_err("invalid keys dir %s: %s",
- keys_dir, strerror(-rc));
+ keys_dir, strerror(-ret));
return 2;
}
cert = cert_path;
@@ -347,15 +347,15 @@ int main(int argc, char **argv)
pr_info("writing %s (no -o given)", output);
}
- rc = shirudo_build_package_unload(unload_name, payload_sha256,
- output, pkey, cert);
- if (rc == 0 && emit_artifacts) {
+ ret = shirudo_build_package_unload(unload_name, payload_sha256,
+ output, pkey, cert);
+ if (ret == 0 && emit_artifacts) {
printf("emitted:\n");
printf(" upatch: %s\n", output);
printf(" bpf.o: (none; --unload embeds the prebuilt "
"unload program)\n");
}
- return rc ? 1 : 0;
+ return ret ? 1 : 0;
}
if (!input) {
@@ -369,10 +369,10 @@ int main(int argc, char **argv)
* same directory as the .upatch.
*/
if (!output) {
- rc = derive_output(input, output_buf, sizeof(output_buf));
- if (rc) {
+ ret = derive_output(input, output_buf, sizeof(output_buf));
+ if (ret) {
pr_err("cannot derive output path from %s: %s",
- input, strerror(-rc));
+ input, strerror(-ret));
return 1;
}
output = output_buf;
@@ -390,26 +390,26 @@ int main(int argc, char **argv)
return 1;
}
if (emit_artifacts) {
- rc = derive_artifact_o(output, artifact_buf,
- sizeof(artifact_buf));
- if (rc) {
+ ret = derive_artifact_o(output, artifact_buf,
+ sizeof(artifact_buf));
+ if (ret) {
pr_err("cannot derive .bpf.o path from %s: %s",
- output, strerror(-rc));
+ output, strerror(-ret));
return 1;
}
- rc = shirudo_build_compile(input, artifact_buf,
- vmlinux_h, extra_cflags, NULL);
- if (rc) {
- pr_err("compile %s: %d", input, rc);
+ ret = shirudo_build_compile(input, artifact_buf,
+ vmlinux_h, extra_cflags, NULL);
+ if (ret) {
+ pr_err("compile %s: %d", input, ret);
return 1;
}
bpf_o = artifact_buf;
emitted_o = artifact_buf;
} else {
- rc = compile_to_temp(input, vmlinux_h, extra_cflags,
- &temp_bpf_o);
- if (rc) {
- pr_err("compile %s: %d", input, rc);
+ ret = compile_to_temp(input, vmlinux_h, extra_cflags,
+ &temp_bpf_o);
+ if (ret) {
+ pr_err("compile %s: %d", input, ret);
return 1;
}
bpf_o = temp_bpf_o;
@@ -425,15 +425,15 @@ int main(int argc, char **argv)
if (!name)
name = derive_name(input, name_buf, sizeof(name_buf));
- rc = shirudo_build_package_load(bpf_o, src_path, output, name,
- pkey, cert);
+ ret = shirudo_build_package_load(bpf_o, src_path, output, name,
+ pkey, cert);
if (temp_bpf_o) {
unlink(temp_bpf_o);
xstrfree(temp_bpf_o);
}
- if (rc == 0 && emit_artifacts) {
+ if (ret == 0 && emit_artifacts) {
printf("emitted:\n");
printf(" upatch: %s\n", output);
if (emitted_o)
@@ -442,5 +442,5 @@ int main(int argc, char **argv)
printf(" bpf.o: (none; input was a pre-compiled "
"object, not recompiled)\n");
}
- return rc ? 1 : 0;
+ return ret ? 1 : 0;
}
diff --git a/tools/shirudo-build/vouch.c b/tools/shirudo-build/vouch.c
index 26db590b..631ee264 100644
--- a/tools/shirudo-build/vouch.c
+++ b/tools/shirudo-build/vouch.c
@@ -45,18 +45,18 @@ static int cert_algorithm_ok(const __u8 *der, size_t der_sz,
{
struct shirudo_cert cert = {};
char name[64] = {};
- int rc;
+ int ret;
- rc = cert_read_der(der, der_sz, &cert);
- if (rc) {
+ ret = cert_read_der(der, der_sz, &cert);
+ if (ret) {
pr_err("%s is not a certificate", what);
- return rc;
+ return ret;
}
- rc = cert_key_algorithm(&cert, name, sizeof(name));
+ ret = cert_key_algorithm(&cert, name, sizeof(name));
cert_free(&cert);
- if (rc || strcmp(name, "ML-DSA-87")) {
+ if (ret || strcmp(name, "ML-DSA-87")) {
pr_err("%s is %s; shirudo accepts only ML-DSA-87", what,
- rc ? "of an unknown algorithm" : name);
+ ret ? "of an unknown algorithm" : name);
return -EKEYREJECTED;
}
return 0;
@@ -64,17 +64,17 @@ static int cert_algorithm_ok(const __u8 *der, size_t der_sz,
static int write_file(const char *path, const void *data, size_t len)
{
- int fd, rc;
+ int fd, ret;
fd = open(path, O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC, 0644);
if (fd < 0)
return -errno;
- rc = write_complete(fd, data, len);
- if (close(fd) && !rc)
- rc = -errno;
- if (rc)
+ ret = write_complete(fd, data, len);
+ if (close(fd) && !ret)
+ ret = -errno;
+ if (ret)
unlink(path);
- return rc;
+ return ret;
}
int shirudo_build_keys_vouch(int argc, char **argv)
@@ -91,7 +91,7 @@ int shirudo_build_keys_vouch(int argc, char **argv)
char cert_path[PATH_MAX];
char out_path[PATH_MAX];
const char *keys_dir;
- int rc = 1;
+ int ret = 1;
for (int i = 1; i < argc; i++) {
const char *a = argv[i];
@@ -156,26 +156,26 @@ int shirudo_build_keys_vouch(int argc, char **argv)
output = out_path;
}
- rc = keys_read_der(input, &der, &der_sz);
- if (rc) {
- pr_err("keys vouch: read %s: %s", input, strerror(-rc));
+ ret = keys_read_der(input, &der, &der_sz);
+ if (ret) {
+ pr_err("keys vouch: read %s: %s", input, strerror(-ret));
return 1;
}
- rc = keys_digest_der(der, der_sz, sha, fp);
- if (rc) {
+ ret = keys_digest_der(der, der_sz, sha, fp);
+ if (ret) {
pr_err("keys vouch: %s is not a certificate", input);
goto out;
}
- rc = cert_algorithm_ok(der, der_sz, input);
- if (rc)
+ ret = cert_algorithm_ok(der, der_sz, input);
+ if (ret)
goto out;
- rc = keys_read_der(cert, &own, &own_sz);
- if (rc) {
- pr_err("keys vouch: read %s: %s", cert, strerror(-rc));
+ ret = keys_read_der(cert, &own, &own_sz);
+ if (ret) {
+ pr_err("keys vouch: read %s: %s", cert, strerror(-ret));
goto out;
}
- rc = keys_digest_der(own, own_sz, sha, own_fp);
- if (rc) {
+ ret = keys_digest_der(own, own_sz, sha, own_fp);
+ if (ret) {
pr_err("keys vouch: %s is not a certificate", cert);
goto out;
}
@@ -184,28 +184,28 @@ int shirudo_build_keys_vouch(int argc, char **argv)
if (!memcmp(fp, own_fp, 32)) {
pr_err("keys vouch: %s holds the signing key itself; a key "
"cannot vouch for its own certificate", input);
- rc = -EINVAL;
+ ret = -EINVAL;
goto out;
}
- rc = keys_vouch_payload(der, der_sz, &payload, &payload_sz);
- if (rc)
+ ret = keys_vouch_payload(der, der_sz, &payload, &payload_sz);
+ if (ret)
goto out;
io.insns = payload;
io.insns_sz = payload_sz;
io.signature_sz = VOUCH_SIG_MAX;
io.signature = xmalloc(VOUCH_SIG_MAX);
if (!io.signature) {
- rc = -ENOMEM;
+ ret = -ENOMEM;
goto out;
}
- rc = cms_sign(&io, pkey, cert);
- if (rc) {
- pr_err("keys vouch: sign: %s", strerror(-rc));
+ ret = cms_sign(&io, pkey, cert);
+ if (ret) {
+ pr_err("keys vouch: sign: %s", strerror(-ret));
goto out;
}
- rc = write_file(output, io.signature, io.signature_sz);
- if (rc) {
- pr_err("keys vouch: write %s: %s", output, strerror(-rc));
+ ret = write_file(output, io.signature, io.signature_sz);
+ if (ret) {
+ pr_err("keys vouch: write %s: %s", output, strerror(-ret));
goto out;
}
pr_info("keys vouch: %s vouched for by %s, written to %s", fp_hex,
@@ -219,5 +219,5 @@ out:
if (own)
xfree(own, own_sz);
xfree(der, der_sz);
- return rc ? 1 : 0;
+ return ret ? 1 : 0;
}
diff --git a/upatches/kernel-obs/kernel-obs.bpf.c b/upatches/kernel-obs/kernel-obs.bpf.c
index e8166610..65ae01e8 100644
--- a/upatches/kernel-obs/kernel-obs.bpf.c
+++ b/upatches/kernel-obs/kernel-obs.bpf.c
@@ -108,23 +108,23 @@ SEC("syscall")
int shirudo_test__kernel_obs(void *ctx)
{
__u64 now = obs_now();
- int rc;
+ int ret;
(void)ctx;
- rc = priv_init(now);
- if (!rc)
- rc = exec_init(now);
- if (!rc)
- rc = net_init(now);
- if (!rc)
- rc = socket_init(now);
- if (!rc)
- rc = listen_init(now);
- if (!rc)
- rc = watch_init(now);
- if (!rc)
- rc = dns_init(now);
- if (!rc)
- rc = file_init(now);
- return rc;
+ ret = priv_init(now);
+ if (!ret)
+ ret = exec_init(now);
+ if (!ret)
+ ret = net_init(now);
+ if (!ret)
+ ret = socket_init(now);
+ if (!ret)
+ ret = listen_init(now);
+ if (!ret)
+ ret = watch_init(now);
+ if (!ret)
+ ret = dns_init(now);
+ if (!ret)
+ ret = file_init(now);
+ return ret;
}
diff --git a/upatches/kernel-obs/obs_table.h b/upatches/kernel-obs/obs_table.h
index 0fdd4771..1f82b59e 100644
--- a/upatches/kernel-obs/obs_table.h
+++ b/upatches/kernel-obs/obs_table.h
@@ -269,7 +269,7 @@ struct OBS_FN(emit_ctx) {
__u32 used;
__u32 output_slots;
__u32 next;
- int rc;
+ int ret;
};
static int OBS_FN(emit_cb)(__u32 scanned, void *data)
@@ -278,9 +278,9 @@ static int OBS_FN(emit_cb)(__u32 scanned, void *data)
struct OBS_FN(entry) __arena *e;
struct shirudo_serial_chunk *chunk;
__u32 idx, off;
- int rc;
+ int ret;
- if (emit->rc)
+ if (emit->ret)
return 1;
idx = emit->start + scanned + 1;
if (idx == 0 || idx > emit->used || idx > OBS_T_CAPACITY) {
@@ -297,14 +297,14 @@ static int OBS_FN(emit_cb)(__u32 scanned, void *data)
return 0;
chunk = OBS_FN(slot)(emit->output_slots, &off);
if (!chunk) {
- emit->rc = -ENOSPC;
+ emit->ret = -ENOSPC;
return 1;
}
*(__u32 *)&chunk->data[off] = idx;
*(__u32 *)&chunk->data[off + 4] = OBS_REC_F_PRESENT;
- rc = OBS_T_EMIT(chunk, off, e);
- if (rc) {
- emit->rc = rc;
+ ret = OBS_T_EMIT(chunk, off, e);
+ if (ret) {
+ emit->ret = ret;
return 1;
}
emit->output_slots++;
@@ -319,7 +319,7 @@ int OBS_CAT(shirudo_serialize__, OBS_T_MAP)(struct shirudo_serialize_ctx *ctx)
__u32 flags = 0, hdr_flags = 0, total_chunks, page_bytes, scan, i;
__u64 now = obs_now();
bool peek;
- int rc;
+ int ret;
if (!obs_serial_ctx_valid(ctx))
return -EINVAL;
@@ -348,19 +348,19 @@ int OBS_CAT(shirudo_serialize__, OBS_T_MAP)(struct shirudo_serialize_ctx *ctx)
#pragma clang loop unroll(full)
for (i = 0; i < OBS_SERIAL_PAGE_CHUNKS; i++) {
- rc = OBS_FN(chunk_meta)(i, 0, OBS_SERIAL_PAGE_CHUNKS,
- OBS_SERIAL_PAGE_CHUNKS *
- SERIAL_CHUNK_PAYLOAD,
- ctx, ctx->cursor);
- if (rc) {
- obs_serial_error(ctx, rc);
- return rc;
+ ret = OBS_FN(chunk_meta)(i, 0, OBS_SERIAL_PAGE_CHUNKS,
+ OBS_SERIAL_PAGE_CHUNKS *
+ SERIAL_CHUNK_PAYLOAD,
+ ctx, ctx->cursor);
+ if (ret) {
+ obs_serial_error(ctx, ret);
+ return ret;
}
}
- rc = OBS_FN(emit_header)(state, hdr_flags, now);
- if (rc) {
- obs_serial_error(ctx, rc);
- return rc;
+ ret = OBS_FN(emit_header)(state, hdr_flags, now);
+ if (ret) {
+ obs_serial_error(ctx, ret);
+ return ret;
}
emit.state = state;
@@ -372,14 +372,14 @@ int OBS_CAT(shirudo_serialize__, OBS_T_MAP)(struct shirudo_serialize_ctx *ctx)
emit.next = emit.start;
if (emit.start < emit.used) {
scan = emit.used - emit.start;
- rc = bpf_loop(scan, OBS_FN(emit_cb), &emit, 0);
- if (rc < 0) {
- obs_serial_error(ctx, rc);
- return rc;
+ ret = bpf_loop(scan, OBS_FN(emit_cb), &emit, 0);
+ if (ret < 0) {
+ obs_serial_error(ctx, ret);
+ return ret;
}
- if (emit.rc) {
- obs_serial_error(ctx, emit.rc);
- return emit.rc;
+ if (emit.ret) {
+ obs_serial_error(ctx, emit.ret);
+ return emit.ret;
}
} else {
emit.next = emit.used;
@@ -401,10 +401,10 @@ int OBS_CAT(shirudo_serialize__, OBS_T_MAP)(struct shirudo_serialize_ctx *ctx)
OBS_T_PER_CHUNK) * OBS_T_RECORD;
#pragma clang loop unroll(full)
for (i = 0; i < OBS_SERIAL_PAGE_CHUNKS; i++) {
- rc = OBS_FN(chunk_meta)(i, flags, total_chunks, page_bytes,
- ctx, emit.next);
- if (rc)
- return rc;
+ ret = OBS_FN(chunk_meta)(i, flags, total_chunks, page_bytes,
+ ctx, emit.next);
+ if (ret)
+ return ret;
}
return 0;
}
diff --git a/util/attest.c b/util/attest.c
index 8f6e710a..5bab355c 100644
--- a/util/attest.c
+++ b/util/attest.c
@@ -54,7 +54,7 @@ static int read_file_base64(const char *path, char **out, size_t *out_cap)
__u8 *raw;
size_t len = 0, cap;
ssize_t got;
- int fd, rc = 0;
+ int fd, ret = 0;
*out = NULL;
*out_cap = 0;
@@ -71,26 +71,26 @@ static int read_file_base64(const char *path, char **out, size_t *out_cap)
if (got < 0 && errno == EINTR)
continue;
if (got < 0)
- rc = -errno;
+ ret = -errno;
if (got <= 0)
break;
len += (size_t)got;
}
close(fd);
- if (!rc && (len == 0 || len > LOG_MAX_BYTES))
- rc = -EFBIG;
- if (rc) {
+ if (!ret && (len == 0 || len > LOG_MAX_BYTES))
+ ret = -EFBIG;
+ if (ret) {
xfree(raw, LOG_MAX_BYTES + 1);
- return rc;
+ return ret;
}
cap = 4 * ((len + 2) / 3) + 1;
*out = xmalloc(cap);
- rc = *out ? base64_encode(raw, len, *out, cap) : -ENOMEM;
+ ret = *out ? base64_encode(raw, len, *out, cap) : -ENOMEM;
xfree(raw, LOG_MAX_BYTES + 1);
- if (rc) {
+ if (ret) {
xfree(*out, cap);
*out = NULL;
- return rc;
+ return ret;
}
*out_cap = cap;
return 0;
@@ -165,7 +165,7 @@ int shirudo_attest_evidence_config(const __u8 *nonce, size_t nonce_len,
struct stat st;
__u32 i, attempt;
bool ek_cert_rsa = false, ek_rsa;
- int rc;
+ int ret;
*out = NULL;
*len = 0;
@@ -174,47 +174,47 @@ int shirudo_attest_evidence_config(const __u8 *nonce, size_t nonce_len,
(pcr_mask & ~0x00FFFFFFu))
return -EINVAL;
- rc = shirudo_config_evidence_collect(update, &config);
- if (rc)
- return rc;
+ ret = shirudo_config_evidence_collect(update, &config);
+ if (ret)
+ return ret;
if (config.present)
pcr_mask |= 1u << config.pcr;
- rc = tpm_open(&tpm);
- if (rc) {
- rc = -ENXIO;
+ ret = tpm_open(&tpm);
+ if (ret) {
+ ret = -ENXIO;
goto out;
}
- rc = tpm_nv_info(tpm, NV_INDEX, &nv);
- if (rc)
+ ret = tpm_nv_info(tpm, NV_INDEX, &nv);
+ if (ret)
goto out;
if (!nv.defined || !nv.written) {
- rc = -ENODEV;
+ ret = -ENODEV;
goto out;
}
- rc = tpm_nv_read(tpm, NV_INDEX, reg);
- if (rc)
+ ret = tpm_nv_read(tpm, NV_INDEX, reg);
+ if (ret)
goto out;
- rc = tpm_ak_create(tpm, &ak);
- if (rc)
+ ret = tpm_ak_create(tpm, &ak);
+ if (ret)
goto out;
for (attempt = 0; attempt < QUOTE_ATTEMPTS; attempt++) {
for (i = 0; i < 24; i++) {
if (!(pcr_mask & (1u << i)))
continue;
- rc = tpm_pcr_read(tpm, i, values[i]);
- if (rc)
+ ret = tpm_pcr_read(tpm, i, values[i]);
+ if (ret)
goto out;
}
- rc = tpm_quote(tpm, &ak, nonce, nonce_len, pcr_mask,
- &quote);
- if (rc)
+ ret = tpm_quote(tpm, &ak, nonce, nonce_len, pcr_mask,
+ &quote);
+ if (ret)
goto out;
if (quote_covers(&quote, pcr_mask, values))
break;
}
if (attempt == QUOTE_ATTEMPTS) {
pr_err("attest: PCRs kept changing while quoting");
- rc = -EAGAIN;
+ ret = -EAGAIN;
goto out;
}
if (config.present &&
@@ -224,16 +224,16 @@ int shirudo_attest_evidence_config(const __u8 *nonce, size_t nonce_len,
quoted.restart_count != config.restart_count ||
memcmp(values[config.pcr],
config.value, 32))) {
- rc = -EUCLEAN;
+ ret = -EUCLEAN;
goto out;
}
- rc = tpm_nv_certify(tpm, &ak, NV_INDEX, nonce,
- nonce_len, &certify);
- if (rc)
+ ret = tpm_nv_certify(tpm, &ak, NV_INDEX, nonce,
+ nonce_len, &certify);
+ if (ret)
goto out;
ek_cert = xmalloc(EK_CERT_MAX);
if (!ek_cert) {
- rc = -ENOMEM;
+ ret = -ENOMEM;
goto out;
}
if (tpm_ek_certificate(tpm, ek_cert, EK_CERT_MAX, &ek_cert_len,
@@ -253,25 +253,25 @@ int shirudo_attest_evidence_config(const __u8 *nonce, size_t nonce_len,
* ECC key, which the operator pins by name.
*/
ek_rsa = challenge ? challenge->ek_rsa : ek_cert_rsa;
- rc = tpm_ek_create(tpm, ek_rsa, &ek);
- if (rc)
+ ret = tpm_ek_create(tpm, ek_rsa, &ek);
+ if (ret)
goto out;
if (challenge) {
if (ak.name_len != TPM_NAME_LEN ||
memcmp(challenge->ak_name, ak.name, TPM_NAME_LEN)) {
pr_err("attest: the challenge was made for another "
"attestation key");
- rc = -EKEYREJECTED;
+ ret = -EKEYREJECTED;
goto out;
}
- rc = tpm_activate_credential(tpm, &ak, &ek,
- challenge->blob,
- challenge->blob_len,
- challenge->secret,
- challenge->secret_len,
- cred, sizeof(cred),
- &cred_len);
- if (rc) {
+ ret = tpm_activate_credential(tpm, &ak, &ek,
+ challenge->blob,
+ challenge->blob_len,
+ challenge->secret,
+ challenge->secret_len,
+ cred, sizeof(cred),
+ &cred_len);
+ if (ret) {
pr_err("attest: the TPM refused the challenge: not "
"made for this attestation key under this "
"endorsement key");
@@ -296,7 +296,7 @@ int shirudo_attest_evidence_config(const __u8 *nonce, size_t nonce_len,
need = JSON_MAX_BYTES;
*out = xmalloc(need);
if (!*out) {
- rc = -ENOMEM;
+ ret = -ENOMEM;
goto out;
}
*cap = need;
@@ -305,7 +305,7 @@ int shirudo_attest_evidence_config(const __u8 *nonce, size_t nonce_len,
eventlog_boot_id(boot_id, sizeof(boot_id));
if (strsprintf(nv_index, sizeof(nv_index), "0x%08X",
NV_INDEX) < 0) {
- rc = -E2BIG;
+ ret = -E2BIG;
goto out;
}
hex_encode(nonce, nonce_len, nonce_hex);
@@ -354,8 +354,8 @@ int shirudo_attest_evidence_config(const __u8 *nonce, size_t nonce_len,
json_arr_open(&e, "eventlog");
eventlog_boot_lines(emit_line, &e);
json_arr_close(&e);
- rc = shirudo_config_evidence_emit(&e, &config);
- if (rc)
+ ret = shirudo_config_evidence_emit(&e, &config);
+ if (ret)
goto out;
if (cred_len) {
json_obj_open_key(&e, "credential");
@@ -380,12 +380,12 @@ int shirudo_attest_evidence_config(const __u8 *nonce, size_t nonce_len,
json_obj_close(&e);
json_obj_close(&e);
if (e.err) {
- rc = e.err;
+ ret = e.err;
goto out;
}
(*out)[e.len] = '\0';
*len = e.len;
- rc = 0;
+ ret = 0;
out:
if (tpm) {
tpm_key_flush(tpm, &ek);
@@ -402,12 +402,12 @@ out:
explicit_bzero(&ek, sizeof(ek));
explicit_bzero(&ak_copy, sizeof(ak_copy));
explicit_bzero(&ek_copy, sizeof(ek_copy));
- if (rc && *out) {
+ if (ret && *out) {
xfree(*out, *cap);
*out = NULL;
*cap = 0;
}
- return rc;
+ return ret;
}
/* ---- verification ---------------------------------------------------- */
@@ -685,7 +685,7 @@ static int check_signed(struct reporter *rep, const char *what,
__u8 sig[TPM_SIGNATURE_MAX], r[32], s[32], digest[32];
__u8 qn[TPM_NAME_LEN];
size_t sig_len;
- int rc;
+ int ret;
if (hex_bytes(attest_hex, attest, attest_cap, attest_len) ||
hex_bytes(sig_hex, sig, sizeof(sig), &sig_len))
@@ -699,8 +699,8 @@ static int check_signed(struct reporter *rep, const char *what,
return -EKEYREJECTED;
}
shirudo_sha256(attest, *attest_len, digest);
- rc = ecdsa_p256_verify(ak->x, ak->y, digest, r, s);
- say(rep, rc == 0, "%s: ECDSA signature by the attestation key", what);
+ ret = ecdsa_p256_verify(ak->x, ak->y, digest, r, s);
+ say(rep, ret == 0, "%s: ECDSA signature by the attestation key", what);
tpm_qualified_name(TPM_RH_ENDORSEMENT, ak_name, qn);
say(rep, parsed->signer_len == TPM_NAME_LEN &&
ct_eq(parsed->signer, qn, TPM_NAME_LEN),
@@ -733,7 +733,7 @@ int attest_verify(const char *evidence, size_t len,
__u64 reg_index;
__u32 bit;
bool have_ek = false, have_cred = false;
- int rc = 0, qrc = -1, crc = -1;
+ int ret = 0, qrc = -1, crc = -1;
if (report_cap)
report[0] = '\0';
@@ -880,26 +880,26 @@ int attest_verify(const char *evidence, size_t len,
cred_sub, ARRAY_SIZE(cred_sub) },
};
- rc = json_parse(evidence, len, top, ARRAY_SIZE(top));
- if (rc || !top[0].seen || !top[1].seen || !top[2].seen ||
+ ret = json_parse(evidence, len, top, ARRAY_SIZE(top));
+ if (ret || !top[0].seen || !top[1].seen || !top[2].seen ||
!top[3].seen || !top[4].seen || !top[5].seen ||
!top[6].seen) {
- rc = -EINVAL;
+ ret = -EINVAL;
goto out;
}
have_ek = ek_sub[0].seen && ek_sub[1].seen && ek_sub[2].seen;
have_cred = cred_sub[0].seen;
}
- rc = shirudo_config_evidence_parse(evidence, len, &config);
- if (rc == -EKEYREJECTED)
+ ret = shirudo_config_evidence_parse(evidence, len, &config);
+ if (ret == -EKEYREJECTED)
say(&rep, false, "config: the events are one boot event followed by updates in sequence");
- if (rc)
+ if (ret)
goto out;
/* Freshness: the document must answer this request. */
if (hex_bytes(p->nonce_hex, nonce, sizeof(nonce), &nonce_len)) {
- rc = -EINVAL;
+ ret = -EINVAL;
goto out;
}
say(&rep, expect->nonce_len == nonce_len &&
@@ -911,13 +911,13 @@ int attest_verify(const char *evidence, size_t len,
&ak_public_len) ||
hex_bytes(p->ak_name_hex, ak_name, sizeof(ak_name), &ak_name_len) ||
ak_name_len != TPM_NAME_LEN) {
- rc = -EINVAL;
+ ret = -EINVAL;
goto out;
}
if (tpm_ecc_public_parse(ak_public, ak_public_len, &ak_pub)) {
say(&rep, false, "attestation key: public area is not a "
"P-256 ECDSA key");
- rc = -EKEYREJECTED;
+ ret = -EKEYREJECTED;
goto out;
}
say(&rep, (ak_pub.attrs & AK_ATTRS_REQUIRED) == AK_ATTRS_REQUIRED,
@@ -948,7 +948,7 @@ int attest_verify(const char *evidence, size_t len,
&ek_public_len) ||
hex_bytes(p->ek_name_hex, ek_name, sizeof(ek_name),
&ek_name_len) || ek_name_len != TPM_NAME_LEN) {
- rc = -EINVAL;
+ ret = -EINVAL;
goto out;
}
parsed = tpm_public_parse(ek_public, ek_public_len,
@@ -976,7 +976,7 @@ int attest_verify(const char *evidence, size_t len,
"endorsement key: the pinned key");
}
if (have_cred && hex_bytes(p->cred_hex, cred, sizeof(cred), &cred_len)) {
- rc = -EINVAL;
+ ret = -EINVAL;
goto out;
}
if (expect->have_credential)
@@ -989,13 +989,13 @@ int attest_verify(const char *evidence, size_t len,
note(&rep, "a credential was activated but none is expected "
"(--expect-credential)");
- rc = check_signed(&rep, "quote", p->quote_attest_hex, p->quote_sig_hex,
- &ak_pub, ak_name, nonce, nonce_len, attest,
- sizeof(attest), &attest_len, &quote);
- if (rc == -EINVAL)
+ ret = check_signed(&rep, "quote", p->quote_attest_hex, p->quote_sig_hex,
+ &ak_pub, ak_name, nonce, nonce_len, attest,
+ sizeof(attest), &attest_len, &quote);
+ if (ret == -EINVAL)
goto out;
- qrc = rc;
- if (rc == 0) {
+ qrc = ret;
+ if (ret == 0) {
struct shirudo_sha256_ctx ctx;
__u8 digest[32] = {};
bool complete =
@@ -1024,12 +1024,12 @@ int attest_verify(const char *evidence, size_t len,
p->pcr_have = 0;
}
- rc = check_signed(&rep, "register", p->reg_attest_hex, p->reg_sig_hex,
- &ak_pub, ak_name, nonce, nonce_len, attest,
- sizeof(attest), &attest_len, &certify);
- if (rc == -EINVAL)
+ ret = check_signed(&rep, "register", p->reg_attest_hex, p->reg_sig_hex,
+ &ak_pub, ak_name, nonce, nonce_len, attest,
+ sizeof(attest), &attest_len, &certify);
+ if (ret == -EINVAL)
goto out;
- crc = rc;
+ crc = ret;
if (hex_bytes(p->reg_name_hex, reg_name, sizeof(reg_name),
&reg_name_len) ||
reg_name_len != TPM_NAME_LEN ||
@@ -1039,10 +1039,10 @@ int attest_verify(const char *evidence, size_t len,
parse_x64(p->reg_index + 2, strlen(p->reg_index + 2), 0xffffffffULL,
&reg_index) ||
p->reg_pcr < 0 || p->reg_pcr >= 24) {
- rc = -EINVAL;
+ ret = -EINVAL;
goto out;
}
- if (rc == 0) {
+ if (ret == 0) {
say(&rep, certify.type == TPM_ST_ATTEST_NV &&
certify.index_name_len == TPM_NAME_LEN &&
ct_eq(certify.index_name, reg_name,
@@ -1066,12 +1066,12 @@ int attest_verify(const char *evidence, size_t len,
int pcr;
pcr = expect->have_config_pcr ? (int)expect->config_pcr : -1;
- rc = shirudo_config_evidence_verify(&config, quote.pcr_mask,
- quote.reset_count,
- quote.restart_count,
- p->pcrs, root, pcr,
- &reason);
- say(&rep, !rc, "config: %s", reason);
+ ret = shirudo_config_evidence_verify(&config, quote.pcr_mask,
+ quote.reset_count,
+ quote.restart_count,
+ p->pcrs, root, pcr,
+ &reason);
+ say(&rep, !ret, "config: %s", reason);
if (config.present && !expect->have_config_root)
note(&rep, "config root has no operator approval; use "
"--expect-config-root with --expect-config-pcr");
@@ -1091,7 +1091,7 @@ int attest_verify(const char *evidence, size_t len,
*/
say(&rep, p->init.present, "eventlog: this boot has an init record");
if (!p->init.present) {
- rc = -EKEYREJECTED;
+ ret = -EKEYREJECTED;
goto out;
}
say(&rep, reg_index == NV_INDEX &&
@@ -1102,14 +1102,14 @@ int attest_verify(const char *evidence, size_t len,
NV_INDEX, CHAIN_PCR, CHAIN_PHASE_PCR);
memcpy(bind, p->init.pcr_before, 32);
memcpy(bind + 32, p->init.phase_before, 32);
- rc = tpm_register_policy(CHAIN_PCR_MASK, bind, 2,
- p->init.writer_public,
- branch_written, branch_init, policy);
- if (rc) {
+ ret = tpm_register_policy(CHAIN_PCR_MASK, bind, 2,
+ p->init.writer_public,
+ branch_written, branch_init, policy);
+ if (ret) {
say(&rep, false, "register: cannot compute the signed write policy");
/* Malformed recorded values are the document's failure, not a parse error. */
- if (rc == -EINVAL)
- rc = -EKEYREJECTED;
+ if (ret == -EINVAL)
+ ret = -EKEYREJECTED;
goto out;
}
tpm_nv_name(NV_INDEX,
@@ -1234,12 +1234,12 @@ int attest_verify(const char *evidence, size_t len,
ct_eq(p->pcrs[bit], expect->pcrs[bit], 32),
"PCR %u matches the expected value", bit);
}
- rc = rep.failed ? -EKEYREJECTED : 0;
+ ret = rep.failed ? -EKEYREJECTED : 0;
out:
shirudo_config_evidence_clear(&config);
xfree(p->recs, RECORDS_MAX * sizeof(*p->recs));
xfree(p, sizeof(*p));
- return rc;
+ return ret;
}
int attest_challenge_read(const char *path,
@@ -1265,7 +1265,7 @@ int attest_challenge_read(const char *path,
};
size_t len, ak_len;
char *doc;
- int rc;
+ int ret;
memset(out, 0, sizeof(*out));
kind[0] = '\0';
@@ -1273,12 +1273,12 @@ int attest_challenge_read(const char *path,
ak_hex[0] = '\0';
blob_hex[0] = '\0';
secret_hex[0] = '\0';
- rc = read_file(path, ATTEST_CHALLENGE_MAX, &doc, &len);
- if (rc)
- return rc;
- rc = json_parse(doc, len, top, ARRAY_SIZE(top));
+ ret = read_file(path, ATTEST_CHALLENGE_MAX, &doc, &len);
+ if (ret)
+ return ret;
+ ret = json_parse(doc, len, top, ARRAY_SIZE(top));
xfree(doc, len + 1);
- if (rc || !top[0].seen || strcmp(kind, "shirudo-credential") ||
+ if (ret || !top[0].seen || strcmp(kind, "shirudo-credential") ||
!ek_sub[0].seen || !top[2].seen || !top[3].seen || !top[4].seen)
return -EINVAL;
if (!strcmp(type, "rsa"))
@@ -1354,7 +1354,7 @@ int attest_challenge_make(const char *evidence, size_t len,
};
size_t ak_len, ek_public_len, ek_name_len, secret_len = 0, der_len = 0;
const char *reason = "";
- int rc = -EINVAL;
+ int ret = -EINVAL;
bool rsa;
*out = NULL;
@@ -1413,7 +1413,7 @@ int attest_challenge_make(const char *evidence, size_t len,
if (top[2].seen) {
der = xmalloc(EK_CERT_MAX);
if (!der) {
- rc = -ENOMEM;
+ ret = -ENOMEM;
goto out;
}
if (base64_decode(cert_b64, strlen(cert_b64), der,
@@ -1459,11 +1459,11 @@ int attest_challenge_make(const char *evidence, size_t len,
"with --ek-name or waive with --trust-presented-ek");
}
if (rep.failed) {
- rc = -EKEYREJECTED;
+ ret = -EKEYREJECTED;
goto out;
}
- rc = -EIO;
+ ret = -EIO;
if (getrandom(credential, TPM_CREDENTIAL_LEN, 0) !=
TPM_CREDENTIAL_LEN)
goto out;
@@ -1492,7 +1492,7 @@ int attest_challenge_make(const char *evidence, size_t len,
*cap = 4096;
*out = xmalloc(*cap);
if (!*out) {
- rc = -ENOMEM;
+ ret = -ENOMEM;
goto out;
}
e = (struct shirudo_json_emit){ .buf = *out, .cap = *cap };
@@ -1510,19 +1510,19 @@ int attest_challenge_make(const char *evidence, size_t len,
json_kv_string(&e, "secret", hex);
json_obj_close(&e);
if (e.err) {
- rc = e.err;
+ ret = e.err;
goto out;
}
(*out)[e.len] = '\0';
*out_len = e.len;
- rc = 0;
+ ret = 0;
out:
explicit_bzero(seed, sizeof(seed));
explicit_bzero(z, sizeof(z));
cert_free(&cert);
xfree(der, der ? EK_CERT_MAX : 0);
xfree(cert_b64, EK_CERT_B64_MAX);
- if (rc) {
+ if (ret) {
explicit_bzero(credential, TPM_CREDENTIAL_LEN);
if (*out) {
xfree(*out, *cap);
@@ -1530,5 +1530,5 @@ out:
*cap = 0;
}
}
- return rc;
+ return ret;
}
diff --git a/util/bpm_oci.c b/util/bpm_oci.c
index 2e8a3265..66d2e24f 100644
--- a/util/bpm_oci.c
+++ b/util/bpm_oci.c
@@ -278,7 +278,7 @@ static int load_registry_auth(const char *registry, struct bpm_oci_client *c)
__u8 *body = NULL;
size_t body_len = 0;
char *p, *end, *auth;
- int rc;
+ int ret;
if (getenv("BPM_OCI_USERNAME") && getenv("BPM_OCI_PASSWORD")) {
if (strscpy(c->username, getenv("BPM_OCI_USERNAME"),
@@ -305,9 +305,9 @@ static int load_registry_auth(const char *registry, struct bpm_oci_client *c)
}
if (strsprintf(needle, sizeof(needle), "\"%s\"", registry) < 0)
return -ENAMETOOLONG;
- rc = read_file(authfile, 4u * 1024u * 1024u, &body, &body_len);
- if (rc)
- return rc == -ENOENT ? 0 : rc;
+ ret = read_file(authfile, 4u * 1024u * 1024u, &body, &body_len);
+ if (ret)
+ return ret == -ENOENT ? 0 : ret;
/*
* The auth file is local input; require the registry key and auth
* member to occur in the same JSON object before accepting
@@ -340,10 +340,10 @@ static int load_registry_auth(const char *registry, struct bpm_oci_client *c)
xfree(body, body_len + 1);
return -EINVAL;
}
- rc = decode_basic(auth + 1, c->username, sizeof(c->username),
- c->password, sizeof(c->password));
+ ret = decode_basic(auth + 1, c->username, sizeof(c->username),
+ c->password, sizeof(c->password));
xfree(body, body_len + 1);
- return rc;
+ return ret;
}
int bpm_oci_parse_endpoint(const char *endpoint, struct bpm_oci_client *c)
@@ -625,7 +625,7 @@ static int get_bearer_token(struct bpm_oci_client *c, const char *challenge)
struct bpm_http_response r = {};
CURLcode cc;
char *esc_service = NULL, *esc_scope = NULL;
- int rc = -EINVAL;
+ int ret = -EINVAL;
if (provided_token && *provided_token) {
if (strlen(provided_token) >= sizeof(c->token))
@@ -645,22 +645,22 @@ static int get_bearer_token(struct bpm_oci_client *c, const char *challenge)
goto out;
if (strsprintf(url, sizeof(url), "%s?service=%s&scope=%s", realm,
esc_service, esc_scope) < 0) {
- rc = -ENAMETOOLONG;
+ ret = -ENAMETOOLONG;
goto out;
}
if (c->username[0]) {
- rc = encode_basic(c->username, c->password, basic,
- sizeof(basic));
- if (rc)
+ ret = encode_basic(c->username, c->password, basic,
+ sizeof(basic));
+ if (ret)
goto out;
if (strsprintf(auth_header, sizeof(auth_header),
"Authorization: Basic %s", basic) < 0) {
- rc = -E2BIG;
+ ret = -E2BIG;
goto out;
}
headers = curl_slist_append(headers, auth_header);
if (!headers) {
- rc = -ENOMEM;
+ ret = -ENOMEM;
goto out;
}
}
@@ -680,23 +680,23 @@ static int get_bearer_token(struct bpm_oci_client *c, const char *challenge)
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 1L);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 2L);
if (tls_curl_policy(curl, &c->tls_ca)) {
- rc = -EINVAL;
+ ret = -EINVAL;
goto out;
}
cc = curl_easy_perform(curl);
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &r.status);
if (cc != CURLE_OK) {
- rc = -EHOSTUNREACH;
+ ret = -EHOSTUNREACH;
goto out;
}
if (r.status >= 300) {
- rc = -EACCES;
+ ret = -EACCES;
goto out;
}
/* curl never calls the write callback for an empty body. */
if (!r.body.data)
goto out;
- rc = token_from_body((char *)r.body.data, c->token, sizeof(c->token));
+ ret = token_from_body((char *)r.body.data, c->token, sizeof(c->token));
out:
curl_free(esc_service);
curl_free(esc_scope);
@@ -704,7 +704,7 @@ out:
curl_easy_cleanup(curl);
tls_ca_cleanup(&c->tls_ca);
bpm_buffer_free(&r.body);
- return rc;
+ return ret;
}
static int get_memory(struct bpm_oci_client *c, const char *url,
@@ -712,49 +712,49 @@ static int get_memory(struct bpm_oci_client *c, const char *url,
{
struct bpm_http_response r = {};
char auth[BPM_OCI_AUTH_VALUE_SIZE];
- int rc;
+ int ret;
- rc = curl_once(c, "GET", url, accept, NULL, &r, NULL, follow);
- if (rc)
+ ret = curl_once(c, "GET", url, accept, NULL, &r, NULL, follow);
+ if (ret)
goto out;
if (r.status == 401 && r.www_auth[0]) {
if (!strncasecmp(r.www_auth, "Bearer", 6)) {
- rc = get_bearer_token(c, r.www_auth);
- if (rc)
+ ret = get_bearer_token(c, r.www_auth);
+ if (ret)
goto out;
if (strsprintf(auth, sizeof(auth), "Bearer %s",
c->token) < 0) {
- rc = -E2BIG;
+ ret = -E2BIG;
goto out;
}
} else if (!strncasecmp(r.www_auth, "Basic", 5) && c->username[0]) {
char encoded[BPM_OCI_BASIC_ENCODED_SIZE];
- rc = encode_basic(c->username, c->password, encoded, sizeof(encoded));
- if (rc)
+ ret = encode_basic(c->username, c->password, encoded, sizeof(encoded));
+ if (ret)
goto out;
if (strsprintf(auth, sizeof(auth), "Basic %s",
encoded) < 0) {
- rc = -E2BIG;
+ ret = -E2BIG;
goto out;
}
} else {
- rc = -EACCES;
+ ret = -EACCES;
goto out;
}
bpm_buffer_free(&r.body);
r = (struct bpm_http_response){};
- rc = curl_once(c, "GET", url, accept, auth, &r, NULL, follow);
+ ret = curl_once(c, "GET", url, accept, auth, &r, NULL, follow);
}
- if (!rc && (r.status < 200 || r.status >= 300))
- rc = r.status == 404 ? -ENOENT : -EACCES;
- if (!rc) {
+ if (!ret && (r.status < 200 || r.status >= 300))
+ ret = r.status == 404 ? -ENOENT : -EACCES;
+ if (!ret) {
*out = r.body;
r.body.data = NULL;
}
out:
bpm_buffer_free(&r.body);
- return rc;
+ return ret;
}
int bpm_oci_get_memory(struct bpm_oci_client *c, const char *url,
@@ -775,54 +775,54 @@ int bpm_oci_get_file(struct bpm_oci_client *c, const char *url,
struct bpm_http_response r = {};
struct bpm_file_sink sink = {};
char auth[BPM_OCI_AUTH_VALUE_SIZE];
- int rc;
+ int ret;
if (size < 0 || fd < 0)
return -EINVAL;
if ((__u64)size > BPM_MAX_PACKAGE_BYTES)
return -EFBIG;
- rc = sink_restart(&sink, fd, (__u64)size);
- if (rc)
- return rc;
- rc = curl_once(c, "GET", url, accept, NULL, &r, &sink, true);
- if (!rc && r.status == 401 && r.www_auth[0] && !strncasecmp(r.www_auth, "Bearer", 6)) {
- rc = sink_restart(&sink, fd, (__u64)size);
- if (!rc)
- rc = get_bearer_token(c, r.www_auth);
- if (!rc && strsprintf(auth, sizeof(auth), "Bearer %s",
- c->token) < 0)
- rc = -E2BIG;
- if (!rc) {
+ ret = sink_restart(&sink, fd, (__u64)size);
+ if (ret)
+ return ret;
+ ret = curl_once(c, "GET", url, accept, NULL, &r, &sink, true);
+ if (!ret && r.status == 401 && r.www_auth[0] && !strncasecmp(r.www_auth, "Bearer", 6)) {
+ ret = sink_restart(&sink, fd, (__u64)size);
+ if (!ret)
+ ret = get_bearer_token(c, r.www_auth);
+ if (!ret && strsprintf(auth, sizeof(auth), "Bearer %s",
+ c->token) < 0)
+ ret = -E2BIG;
+ if (!ret) {
bpm_buffer_free(&r.body);
r = (struct bpm_http_response){};
- rc = curl_once(c, "GET", url, accept, auth, &r, &sink, true);
+ ret = curl_once(c, "GET", url, accept, auth, &r, &sink, true);
}
- } else if (!rc && r.status == 401 && r.www_auth[0] &&
+ } else if (!ret && r.status == 401 && r.www_auth[0] &&
!strncasecmp(r.www_auth, "Basic", 5) && c->username[0]) {
char encoded[BPM_OCI_BASIC_ENCODED_SIZE];
- rc = sink_restart(&sink, fd, (__u64)size);
- if (!rc)
- rc = encode_basic(c->username, c->password, encoded,
- sizeof(encoded));
- if (!rc && strsprintf(auth, sizeof(auth), "Basic %s",
- encoded) < 0)
- rc = -E2BIG;
- if (!rc) {
+ ret = sink_restart(&sink, fd, (__u64)size);
+ if (!ret)
+ ret = encode_basic(c->username, c->password, encoded,
+ sizeof(encoded));
+ if (!ret && strsprintf(auth, sizeof(auth), "Basic %s",
+ encoded) < 0)
+ ret = -E2BIG;
+ if (!ret) {
bpm_buffer_free(&r.body);
r = (struct bpm_http_response){};
- rc = curl_once(c, "GET", url, accept, auth, &r, &sink, true);
+ ret = curl_once(c, "GET", url, accept, auth, &r, &sink, true);
}
}
/* A failed write ends the transfer too; it, not the transfer, is the cause. */
if (sink.overflow)
- rc = -EFBIG;
+ ret = -EFBIG;
else if (sink.err)
- rc = sink.err;
- if (!rc && (r.status < 200 || r.status >= 300))
- rc = r.status == 404 ? -ENOENT : -EACCES;
+ ret = sink.err;
+ if (!ret && (r.status < 200 || r.status >= 300))
+ ret = r.status == 404 ? -ENOENT : -EACCES;
bpm_buffer_free(&r.body);
- return rc;
+ return ret;
}
/*
@@ -836,28 +836,28 @@ static int bpm_oci_request(struct bpm_oci_client *c, const char *method,
size_t body_len, struct bpm_http_response *r)
{
char auth[BPM_OCI_AUTH_VALUE_SIZE] = {};
- int rc;
+ int ret;
*r = (struct bpm_http_response){};
- rc = curl_once_ex(c, method, url, accept, content_type, body, body_len,
- NULL, r, NULL, false);
- if (rc)
- return rc;
+ ret = curl_once_ex(c, method, url, accept, content_type, body, body_len,
+ NULL, r, NULL, false);
+ if (ret)
+ return ret;
if (r->status == 401 && r->www_auth[0]) {
if (!strncasecmp(r->www_auth, "Bearer", 6)) {
- rc = get_bearer_token(c, r->www_auth);
- if (rc)
- return rc;
+ ret = get_bearer_token(c, r->www_auth);
+ if (ret)
+ return ret;
if (strsprintf(auth, sizeof(auth), "Bearer %s",
c->token) < 0)
return -E2BIG;
} else if (!strncasecmp(r->www_auth, "Basic", 5) && c->username[0]) {
char encoded[BPM_OCI_BASIC_ENCODED_SIZE];
- rc = encode_basic(c->username, c->password, encoded,
- sizeof(encoded));
- if (rc)
- return rc;
+ ret = encode_basic(c->username, c->password, encoded,
+ sizeof(encoded));
+ if (ret)
+ return ret;
if (strsprintf(auth, sizeof(auth), "Basic %s",
encoded) < 0)
return -E2BIG;
@@ -866,10 +866,10 @@ static int bpm_oci_request(struct bpm_oci_client *c, const char *method,
}
bpm_buffer_free(&r->body);
*r = (struct bpm_http_response){};
- rc = curl_once_ex(c, method, url, accept, content_type, body,
- body_len, auth, r, NULL, false);
- if (rc)
- return rc;
+ ret = curl_once_ex(c, method, url, accept, content_type, body,
+ body_len, auth, r, NULL, false);
+ if (ret)
+ return ret;
}
if (r->status < 200 || r->status >= 300) {
if (r->status != 404) {
@@ -910,7 +910,7 @@ int bpm_oci_get_signed(struct bpm_oci_client *c, const char *repository,
const char *payload_media, const char *sig_media,
struct bpm_buffer *payload, struct bpm_buffer *sig)
{
- int n_payload = 0, n_sig = 0, i, rc;
+ int n_payload = 0, n_sig = 0, i, ret;
char url[PATH_MAX], hex[65];
for (i = 0; i < n_layers; i++) {
@@ -928,13 +928,13 @@ int bpm_oci_get_signed(struct bpm_oci_client *c, const char *repository,
}
if ((*seen)++)
return -EINVAL;
- rc = bpm_oci_url(c, repository, "blobs", layers[i].digest,
- url, sizeof(url));
- if (rc)
- return rc;
- rc = bpm_oci_get_blob(c, url, layers[i].media, dst);
- if (rc)
- return rc;
+ ret = bpm_oci_url(c, repository, "blobs", layers[i].digest,
+ url, sizeof(url));
+ if (ret)
+ return ret;
+ ret = bpm_oci_get_blob(c, url, layers[i].media, dst);
+ if (ret)
+ return ret;
if ((layers[i].size >= 0 && (__s64)dst->len != layers[i].size) ||
bpm_sha256_hex(dst->data, dst->len, hex, sizeof(hex)) ||
!bpm_digest_matches(layers[i].digest, hex))
@@ -1121,7 +1121,7 @@ int bpm_oci_parse_tree_repo(const char *raw, struct bpm_oci_client *c,
int bpm_trim(const char *in, char *out, size_t out_sz)
{
const char *start = in, *end;
- int rc = 0;
+ int ret = 0;
while (*start && isspace((__u8)*start))
start++;
@@ -1130,11 +1130,11 @@ int bpm_trim(const char *in, char *out, size_t out_sz)
end--;
if ((size_t)(end - start) >= out_sz) {
end = start + out_sz - 1;
- rc = -E2BIG;
+ ret = -E2BIG;
}
memmove(out, start, end - start);
out[end - start] = '\0';
- return rc;
+ return ret;
}
int bpm_oci_url(const struct bpm_oci_client *c, const char *repo,
@@ -1194,59 +1194,59 @@ int bpm_oci_push_blob(struct bpm_oci_client *c, const char *repository,
struct bpm_http_response r = {};
char hex[65], digest[72], url[PATH_MAX], upload[PATH_MAX];
char location[PATH_MAX], *sep;
- int rc;
+ int ret;
if (bpm_sha256_hex(body, body_len, hex, sizeof(hex)))
return -EINVAL;
if (strsprintf(digest, sizeof(digest), "sha256:%s", hex) < 0)
return -ENAMETOOLONG;
- rc = bpm_oci_url(c, repository, "blobs", digest, url, sizeof(url));
- if (rc)
- return rc;
- rc = bpm_oci_request(c, "HEAD", url, NULL, NULL, NULL, 0, &r);
+ ret = bpm_oci_url(c, repository, "blobs", digest, url, sizeof(url));
+ if (ret)
+ return ret;
+ ret = bpm_oci_request(c, "HEAD", url, NULL, NULL, NULL, 0, &r);
bpm_buffer_free(&r.body);
- if (!rc) {
+ if (!ret) {
bpm_copy_string(out->media, sizeof(out->media), media);
bpm_copy_string(out->digest, sizeof(out->digest), digest);
out->size = (__s64)body_len;
return 0;
}
- if (rc != -ENOENT)
- return rc;
-
- rc = bpm_oci_url(c, repository, "blobs/uploads", "", url, sizeof(url));
- if (rc)
- return rc;
- rc = bpm_oci_request(c, "POST", url, NULL, NULL, NULL, 0, &r);
- if (rc)
+ if (ret != -ENOENT)
+ return ret;
+
+ ret = bpm_oci_url(c, repository, "blobs/uploads", "", url, sizeof(url));
+ if (ret)
+ return ret;
+ ret = bpm_oci_request(c, "POST", url, NULL, NULL, NULL, 0, &r);
+ if (ret)
goto out;
if (r.status != 202 || !r.location[0]) {
- rc = r.status == 202 ? -EINVAL : -EACCES;
+ ret = r.status == 202 ? -EINVAL : -EACCES;
goto out;
}
bpm_copy_string(location, sizeof(location), r.location);
bpm_buffer_free(&r.body);
r = (struct bpm_http_response){};
- rc = upload_location(c, location, upload, sizeof(upload));
- if (rc)
+ ret = upload_location(c, location, upload, sizeof(upload));
+ if (ret)
goto out;
sep = strchr(upload, '?') ? "&" : "?";
if (strsprintf(url, sizeof(url), "%s%sdigest=%s", upload, sep, digest) < 0) {
- rc = -ENAMETOOLONG;
+ ret = -ENAMETOOLONG;
goto out;
}
- rc = bpm_oci_request(c, "PUT", url, NULL, "application/octet-stream",
- body, body_len, &r);
- if (!rc && r.status != 201)
- rc = -EACCES;
- if (!rc) {
+ ret = bpm_oci_request(c, "PUT", url, NULL, "application/octet-stream",
+ body, body_len, &r);
+ if (!ret && r.status != 201)
+ ret = -EACCES;
+ if (!ret) {
bpm_copy_string(out->media, sizeof(out->media), media);
bpm_copy_string(out->digest, sizeof(out->digest), digest);
out->size = (__s64)body_len;
}
out:
bpm_buffer_free(&r.body);
- return rc;
+ return ret;
}
void bpm_oci_emit_descriptor(struct shirudo_json_emit *e, const char *key,
@@ -1273,17 +1273,17 @@ int bpm_oci_put_manifest(struct bpm_oci_client *c, const char *repository,
{
struct bpm_http_response r = {};
char hex[65], url[PATH_MAX];
- int rc;
+ int ret;
if (bpm_sha256_hex(body, body_len, hex, sizeof(hex)) ||
strsprintf(digest, digest_sz, "sha256:%s", hex) < 0)
return -ENAMETOOLONG;
- rc = bpm_oci_url(c, repository, "manifests", reference, url,
- sizeof(url));
- if (rc)
- return rc;
- rc = bpm_oci_request(c, "PUT", url, "application/vnd.oci.image.manifest.v1+json",
- "application/vnd.oci.image.manifest.v1+json", body, body_len, &r);
+ ret = bpm_oci_url(c, repository, "manifests", reference, url,
+ sizeof(url));
+ if (ret)
+ return ret;
+ ret = bpm_oci_request(c, "PUT", url, "application/vnd.oci.image.manifest.v1+json",
+ "application/vnd.oci.image.manifest.v1+json", body, body_len, &r);
bpm_buffer_free(&r.body);
- return rc;
+ return ret;
}
diff --git a/util/bpm_package.c b/util/bpm_package.c
index 67724aed..0c7f58d8 100644
--- a/util/bpm_package.c
+++ b/util/bpm_package.c
@@ -188,24 +188,24 @@ int bpm_verify_cms(const __u8 *payload, size_t payload_len,
const __u8 *sig, size_t sig_len, const char *cert_path)
{
struct shirudo_cert cert = {};
- int rc = -EINVAL;
+ int ret = -EINVAL;
if (!cert_read_file(cert_path, &cert))
- rc = verify_detached(payload, payload_len, sig, sig_len, &cert);
+ ret = verify_detached(payload, payload_len, sig, sig_len, &cert);
cert_free(&cert);
- return rc;
+ return ret;
}
int bpm_verify_cms_fd(const __u8 *payload, size_t payload_len,
const __u8 *sig, size_t sig_len, int cert_fd)
{
struct shirudo_cert cert = {};
- int rc = -EINVAL;
+ int ret = -EINVAL;
if (!cert_read_fd(cert_fd, &cert))
- rc = verify_detached(payload, payload_len, sig, sig_len, &cert);
+ ret = verify_detached(payload, payload_len, sig, sig_len, &cert);
cert_free(&cert);
- return rc;
+ return ret;
}
/*
@@ -282,7 +282,7 @@ int bpm_pkg_read_member_in(const char *archive, const char *member,
size_t *out_len, size_t max)
{
gzFile gz = gzopen(archive, "rb");
- int rc = -ENOENT;
+ int ret = -ENOENT;
__u8 h[512];
if (!gz)
@@ -300,7 +300,7 @@ int bpm_pkg_read_member_in(const char *archive, const char *member,
if (n == 0)
break;
if (n != (int)sizeof(h)) {
- rc = -EINVAL;
+ ret = -EINVAL;
break;
}
for (size_t i = 0; i < sizeof(h); i++) {
@@ -315,7 +315,7 @@ int bpm_pkg_read_member_in(const char *archive, const char *member,
name[100] = '\0';
if (!bpm_tar_header_ok(h) || !memchr(h, '\0', 100) ||
bpm_tar_octal((char *)h + 124, 12, &size)) {
- rc = -EINVAL;
+ ret = -EINVAL;
break;
}
remain = size;
@@ -328,16 +328,16 @@ int bpm_pkg_read_member_in(const char *archive, const char *member,
if ((h[156] && h[156] != '0') || h[345] ||
(found_dir && dir_len >= found_dir_sz)) {
- rc = -EINVAL;
+ ret = -EINVAL;
break;
}
if (size > max || size > SIZE_MAX - 1) {
- rc = -E2BIG;
+ ret = -E2BIG;
break;
}
body = xmalloc((size_t)size + 1);
if (!body) {
- rc = -ENOMEM;
+ ret = -ENOMEM;
break;
}
while (remain) {
@@ -346,7 +346,7 @@ int bpm_pkg_read_member_in(const char *archive, const char *member,
n = gzread(gz, body + size - remain, (__u32)want);
if (n <= 0) {
xfree(body, (size_t)size + 1);
- rc = -EINVAL;
+ ret = -EINVAL;
goto done;
}
remain -= (size_t)n;
@@ -358,7 +358,7 @@ int bpm_pkg_read_member_in(const char *archive, const char *member,
memcpy(found_dir, name, dir_len);
found_dir[dir_len] = '\0';
}
- rc = 0;
+ ret = 0;
break;
}
while (remain) {
@@ -367,7 +367,7 @@ int bpm_pkg_read_member_in(const char *archive, const char *member,
n = gzread(gz, discard, (__u32)want);
if (n <= 0) {
- rc = -EINVAL;
+ ret = -EINVAL;
goto done;
}
remain -= (size_t)n;
@@ -379,20 +379,20 @@ int bpm_pkg_read_member_in(const char *archive, const char *member,
n = gzread(gz, discard, (__u32)want);
if (n <= 0) {
- rc = -EINVAL;
+ ret = -EINVAL;
goto done;
}
pad -= (size_t)n;
}
}
done:
- if (gzclose(gz) != Z_OK && rc == 0) {
+ if (gzclose(gz) != Z_OK && ret == 0) {
xfree(*out, *out_len + 1);
*out = NULL;
*out_len = 0;
- rc = -EINVAL;
+ ret = -EINVAL;
}
- return rc;
+ return ret;
}
int bpm_pkg_read_member(const char *archive, const char *member,
@@ -408,7 +408,7 @@ int bpm_pkg_visit_members(const char *archive, const char *package_dir,
gzFile gz = gzopen(archive, "rb");
char root[256] = {};
__u8 h[512];
- int rc = 0;
+ int ret = 0;
if (!gz)
return -errno;
@@ -427,7 +427,7 @@ int bpm_pkg_visit_members(const char *archive, const char *package_dir,
if (n == 0)
break;
if (n != (int)sizeof(h)) {
- rc = -EINVAL;
+ ret = -EINVAL;
break;
}
for (size_t i = 0; i < sizeof(h); i++) {
@@ -440,7 +440,7 @@ int bpm_pkg_visit_members(const char *archive, const char *package_dir,
break;
if (!bpm_tar_header_ok(h) || !memchr(h, '\0', 100) || h[345] ||
bpm_tar_octal((char *)h + 124, 12, &size)) {
- rc = -EINVAL;
+ ret = -EINVAL;
break;
}
strscpy(name, (char *)h, sizeof(name));
@@ -449,7 +449,7 @@ int bpm_pkg_visit_members(const char *archive, const char *package_dir,
if (type == '5' && name_len && name[name_len - 1] == '/')
name[--name_len] = '\0';
if (!bpm_archive_rel_ok(name)) {
- rc = -EINVAL;
+ ret = -EINVAL;
break;
}
if (!root[0]) {
@@ -457,7 +457,7 @@ int bpm_pkg_visit_members(const char *archive, const char *package_dir,
if ((!slash && type != '5') || (slash && slash == name) ||
(slash ? (size_t)(slash - name) : name_len) >=
sizeof(root)) {
- rc = -EINVAL;
+ ret = -EINVAL;
break;
}
root_len = slash ? (size_t)(slash - name) : name_len;
@@ -467,30 +467,30 @@ int bpm_pkg_visit_members(const char *archive, const char *package_dir,
root_len = strlen(root);
if (strncmp(name, root, root_len) ||
(name[root_len] && name[root_len] != '/')) {
- rc = -EINVAL;
+ ret = -EINVAL;
break;
}
if (package_dir && strcmp(root, package_dir)) {
- rc = -EINVAL;
+ ret = -EINVAL;
break;
}
if (type != '0' && type != '5') {
- rc = -EPERM;
+ ret = -EPERM;
break;
}
strscpy(rel, name + root_len + (name[root_len] == '/'),
sizeof(rel));
if (!*rel) {
if (type != '5') {
- rc = -EINVAL;
+ ret = -EINVAL;
break;
}
} else if (!bpm_archive_rel_ok(rel)) {
- rc = -EINVAL;
+ ret = -EINVAL;
break;
} else if (visit) {
- rc = visit(ctx, rel, (char)type);
- if (rc)
+ ret = visit(ctx, rel, (char)type);
+ if (ret)
break;
}
remain = size;
@@ -501,7 +501,7 @@ int bpm_pkg_visit_members(const char *archive, const char *package_dir,
n = gzread(gz, discard, (__u32)want);
if (n <= 0) {
- rc = -EINVAL;
+ ret = -EINVAL;
goto done;
}
remain -= (size_t)n;
@@ -514,18 +514,18 @@ int bpm_pkg_visit_members(const char *archive, const char *package_dir,
n = gzread(gz, discard, (__u32)want);
if (n <= 0) {
- rc = -EINVAL;
+ ret = -EINVAL;
goto done;
}
pad -= (size_t)n;
}
}
if (!root[0])
- rc = -EINVAL;
+ ret = -EINVAL;
done:
- if (gzclose(gz) != Z_OK && !rc)
- rc = -EINVAL;
- return rc;
+ if (gzclose(gz) != Z_OK && !ret)
+ ret = -EINVAL;
+ return ret;
}
static X509 *read_x509_memory(const __u8 *body, size_t len)
@@ -552,14 +552,14 @@ int bpm_pkg_extract(const char *archive, const char *dest)
__u64 total = 0;
__u32 entries = 0;
__u8 h[512];
- int rc = 0;
+ int ret = 0;
if (!gz)
return -EINVAL;
- rc = seal_mkdir_p(dest, 0700);
- if (rc) {
+ ret = seal_mkdir_p(dest, 0700);
+ if (ret) {
gzclose(gz);
- return rc;
+ return ret;
}
for (;;) {
char name[PATH_MAX], rel[PATH_MAX], path[PATH_MAX], *slash;
@@ -571,7 +571,7 @@ int bpm_pkg_extract(const char *archive, const char *dest)
if (n == 0)
break;
if (n != (int)sizeof(h)) {
- rc = -EINVAL;
+ ret = -EINVAL;
break;
}
for (size_t i = 0; i < sizeof(h); i++) {
@@ -584,12 +584,12 @@ int bpm_pkg_extract(const char *archive, const char *dest)
break;
/* A ustar prefix would make the member another reader's prefix/name. */
if (!bpm_tar_header_ok(h) || !memchr(h, '\0', 100) || h[345]) {
- rc = -EINVAL;
+ ret = -EINVAL;
break;
}
strscpy(name, (char *)h, sizeof(name));
if (!bpm_archive_rel_ok(name) || bpm_tar_octal((char *)h + 124, 12, &size)) {
- rc = -EINVAL;
+ ret = -EINVAL;
break;
}
type = h[156];
@@ -597,35 +597,35 @@ int bpm_pkg_extract(const char *archive, const char *dest)
type = '0';
if (++entries > BPM_MAX_PACKAGE_ENTRIES ||
size > BPM_MAX_PACKAGE_BYTES - total) {
- rc = -EFBIG;
+ ret = -EFBIG;
break;
}
total += size;
if (!root[0]) {
slash = strchr(name, '/');
if (!slash || slash == name || (size_t)(slash - name) >= sizeof(root)) {
- rc = -EINVAL;
+ ret = -EINVAL;
break;
}
memcpy(root, name, slash - name);
root[slash - name] = 0;
}
if (strncmp(name, root, strlen(root)) || name[strlen(root)] != '/') {
- rc = -EINVAL;
+ ret = -EINVAL;
break;
}
strscpy(rel, name + strlen(root) + 1, sizeof(rel));
if ((!*rel && type != '5') || (*rel && !bpm_archive_rel_ok(rel))) {
- rc = -EINVAL;
+ ret = -EINVAL;
break;
}
if (strsprintf(path, sizeof(path), "%s/%s", dest, rel) < 0) {
- rc = -ENAMETOOLONG;
+ ret = -ENAMETOOLONG;
break;
}
if (type == '5') {
- rc = seal_mkdir_p(path, 0700);
- if (rc)
+ ret = seal_mkdir_p(path, 0700);
+ if (ret)
break;
/* Read as the other walkers do, whatever a directory carries. */
remain = size;
@@ -635,12 +635,12 @@ int bpm_pkg_extract(const char *archive, const char *dest)
n = gzread(gz, buf, (__u32)want);
if (n <= 0) {
- rc = -EIO;
+ ret = -EIO;
break;
}
remain -= (size_t)n;
}
- if (rc)
+ if (ret)
break;
} else if (type == '0') {
char parent[PATH_MAX];
@@ -650,13 +650,13 @@ int bpm_pkg_extract(const char *archive, const char *dest)
slash = strrchr(parent, '/');
if (slash) {
*slash = 0;
- rc = seal_mkdir_p(parent, 0700);
- if (rc)
+ ret = seal_mkdir_p(parent, 0700);
+ if (ret)
break;
}
fd = seal_open(path, O_WRONLY | O_CREAT | O_EXCL, 0644);
if (fd < 0) {
- rc = fd;
+ ret = fd;
break;
}
remain = size;
@@ -666,18 +666,18 @@ int bpm_pkg_extract(const char *archive, const char *dest)
n = gzread(gz, buf, (__u32)want);
if (n <= 0 || write_complete(fd, buf, (size_t)n)) {
- rc = -EIO;
+ ret = -EIO;
break;
}
remain -= (size_t)n;
}
- if (!rc && fchmod(fd, 0644))
- rc = -errno;
+ if (!ret && fchmod(fd, 0644))
+ ret = -errno;
close(fd);
- if (rc)
+ if (ret)
break;
} else {
- rc = -EPERM;
+ ret = -EPERM;
break;
}
pad = (512 - (size % 512)) % 512;
@@ -687,18 +687,18 @@ int bpm_pkg_extract(const char *archive, const char *dest)
n = gzread(gz, buf, (__u32)want);
if (n <= 0) {
- rc = -EINVAL;
+ ret = -EINVAL;
break;
}
pad -= (size_t)n;
}
- if (rc)
+ if (ret)
break;
}
- if (gzclose(gz) != Z_OK && !rc)
- rc = -EINVAL;
- if (rc)
- return rc;
+ if (gzclose(gz) != Z_OK && !ret)
+ ret = -EINVAL;
+ if (ret)
+ return ret;
return root[0] ? 0 : -EINVAL;
}
@@ -716,7 +716,7 @@ int bpm_pkg_load_info(const char *archive, struct bpm_package_info *info)
X509 *cert = NULL;
char hex[EVP_MAX_MD_SIZE * 2 + 1];
size_t environment_len;
- int rc;
+ int ret;
memset(package_fields, 0, sizeof(package_fields));
package_fields[0] = (struct shirudo_json_field){
@@ -740,26 +740,26 @@ int bpm_pkg_load_info(const char *archive, struct bpm_package_info *info)
.sub = shirudo_fields, .n_sub = ARRAY_SIZE(shirudo_fields),
};
- rc = bpm_pkg_read_member(archive, "build-environment.json", &environment,
- &environment_len, 4u * 1024u * 1024u);
- if (rc)
- return rc;
+ ret = bpm_pkg_read_member(archive, "build-environment.json", &environment,
+ &environment_len, 4u * 1024u * 1024u);
+ if (ret)
+ return ret;
if (json_parse((const char *)environment, environment_len,
root, ARRAY_SIZE(root)) ||
!root[0].seen || !parsed.name[0] || !parsed.version[0] ||
!bpm_package_name_ok(parsed.name) || !bpm_version_ok(parsed.version)) {
- rc = -EINVAL;
+ ret = -EINVAL;
goto out;
}
- rc = bpm_pkg_read_member(archive, "cert.der", &info->cert, &info->cert_len,
- 4u * 1024u * 1024u);
- if (rc)
+ ret = bpm_pkg_read_member(archive, "cert.der", &info->cert, &info->cert_len,
+ 4u * 1024u * 1024u);
+ if (ret)
goto out;
cert = read_x509_memory(info->cert, info->cert_len);
signer.impl = cert;
if (!cert || cert_pubkey_digest(&signer, digest)) {
- rc = -EINVAL;
+ ret = -EINVAL;
goto out;
}
hex_encode(digest, sizeof(digest), hex);
@@ -767,22 +767,22 @@ int bpm_pkg_load_info(const char *archive, struct bpm_package_info *info)
pr_err("bpm: package signer fingerprint mismatch: "
"certificate=%s build-environment.json=%s",
hex, parsed.signer);
- rc = -EKEYREJECTED;
+ ret = -EKEYREJECTED;
goto out;
}
bpm_copy_string(info->name, sizeof(info->name), parsed.name);
bpm_copy_string(info->version, sizeof(info->version), parsed.version);
bpm_copy_string(info->signer, sizeof(info->signer), hex);
- rc = 0;
+ ret = 0;
out:
X509_free(cert);
xfree(environment, environment_len + 1);
- if (rc) {
+ if (ret) {
xfree(info->cert, info->cert_len + 1);
info->cert = NULL;
info->cert_len = 0;
}
- return rc;
+ return ret;
}
int bpm_tree_fetch_publication(struct bpm_oci_client *c,
@@ -795,49 +795,49 @@ int bpm_tree_fetch_publication(struct bpm_oci_client *c,
struct bpm_buffer manifest = {}, payload = {}, sig = {};
struct bpm_descriptor *layers = NULL;
char url[PATH_MAX], hex[65];
- int nl = 0, rc;
+ int nl = 0, ret;
if (!reference[0] || strchr(reference, '/') || strchr(reference, '?') ||
strchr(reference, '#') || strstr(reference, ".."))
return -EINVAL;
- rc = bpm_oci_url(c, repository, "manifests", reference, url,
- sizeof(url));
- if (rc)
- return rc;
- rc = bpm_oci_get_memory(c, url, BPM_MANIFEST_MEDIA, &manifest);
- if (rc)
+ ret = bpm_oci_url(c, repository, "manifests", reference, url,
+ sizeof(url));
+ if (ret)
+ return ret;
+ ret = bpm_oci_get_memory(c, url, BPM_MANIFEST_MEDIA, &manifest);
+ if (ret)
goto out;
if (bpm_sha256_hex(manifest.data, manifest.len, hex, sizeof(hex))) {
- rc = -EKEYREJECTED;
+ ret = -EKEYREJECTED;
goto out;
}
if (strsprintf(manifest_digest, digest_sz, "sha256:%s", hex) < 0) {
- rc = -ENAMETOOLONG;
+ ret = -ENAMETOOLONG;
goto out;
}
layers = xcalloc(BPM_MAX_ENTRIES, sizeof(*layers));
if (!layers) {
- rc = -ENOMEM;
+ ret = -ENOMEM;
goto out;
}
- rc = bpm_oci_parse_manifest(manifest.data, manifest.len, layers,
- BPM_MAX_ENTRIES, &nl, NULL, 0);
- if (rc)
+ ret = bpm_oci_parse_manifest(manifest.data, manifest.len, layers,
+ BPM_MAX_ENTRIES, &nl, NULL, 0);
+ if (ret)
goto out;
- rc = bpm_oci_get_signed(c, repository, layers, nl, BPM_TREE_MEDIA,
- BPM_TREE_SIG_MEDIA, &payload, &sig);
- if (rc)
+ ret = bpm_oci_get_signed(c, repository, layers, nl, BPM_TREE_MEDIA,
+ BPM_TREE_SIG_MEDIA, &payload, &sig);
+ if (ret)
goto out;
if (bpm_verify_cms(payload.data, payload.len, sig.data, sig.len, cert_path)) {
- rc = -EKEYREJECTED;
+ ret = -EKEYREJECTED;
goto out;
}
- rc = tree_parse((const char *)payload.data, payload.len, pub);
+ ret = tree_parse((const char *)payload.data, payload.len, pub);
out:
if (layers)
xfree(layers, BPM_MAX_ENTRIES * sizeof(*layers));
bpm_buffer_free(&manifest);
bpm_buffer_free(&payload);
bpm_buffer_free(&sig);
- return rc;
+ return ret;
}
diff --git a/util/bpm_tree.c b/util/bpm_tree.c
index 049a24c3..1ac1d034 100644
--- a/util/bpm_tree.c
+++ b/util/bpm_tree.c
@@ -413,13 +413,13 @@ static int tree_operations_reserve(struct shirudo_tree_publication *pub)
int tree_publication_append(struct shirudo_tree_publication *pub,
const struct shirudo_tree_operation *op)
{
- int rc;
+ int ret;
if (!pub || !op)
return -EINVAL;
- rc = tree_operations_reserve(pub);
- if (rc)
- return rc;
+ ret = tree_operations_reserve(pub);
+ if (ret)
+ return ret;
pub->operations[pub->n_operations++] = *op;
return 0;
}
@@ -460,14 +460,14 @@ int tree_parse(const char *body, size_t len,
bool seen_base = false, seen_base_seq = false;
bool seen_operations = false, seen_head = false, seen_head_seq = false;
__s64 schema = 0;
- int rc;
+ int ret;
if (!body || !out || len > JSON_MAX_BYTES)
return -EINVAL;
p = (struct tree_parser){ .p = body, .end = body + len };
*out = (struct shirudo_tree_publication){};
if (tp_char(&p, '{')) {
- rc = -EINVAL;
+ ret = -EINVAL;
goto fail;
}
for (;;) {
@@ -477,44 +477,44 @@ int tree_parse(const char *body, size_t len,
break;
}
if (tp_key(&p, key, sizeof(key), &first)) {
- rc = -EINVAL;
+ ret = -EINVAL;
goto fail;
}
if (!strcmp(key, "schema")) {
if (tp_int(&p, &schema)) {
- rc = -EINVAL;
+ ret = -EINVAL;
goto fail;
}
out->schema = (int)schema;
seen_schema = true;
} else if (!strcmp(key, "tree_id")) {
if (tp_string(&p, out->tree_id, sizeof(out->tree_id))) {
- rc = -EINVAL;
+ ret = -EINVAL;
goto fail;
}
} else if (!strcmp(key, "generation")) {
if (tp_int(&p, &out->generation)) {
- rc = -EINVAL;
+ ret = -EINVAL;
goto fail;
}
seen_generation = true;
} else if (!strcmp(key, "parent_manifest_digest")) {
if (tp_string(&p, out->parent_manifest_digest,
sizeof(out->parent_manifest_digest))) {
- rc = -EINVAL;
+ ret = -EINVAL;
goto fail;
}
} else if (!strcmp(key, "base")) {
seen_base = true;
if (tp_seq_object(&p, key, sizeof(key), &out->base_seq,
&seen_base_seq)) {
- rc = -EINVAL;
+ ret = -EINVAL;
goto fail;
}
} else if (!strcmp(key, "operations")) {
seen_operations = true;
if (tp_char(&p, '[')) {
- rc = -EINVAL;
+ ret = -EINVAL;
goto fail;
}
for (;;) {
@@ -523,11 +523,11 @@ int tree_parse(const char *body, size_t len,
p.p++;
break;
}
- rc = tree_operations_reserve(out);
- if (rc)
+ ret = tree_operations_reserve(out);
+ if (ret)
goto fail;
if (tp_operation(&p, &out->operations[out->n_operations])) {
- rc = -EINVAL;
+ ret = -EINVAL;
goto fail;
}
out->n_operations++;
@@ -540,18 +540,18 @@ int tree_parse(const char *body, size_t len,
p.p++;
break;
}
- rc = -EINVAL;
+ ret = -EINVAL;
goto fail;
}
} else if (!strcmp(key, "head")) {
seen_head = true;
if (tp_seq_object(&p, key, sizeof(key), &out->head_seq,
&seen_head_seq)) {
- rc = -EINVAL;
+ ret = -EINVAL;
goto fail;
}
} else if (tp_skip(&p)) {
- rc = -EINVAL;
+ ret = -EINVAL;
goto fail;
}
tp_ws(&p);
@@ -560,7 +560,7 @@ int tree_parse(const char *body, size_t len,
break;
}
if (p.p >= p.end) {
- rc = -EINVAL;
+ ret = -EINVAL;
goto fail;
}
}
@@ -571,20 +571,20 @@ int tree_parse(const char *body, size_t len,
out->generation < 0 || out->generation == INT64_MAX ||
out->base_seq < 0 || out->head_seq < out->base_seq ||
out->head_seq == INT64_MAX) {
- rc = -EINVAL;
+ ret = -EINVAL;
goto fail;
}
/* Every operation's seq is positive, so seq - 1 cannot overflow. */
for (int i = 0; i < out->n_operations; i++) {
if (i && out->operations[i].seq - 1 != out->operations[i - 1].seq) {
- rc = -EINVAL;
+ ret = -EINVAL;
goto fail;
}
}
return 0;
fail:
tree_publication_free(out);
- return rc;
+ return ret;
}
static int tree_selector_kv_compare(const void *left, const void *right)
@@ -677,15 +677,15 @@ static int tree_emit_operation(struct shirudo_json_emit *e,
const struct shirudo_tree_operation *op,
bool with_digest)
{
- int rc;
+ int ret;
json_obj_open(e);
json_kv_int(e, "seq", op->seq);
json_kv_string(e, "op", op->op);
json_kv_string(e, "id", op->id);
- rc = tree_emit_selector(e, &op->selector);
- if (rc)
- return rc;
+ ret = tree_emit_selector(e, &op->selector);
+ if (ret)
+ return ret;
tree_emit_artifact(e, &op->artifact);
if (with_digest)
json_kv_string(e, "operation_digest", op->operation_digest);
@@ -704,22 +704,22 @@ int tree_operation_digest(const struct shirudo_tree_operation *op,
struct shirudo_json_emit e;
char *body, hex[65];
__u8 digest[32];
- int rc;
+ int ret;
body = xmalloc(body_cap);
if (!body)
return -ENOMEM;
e = (struct shirudo_json_emit){ .buf = body, .cap = body_cap };
- rc = tree_emit_operation(&e, op, false);
- if (!rc && sha256_buffer(body, e.len, digest))
- rc = -EIO;
- if (!rc) {
+ ret = tree_emit_operation(&e, op, false);
+ if (!ret && sha256_buffer(body, e.len, digest))
+ ret = -EIO;
+ if (!ret) {
hex_encode(digest, sizeof(digest), hex);
memcpy(out, "sha256:", 7);
memcpy(out + 7, hex, sizeof(hex));
}
xfree(body, body_cap);
- return rc;
+ return ret;
}
static size_t tree_json_bound(const char *s)
@@ -771,7 +771,7 @@ int tree_emit_publication(const struct shirudo_tree_publication *pub,
struct shirudo_json_emit e;
size_t cap = 4096;
char *body;
- int rc = 0;
+ int ret = 0;
for (int i = 0; i < pub->n_operations; i++)
cap += tree_operation_bound(&pub->operations[i]);
@@ -790,18 +790,18 @@ int tree_emit_publication(const struct shirudo_tree_publication *pub,
json_kv_int(&e, "seq", pub->base_seq);
json_obj_close(&e);
json_arr_open(&e, "operations");
- for (int i = 0; !rc && i < pub->n_operations; i++)
- rc = tree_emit_operation(&e, &pub->operations[i], true);
+ for (int i = 0; !ret && i < pub->n_operations; i++)
+ ret = tree_emit_operation(&e, &pub->operations[i], true);
json_arr_close(&e);
json_obj_open_key(&e, "head");
json_kv_int(&e, "seq", pub->head_seq);
json_obj_close(&e);
json_obj_close(&e);
- if (!rc)
- rc = e.err;
- if (rc) {
+ if (!ret)
+ ret = e.err;
+ if (ret) {
xfree(body, cap);
- return rc;
+ return ret;
}
*out = body;
*out_len = e.len;
diff --git a/util/bpm_tree_state.c b/util/bpm_tree_state.c
index b0a4389b..8f71e7e9 100644
--- a/util/bpm_tree_state.c
+++ b/util/bpm_tree_state.c
@@ -89,7 +89,7 @@ static int read_config_file(const char *path, struct shirudo_tree_kv *out,
int *n, int max, bool gz)
{
char line[512];
- int rc = 0;
+ int ret = 0;
*n = 0;
if (gz) {
@@ -106,7 +106,7 @@ static int read_config_file(const char *path, struct shirudo_tree_kv *out,
eq = strstr(key, " is not set");
if (eq) {
*eq = '\0';
- rc = kv_add(out, n, max, key, "n");
+ ret = kv_add(out, n, max, key, "n");
}
} else if (eq) {
*eq++ = '\0';
@@ -121,13 +121,13 @@ static int read_config_file(const char *path, struct shirudo_tree_kv *out,
value++;
}
}
- rc = kv_add(out, n, max, key, value);
+ ret = kv_add(out, n, max, key, value);
}
- if (rc)
+ if (ret)
break;
}
gzclose(f);
- return rc;
+ return ret;
}
{
FILE *f = fopen(path, "r");
@@ -144,14 +144,14 @@ static int read_config_stream(FILE *f, struct shirudo_tree_kv *out, int *n,
{
size_t capacity = 0;
char *line = NULL;
- int got, rc = 0;
+ int got, ret = 0;
*n = 0;
while ((got = read_text_line(f, &line, &capacity, 511)) != 0) {
char *start = line, *end, *eq;
if (got < 0) {
- rc = got;
+ ret = got;
break;
}
@@ -171,13 +171,13 @@ static int read_config_stream(FILE *f, struct shirudo_tree_kv *out, int *n,
*--end = '\0';
while (*eq && isspace((__u8)*eq))
eq++;
- rc = kv_add(out, n, max, start, eq);
- if (rc)
+ ret = kv_add(out, n, max, start, eq);
+ if (ret)
break;
}
libc_free(line);
fclose(f);
- return rc;
+ return ret;
}
static int read_config_fd(int fd, struct shirudo_tree_kv *out, int *n,
@@ -186,10 +186,10 @@ static int read_config_fd(int fd, struct shirudo_tree_kv *out, int *n,
FILE *f = fdopen(fd, "r");
if (!f) {
- int rc = -errno;
+ int ret = -errno;
close(fd);
- return rc;
+ return ret;
}
return read_config_stream(f, out, n, max);
}
@@ -311,7 +311,7 @@ static int read_selector_config_file(const char *path,
bool found[], bool gz)
{
char line[1024];
- int rc = 0;
+ int ret = 0;
if (gz) {
gzFile f = gzopen(path, "rb");
@@ -319,15 +319,15 @@ static int read_selector_config_file(const char *path,
if (!f)
return -errno;
while (gzgets(f, line, sizeof(line))) {
- rc = selector_config_line(line, s, slots, values, found);
- if (rc)
+ ret = selector_config_line(line, s, slots, values, found);
+ if (ret)
break;
}
- if (!rc && gzclose(f) != Z_OK)
- rc = -EIO;
- else if (rc)
+ if (!ret && gzclose(f) != Z_OK)
+ ret = -EIO;
+ else if (ret)
gzclose(f);
- return rc;
+ return ret;
}
{
@@ -336,15 +336,15 @@ static int read_selector_config_file(const char *path,
if (!f)
return -errno;
while (fgets(line, sizeof(line), f)) {
- rc = selector_config_line(line, s, slots, values, found);
- if (rc)
+ ret = selector_config_line(line, s, slots, values, found);
+ if (ret)
break;
}
- if (!rc && ferror(f))
- rc = errno ? -errno : -EIO;
+ if (!ret && ferror(f))
+ ret = errno ? -errno : -EIO;
fclose(f);
}
- return rc;
+ return ret;
}
int tree_selector_matches(const struct shirudo_tree_selector *s)
@@ -354,7 +354,7 @@ int tree_selector_matches(const struct shirudo_tree_selector *s)
char cfg_values[TREE_MAX_KCONFIG][TREE_STRING_MAX];
int cfg_slots[TREE_SELECTOR_HASH_SIZE];
bool cfg_found[TREE_MAX_KCONFIG] = {};
- int nl = 0, config_rc, rc;
+ int nl = 0, config_rc, ret;
const char *v;
char path[PATH_MAX];
bool matched, config_any;
@@ -454,16 +454,16 @@ int tree_selector_matches(const struct shirudo_tree_selector *s)
return 0;
if (fd < 0)
return fd;
- rc = read_config_fd(fd, labels, &nl, ARRAY_SIZE(labels));
+ ret = read_config_fd(fd, labels, &nl, ARRAY_SIZE(labels));
} else {
- rc = read_config_file("/etc/shirudo/node.labels",
- labels, &nl, ARRAY_SIZE(labels),
- false);
+ ret = read_config_file("/etc/shirudo/node.labels",
+ labels, &nl, ARRAY_SIZE(labels),
+ false);
}
- if (rc == -ENOENT)
+ if (ret == -ENOENT)
return 0;
- if (rc)
- return rc;
+ if (ret)
+ return ret;
for (int i = 0; i < s->n_labels; i++) {
v = kv_value(labels, nl, s->labels[i].key);
if (!v || !selector_values_match(&s->labels[i], v))
@@ -504,50 +504,50 @@ int tree_state_read(struct shirudo_tree_state *out)
{ "manifest_digest", SHIRUDO_JSON_T_STRING, out->manifest_digest,
sizeof(out->manifest_digest), 0, NULL, 0 },
};
- int rc;
+ int ret;
*out = (struct shirudo_tree_state){};
- rc = tree_read_file(BPM_TREE_STATE_PATH, &body, &len);
- if (rc)
- return rc;
- rc = json_parse((const char *)body, len, f, ARRAY_SIZE(f));
- if (!rc && (schema != 1 || !f[1].seen || !f[3].seen || !f[4].seen))
- rc = -EINVAL;
- if (!rc && !f[5].seen) {
+ ret = tree_read_file(BPM_TREE_STATE_PATH, &body, &len);
+ if (ret)
+ return ret;
+ ret = json_parse((const char *)body, len, f, ARRAY_SIZE(f));
+ if (!ret && (schema != 1 || !f[1].seen || !f[3].seen || !f[4].seen))
+ ret = -EINVAL;
+ if (!ret && !f[5].seen) {
/* State written before the software projection field was added. */
memcpy(out->projection_root_tpm, out->projection_root,
sizeof(out->projection_root_tpm));
}
- if (!rc && (strlen(out->projection_root) != 64 ||
- !hex32_valid(out->projection_root) ||
- (out->projection_root_tpm[0] &&
- (strlen(out->projection_root_tpm) != 64 ||
- !hex32_valid(out->projection_root_tpm)))))
- rc = -EINVAL;
- if (!rc && out->manifest_digest[0] &&
+ if (!ret && (strlen(out->projection_root) != 64 ||
+ !hex32_valid(out->projection_root) ||
+ (out->projection_root_tpm[0] &&
+ (strlen(out->projection_root_tpm) != 64 ||
+ !hex32_valid(out->projection_root_tpm)))))
+ ret = -EINVAL;
+ if (!ret && out->manifest_digest[0] &&
(strlen(out->manifest_digest) != 71 ||
strncmp(out->manifest_digest, "sha256:", 7) ||
!hex32_valid(out->manifest_digest + 7)))
- rc = -EINVAL;
+ ret = -EINVAL;
out->schema = (int)schema;
xfree(body, len + 1);
- return rc;
+ return ret;
}
static int tree_atomic_write(const char *path, const void *data, size_t len)
{
const char *slash = strrchr(path, '/');
char dir[PATH_MAX];
- int rc;
+ int ret;
if (!slash || (size_t)(slash - path) >= sizeof(dir))
return -EINVAL;
memcpy(dir, path, slash - path);
dir[slash - path] = '\0';
- rc = seal_mkdir_p(dir, 0700);
- if (rc) {
- pr_err("tree state mkdir %s: %s", dir, strerror(-rc));
- return rc;
+ ret = seal_mkdir_p(dir, 0700);
+ if (ret) {
+ pr_err("tree state mkdir %s: %s", dir, strerror(-ret));
+ return ret;
}
return seal_write_file(path, data, len, 0600);
}
@@ -577,7 +577,7 @@ int tree_event_append(__s64 seq, const char *operation_digest,
char buf[1024], root[65];
struct shirudo_json_emit e = { .buf = buf, .cap = sizeof(buf) };
struct stat st;
- int fd, rc;
+ int fd, ret;
if (!operation_digest || strncmp(operation_digest, "sha256:", 7) ||
!hex32_valid(operation_digest + 7))
@@ -591,9 +591,9 @@ int tree_event_append(__s64 seq, const char *operation_digest,
json_obj_close(&e);
if (e.err)
return e.err;
- rc = seal_mkdir_p(BPM_TREE_VAR_DIR, 0700);
- if (rc)
- return rc;
+ ret = seal_mkdir_p(BPM_TREE_VAR_DIR, 0700);
+ if (ret)
+ return ret;
fd = seal_open(BPM_TREE_EVENTLOG_PATH,
O_WRONLY | O_CREAT | O_APPEND, 0600);
if (fd < 0)
@@ -601,26 +601,26 @@ int tree_event_append(__s64 seq, const char *operation_digest,
/* A partial line would fail every later replay; roll it back. */
while (flock(fd, LOCK_EX) != 0) {
if (errno != EINTR) {
- rc = -errno;
+ ret = -errno;
goto out;
}
}
if (fstat(fd, &st) != 0) {
- rc = -errno;
+ ret = -errno;
goto out;
}
- rc = write_complete(fd, buf, e.len);
- if (!rc)
- rc = write_complete(fd, "\n", 1);
- if (!rc && fsync(fd))
- rc = -errno;
- if (rc && ftruncate(fd, st.st_size))
+ ret = write_complete(fd, buf, e.len);
+ if (!ret)
+ ret = write_complete(fd, "\n", 1);
+ if (!ret && fsync(fd))
+ ret = -errno;
+ if (ret && ftruncate(fd, st.st_size))
pr_warn("tree: could not roll back a partial append to %s: %s",
BPM_TREE_EVENTLOG_PATH, strerror(errno));
out:
- if (close(fd) && !rc)
- rc = -errno;
- return rc;
+ if (close(fd) && !ret)
+ ret = -errno;
+ return ret;
}
int tree_event_replay(__u8 out[32])
@@ -630,10 +630,10 @@ int tree_event_replay(__u8 out[32])
char *save, *line;
__u8 chain[32] = {};
__s64 previous_seq = 0;
- int rc = tree_read_file(BPM_TREE_EVENTLOG_PATH, &body, &len);
+ int ret = tree_read_file(BPM_TREE_EVENTLOG_PATH, &body, &len);
- if (rc)
- return rc;
+ if (ret)
+ return ret;
/* A NUL would end the walk early and replay a shorter chain. */
if (memchr(body, '\0', len)) {
xfree(body, len + 1);
@@ -653,33 +653,33 @@ int tree_event_replay(__u8 out[32])
};
__u8 d[32], next[64], recorded[32];
- rc = json_parse(line, strlen(line), f, ARRAY_SIZE(f));
- if (rc || !f[0].seen || !f[1].seen || !f[2].seen ||
+ ret = json_parse(line, strlen(line), f, ARRAY_SIZE(f));
+ if (ret || !f[0].seen || !f[1].seen || !f[2].seen ||
seq <= previous_seq || strlen(projection) != 64 ||
hex_decode(projection, recorded, 32)) {
- rc = -EINVAL;
+ ret = -EINVAL;
break;
}
previous_seq = seq;
if (strncmp(digest, "sha256:", 7) ||
hex_decode(digest + 7, d, sizeof(d))) {
- rc = -EINVAL;
+ ret = -EINVAL;
break;
}
memcpy(next, chain, 32);
memcpy(next + 32, d, 32);
- rc = shirudo_sha256(next, sizeof(next), chain);
- if (rc)
+ ret = shirudo_sha256(next, sizeof(next), chain);
+ if (ret)
break;
if (!ct_eq(chain, recorded, 32)) {
- rc = -EINVAL;
+ ret = -EINVAL;
break;
}
}
- if (!rc)
+ if (!ret)
memcpy(out, chain, 32);
xfree(body, len + 1);
- return rc;
+ return ret;
}
void tree_emit_status(struct shirudo_json_emit *e)
diff --git a/util/chain.c b/util/chain.c
index e563726d..6a37ac7a 100644
--- a/util/chain.c
+++ b/util/chain.c
@@ -31,11 +31,11 @@
int shirudo_sha256(const void *data, size_t len, __u8 out[32])
{
- int rc = sha256_buffer(data, len, out);
+ int ret = sha256_buffer(data, len, out);
- if (rc)
+ if (ret)
memset(out, 0, 32);
- return rc;
+ return ret;
}
void sha256_2(const void *a, size_t a_len,
@@ -80,7 +80,7 @@ int chain_init_event(const __u8 cert_sha[32],
__u8 tag[sizeof("shirudo-init") + 96];
size_t taglen = sizeof("shirudo-init"), listing_len = 0, off = 0, i;
char *listing;
- int rc;
+ int ret;
/* set_digest = SHA256(sorted "<payload_hex> <name>\n" listing) */
if (n > 1)
@@ -103,10 +103,10 @@ int chain_init_event(const __u8 cert_sha[32],
}
off += (size_t)w;
}
- rc = shirudo_sha256(listing, listing_len, set_digest);
+ ret = shirudo_sha256(listing, listing_len, set_digest);
xfree(listing, listing_len + 1);
- if (rc)
- return rc;
+ if (ret)
+ return ret;
memcpy(tag, "shirudo-init", taglen);
memcpy(tag + taglen, cert_sha, 32);
@@ -202,14 +202,14 @@ static int register_expectation(const __u8 pcr_before[32],
__u8 name_written[TPM_NAME_LEN])
{
__u8 values[64];
- int rc;
+ int ret;
bind_values(pcr_before, phase_before, values);
- rc = tpm_register_policy(CHAIN_PCR_MASK, values, 2, writer_public,
- branch_written, branch_init, policy);
- if (rc) {
- pr_err("tpm: compute signed register policy: %s", strerror(-rc));
- return rc;
+ ret = tpm_register_policy(CHAIN_PCR_MASK, values, 2, writer_public,
+ branch_written, branch_init, policy);
+ if (ret) {
+ pr_err("tpm: compute signed register policy: %s", strerror(-ret));
+ return ret;
}
tpm_nv_name(NV_INDEX, TPM_REGISTER_ATTRS,
policy, TPM_NV_DIGEST_LEN, name_unwritten);
@@ -230,31 +230,31 @@ static int register_define(struct shirudo_tpm *tpm, bool defined,
const __u8 policy[32])
{
struct shirudo_config cfg = {};
- int rc;
+ int ret;
config_load(&cfg);
if (defined) {
- rc = tpm_nv_undefine(tpm, NV_INDEX,
- cfg.tpm_owner_auth,
- cfg.tpm_owner_auth_len);
- if (rc)
+ ret = tpm_nv_undefine(tpm, NV_INDEX,
+ cfg.tpm_owner_auth,
+ cfg.tpm_owner_auth_len);
+ if (ret)
goto out;
}
- rc = tpm_nv_define(tpm, NV_INDEX, policy,
- cfg.tpm_owner_auth, cfg.tpm_owner_auth_len);
+ ret = tpm_nv_define(tpm, NV_INDEX, policy,
+ cfg.tpm_owner_auth, cfg.tpm_owner_auth_len);
out:
explicit_bzero(&cfg, sizeof(cfg));
- return rc;
+ return ret;
}
static int register_writer(struct shirudo_tpm *tpm,
__u8 public[TPM_NV_RSA_BYTES])
{
__u8 seed[32];
- int rc;
+ int ret;
- rc = nv_writer_read(seed, public);
- return rc ? rc : tpm_nv_set_writer(tpm, seed, public);
+ ret = nv_writer_read(seed, public);
+ return ret ? ret : tpm_nv_set_writer(tpm, seed, public);
}
/*
@@ -266,31 +266,31 @@ int chain_tpm_bound(struct shirudo_tpm *tpm)
{
struct shirudo_identity id = {};
struct shirudo_tpm_key ak = {};
- int rc;
-
- rc = shirudo_enforcement_active();
- if (rc <= 0)
- return rc;
- rc = identity_read(&id);
- if (rc) {
- pr_err("tpm: frozen identity unreadable: %s", strerror(-rc));
- return rc;
+ int ret;
+
+ ret = shirudo_enforcement_active();
+ if (ret <= 0)
+ return ret;
+ ret = identity_read(&id);
+ if (ret) {
+ pr_err("tpm: frozen identity unreadable: %s", strerror(-ret));
+ return ret;
}
if (id.ak_name_len != TPM_NAME_LEN) {
pr_err("tpm: no attestation key name on record");
return -EPROTO;
}
- rc = tpm_ak_create(tpm, &ak);
- if (rc)
- return rc;
+ ret = tpm_ak_create(tpm, &ak);
+ if (ret)
+ return ret;
if (ak.name_len != TPM_NAME_LEN ||
!ct_eq(ak.name, id.ak_name, TPM_NAME_LEN)) {
pr_err("tpm: not the TPM init bound (attestation key name "
"differs)");
- rc = -EACCES;
+ ret = -EACCES;
}
tpm_key_flush(tpm, &ak);
- return rc;
+ return ret;
}
int chain_init(const __u8 event[32],
@@ -302,20 +302,20 @@ int chain_init(const __u8 event[32],
struct tpm_nv_info nv;
struct shirudo_tpm *tpm = NULL;
bool recorded;
- int rc;
+ int ret;
memset(info, 0, sizeof(*info));
- rc = tpm_open(&tpm);
- if (rc)
+ ret = tpm_open(&tpm);
+ if (ret)
return -ENODEV;
- rc = chain_tpm_bound(tpm);
- if (rc)
+ ret = chain_tpm_bound(tpm);
+ if (ret)
goto out;
- rc = tpm_reset_count(tpm, &info->reset_count);
- if (rc)
+ ret = tpm_reset_count(tpm, &info->reset_count);
+ if (ret)
goto out;
- rc = tpm_nv_info(tpm, NV_INDEX, &nv);
- if (rc)
+ ret = tpm_nv_info(tpm, NV_INDEX, &nv);
+ if (ret)
goto out;
/*
@@ -329,49 +329,49 @@ int chain_init(const __u8 event[32],
* PCR keeps the record of both bindings. A log that cannot be
* read may hold the record, so it is refused as well.
*/
- rc = eventlog_boot_init(&rec);
- if (rc && rc != -ENOENT) {
+ ret = eventlog_boot_init(&rec);
+ if (ret && ret != -ENOENT) {
pr_err("tpm: eventlog %s unreadable: %s; not binding register "
- "0x%08x", eventlog_path(), strerror(-rc),
+ "0x%08x", eventlog_path(), strerror(-ret),
NV_INDEX);
goto out;
}
- recorded = !rc && (!rec.have_reset_count ||
- rec.reset_count == info->reset_count);
+ recorded = !ret && (!rec.have_reset_count ||
+ rec.reset_count == info->reset_count);
if (recorded) {
- rc = register_writer(tpm, info->writer_public);
- if (rc)
+ ret = register_writer(tpm, info->writer_public);
+ if (ret)
goto out;
- rc = register_expectation(rec.pcr_before, rec.phase_before,
- info->writer_public, branch_written,
- branch_init, policy, unwritten, written);
- if (rc)
+ ret = register_expectation(rec.pcr_before, rec.phase_before,
+ info->writer_public, branch_written,
+ branch_init, policy, unwritten, written);
+ if (ret)
goto out;
if (!name_equals(&nv, written)) {
pr_err("tpm: recorded register has an obsolete policy; "
"trusted reboot required");
- rc = -EEXIST;
+ ret = -EEXIST;
goto out;
}
if (!ct_eq(info->writer_public, rec.writer_public,
sizeof(info->writer_public))) {
pr_err("tpm: recorded NV writer differs from the guarded key");
- rc = -EKEYREJECTED;
+ ret = -EKEYREJECTED;
goto out;
}
if (nv.defined && nv.written && name_equals(&nv, rec.name)) {
- rc = tpm_nv_read(tpm, NV_INDEX,
- info->value);
- if (rc)
+ ret = tpm_nv_read(tpm, NV_INDEX,
+ info->value);
+ if (ret)
goto out;
memcpy(info->name, nv.name, nv.name_len);
info->name_len = nv.name_len;
memcpy(info->pcr_before, rec.pcr_before, 32);
memcpy(info->phase_before, rec.phase_before, 32);
memcpy(info->anchor_digest, rec.anchor_digest, 32);
- rc = chain_anchor(info->name, info->anchor,
- sizeof(info->anchor));
- if (rc)
+ ret = chain_anchor(info->name, info->anchor,
+ sizeof(info->anchor));
+ if (ret)
goto out;
info->initrd = rec.initrd;
info->reused = true;
@@ -381,69 +381,69 @@ int chain_init(const __u8 event[32],
"binding another before the next TPM reset",
NV_INDEX, !nv.defined ? "gone" :
!nv.written ? "unwritten" : "not the recorded index");
- rc = -EEXIST;
+ ret = -EEXIST;
goto out;
}
if (nv.defined && nv.written)
pr_warn("tpm: register 0x%08x written this boot without a "
"record; rebinding it", NV_INDEX);
- rc = tpm_pcr_read(tpm, CHAIN_PCR, info->pcr_before);
- if (!rc)
- rc = tpm_pcr_read(tpm, CHAIN_PHASE_PCR,
- info->phase_before);
- if (rc)
+ ret = tpm_pcr_read(tpm, CHAIN_PCR, info->pcr_before);
+ if (!ret)
+ ret = tpm_pcr_read(tpm, CHAIN_PHASE_PCR,
+ info->phase_before);
+ if (ret)
goto out;
info->initrd = in_initrd();
- rc = register_writer(tpm, info->writer_public);
- if (rc)
+ ret = register_writer(tpm, info->writer_public);
+ if (ret)
goto out;
- rc = register_expectation(info->pcr_before, info->phase_before,
- info->writer_public, branch_written,
- branch_init, policy, unwritten, written);
- if (!rc)
- rc = chain_anchor(written, info->anchor, sizeof(info->anchor));
- if (rc)
+ ret = register_expectation(info->pcr_before, info->phase_before,
+ info->writer_public, branch_written,
+ branch_init, policy, unwritten, written);
+ if (!ret)
+ ret = chain_anchor(written, info->anchor, sizeof(info->anchor));
+ if (ret)
goto out;
if (!nv.defined || nv.written || !name_equals(&nv, unwritten)) {
- rc = register_define(tpm, nv.defined, policy);
- if (rc)
+ ret = register_define(tpm, nv.defined, policy);
+ if (ret)
goto out;
- rc = tpm_nv_info(tpm, NV_INDEX, &nv);
- if (rc)
+ ret = tpm_nv_info(tpm, NV_INDEX, &nv);
+ if (ret)
goto out;
if (!nv.defined || !name_equals(&nv, unwritten)) {
pr_err("tpm: register 0x%08x name does not match the "
"computed public area", NV_INDEX);
- rc = -EPROTO;
+ ret = -EPROTO;
goto out;
}
}
- rc = tpm_nv_extend_first(tpm, NV_INDEX,
- CHAIN_PCR_MASK, branch_written,
- branch_init, event);
- if (rc)
+ ret = tpm_nv_extend_first(tpm, NV_INDEX,
+ CHAIN_PCR_MASK, branch_written,
+ branch_init, event);
+ if (ret)
goto out;
memcpy(info->name, written, sizeof(written));
info->name_len = sizeof(written);
- rc = shirudo_sha256(info->anchor, strlen(info->anchor),
- info->anchor_digest);
- if (rc)
+ ret = shirudo_sha256(info->anchor, strlen(info->anchor),
+ info->anchor_digest);
+ if (ret)
goto out;
- rc = tpm_pcr_extend(tpm, CHAIN_PCR,
- info->anchor_digest);
- if (rc) {
+ ret = tpm_pcr_extend(tpm, CHAIN_PCR,
+ info->anchor_digest);
+ if (ret) {
pr_err("tpm: register written but PCR %u not anchored; "
"the init branch stays open until reboot",
CHAIN_PCR);
goto out;
}
- rc = tpm_nv_read(tpm, NV_INDEX, info->value);
+ ret = tpm_nv_read(tpm, NV_INDEX, info->value);
out:
tpm_close(tpm);
- return rc;
+ return ret;
}
int chain_extend(const __u8 event[32], __u8 out_chain[32])
@@ -454,84 +454,84 @@ int chain_extend(const __u8 event[32], __u8 out_chain[32])
struct tpm_nv_info nv;
struct shirudo_tpm *tpm = NULL;
__u32 reset;
- int rc;
+ int ret;
- rc = eventlog_boot_init(&rec);
- if (rc)
+ ret = eventlog_boot_init(&rec);
+ if (ret)
return -ENODEV; /* no register this boot */
bind_values(rec.pcr_before, rec.phase_before, values);
- rc = tpm_register_policy(CHAIN_PCR_MASK, values, 2, rec.writer_public,
- branch_written, branch_init, policy);
- if (rc) {
- pr_err("tpm: compute signed register policy: %s", strerror(-rc));
- return rc;
+ ret = tpm_register_policy(CHAIN_PCR_MASK, values, 2, rec.writer_public,
+ branch_written, branch_init, policy);
+ if (ret) {
+ pr_err("tpm: compute signed register policy: %s", strerror(-ret));
+ return ret;
}
- rc = tpm_open(&tpm);
- if (rc)
+ ret = tpm_open(&tpm);
+ if (ret)
return -ENODEV;
- rc = chain_tpm_bound(tpm);
- if (rc)
+ ret = chain_tpm_bound(tpm);
+ if (ret)
goto out;
- rc = tpm_nv_info(tpm, NV_INDEX, &nv);
- if (rc)
+ ret = tpm_nv_info(tpm, NV_INDEX, &nv);
+ if (ret)
goto out;
if (!nv.defined || !nv.written) {
- rc = -ENODEV;
+ ret = -ENODEV;
goto out;
}
if (!name_equals(&nv, rec.name)) {
pr_err("tpm: register 0x%08x is not the index init recorded "
"(recreated?)", NV_INDEX);
- rc = -EACCES;
+ ret = -EACCES;
goto out;
}
if (!ct_eq(nv.policy, policy, sizeof(policy))) {
pr_err("tpm: register write policy is obsolete or substituted");
- rc = -EACCES;
+ ret = -EACCES;
goto out;
}
- rc = tpm_reset_count(tpm, &reset);
- if (rc)
+ ret = tpm_reset_count(tpm, &reset);
+ if (ret)
goto out;
if (!rec.have_reset_count || reset != rec.reset_count) {
pr_err("tpm: register reset differs from the init record");
- rc = -EACCES;
+ ret = -EACCES;
goto out;
}
- rc = register_writer(tpm, writer_public);
- if (rc)
+ ret = register_writer(tpm, writer_public);
+ if (ret)
goto out;
if (!ct_eq(writer_public, rec.writer_public, sizeof(writer_public))) {
pr_err("tpm: recorded NV writer differs from the guarded key");
- rc = -EKEYREJECTED;
+ ret = -EKEYREJECTED;
goto out;
}
- rc = tpm_nv_extend(tpm, NV_INDEX, branch_written,
- branch_init, event);
- if (rc) {
- rc = -EIO;
+ ret = tpm_nv_extend(tpm, NV_INDEX, branch_written,
+ branch_init, event);
+ if (ret) {
+ ret = -EIO;
goto out;
}
if (out_chain)
- rc = tpm_nv_read(tpm, NV_INDEX, out_chain) ?
+ ret = tpm_nv_read(tpm, NV_INDEX, out_chain) ?
-EIO : 0;
out:
tpm_close(tpm);
- return rc;
+ return ret;
}
int chain_read(__u8 out[32])
{
struct shirudo_tpm *tpm = NULL;
- int rc;
+ int ret;
- rc = tpm_open(&tpm);
- if (rc)
+ ret = tpm_open(&tpm);
+ if (ret)
return -ENODEV;
- rc = tpm_nv_read(tpm, NV_INDEX, out);
+ ret = tpm_nv_read(tpm, NV_INDEX, out);
tpm_close(tpm);
- return rc ? -ENODEV : 0;
+ return ret ? -ENODEV : 0;
}
bool chain_bound(void)
@@ -555,38 +555,38 @@ int chain_status(struct chain_status *st)
struct shirudo_tpm *tpm = NULL;
struct tpm_nv_info nv;
__u32 reset_count = 0;
- int rc;
+ int ret;
memset(st, 0, sizeof(*st));
st->logged = eventlog_boot_init(&st->init) == 0;
st->rebound = st->logged && st->init.records_epoch > 1;
- rc = tpm_open_quiet(&tpm);
- if (rc)
+ ret = tpm_open_quiet(&tpm);
+ if (ret)
return -ENODEV;
st->tpm = true;
- rc = tpm_reset_count(tpm, &reset_count);
- if (rc)
+ ret = tpm_reset_count(tpm, &reset_count);
+ if (ret)
goto out;
- rc = tpm_nv_info(tpm, NV_INDEX, &nv);
- if (rc)
+ ret = tpm_nv_info(tpm, NV_INDEX, &nv);
+ if (ret)
goto out;
st->defined = nv.defined;
st->written = nv.written;
memcpy(st->name, nv.name, nv.name_len);
st->name_len = nv.name_len;
if (nv.defined && nv.written)
- rc = tpm_nv_read(tpm, NV_INDEX, st->value);
+ ret = tpm_nv_read(tpm, NV_INDEX, st->value);
st->anchored = nv.defined && nv.written && st->logged &&
name_equals(&nv, st->init.name) &&
(!st->init.have_reset_count ||
st->init.reset_count == reset_count);
if (st->anchored) {
bind_values(st->init.pcr_before, st->init.phase_before, values);
- rc = tpm_register_policy(CHAIN_PCR_MASK, values, 2,
- st->init.writer_public, branch_written,
- branch_init, policy);
- if (rc) {
- pr_err("tpm: compute signed register policy: %s", strerror(-rc));
+ ret = tpm_register_policy(CHAIN_PCR_MASK, values, 2,
+ st->init.writer_public, branch_written,
+ branch_init, policy);
+ if (ret) {
+ pr_err("tpm: compute signed register policy: %s", strerror(-ret));
st->anchored = false;
goto out;
}
@@ -597,5 +597,5 @@ int chain_status(struct chain_status *st)
}
out:
tpm_close(tpm);
- return rc;
+ return ret;
}
diff --git a/util/config.c b/util/config.c
index 1b7db563..debc7e1a 100644
--- a/util/config.c
+++ b/util/config.c
@@ -154,7 +154,7 @@ static int config_parse(struct shirudo_config *cfg, FILE *f,
const size_t max = MAP_EXPORT_PATH_MAX + 127;
size_t capacity = 0;
char *line = NULL;
- int got, rc = 0;
+ int got, ret = 0;
if (check_trusted(fileno(f), path, false)) {
fclose(f);
@@ -171,7 +171,7 @@ static int config_parse(struct shirudo_config *cfg, FILE *f,
if (got < 0) {
pr_err("config: %s: unreadable line: %s", path,
strerror(-got));
- rc = got;
+ ret = got;
break;
}
p = trim(line);
@@ -272,27 +272,27 @@ static int config_parse(struct shirudo_config *cfg, FILE *f,
}
}
}
- if (ferror(f) && !rc)
- rc = -EIO;
+ if (ferror(f) && !ret)
+ ret = -EIO;
/* The TPM owner's authorization is for no other user's eyes. */
if (cfg->tpm_owner_auth_len &&
check_trusted(fileno(f), path, true)) {
explicit_bzero(cfg->tpm_owner_auth,
sizeof(cfg->tpm_owner_auth));
cfg->tpm_owner_auth_len = 0;
- rc = -EPERM;
+ ret = -EPERM;
}
if (line) {
/* The owner's authorization may have been read into it. */
explicit_bzero(line, capacity);
libc_free(line);
}
- if (fclose(f) && !rc)
- rc = -errno;
- return rc;
+ if (fclose(f) && !ret)
+ ret = -errno;
+ return ret;
}
-static int config_finish(struct shirudo_config *cfg, int rc)
+static int config_finish(struct shirudo_config *cfg, int ret)
{
if (cfg->map_export_s3_uri[0] && !cfg->map_export_otel_endpoint[0])
map_export_bad(cfg, "map_export.s3_uri", "",
@@ -300,12 +300,12 @@ static int config_finish(struct shirudo_config *cfg, int rc)
if (cfg->map_export_log_record_max_bytes > cfg->map_export_otlp_max_bytes)
map_export_bad(cfg, "map_export.log_record_max_bytes", "",
"must not exceed otlp_max_bytes");
- return rc;
+ return ret;
}
int config_load_path(struct shirudo_config *cfg, const char *path)
{
- int rc = 0;
+ int ret = 0;
FILE *f;
if (!cfg || !path)
@@ -314,17 +314,17 @@ int config_load_path(struct shirudo_config *cfg, const char *path)
f = fopen(path, "r");
if (!f) {
if (errno != ENOENT)
- rc = -errno; /* still apply env override below */
+ ret = -errno; /* still apply env override below */
} else {
- rc = config_parse(cfg, f, path);
+ ret = config_parse(cfg, f, path);
}
- return config_finish(cfg, rc);
+ return config_finish(cfg, ret);
}
/* A copy of the descriptor is read from its start; the caller keeps its own. */
int config_load_fd(struct shirudo_config *cfg, int fd, const char *label)
{
- int copy, rc;
+ int copy, ret;
FILE *f;
if (!cfg || fd < 0)
@@ -334,15 +334,15 @@ int config_load_fd(struct shirudo_config *cfg, int fd, const char *label)
if (copy < 0)
return -errno;
if (lseek(copy, 0, SEEK_SET) < 0) {
- rc = -errno;
+ ret = -errno;
close(copy);
- return rc;
+ return ret;
}
f = fdopen(copy, "r");
if (!f) {
- rc = -errno;
+ ret = -errno;
close(copy);
- return rc;
+ return ret;
}
return config_finish(cfg, config_parse(cfg, f, label));
}
@@ -350,13 +350,13 @@ int config_load_fd(struct shirudo_config *cfg, int fd, const char *label)
int config_load(struct shirudo_config *cfg)
{
const char *env;
- int rc;
+ int ret;
if (shirudo_image_config_get(cfg))
return 0;
- rc = config_load_path(cfg, CONF_PATH);
- if (rc && rc != -ENOENT)
- return rc;
+ ret = config_load_path(cfg, CONF_PATH);
+ if (ret && ret != -ENOENT)
+ return ret;
/* Env override (handy for tests / not persisting a secret to disk). */
env = getenv("SHIRUDO_TPM_OWNER_AUTH");
@@ -375,5 +375,5 @@ int config_load(struct shirudo_config *cfg)
pr_warn("SHIRUDO_TPM_TCTI too long (ignored)");
}
- return rc == -ENOENT ? 0 : rc;
+ return ret == -ENOENT ? 0 : ret;
}
diff --git a/util/config_attest.c b/util/config_attest.c
index 29dbc988..d776a87f 100644
--- a/util/config_attest.c
+++ b/util/config_attest.c
@@ -41,7 +41,7 @@ static int replay(const struct shirudo_config_evidence *view, __u8 out[32])
__u8 digest[32];
__u64 sequence = 0;
size_t i;
- int rc;
+ int ret;
if (!view->events || !view->n_events ||
view->n_events > CONFIG_EVIDENCE_EVENTS_MAX)
@@ -56,12 +56,12 @@ static int replay(const struct shirudo_config_evidence *view, __u8 out[32])
event->kind != (i ? SHIRUDO_CONFIG_EVENT_UPDATE :
SHIRUDO_CONFIG_EVENT_BOOT))
return -EKEYREJECTED;
- rc = shirudo_config_measure_event(event->kind, event->root_hash,
- digest);
- if (!rc)
- rc = shirudo_chain_fold_checked(out, digest);
- if (rc)
- return rc;
+ ret = shirudo_config_measure_event(event->kind, event->root_hash,
+ digest);
+ if (!ret)
+ ret = shirudo_chain_fold_checked(out, digest);
+ if (ret)
+ return ret;
sequence = event->sequence;
}
return 0;
@@ -90,30 +90,30 @@ int shirudo_config_evidence_collect(struct shirudo_config_update *update,
{
struct shirudo_config_update_record active;
const struct shirudo_config_evidence_event *last;
- int rc;
+ int ret;
memset(out, 0, sizeof(*out));
if (!update)
return 0;
- rc = shirudo_config_update_check(update, &active);
- if (rc)
- return rc;
+ ret = shirudo_config_update_check(update, &active);
+ if (ret)
+ return ret;
out->pcr = active.pcr;
out->reset_count = active.reset_count;
out->restart_count = active.restart_count;
memcpy(out->initial_pcr, active.initial_pcr, 32);
- rc = shirudo_config_update_events(update, collect_event, out);
- if (!rc)
- rc = replay(out, out->value);
- if (!rc) {
+ ret = shirudo_config_update_events(update, collect_event, out);
+ if (!ret)
+ ret = replay(out, out->value);
+ if (!ret) {
last = &out->events[out->n_events - 1];
if (last->sequence != active.sequence ||
memcmp(last->root_hash, active.target.root_hash, 32))
- rc = -EUCLEAN;
+ ret = -EUCLEAN;
}
- if (rc) {
+ if (ret) {
shirudo_config_evidence_clear(out);
- return rc;
+ return ret;
}
out->present = true;
return 0;
@@ -203,7 +203,7 @@ int shirudo_config_evidence_parse(const char *evidence, size_t length,
__s64 schema = 0, reset = 0, restart = 0, pcr = 0;
char initial[65] = {};
size_t i;
- int rc;
+ int ret;
struct shirudo_json_field event_fields[] = {
{ "sequence", SHIRUDO_JSON_T_INT, &parser.sequence, 0, 0, NULL,
0 },
@@ -230,34 +230,34 @@ int shirudo_config_evidence_parse(const char *evidence, size_t length,
memset(out, 0, sizeof(*out));
parser.event_fields = event_fields;
parser.n_fields = ARRAY_SIZE(event_fields);
- rc = json_parse(evidence, length, top, ARRAY_SIZE(top));
- if (rc)
+ ret = json_parse(evidence, length, top, ARRAY_SIZE(top));
+ if (ret)
goto fail;
if (!top[0].seen)
return 0;
for (i = 0; i < ARRAY_SIZE(config_fields); i++)
if (!config_fields[i].seen) {
- rc = -EINVAL;
+ ret = -EINVAL;
goto fail;
}
if (schema != 1 || reset < 0 || reset > UINT32_MAX || restart < 0 ||
restart > UINT32_MAX || pcr < 0 || pcr > 15 ||
shirudo_config_measure_pcr_valid(pcr) || strlen(initial) != 64 ||
hex_decode(initial, out->initial_pcr, 32)) {
- rc = -EINVAL;
+ ret = -EINVAL;
goto fail;
}
out->pcr = pcr;
out->reset_count = reset;
out->restart_count = restart;
- rc = replay(out, out->value);
- if (rc)
+ ret = replay(out, out->value);
+ if (ret)
goto fail;
out->present = true;
return 0;
fail:
shirudo_config_evidence_clear(out);
- return rc;
+ return ret;
}
int shirudo_config_evidence_verify(const struct shirudo_config_evidence *view,
@@ -267,7 +267,7 @@ int shirudo_config_evidence_verify(const struct shirudo_config_evidence *view,
int expected_pcr, const char **reason)
{
__u8 value[32];
- int rc;
+ int ret;
*reason = "config root history matches the quoted PCR";
if (!view->present) {
@@ -288,10 +288,10 @@ int shirudo_config_evidence_verify(const struct shirudo_config_evidence *view,
*reason = "expected config root needs an expected PCR";
return -EKEYREJECTED;
}
- rc = replay(view, value);
- if (rc || memcmp(value, pcrs[view->pcr], 32)) {
+ ret = replay(view, value);
+ if (ret || memcmp(value, pcrs[view->pcr], 32)) {
*reason = "config history does not match the quoted PCR";
- return rc ? rc : -EKEYREJECTED;
+ return ret ? ret : -EKEYREJECTED;
}
if (expected_root && memcmp(view->events[view->n_events - 1].root_hash,
expected_root, 32)) {
diff --git a/util/config_image.c b/util/config_image.c
index 150ccf1a..0025e03e 100644
--- a/util/config_image.c
+++ b/util/config_image.c
@@ -108,19 +108,19 @@ int shirudo_config_image_read_header(int hash_fd,
{
struct shirudo_config_image image = {};
struct verity_superblock header;
- int rc;
+ int ret;
if (!out)
return -EINVAL;
- rc = read_exact_at_start(hash_fd, &header, sizeof(header));
- if (!rc)
- rc = validate_superblock(&header);
- if (rc)
- return rc;
+ ret = read_exact_at_start(hash_fd, &header, sizeof(header));
+ if (!ret)
+ ret = validate_superblock(&header);
+ if (ret)
+ return ret;
image.data_blocks = le64_to_cpu(header.data_blocks);
- rc = verity_hash_blocks(image.data_blocks, &image.hash_blocks);
- if (rc)
- return rc;
+ ret = verity_hash_blocks(image.data_blocks, &image.hash_blocks);
+ if (ret)
+ return ret;
memcpy(image.salt, header.salt, sizeof(image.salt));
*out = image;
return 0;
@@ -130,20 +130,20 @@ int shirudo_config_image_check_files(int data_fd, int hash_fd,
const struct shirudo_config_image *image)
{
__u64 data_size, hash_size, blocks;
- int rc;
+ int ret;
if (!image)
return -EINVAL;
- rc = verity_hash_blocks(image->data_blocks, &blocks);
- if (rc)
- return rc;
+ ret = verity_hash_blocks(image->data_blocks, &blocks);
+ if (ret)
+ return ret;
if (blocks != image->hash_blocks)
return -EINVAL;
- rc = regular_file_size(data_fd, &data_size);
- if (!rc)
- rc = regular_file_size(hash_fd, &hash_size);
- if (rc)
- return rc;
+ ret = regular_file_size(data_fd, &data_size);
+ if (!ret)
+ ret = regular_file_size(hash_fd, &hash_size);
+ if (ret)
+ return ret;
if (data_size != image->data_blocks * CONFIG_IMAGE_BLOCK_SIZE ||
hash_size != image->hash_blocks * CONFIG_IMAGE_BLOCK_SIZE)
return -EINVAL;
@@ -166,19 +166,19 @@ static int read_root(const char *prefix, __u8 root[32])
char text[65] = {};
__u64 size;
__u32 i;
- int fd, rc;
+ int fd, ret;
fd = open_part(prefix, ".roothash");
if (fd < 0)
return fd;
- rc = regular_file_size(fd, &size);
- if (!rc && size != 64)
- rc = -EINVAL;
- if (!rc)
- rc = read_exact_at_start(fd, text, 64);
+ ret = regular_file_size(fd, &size);
+ if (!ret && size != 64)
+ ret = -EINVAL;
+ if (!ret)
+ ret = read_exact_at_start(fd, text, 64);
close(fd);
- if (rc)
- return rc;
+ if (ret)
+ return ret;
for (i = 0; i < 64; i++)
if (!((text[i] >= '0' && text[i] <= '9') ||
(text[i] >= 'a' && text[i] <= 'f')))
@@ -208,7 +208,7 @@ static int open_image(const char *prefix, const __u8 *expected_root,
.data_fd = -1, .hash_fd = -1, .signature_fd = -1,
};
__u64 size;
- int rc;
+ int ret;
if (!prefix || !*prefix || !out)
return -EINVAL;
@@ -218,36 +218,36 @@ static int open_image(const char *prefix, const __u8 *expected_root,
return image.data_fd;
image.hash_fd = open_part(prefix, ".verity");
if (image.hash_fd < 0) {
- rc = image.hash_fd;
+ ret = image.hash_fd;
goto out;
}
- rc = shirudo_config_image_read_header(image.hash_fd,
- &image.image);
- if (!rc)
- rc = read_root(prefix, image.image.root_hash);
- if (!rc)
- rc = shirudo_config_image_check_files(image.data_fd,
- image.hash_fd,
- &image.image);
- if (rc)
+ ret = shirudo_config_image_read_header(image.hash_fd,
+ &image.image);
+ if (!ret)
+ ret = read_root(prefix, image.image.root_hash);
+ if (!ret)
+ ret = shirudo_config_image_check_files(image.data_fd,
+ image.hash_fd,
+ &image.image);
+ if (ret)
goto out;
if (expected_root) {
if (memcmp(expected_root, image.image.root_hash, 32))
- rc = -EKEYREJECTED;
+ ret = -EKEYREJECTED;
} else {
image.image.signed_root = true;
image.signature_fd = open_part(prefix, ".p7s");
- rc = image.signature_fd < 0 ? image.signature_fd :
+ ret = image.signature_fd < 0 ? image.signature_fd :
regular_file_size(image.signature_fd, &size);
- if (!rc && (!size || size > CONFIG_IMAGE_SIG_MAX))
- rc = -EINVAL;
+ if (!ret && (!size || size > CONFIG_IMAGE_SIG_MAX))
+ ret = -EINVAL;
}
out:
- if (rc)
+ if (ret)
shirudo_config_image_close(&image);
else
*out = image;
- return rc;
+ return ret;
}
int shirudo_config_image_open(const char *prefix,
diff --git a/util/config_update.c b/util/config_update.c
index ad072209..99c4fc7f 100644
--- a/util/config_update.c
+++ b/util/config_update.c
@@ -78,7 +78,7 @@ static int record_decode(const char *data, size_t length, bool state,
__s64 pcr = 0, kind = 0;
int pending = 0;
size_t i;
- int rc;
+ int ret;
struct shirudo_json_field fields[] = {
{ "schema", SHIRUDO_JSON_T_INT, &schema, 0, 0, NULL, 0 },
{ "sequence", SHIRUDO_JSON_T_INT, &sequence, 0, 0, NULL, 0 },
@@ -97,9 +97,9 @@ static int record_decode(const char *data, size_t length, bool state,
};
memset(record, 0, sizeof(*record));
- rc = json_parse(data, length, fields, ARRAY_SIZE(fields));
- if (rc)
- return rc;
+ ret = json_parse(data, length, fields, ARRAY_SIZE(fields));
+ if (ret)
+ return ret;
for (i = 0; i < ARRAY_SIZE(fields) - (state ? 0 : 2); i++)
if (!fields[i].seen)
return -EBADMSG;
@@ -173,7 +173,7 @@ int shirudo_config_update_open(const char *directory,
void *ctx, struct shirudo_config_update *out)
{
struct stat st;
- int rc;
+ int ret;
if (!out)
return -EINVAL;
@@ -191,45 +191,45 @@ int shirudo_config_update_open(const char *directory,
if (out->dir_fd < 0)
return -errno;
if (fstat(out->dir_fd, &st)) {
- rc = -errno;
+ ret = -errno;
goto fail;
}
if (st.st_uid != geteuid() || (st.st_mode & 022)) {
- rc = -EPERM;
+ ret = -EPERM;
goto fail;
}
- rc = ops->seal(ctx, out->dir_fd);
- if (rc)
+ ret = ops->seal(ctx, out->dir_fd);
+ if (ret)
goto fail;
out->lock_fd = openat(out->dir_fd,
"lock",
O_RDWR | O_CREAT | O_CLOEXEC |
O_NOFOLLOW | O_NONBLOCK, 0600);
if (out->lock_fd < 0) {
- rc = -errno;
+ ret = -errno;
goto fail;
}
- rc = regular_file(out->lock_fd);
- if (rc)
+ ret = regular_file(out->lock_fd);
+ if (ret)
goto fail;
- rc = lock_wait(out->lock_fd, ops->lock_wait_ms);
- if (rc) {
- if (rc == -EWOULDBLOCK)
+ ret = lock_wait(out->lock_fd, ops->lock_wait_ms);
+ if (ret) {
+ if (ret == -EWOULDBLOCK)
pr_err("image: another shirudo command still holds the config operation lock %s/lock after %u seconds",
directory, ops->lock_wait_ms / 1000);
goto fail;
}
- rc = ops->seal(ctx, out->lock_fd);
- if (rc)
+ ret = ops->seal(ctx, out->lock_fd);
+ if (ret)
goto fail;
if (fsync(out->lock_fd) || fsync(out->dir_fd)) {
- rc = -errno;
+ ret = -errno;
goto fail;
}
return 0;
fail:
shirudo_config_update_close(out);
- return rc;
+ return ret;
}
void shirudo_config_update_close(struct shirudo_config_update *update)
@@ -251,7 +251,7 @@ int shirudo_config_update_read(struct shirudo_config_update *update,
struct stat st;
size_t done = 0;
ssize_t got;
- int fd, rc;
+ int fd, ret;
if (!update || update->dir_fd < 0 || !out)
return -EINVAL;
@@ -259,27 +259,27 @@ int shirudo_config_update_read(struct shirudo_config_update *update,
O_RDONLY | O_CLOEXEC | O_NOFOLLOW | O_NONBLOCK);
if (fd < 0)
return -errno;
- rc = regular_file(fd);
- if (!rc && fstat(fd, &st))
- rc = -errno;
- if (!rc && (st.st_size <= 0 || (__u64)st.st_size >= sizeof(wire)))
- rc = -EBADMSG;
- while (!rc && done < (size_t)st.st_size) {
+ ret = regular_file(fd);
+ if (!ret && fstat(fd, &st))
+ ret = -errno;
+ if (!ret && (st.st_size <= 0 || (__u64)st.st_size >= sizeof(wire)))
+ ret = -EBADMSG;
+ while (!ret && done < (size_t)st.st_size) {
got = read(fd, wire + done, st.st_size - done);
if (got < 0) {
if (errno == EINTR)
continue;
- rc = -errno;
+ ret = -errno;
} else if (!got) {
- rc = -EIO;
+ ret = -EIO;
} else {
done += got;
}
}
- if (!rc)
- rc = record_decode(wire, done, true, out);
+ if (!ret)
+ ret = record_decode(wire, done, true, out);
close(fd);
- return rc;
+ return ret;
}
static int state_save(struct shirudo_config_update *update,
@@ -288,36 +288,36 @@ static int state_save(struct shirudo_config_update *update,
{
char wire[RECORD_MAX];
size_t length;
- int fd, rc;
+ int fd, ret;
- rc = record_encode(record, true, wire, sizeof(wire), &length);
- if (rc)
- return rc;
+ ret = record_encode(record, true, wire, sizeof(wire), &length);
+ if (ret)
+ return ret;
if (unlinkat(update->dir_fd, ".state.tmp", 0) && errno != ENOENT)
return -errno;
fd = openat(update->dir_fd, ".state.tmp",
O_WRONLY | O_CREAT | O_EXCL | O_CLOEXEC | O_NOFOLLOW, 0600);
if (fd < 0)
return -errno;
- rc = update->ops->seal(update->ctx, fd);
- if (!rc)
- rc = write_complete(fd, wire, length);
- if (!rc && inject)
- rc = checkpoint(update, SHIRUDO_CONFIG_CHECK_STATE_WRITE);
- if (!rc && fsync(fd))
- rc = -errno;
- if (close(fd) && !rc)
- rc = -errno;
- if (!rc &&
+ ret = update->ops->seal(update->ctx, fd);
+ if (!ret)
+ ret = write_complete(fd, wire, length);
+ if (!ret && inject)
+ ret = checkpoint(update, SHIRUDO_CONFIG_CHECK_STATE_WRITE);
+ if (!ret && fsync(fd))
+ ret = -errno;
+ if (close(fd) && !ret)
+ ret = -errno;
+ if (!ret &&
renameat(update->dir_fd, ".state.tmp", update->dir_fd, "state"))
- rc = -errno;
- if (!rc && inject)
- rc = checkpoint(update, SHIRUDO_CONFIG_CHECK_STATE_RENAME);
- if (!rc && fsync(update->dir_fd))
- rc = -errno;
- if (rc)
+ ret = -errno;
+ if (!ret && inject)
+ ret = checkpoint(update, SHIRUDO_CONFIG_CHECK_STATE_RENAME);
+ if (!ret && fsync(update->dir_fd))
+ ret = -errno;
+ if (ret)
unlinkat(update->dir_fd, ".state.tmp", 0);
- return rc;
+ return ret;
}
static bool same_boot(const struct shirudo_config_update_record *a,
@@ -379,7 +379,7 @@ static int events_scan(struct shirudo_config_update *update,
__u8 running[32] = {}, digest[32];
char wire[RECORD_MAX];
size_t length;
- int fd, rc;
+ int fd, ret;
FILE *file;
memset(last, 0, sizeof(*last));
@@ -389,50 +389,50 @@ static int events_scan(struct shirudo_config_update *update,
O_RDONLY | O_CLOEXEC | O_NOFOLLOW | O_NONBLOCK);
if (fd < 0)
return errno == ENOENT ? 0 : -errno;
- rc = regular_file(fd);
- if (rc) {
+ ret = regular_file(fd);
+ if (ret) {
close(fd);
- return rc;
+ return ret;
}
file = fdopen(fd, "r");
if (!file) {
- rc = -errno;
+ ret = -errno;
close(fd);
- return rc;
+ return ret;
}
- while ((rc = read_line(file, wire, sizeof(wire), &length)) > 0) {
- rc = record_decode(wire, length, false, &record);
- if (!rc)
- rc = event_follows(&previous, &record);
- if (!rc && record.kind == SHIRUDO_CONFIG_EVENT_BOOT)
+ while ((ret = read_line(file, wire, sizeof(wire), &length)) > 0) {
+ ret = record_decode(wire, length, false, &record);
+ if (!ret)
+ ret = event_follows(&previous, &record);
+ if (!ret && record.kind == SHIRUDO_CONFIG_EVENT_BOOT)
memcpy(running, record.initial_pcr, 32);
- if (!rc)
- rc = shirudo_config_measure_event(record.kind,
- root, digest);
- if (!rc)
- rc = shirudo_chain_fold_checked(running, digest);
- if (!rc && consume)
- rc = consume(&record, ctx);
- if (rc)
+ if (!ret)
+ ret = shirudo_config_measure_event(record.kind,
+ root, digest);
+ if (!ret)
+ ret = shirudo_chain_fold_checked(running, digest);
+ if (!ret && consume)
+ ret = consume(&record, ctx);
+ if (ret)
break;
previous = record;
if (end) {
*end = ftello(file);
if (*end < 0) {
- rc = -errno;
+ ret = -errno;
break;
}
}
}
- if (rc == -ENODATA && partial)
- rc = 0;
- if (!rc) {
+ if (ret == -ENODATA && partial)
+ ret = 0;
+ if (!ret) {
*last = previous;
if (value)
memcpy(value, running, 32);
}
fclose(file);
- return rc;
+ return ret;
}
int shirudo_config_update_events(struct shirudo_config_update *update,
@@ -451,55 +451,55 @@ static int event_append(struct shirudo_config_update *update,
struct shirudo_config_update_record last;
char wire[RECORD_MAX];
size_t length;
- int fd, rc;
+ int fd, ret;
off_t end;
- rc = events_scan(update, &last, NULL, &end,
- record->kind == SHIRUDO_CONFIG_EVENT_BOOT, NULL, NULL);
- if (!rc)
- rc = event_follows(&last, record);
- if (!rc)
- rc = record_encode(record, false, wire, sizeof(wire), &length);
- if (rc)
- return rc;
+ ret = events_scan(update, &last, NULL, &end,
+ record->kind == SHIRUDO_CONFIG_EVENT_BOOT, NULL, NULL);
+ if (!ret)
+ ret = event_follows(&last, record);
+ if (!ret)
+ ret = record_encode(record, false, wire, sizeof(wire), &length);
+ if (ret)
+ return ret;
fd = openat(update->dir_fd, "events",
O_WRONLY | O_APPEND | O_CREAT | O_CLOEXEC | O_NOFOLLOW |
O_NONBLOCK, 0600);
if (fd < 0)
return -errno;
- rc = regular_file(fd);
- if (!rc)
- rc = update->ops->seal(update->ctx, fd);
- if (!rc && ftruncate(fd, end))
- rc = -errno;
- if (!rc)
- rc = write_complete(fd, wire, length);
- if (!rc)
- rc = checkpoint(update, SHIRUDO_CONFIG_CHECK_EVENT_WRITE);
- if (!rc && fsync(fd))
- rc = -errno;
- if (close(fd) && !rc)
- rc = -errno;
- if (!rc && fsync(update->dir_fd))
- rc = -errno;
- return rc;
+ ret = regular_file(fd);
+ if (!ret)
+ ret = update->ops->seal(update->ctx, fd);
+ if (!ret && ftruncate(fd, end))
+ ret = -errno;
+ if (!ret)
+ ret = write_complete(fd, wire, length);
+ if (!ret)
+ ret = checkpoint(update, SHIRUDO_CONFIG_CHECK_EVENT_WRITE);
+ if (!ret && fsync(fd))
+ ret = -errno;
+ if (close(fd) && !ret)
+ ret = -errno;
+ if (!ret && fsync(update->dir_fd))
+ ret = -errno;
+ return ret;
}
static int live_read(struct shirudo_config_update *update, __u32 pcr,
__u32 *reset, __u32 *restart, __u8 value[32])
{
__u32 reset_after, restart_after;
- int rc;
-
- rc = update->ops->boot_identity(update->ctx, reset, restart);
- if (!rc)
- rc = update->ops->pcr_read(update->ctx, pcr, value);
- if (!rc)
- rc = update->ops->boot_identity(update->ctx, &reset_after,
- &restart_after);
- if (!rc && (*reset != reset_after || *restart != restart_after))
- rc = -ESTALE;
- return rc;
+ int ret;
+
+ ret = update->ops->boot_identity(update->ctx, reset, restart);
+ if (!ret)
+ ret = update->ops->pcr_read(update->ctx, pcr, value);
+ if (!ret)
+ ret = update->ops->boot_identity(update->ctx, &reset_after,
+ &restart_after);
+ if (!ret && (*reset != reset_after || *restart != restart_after))
+ ret = -ESTALE;
+ return ret;
}
static int check_record(struct shirudo_config_update *update,
@@ -508,59 +508,59 @@ static int check_record(struct shirudo_config_update *update,
struct shirudo_config_update_record last;
__u8 expected[32], value[32];
__u32 reset, restart;
- int rc;
-
- rc = events_scan(update, &last, expected, NULL, false, NULL, NULL);
- if (!rc && !same_event(record, &last))
- rc = -EUCLEAN;
- if (!rc)
- rc = live_read(update, record->pcr, &reset, &restart, value);
- if (!rc && (reset != record->reset_count ||
- restart != record->restart_count))
- rc = -ESTALE;
- if (!rc && memcmp(value, expected, 32))
- rc = -EUCLEAN;
- return rc;
+ int ret;
+
+ ret = events_scan(update, &last, expected, NULL, false, NULL, NULL);
+ if (!ret && !same_event(record, &last))
+ ret = -EUCLEAN;
+ if (!ret)
+ ret = live_read(update, record->pcr, &reset, &restart, value);
+ if (!ret && (reset != record->reset_count ||
+ restart != record->restart_count))
+ ret = -ESTALE;
+ if (!ret && memcmp(value, expected, 32))
+ ret = -EUCLEAN;
+ return ret;
}
int shirudo_config_update_check(struct shirudo_config_update *update,
struct shirudo_config_update_record *out)
{
struct shirudo_config_update_record record;
- int rc;
-
- rc = shirudo_config_update_read(update, &record);
- if (!rc && record.pending)
- rc = -EINPROGRESS;
- if (!rc)
- rc = check_record(update, &record);
- if (!rc && out)
+ int ret;
+
+ ret = shirudo_config_update_read(update, &record);
+ if (!ret && record.pending)
+ ret = -EINPROGRESS;
+ if (!ret)
+ ret = check_record(update, &record);
+ if (!ret && out)
*out = record;
- return rc;
+ return ret;
}
static int complete(struct shirudo_config_update *update)
{
struct shirudo_config_update_record record;
- int rc, restore;
+ int ret, restore;
- rc = shirudo_config_update_read(update, &record);
- if (!rc)
- rc = check_record(update, &record);
- if (rc)
- return rc;
+ ret = shirudo_config_update_read(update, &record);
+ if (!ret)
+ ret = check_record(update, &record);
+ if (ret)
+ return ret;
record.pending = false;
- rc = state_save(update, &record, true);
- if (!rc)
- rc = checkpoint(update, SHIRUDO_CONFIG_CHECK_COMPLETE_SYNC);
- if (rc) {
+ ret = state_save(update, &record, true);
+ if (!ret)
+ ret = checkpoint(update, SHIRUDO_CONFIG_CHECK_COMPLETE_SYNC);
+ if (ret) {
record.pending = true;
restore = state_save(update, &record, false);
if (restore)
pr_err("image: cannot restore pending selection: %s",
strerror(-restore));
}
- return rc;
+ return ret;
}
static int begin_event(struct shirudo_config_update *update,
@@ -571,56 +571,56 @@ static int begin_event(struct shirudo_config_update *update,
struct shirudo_config_update_record record = {};
__u8 before[32], expected[32], value[32], event[32];
__u32 reset, restart;
- int rc;
+ int ret;
if (previous->sequence == INT64_MAX)
return -EOVERFLOW;
- rc = update->ops->prepare(update->ctx, target);
- if (rc)
- return rc;
+ ret = update->ops->prepare(update->ctx, target);
+ if (ret)
+ return ret;
record.target = *target;
record.sequence = previous->sequence + 1;
record.pcr = pcr;
record.kind = kind;
record.pending = true;
- rc = live_read(update, pcr, &record.reset_count, &record.restart_count,
- before);
- if (rc)
- return rc;
+ ret = live_read(update, pcr, &record.reset_count, &record.restart_count,
+ before);
+ if (ret)
+ return ret;
memcpy(record.initial_pcr, kind == SHIRUDO_CONFIG_EVENT_BOOT ?
before : previous->initial_pcr, 32);
- if (!rc)
- rc = event_follows(previous, &record);
- if (!rc)
- rc = shirudo_config_measure_event(kind, target->root_hash,
- event);
+ if (!ret)
+ ret = event_follows(previous, &record);
+ if (!ret)
+ ret = shirudo_config_measure_event(kind, target->root_hash,
+ event);
memcpy(expected, before, 32);
- if (!rc)
- rc = shirudo_chain_fold_checked(expected, event);
- if (!rc)
- rc = state_save(update, &record, true);
- if (!rc)
- rc = checkpoint(update, SHIRUDO_CONFIG_CHECK_PENDING_SYNC);
- if (!rc)
- rc = update->ops->pcr_extend(update->ctx, pcr, event);
- if (!rc)
- rc = checkpoint(update, SHIRUDO_CONFIG_CHECK_EXTEND);
- if (!rc)
- rc = live_read(update, pcr, &reset, &restart, value);
- if (!rc && (reset != record.reset_count ||
- restart != record.restart_count ||
- memcmp(value, expected, 32)))
- rc = -EUCLEAN;
- if (!rc)
- rc = event_append(update, &record);
- if (!rc)
- rc = checkpoint(update, SHIRUDO_CONFIG_CHECK_EVENT_SYNC);
- if (!rc)
- rc = update->ops->activate(update->ctx, target);
- if (!rc)
- rc = checkpoint(update, SHIRUDO_CONFIG_CHECK_ACTIVATE);
- if (rc)
- return rc;
+ if (!ret)
+ ret = shirudo_chain_fold_checked(expected, event);
+ if (!ret)
+ ret = state_save(update, &record, true);
+ if (!ret)
+ ret = checkpoint(update, SHIRUDO_CONFIG_CHECK_PENDING_SYNC);
+ if (!ret)
+ ret = update->ops->pcr_extend(update->ctx, pcr, event);
+ if (!ret)
+ ret = checkpoint(update, SHIRUDO_CONFIG_CHECK_EXTEND);
+ if (!ret)
+ ret = live_read(update, pcr, &reset, &restart, value);
+ if (!ret && (reset != record.reset_count ||
+ restart != record.restart_count ||
+ memcmp(value, expected, 32)))
+ ret = -EUCLEAN;
+ if (!ret)
+ ret = event_append(update, &record);
+ if (!ret)
+ ret = checkpoint(update, SHIRUDO_CONFIG_CHECK_EVENT_SYNC);
+ if (!ret)
+ ret = update->ops->activate(update->ctx, target);
+ if (!ret)
+ ret = checkpoint(update, SHIRUDO_CONFIG_CHECK_ACTIVATE);
+ if (ret)
+ return ret;
if (kind == SHIRUDO_CONFIG_EVENT_BOOT) {
update->boot_pending = true;
return 0;
@@ -633,14 +633,14 @@ int shirudo_config_update_begin(struct shirudo_config_update *update,
__u32 pcr)
{
struct shirudo_config_update_record previous;
- int rc;
+ int ret;
if (!update || update->dir_fd < 0 || target_valid(t) ||
shirudo_config_measure_pcr_valid(pcr))
return -EINVAL;
- rc = shirudo_config_update_check(update, &previous);
- if (rc)
- return rc;
+ ret = shirudo_config_update_check(update, &previous);
+ if (ret)
+ return ret;
if (pcr != previous.pcr)
return -EPERM;
if (!memcmp(t->root_hash, previous.target.root_hash, 32))
@@ -655,18 +655,18 @@ int shirudo_config_update_boot(struct shirudo_config_update *update,
{
struct shirudo_config_update_record previous = {}, last;
__u32 reset, restart;
- int rc;
+ int ret;
if (!update || update->dir_fd < 0 || target_valid(t) ||
shirudo_config_measure_pcr_valid(pcr))
return -EINVAL;
update->boot_pending = false;
- rc = shirudo_config_update_read(update, &previous);
- if (rc && rc != -ENOENT)
- return rc;
- rc = update->ops->boot_identity(update->ctx, &reset, &restart);
- if (rc)
- return rc;
+ ret = shirudo_config_update_read(update, &previous);
+ if (ret && ret != -ENOENT)
+ return ret;
+ ret = update->ops->boot_identity(update->ctx, &reset, &restart);
+ if (ret)
+ return ret;
if (previous.sequence && previous.reset_count == reset &&
previous.restart_count == restart) {
if (previous.pending)
@@ -680,10 +680,10 @@ int shirudo_config_update_boot(struct shirudo_config_update *update,
(strcmp(t->prefix, previous.target.prefix) ||
memcmp(t->root_hash, previous.target.root_hash, 32)))
return -EUCLEAN;
- rc = events_scan(update, &last, NULL, NULL, previous.pending,
- NULL, NULL);
- if (rc)
- return rc;
+ ret = events_scan(update, &last, NULL, NULL, previous.pending,
+ NULL, NULL);
+ if (ret)
+ return ret;
if (!previous.sequence && last.sequence)
return -EUCLEAN;
if (previous.sequence &&
@@ -696,13 +696,13 @@ int shirudo_config_update_boot(struct shirudo_config_update *update,
int shirudo_config_update_complete_boot(struct shirudo_config_update *update)
{
- int rc;
+ int ret;
if (!update || update->dir_fd < 0)
return -EINVAL;
if (!update->boot_pending)
return shirudo_config_update_check(update, NULL);
update->boot_pending = false;
- rc = complete(update);
- return rc;
+ ret = complete(update);
+ return ret;
}
diff --git a/util/crypto_openssl.c b/util/crypto_openssl.c
index e8e4c136..30c9a0ad 100644
--- a/util/crypto_openssl.c
+++ b/util/crypto_openssl.c
@@ -41,15 +41,15 @@ static int read_x509(const char *path, X509 **out)
int fd = open(path, O_RDONLY | O_CLOEXEC);
X509 *cert;
BIO *bio;
- int rc;
+ int ret;
*out = NULL;
if (fd < 0)
return -errno;
- rc = check_trusted(fd, path, false);
- if (rc) {
+ ret = check_trusted(fd, path, false);
+ if (ret) {
close(fd);
- return rc;
+ return ret;
}
bio = BIO_new_fd(fd, BIO_CLOSE);
if (!bio) {
@@ -100,14 +100,14 @@ int sha256_final(struct shirudo_sha256_ctx *ctx,
__u8 out[CRYPTO_SHA256_LEN])
{
__u32 len = 0;
- int rc;
+ int ret;
if (!ctx || !ctx->impl || !out)
return -EINVAL;
- rc = EVP_DigestFinal_ex(ctx->impl, out, &len) == 1 && len == 32 ? 0 : -EIO;
+ ret = EVP_DigestFinal_ex(ctx->impl, out, &len) == 1 && len == 32 ? 0 : -EIO;
EVP_MD_CTX_free(ctx->impl);
ctx->impl = NULL;
- return rc;
+ return ret;
}
void sha256_free(struct shirudo_sha256_ctx *ctx)
@@ -122,16 +122,16 @@ int sha256_buffer(const void *data, size_t len,
__u8 out[CRYPTO_SHA256_LEN])
{
struct shirudo_sha256_ctx ctx;
- int rc;
+ int ret;
- rc = sha256_init(&ctx);
- if (!rc)
- rc = sha256_update(&ctx, data, len);
- if (!rc)
- rc = sha256_final(&ctx, out);
+ ret = sha256_init(&ctx);
+ if (!ret)
+ ret = sha256_update(&ctx, data, len);
+ if (!ret)
+ ret = sha256_final(&ctx, out);
else
sha256_free(&ctx);
- return rc;
+ return ret;
}
int base64_encode(const __u8 *data, size_t len,
@@ -180,12 +180,12 @@ int ecdsa_p256_verify(const __u8 x[32], const __u8 y[32],
EVP_PKEY_CTX *vctx = NULL;
ECDSA_SIG *sig = NULL;
EVP_PKEY *pkey = NULL;
- int der_len, rc = -EIO;
+ int der_len, ret = -EIO;
__u8 *der = NULL;
pkey = p256_public_key(x, y);
if (!pkey) {
- rc = -EINVAL;
+ ret = -EINVAL;
goto out;
}
br = BN_bin2bn(r, 32, NULL);
@@ -202,7 +202,7 @@ int ecdsa_p256_verify(const __u8 x[32], const __u8 y[32],
if (!vctx || EVP_PKEY_verify_init(vctx) <= 0 ||
EVP_PKEY_CTX_set_signature_md(vctx, EVP_sha256()) <= 0)
goto out;
- rc = EVP_PKEY_verify(vctx, der, (size_t)der_len, digest, 32) == 1 ?
+ ret = EVP_PKEY_verify(vctx, der, (size_t)der_len, digest, 32) == 1 ?
0 : -EKEYREJECTED;
out:
OPENSSL_free(der);
@@ -212,35 +212,35 @@ out:
EVP_PKEY_CTX_free(vctx);
EVP_PKEY_free(pkey);
ERR_clear_error();
- return rc;
+ return ret;
}
int cert_read_file(const char *path, struct shirudo_cert *cert)
{
X509 *x509;
- int rc;
+ int ret;
if (!path || !cert)
return -EINVAL;
- rc = read_x509(path, &x509);
+ ret = read_x509(path, &x509);
cert->impl = x509;
- return rc;
+ return ret;
}
int cert_read_fd(int fd, struct shirudo_cert *cert)
{
size_t len = 0;
__u8 *der;
- int rc;
+ int ret;
if (fd < 0 || !cert)
return -EINVAL;
- rc = read_fd(fd, "certificate", KEYS_DER_MAX, &der, &len);
- if (rc)
- return rc;
- rc = cert_read_der(der, len, cert);
+ ret = read_fd(fd, "certificate", KEYS_DER_MAX, &der, &len);
+ if (ret)
+ return ret;
+ ret = cert_read_der(der, len, cert);
xfree(der, len + 1);
- return rc;
+ return ret;
}
void cert_free(struct shirudo_cert *cert)
@@ -263,7 +263,7 @@ int cert_pubkey_digest(const struct shirudo_cert *cert,
__u8 out[CRYPTO_SHA256_LEN])
{
__u8 *der = NULL, *p;
- int der_len, encoded_len, rc = -EINVAL;
+ int der_len, encoded_len, ret = -EINVAL;
__u32 len = 0;
X509_PUBKEY *spki;
@@ -285,10 +285,10 @@ int cert_pubkey_digest(const struct shirudo_cert *cert,
if (!EVP_Digest(der, (size_t)der_len, out, &len,
EVP_sha256(), NULL) || len != CRYPTO_SHA256_LEN)
goto out;
- rc = 0;
+ ret = 0;
out:
xfree(der, (size_t)der_len);
- return rc;
+ return ret;
}
int cert_key_algorithm(const struct shirudo_cert *cert,
@@ -313,27 +313,27 @@ int cert_subject(const struct shirudo_cert *cert, char *out, size_t out_sz)
char *text;
long len;
BIO *bio;
- int rc;
+ int ret;
if (!cert || !cert->impl || !out || !out_sz)
return -EINVAL;
bio = BIO_new(BIO_s_mem());
if (!bio)
return -ENOMEM;
- rc = -EINVAL;
+ ret = -EINVAL;
if (X509_NAME_print_ex(bio, X509_get_subject_name(cert->impl), 0,
XN_FLAG_ONELINE & ~XN_FLAG_SPC_EQ) < 0)
goto out;
len = BIO_get_mem_data(bio, &text);
- rc = -ENAMETOOLONG;
+ ret = -ENAMETOOLONG;
if (len < 0 || (size_t)len >= out_sz)
goto out;
memcpy(out, text, (size_t)len);
out[len] = '\0';
- rc = 0;
+ ret = 0;
out:
BIO_free(bio);
- return rc;
+ return ret;
}
static int asn1_date(const ASN1_TIME *t, char out[11])
@@ -348,14 +348,14 @@ static int asn1_date(const ASN1_TIME *t, char out[11])
int cert_validity(const struct shirudo_cert *cert, char not_before[11],
char not_after[11])
{
- int rc;
+ int ret;
if (!cert || !cert->impl)
return -EINVAL;
- rc = asn1_date(X509_get0_notBefore(cert->impl), not_before);
- if (!rc)
- rc = asn1_date(X509_get0_notAfter(cert->impl), not_after);
- return rc;
+ ret = asn1_date(X509_get0_notBefore(cert->impl), not_before);
+ if (!ret)
+ ret = asn1_date(X509_get0_notAfter(cert->impl), not_after);
+ return ret;
}
static CMS_ContentInfo *read_cms(const __u8 *signature, size_t len)
@@ -386,7 +386,7 @@ int verify_detached(const __u8 *payload, size_t payload_len,
BIO *data = NULL, *out = NULL;
CMS_ContentInfo *cms = NULL;
X509_STORE *store = NULL;
- int rc = -EINVAL;
+ int ret = -EINVAL;
if (!payload || !signature || !cert || !cert->impl ||
payload_len > INT_MAX || signature_len > INT_MAX)
@@ -404,16 +404,16 @@ int verify_detached(const __u8 *payload, size_t payload_len,
cms = read_cms(signature, signature_len);
if (cms && CMS_verify(cms, signers, store, data, out,
CMS_BINARY | CMS_DETACHED) == 1)
- rc = 0;
+ ret = 0;
done:
- if (rc)
+ if (ret)
ERR_clear_error();
CMS_ContentInfo_free(cms);
sk_X509_free(signers);
X509_STORE_free(store);
BIO_free(out);
BIO_free(data);
- return rc;
+ return ret;
}
int cms_signed_by(const __u8 *signature, size_t signature_len,
@@ -421,7 +421,7 @@ int cms_signed_by(const __u8 *signature, size_t signature_len,
{
STACK_OF(CMS_SignerInfo) *sis;
CMS_ContentInfo *cms = NULL;
- int i, rc = -EINVAL;
+ int i, ret = -EINVAL;
if (!signature || !cert || !cert->impl || signature_len > INT_MAX)
return -EINVAL;
@@ -431,17 +431,17 @@ int cms_signed_by(const __u8 *signature, size_t signature_len,
sis = CMS_get0_SignerInfos(cms);
if (!sis)
goto done;
- rc = 0;
- for (i = 0; i < sk_CMS_SignerInfo_num(sis) && !rc; i++) {
+ ret = 0;
+ for (i = 0; i < sk_CMS_SignerInfo_num(sis) && !ret; i++) {
if (CMS_SignerInfo_cert_cmp(sk_CMS_SignerInfo_value(sis, i),
cert->impl) == 0)
- rc = 1;
+ ret = 1;
}
done:
- if (rc < 0)
+ if (ret < 0)
ERR_clear_error();
CMS_ContentInfo_free(cms);
- return rc;
+ return ret;
}
int hmac_sha256(const __u8 *key, size_t key_len,
@@ -450,7 +450,7 @@ int hmac_sha256(const __u8 *key, size_t key_len,
EVP_MAC_CTX *ctx = NULL;
OSSL_PARAM params[2];
size_t outl = 0;
- int rc = -EIO;
+ int ret = -EIO;
EVP_MAC *mac;
mac = EVP_MAC_fetch(NULL, "HMAC", NULL);
@@ -463,17 +463,17 @@ int hmac_sha256(const __u8 *key, size_t key_len,
if (ctx && EVP_MAC_init(ctx, key, key_len, params) == 1 &&
EVP_MAC_update(ctx, data, len) == 1 &&
EVP_MAC_final(ctx, out, &outl, 32) == 1 && outl == 32)
- rc = 0;
+ ret = 0;
EVP_MAC_CTX_free(ctx);
EVP_MAC_free(mac);
- return rc;
+ return ret;
}
int aes128_cfb_encrypt(const __u8 key[16], const __u8 *in,
size_t len, __u8 *out)
{
EVP_CIPHER_CTX *ctx = EVP_CIPHER_CTX_new();
- int n = 0, fin = 0, rc = -EIO;
+ int n = 0, fin = 0, ret = -EIO;
__u8 iv[16] = {};
if (!ctx || len > INT_MAX)
@@ -483,10 +483,10 @@ int aes128_cfb_encrypt(const __u8 key[16], const __u8 *in,
EVP_EncryptUpdate(ctx, out, &n, in, (int)len) == 1 &&
EVP_EncryptFinal_ex(ctx, out + n, &fin) == 1 &&
(size_t)n + (size_t)fin == len)
- rc = 0;
+ ret = 0;
out:
EVP_CIPHER_CTX_free(ctx);
- return rc;
+ return ret;
}
int rsa_oaep_encrypt(const __u8 *n, size_t n_len, __u32 e,
@@ -500,7 +500,7 @@ int rsa_oaep_encrypt(const __u8 *n, size_t n_len, __u32 e,
OSSL_PARAM *params = NULL;
__u8 *lbl = NULL;
EVP_PKEY *pkey = NULL;
- int rc = -EIO;
+ int ret = -EIO;
if (n_len > INT_MAX || label_len > INT_MAX)
return -EINVAL;
@@ -515,7 +515,7 @@ int rsa_oaep_encrypt(const __u8 *n, size_t n_len, __u32 e,
kctx = EVP_PKEY_CTX_new_from_name(NULL, "RSA", NULL);
if (!params || !kctx || EVP_PKEY_fromdata_init(kctx) <= 0 ||
EVP_PKEY_fromdata(kctx, &pkey, EVP_PKEY_PUBLIC_KEY, params) <= 0) {
- rc = -EINVAL;
+ ret = -EINVAL;
goto out;
}
lbl = OPENSSL_malloc(label_len ? label_len : 1);
@@ -533,7 +533,7 @@ int rsa_oaep_encrypt(const __u8 *n, size_t n_len, __u32 e,
*out_len = cap;
if (EVP_PKEY_encrypt(ectx, out, out_len, in, in_len) <= 0)
goto out;
- rc = 0;
+ ret = 0;
out:
OPENSSL_free(lbl);
EVP_PKEY_CTX_free(ectx);
@@ -543,7 +543,7 @@ out:
OSSL_PARAM_BLD_free(bld);
BN_free(bn);
BN_free(be);
- return rc;
+ return ret;
}
int ecdh_p256_ephemeral(const __u8 x[32], const __u8 y[32],
@@ -554,11 +554,11 @@ int ecdh_p256_ephemeral(const __u8 x[32], const __u8 y[32],
BIGNUM *bx = NULL, *by = NULL;
EVP_PKEY_CTX *dctx = NULL;
size_t zlen = 32;
- int rc = -EIO;
+ int ret = -EIO;
peer = p256_public_key(x, y);
if (!peer) {
- rc = -EINVAL;
+ ret = -EINVAL;
goto out;
}
eph = EVP_PKEY_Q_keygen(NULL, NULL, "EC", "P-256");
@@ -572,21 +572,21 @@ int ecdh_p256_ephemeral(const __u8 x[32], const __u8 y[32],
EVP_PKEY_derive_set_peer(dctx, peer) <= 0 ||
EVP_PKEY_derive(dctx, z, &zlen) <= 0 || zlen != 32)
goto out;
- rc = 0;
+ ret = 0;
out:
BN_free(bx);
BN_free(by);
EVP_PKEY_CTX_free(dctx);
EVP_PKEY_free(eph);
EVP_PKEY_free(peer);
- return rc;
+ return ret;
}
int base64_decode(const char *in, size_t in_len, __u8 *out,
size_t cap, size_t *out_len)
{
EVP_ENCODE_CTX *ctx = EVP_ENCODE_CTX_new();
- int n = 0, fin = 0, rc = -EINVAL;
+ int n = 0, fin = 0, ret = -EINVAL;
if (!ctx || in_len > INT_MAX || cap < 3 * ((in_len + 3) / 4))
goto out;
@@ -596,10 +596,10 @@ int base64_decode(const char *in, size_t in_len, __u8 *out,
EVP_DecodeFinal(ctx, out + n, &fin) < 0)
goto out;
*out_len = (size_t)n + (size_t)fin;
- rc = 0;
+ ret = 0;
out:
EVP_ENCODE_CTX_free(ctx);
- return rc;
+ return ret;
}
int cert_read_der(const __u8 *der, size_t len,
@@ -618,7 +618,7 @@ int cert_pubkey(const struct shirudo_cert *cert,
{
BIGNUM *a = NULL, *b = NULL;
char group[32] = "";
- int id, rc = -EINVAL;
+ int id, ret = -EINVAL;
EVP_PKEY *pk;
memset(out, 0, sizeof(*out));
@@ -634,7 +634,7 @@ int cert_pubkey(const struct shirudo_cert *cert,
out->rsa = true;
out->n_len = (size_t)BN_bn2bin(a, out->n);
out->e = (__u32)BN_get_word(b);
- rc = 0;
+ ret = 0;
} else if (id == EVP_PKEY_EC) {
if (!EVP_PKEY_get_utf8_string_param(pk, OSSL_PKEY_PARAM_GROUP_NAME,
group, sizeof(group), NULL) ||
@@ -644,14 +644,14 @@ int cert_pubkey(const struct shirudo_cert *cert,
BN_bn2binpad(a, out->x, 32) != 32 ||
BN_bn2binpad(b, out->y, 32) != 32)
goto out;
- rc = 0;
+ ret = 0;
} else {
- rc = -EPROTONOSUPPORT;
+ ret = -EPROTONOSUPPORT;
}
out:
BN_free(a);
BN_free(b);
- return rc;
+ return ret;
}
int cert_verify_chain(const struct shirudo_cert *cert,
@@ -659,7 +659,7 @@ int cert_verify_chain(const struct shirudo_cert *cert,
{
X509_STORE_CTX *ctx = NULL;
X509_STORE *store;
- int rc = -EIO;
+ int ret = -EIO;
*reason = "";
if (!cert || !cert->impl || !bundle_path)
@@ -668,7 +668,7 @@ int cert_verify_chain(const struct shirudo_cert *cert,
if (!store)
return -ENOMEM;
if (X509_STORE_load_file(store, bundle_path) != 1) {
- rc = -EINVAL;
+ ret = -EINVAL;
goto out;
}
/* An intermediate in the bundle is a trust anchor too. */
@@ -677,15 +677,15 @@ int cert_verify_chain(const struct shirudo_cert *cert,
if (!ctx || X509_STORE_CTX_init(ctx, store, cert->impl, NULL) != 1)
goto out;
if (X509_verify_cert(ctx) == 1) {
- rc = 0;
+ ret = 0;
} else {
*reason = X509_verify_cert_error_string(X509_STORE_CTX_get_error(ctx));
- rc = -EKEYREJECTED;
+ ret = -EKEYREJECTED;
}
out:
X509_STORE_CTX_free(ctx);
X509_STORE_free(store);
- return rc;
+ return ret;
}
void openssl_complain(const char *where)
diff --git a/util/dm_verity.c b/util/dm_verity.c
index c7ea9dc4..6602f3db 100644
--- a/util/dm_verity.c
+++ b/util/dm_verity.c
@@ -77,17 +77,17 @@ static int dm_command(int fd, __u64 command, union dm_buffer *buf)
static int dm_control_open(void)
{
struct stat st;
- int fd, rc;
+ int fd, ret;
fd = open("/dev/mapper/control", O_RDWR | O_CLOEXEC | O_NOFOLLOW);
if (fd < 0)
return -errno;
- rc = fstat(fd, &st) ? -errno : 0;
- if (!rc && (!S_ISCHR(st.st_mode) || st.st_rdev != makedev(10, 236)))
- rc = -ENODEV;
- if (rc) {
+ ret = fstat(fd, &st) ? -errno : 0;
+ if (!ret && (!S_ISCHR(st.st_mode) || st.st_rdev != makedev(10, 236)))
+ ret = -ENODEV;
+ if (ret) {
close(fd);
- return rc;
+ return ret;
}
return fd;
}
@@ -99,7 +99,7 @@ int shirudo_dm_verity_list(shirudo_dm_verity_cb callback, void *ctx)
struct dm_name_list *entry;
struct dm_ioctl *io;
size_t offset, avail;
- int control, rc;
+ int control, ret;
void *buffer;
if (!callback)
@@ -116,29 +116,29 @@ int shirudo_dm_verity_list(shirudo_dm_verity_cb callback, void *ctx)
io->version[0] = DM_VERSION_MAJOR;
io->data_size = capacity;
io->data_start = sizeof(*io);
- rc = ioctl(control, DM_LIST_DEVICES, io) ? -errno : 0;
- if (!rc && io->flags & DM_BUFFER_FULL_FLAG)
- rc = -EOVERFLOW;
- if (!rc && (io->data_size > capacity || io->data_start < sizeof(*io) ||
- io->data_start > io->data_size || io->data_start % 8))
- rc = -EINVAL;
+ ret = ioctl(control, DM_LIST_DEVICES, io) ? -errno : 0;
+ if (!ret && io->flags & DM_BUFFER_FULL_FLAG)
+ ret = -EOVERFLOW;
+ if (!ret && (io->data_size > capacity || io->data_start < sizeof(*io) ||
+ io->data_start > io->data_size || io->data_start % 8))
+ ret = -EINVAL;
offset = io->data_start;
- while (!rc && offset < io->data_size) {
+ while (!ret && offset < io->data_size) {
avail = io->data_size - offset;
if (avail < header + 1) {
- rc = -EINVAL;
+ ret = -EINVAL;
break;
}
entry = (void *)((__u8 *)buffer + offset);
if (!entry->dev) {
if (entry->next || entry->name[0])
- rc = -EINVAL;
+ ret = -EINVAL;
break;
}
if (entry->next) {
if (entry->next > avail || entry->next % 8 ||
entry->next < header + 1) {
- rc = -EINVAL;
+ ret = -EINVAL;
break;
}
avail = entry->next;
@@ -147,33 +147,33 @@ int shirudo_dm_verity_list(shirudo_dm_verity_cb callback, void *ctx)
if (avail > DM_NAME_LEN)
avail = DM_NAME_LEN;
if (!memchr(entry->name, 0, avail) || !entry->name[0]) {
- rc = -EINVAL;
+ ret = -EINVAL;
break;
}
- rc = callback(entry->name, (dev_t)entry->dev, ctx);
+ ret = callback(entry->name, (dev_t)entry->dev, ctx);
if (!entry->next)
break;
offset += entry->next;
}
xfree(buffer, capacity);
close(control);
- return rc;
+ return ret;
}
static int loop_attach(int file_fd, __u64 bytes, int *out)
{
struct loop_config config = {};
char path[64];
- int control, loop, n, rc;
+ int control, loop, n, ret;
control = open("/dev/loop-control", O_RDWR | O_CLOEXEC);
if (control < 0)
return -errno;
n = ioctl(control, LOOP_CTL_GET_FREE);
- rc = n < 0 ? -errno : 0;
+ ret = n < 0 ? -errno : 0;
close(control);
- if (rc)
- return rc;
+ if (ret)
+ return ret;
if (strsprintf(path, sizeof(path), "/dev/loop%d", n) < 0)
return -ENAMETOOLONG;
loop = open(path, O_RDONLY | O_CLOEXEC | O_NOFOLLOW);
@@ -184,9 +184,9 @@ static int loop_attach(int file_fd, __u64 bytes, int *out)
config.info.lo_sizelimit = bytes;
config.info.lo_flags = LO_FLAGS_READ_ONLY | LO_FLAGS_AUTOCLEAR;
if (ioctl(loop, LOOP_CONFIGURE, &config)) {
- rc = -errno;
+ ret = -errno;
close(loop);
- return rc;
+ return ret;
}
*out = loop;
return 0;
@@ -311,7 +311,7 @@ int shirudo_dm_verity_inspect(const char *name,
struct shirudo_dm_verity device = {.data_loop_fd = -1,
.hash_loop_fd = -1};
union dm_buffer buf;
- int control, rc;
+ int control, ret;
if (!out || !image || !dm_name_ok(name))
return -EINVAL;
@@ -321,18 +321,18 @@ int shirudo_dm_verity_inspect(const char *name,
return control;
dm_init(&buf, name);
buf.io.flags = DM_STATUS_TABLE_FLAG;
- rc = dm_command(control, DM_TABLE_STATUS, &buf);
- if (!rc)
- rc = check_table(&buf, image, &device);
- if (!rc)
- rc = device_path(&device, buf.io.dev);
+ ret = dm_command(control, DM_TABLE_STATUS, &buf);
+ if (!ret)
+ ret = check_table(&buf, image, &device);
+ if (!ret)
+ ret = device_path(&device, buf.io.dev);
close(control);
- if (!rc) {
+ if (!ret) {
strscpy(device.name, name, sizeof(device.name));
device.image = *image;
*out = device;
}
- return rc;
+ return ret;
}
void shirudo_dm_verity_close(struct shirudo_dm_verity *device)
@@ -350,7 +350,7 @@ void shirudo_dm_verity_close(struct shirudo_dm_verity *device)
int shirudo_dm_verity_remove(struct shirudo_dm_verity *device, bool deferred)
{
union dm_buffer buf;
- int control, rc;
+ int control, ret;
if (!device || !dm_name_ok(device->name))
return -EINVAL;
@@ -360,11 +360,11 @@ int shirudo_dm_verity_remove(struct shirudo_dm_verity *device, bool deferred)
dm_init(&buf, device->name);
if (deferred)
buf.io.flags = DM_DEFERRED_REMOVE;
- rc = dm_command(control, DM_DEV_REMOVE, &buf);
+ ret = dm_command(control, DM_DEV_REMOVE, &buf);
close(control);
- if (!rc)
+ if (!ret)
shirudo_dm_verity_close(device);
- return rc;
+ return ret;
}
/* request_key() can find this immutable signature in the caller's thread. */
@@ -414,10 +414,10 @@ static key_serial_t signature_key(int fd, char description[64])
return -errno;
/* Keep possessor search, but prevent payload and permission changes. */
if (syscall(__NR_keyctl, KEYCTL_SETPERM, key, 0x08000000, 0, 0) < 0) {
- int rc = -errno;
+ int ret = -errno;
(void)keyring_unlink_key(KEY_SPEC_THREAD_KEYRING, key);
- return rc;
+ return ret;
}
return key;
}
@@ -437,31 +437,31 @@ int shirudo_dm_verity_create(const struct shirudo_config_image_open *image,
union dm_buffer buf;
bool created = false;
key_serial_t key = -1;
- int control = -1, rc, cleanup, n;
+ int control = -1, ret, cleanup, n;
if (!image || !out || !dm_name_ok(name))
return -EINVAL;
*out = device;
- rc = shirudo_config_image_check_files(image->data_fd, image->hash_fd,
- &image->image);
- if (rc)
- return rc;
+ ret = shirudo_config_image_check_files(image->data_fd, image->hash_fd,
+ &image->image);
+ if (ret)
+ return ret;
device.image = image->image;
strscpy(device.name, name, sizeof(device.name));
- rc = loop_attach(image->data_fd,
- image->image.data_blocks *
+ ret = loop_attach(image->data_fd,
+ image->image.data_blocks *
CONFIG_IMAGE_BLOCK_SIZE,
- &device.data_loop_fd);
- if (!rc)
- rc = loop_attach(image->hash_fd,
- image->image.hash_blocks *
+ &device.data_loop_fd);
+ if (!ret)
+ ret = loop_attach(image->hash_fd,
+ image->image.hash_blocks *
CONFIG_IMAGE_BLOCK_SIZE,
- &device.hash_loop_fd);
- if (rc)
+ &device.hash_loop_fd);
+ if (ret)
goto out;
if (fstat(device.data_loop_fd, &data_st) ||
fstat(device.hash_loop_fd, &hash_st)) {
- rc = -errno;
+ ret = -errno;
goto out;
}
hex_encode(image->image.root_hash, 32, root);
@@ -472,7 +472,7 @@ int shirudo_dm_verity_create(const struct shirudo_config_image_open *image,
major(hash_st.st_rdev), minor(hash_st.st_rdev),
(__u64)image->image.data_blocks, root, salt);
if (n < 0) {
- rc = -EOVERFLOW;
+ ret = -EOVERFLOW;
goto out;
}
if (image->image.signed_root) {
@@ -481,25 +481,25 @@ int shirudo_dm_verity_create(const struct shirudo_config_image_open *image,
key = signature_key(image->signature_fd, signature);
if (key < 0) {
- rc = key;
+ ret = key;
goto out;
}
written = strsprintf(params + n, remaining,
" 2 root_hash_sig_key_desc %s", signature);
if (written < 0) {
- rc = -EOVERFLOW;
+ ret = -EOVERFLOW;
goto out;
}
n += written;
}
control = dm_control_open();
if (control < 0) {
- rc = control;
+ ret = control;
goto out;
}
dm_init(&buf, name);
- rc = dm_command(control, DM_DEV_CREATE, &buf);
- if (rc)
+ ret = dm_command(control, DM_DEV_CREATE, &buf);
+ if (ret)
goto out;
created = true;
dm_init(&buf, name);
@@ -513,32 +513,32 @@ int shirudo_dm_verity_create(const struct shirudo_config_image_open *image,
target->next = (sizeof(*target) + n + 1 + 7) & ~7u;
buf.io.data_size = buf.io.data_start + target->next;
if (image->image.signed_root) {
- rc = shirudo_config_root_begin(image->image.root_hash, &guard);
- if (rc)
+ ret = shirudo_config_root_begin(image->image.root_hash, &guard);
+ if (ret)
goto out;
}
- rc = dm_command(control, DM_TABLE_LOAD, &buf);
- if (rc)
+ ret = dm_command(control, DM_TABLE_LOAD, &buf);
+ if (ret)
goto out;
dm_init(&buf, name);
buf.io.flags = DM_READONLY_FLAG;
- rc = dm_command(control, DM_DEV_SUSPEND, &buf);
- if (rc)
+ ret = dm_command(control, DM_DEV_SUSPEND, &buf);
+ if (ret)
goto out;
dm_init(&buf, name);
buf.io.flags = DM_STATUS_TABLE_FLAG;
- rc = dm_command(control, DM_TABLE_STATUS, &buf);
- if (!rc)
- rc = check_table(&buf, &image->image, &device);
- if (!rc)
- rc = device_path(&device, buf.io.dev);
+ ret = dm_command(control, DM_TABLE_STATUS, &buf);
+ if (!ret)
+ ret = check_table(&buf, &image->image, &device);
+ if (!ret)
+ ret = device_path(&device, buf.io.dev);
out:
cleanup = shirudo_config_root_end(&guard);
- if (!rc)
- rc = cleanup;
+ if (!ret)
+ ret = cleanup;
if (key >= 0)
(void)keyring_unlink_key(KEY_SPEC_THREAD_KEYRING, key);
- if (rc) {
+ if (ret) {
if (created) {
dm_init(&buf, name);
(void)dm_command(control, DM_DEV_REMOVE, &buf);
@@ -549,14 +549,14 @@ out:
}
if (control >= 0)
close(control);
- return rc;
+ return ret;
}
static int loop_open(dev_t device)
{
struct stat st;
char path[64];
- int fd, rc;
+ int fd, ret;
if (major(device) != 7)
return -ENODEV;
@@ -565,12 +565,12 @@ static int loop_open(dev_t device)
fd = open(path, O_RDONLY | O_CLOEXEC | O_NOFOLLOW | O_NONBLOCK);
if (fd < 0)
return -errno;
- rc = fstat(fd, &st) ? -errno : 0;
- if (!rc && (!S_ISBLK(st.st_mode) || st.st_rdev != device))
- rc = -ESTALE;
- if (rc) {
+ ret = fstat(fd, &st) ? -errno : 0;
+ if (!ret && (!S_ISBLK(st.st_mode) || st.st_rdev != device))
+ ret = -ESTALE;
+ if (ret) {
close(fd);
- return rc;
+ return ret;
}
return fd;
}
@@ -600,21 +600,21 @@ int shirudo_dm_verity_verify(const struct shirudo_dm_verity *device,
int data = -1, hashes = -1, fd = -1;
struct shirudo_dm_verity checked;
__u64 bytes, size, offset = 0;
- int rc, readonly;
+ int ret, readonly;
struct stat st;
size_t count;
ssize_t n;
if (!device || !image)
return -EINVAL;
- rc = shirudo_config_image_check_files(image->data_fd, image->hash_fd,
- &image->image);
- if (rc)
- return rc;
+ ret = shirudo_config_image_check_files(image->data_fd, image->hash_fd,
+ &image->image);
+ if (ret)
+ return ret;
bytes = image->image.data_blocks * CONFIG_IMAGE_BLOCK_SIZE;
- rc = shirudo_dm_verity_inspect(device->name, &image->image, &checked);
- if (rc)
- return rc;
+ ret = shirudo_dm_verity_inspect(device->name, &image->image, &checked);
+ if (ret)
+ return ret;
if (checked.device != device->device ||
checked.data_device != device->data_device ||
checked.hash_device != device->hash_device)
@@ -624,30 +624,30 @@ int shirudo_dm_verity_verify(const struct shirudo_dm_verity *device,
return data;
hashes = loop_open(device->hash_device);
if (hashes < 0) {
- rc = hashes;
+ ret = hashes;
goto out;
}
- rc = loop_check(data, image->data_fd, bytes);
- if (!rc)
- rc = loop_check(hashes, image->hash_fd,
- image->image.hash_blocks *
+ ret = loop_check(data, image->data_fd, bytes);
+ if (!ret)
+ ret = loop_check(hashes, image->hash_fd,
+ image->image.hash_blocks *
CONFIG_IMAGE_BLOCK_SIZE);
- if (rc)
+ if (ret)
goto out;
fd = open(device->path,
O_RDONLY | O_CLOEXEC | O_NOFOLLOW | O_NONBLOCK | O_DIRECT);
if (fd < 0) {
- rc = -errno;
+ ret = -errno;
goto out;
}
if (fstat(fd, &st) || ioctl(fd, BLKGETSIZE64, &size) ||
ioctl(fd, BLKROGET, &readonly)) {
- rc = -errno;
+ ret = -errno;
goto out;
}
if (!S_ISBLK(st.st_mode) || st.st_rdev != device->device ||
size != bytes || !readonly) {
- rc = -ESTALE;
+ ret = -ESTALE;
goto out;
}
while (offset < bytes) {
@@ -658,25 +658,25 @@ int shirudo_dm_verity_verify(const struct shirudo_dm_verity *device,
if (n < 0) {
if (errno == EINTR)
continue;
- rc = -errno;
+ ret = -errno;
goto out;
}
if (!n) {
- rc = -EIO;
+ ret = -EIO;
goto out;
}
offset += n;
}
- rc = shirudo_dm_verity_inspect(device->name, &image->image, &checked);
- if (!rc && (checked.device != device->device ||
- checked.data_device != device->data_device ||
- checked.hash_device != device->hash_device))
- rc = -ESTALE;
- if (!rc)
- rc = loop_check(data, image->data_fd, bytes);
- if (!rc)
- rc = loop_check(hashes, image->hash_fd,
- image->image.hash_blocks *
+ ret = shirudo_dm_verity_inspect(device->name, &image->image, &checked);
+ if (!ret && (checked.device != device->device ||
+ checked.data_device != device->data_device ||
+ checked.hash_device != device->hash_device))
+ ret = -ESTALE;
+ if (!ret)
+ ret = loop_check(data, image->data_fd, bytes);
+ if (!ret)
+ ret = loop_check(hashes, image->hash_fd,
+ image->image.hash_blocks *
CONFIG_IMAGE_BLOCK_SIZE);
out:
if (fd >= 0)
@@ -684,7 +684,7 @@ out:
if (hashes >= 0)
close(hashes);
close(data);
- return rc;
+ return ret;
}
int shirudo_dm_verity_mount(const struct shirudo_dm_verity *device,
@@ -693,13 +693,13 @@ int shirudo_dm_verity_mount(const struct shirudo_dm_verity *device,
__u64 flags = MS_RDONLY | MS_NODEV | MS_NOSUID;
struct shirudo_dm_verity checked;
struct stat st;
- int rc;
+ int ret;
if (!device || !mountpoint || mountpoint[0] != '/')
return -EINVAL;
- rc = shirudo_dm_verity_inspect(device->name, &device->image, &checked);
- if (rc)
- return rc;
+ ret = shirudo_dm_verity_inspect(device->name, &device->image, &checked);
+ if (ret)
+ return ret;
if (checked.device != device->device)
return -ESTALE;
if (!executable)
@@ -707,13 +707,13 @@ int shirudo_dm_verity_mount(const struct shirudo_dm_verity *device,
if (mount(device->path, mountpoint, "ext4", flags, "noload"))
return -errno;
if (stat(mountpoint, &st))
- rc = -errno;
+ ret = -errno;
else if (st.st_dev != device->device)
- rc = -ESTALE;
+ ret = -ESTALE;
else
- rc = shirudo_dm_verity_inspect(device->name, &device->image,
- &checked);
- if (rc)
+ ret = shirudo_dm_verity_inspect(device->name, &device->image,
+ &checked);
+ if (ret)
(void)umount2(mountpoint, 0);
- return rc;
+ return ret;
}
diff --git a/util/eventlog.c b/util/eventlog.c
index bc1381fe..8345d297 100644
--- a/util/eventlog.c
+++ b/util/eventlog.c
@@ -56,11 +56,11 @@ static int adopt_pending(void);
*/
int eventlog_append(const char *json_line)
{
- int rc;
+ int ret;
- rc = adopt_pending();
- if (rc)
- return rc;
+ ret = adopt_pending();
+ if (ret)
+ return ret;
return eventlog_append_to(eventlog_path(), json_line);
}
@@ -73,7 +73,7 @@ int eventlog_append_to(const char *path, const char *json_line)
{
size_t len = strlen(json_line);
struct stat st;
- int fd, rc;
+ int fd, ret;
fd = seal_open(path, O_WRONLY | O_CREAT | O_APPEND, 0600);
if (fd < 0) {
@@ -82,29 +82,29 @@ int eventlog_append_to(const char *path, const char *json_line)
}
while (flock(fd, LOCK_EX) != 0) {
if (errno != EINTR) {
- rc = -errno;
+ ret = -errno;
goto out;
}
}
if (fstat(fd, &st) != 0) {
- rc = -errno;
+ ret = -errno;
goto out;
}
- rc = write_complete(fd, json_line, len);
- if (!rc && (len == 0 || json_line[len - 1] != '\n'))
- rc = write_complete(fd, "\n", 1);
- if (!rc && fsync(fd) != 0)
- rc = -errno;
- if (rc && ftruncate(fd, st.st_size) != 0)
+ ret = write_complete(fd, json_line, len);
+ if (!ret && (len == 0 || json_line[len - 1] != '\n'))
+ ret = write_complete(fd, "\n", 1);
+ if (!ret && fsync(fd) != 0)
+ ret = -errno;
+ if (ret && ftruncate(fd, st.st_size) != 0)
pr_warn("eventlog: could not roll back a partial append to "
"%s: %s", path, strerror(errno));
out:
- if (close(fd) != 0 && !rc)
- rc = -errno;
- if (rc) {
- pr_err("eventlog: append: %s", strerror(-rc));
- return rc;
+ if (close(fd) != 0 && !ret)
+ ret = -errno;
+ if (ret) {
+ pr_err("eventlog: append: %s", strerror(-ret));
+ return ret;
}
return 0;
}
@@ -125,12 +125,12 @@ static int read_log(char **out, size_t *out_len)
{
size_t base_len = 0, pending_len = 0, off;
char *base = NULL, *pending = NULL, *buf;
- int rc, rc_pending;
+ int ret, rc_pending;
- rc = read_file(eventlog_path(), JSON_MAX_BYTES,
- &base, &base_len);
- if (rc && rc != -ENOENT)
- return rc;
+ ret = read_file(eventlog_path(), JSON_MAX_BYTES,
+ &base, &base_len);
+ if (ret && ret != -ENOENT)
+ return ret;
rc_pending = read_file(eventlog_pending_path(),
JSON_MAX_BYTES, &pending,
&pending_len);
@@ -138,25 +138,25 @@ static int read_log(char **out, size_t *out_len)
xfree(base, base_len + 1);
return rc_pending;
}
- if (rc && rc_pending)
+ if (ret && rc_pending)
return -ENOENT;
if (rc_pending) {
*out = base;
*out_len = base_len;
return 0;
}
- if (rc) {
+ if (ret) {
*out = pending;
*out_len = pending_len;
return 0;
}
if (base_len + pending_len > JSON_MAX_BYTES) {
- rc = -EFBIG;
+ ret = -EFBIG;
goto out;
}
buf = xmalloc(base_len + pending_len + 2);
if (!buf) {
- rc = -ENOMEM;
+ ret = -ENOMEM;
goto out;
}
memcpy(buf, base, base_len);
@@ -171,7 +171,7 @@ static int read_log(char **out, size_t *out_len)
out:
xfree(base, base_len + 1);
xfree(pending, pending_len + 1);
- return rc;
+ return ret;
}
/*
@@ -184,10 +184,10 @@ static int walk_lines(char *buf, int (*cb)(const char *line, size_t len,
char boot_id[64], line_boot[64], type[32];
bool in_boot = false;
char *line, *save;
- int rc = 0;
+ int ret = 0;
eventlog_boot_id(boot_id, sizeof(boot_id));
- for (line = strtok_r(buf, "\n", &save); line && !rc;
+ for (line = strtok_r(buf, "\n", &save); line && !ret;
line = strtok_r(NULL, "\n", &save)) {
struct shirudo_json_field f[] = {
{ "boot_id", SHIRUDO_JSON_T_STRING, line_boot,
@@ -200,7 +200,7 @@ static int walk_lines(char *buf, int (*cb)(const char *line, size_t len,
line_boot[0] = '\0';
type[0] = '\0';
if (json_parse(line, strlen(line), f, 2)) {
- rc = -EINVAL;
+ ret = -EINVAL;
break;
}
if (!f[0].seen || !boot_id[0] || strcmp(line_boot, boot_id))
@@ -210,11 +210,11 @@ static int walk_lines(char *buf, int (*cb)(const char *line, size_t len,
in_boot = true;
if (!in_boot)
continue;
- rc = cb(line, strlen(line), is_init, ctx);
+ ret = cb(line, strlen(line), is_init, ctx);
}
- if (!rc && !in_boot)
+ if (!ret && !in_boot)
return -ENOENT;
- return rc;
+ return ret;
}
static int walk_boot(int (*cb)(const char *line, size_t len, bool is_init,
@@ -222,14 +222,14 @@ static int walk_boot(int (*cb)(const char *line, size_t len, bool is_init,
{
char *buf = NULL;
size_t len = 0;
- int rc;
+ int ret;
- rc = read_log(&buf, &len);
- if (rc)
- return rc;
- rc = walk_lines(buf, cb, ctx);
+ ret = read_log(&buf, &len);
+ if (ret)
+ return ret;
+ ret = walk_lines(buf, cb, ctx);
xfree(buf, len + 1);
- return rc;
+ return ret;
}
struct adopt_ctx {
@@ -253,18 +253,18 @@ static int log_holds(const char *line, size_t len)
struct adopt_ctx a = { .line = line, .len = len };
char *buf = NULL;
size_t blen = 0;
- int rc;
+ int ret;
- rc = read_file(eventlog_path(), JSON_MAX_BYTES,
- &buf, &blen);
- if (rc == -ENOENT)
+ ret = read_file(eventlog_path(), JSON_MAX_BYTES,
+ &buf, &blen);
+ if (ret == -ENOENT)
return 0;
- if (rc)
- return rc;
- rc = walk_lines(buf, adopt_seen, &a);
+ if (ret)
+ return ret;
+ ret = walk_lines(buf, adopt_seen, &a);
xfree(buf, blen + 1);
- if (rc && rc != -ENOENT)
- return rc;
+ if (ret && ret != -ENOENT)
+ return ret;
return a.found ? 1 : 0;
}
@@ -273,29 +273,29 @@ static int adopt_pending(void)
const char *pending = eventlog_pending_path();
char *buf = NULL, *line, *save;
size_t len = 0;
- int rc;
+ int ret;
- rc = read_file(pending, JSON_MAX_BYTES, &buf, &len);
- if (rc == -ENOENT)
+ ret = read_file(pending, JSON_MAX_BYTES, &buf, &len);
+ if (ret == -ENOENT)
return 0;
- if (rc)
- return rc;
- for (line = strtok_r(buf, "\n", &save); line && !rc;
+ if (ret)
+ return ret;
+ for (line = strtok_r(buf, "\n", &save); line && !ret;
line = strtok_r(NULL, "\n", &save)) {
if (!*line)
continue;
- rc = log_holds(line, strlen(line));
- if (rc > 0) {
- rc = 0;
+ ret = log_holds(line, strlen(line));
+ if (ret > 0) {
+ ret = 0;
continue;
}
- if (!rc)
- rc = eventlog_append_to(eventlog_path(),
- line);
+ if (!ret)
+ ret = eventlog_append_to(eventlog_path(),
+ line);
}
xfree(buf, len + 1);
- if (rc)
- return rc;
+ if (ret)
+ return ret;
if (unlink(pending) != 0 && errno != ENOENT)
return -errno;
return 0;
@@ -311,7 +311,7 @@ static int adopt_pending(void)
int eventlog_lock(void)
{
char path[PATH_MAX];
- int fd, rc;
+ int fd, ret;
if (strsprintf(path, sizeof(path), "%s.lock", eventlog_path()) < 0)
return -ENAMETOOLONG;
@@ -320,9 +320,9 @@ int eventlog_lock(void)
return fd;
while (flock(fd, LOCK_EX)) {
if (errno != EINTR) {
- rc = -errno;
+ ret = -errno;
close(fd);
- return rc;
+ return ret;
}
}
return fd;
@@ -342,16 +342,16 @@ void eventlog_unlock(int fd)
*/
int eventlog_adopt_pending(void)
{
- int lock, rc;
+ int lock, ret;
if (access(eventlog_pending_path(), F_OK) && errno == ENOENT)
return 0;
lock = eventlog_lock();
if (lock < 0)
return lock;
- rc = adopt_pending();
+ ret = adopt_pending();
eventlog_unlock(lock);
- return rc;
+ return ret;
}
static int replay_line(const char *line, size_t len, bool is_init, void *ctx)
@@ -378,12 +378,12 @@ static int replay_line(const char *line, size_t len, bool is_init, void *ctx)
int eventlog_replay(__u8 out[32])
{
__u8 chain[32] = {};
- int rc;
+ int ret;
- rc = walk_boot(replay_line, chain);
- if (!rc)
+ ret = walk_boot(replay_line, chain);
+ if (!ret)
memcpy(out, chain, 32);
- return rc;
+ return ret;
}
static int init_line(const char *line, size_t len, bool is_init, void *ctx)
diff --git a/util/identity.c b/util/identity.c
index f1e6ecff..fe9eb4cb 100644
--- a/util/identity.c
+++ b/util/identity.c
@@ -22,9 +22,9 @@
int shirudo_enforcement_active(void)
{
- int rc = prctl(PR_GET_ENFORCEMENT, 0, 0, 0, 0);
+ int ret = prctl(PR_GET_ENFORCEMENT, 0, 0, 0, 0);
- if (rc >= 0)
+ if (ret >= 0)
return -EPROTO;
if (errno == PR_ENFORCING_ERR)
return 1;
@@ -36,22 +36,22 @@ int identity_read(struct shirudo_identity *out)
struct bpf_map_info info = {};
__u32 len = sizeof(info);
__u32 zero = 0;
- int fd, rc;
+ int fd, ret;
memset(out, 0, sizeof(*out));
fd = bpf_obj_get(IDENTITY_PIN);
if (fd < 0)
return -errno;
- rc = bpf_map_get_info_by_fd(fd, &info, &len);
- if (rc) {
- rc = -errno;
+ ret = bpf_map_get_info_by_fd(fd, &info, &len);
+ if (ret) {
+ ret = -errno;
} else if (info.value_size != sizeof(*out)) {
- rc = -EPROTO;
+ ret = -EPROTO;
} else {
- rc = bpf_map_lookup_elem(fd, &zero, out);
- if (rc)
- rc = -errno;
+ ret = bpf_map_lookup_elem(fd, &zero, out);
+ if (ret)
+ ret = -errno;
}
close(fd);
- return rc;
+ return ret;
}
diff --git a/util/image_bootstrap.c b/util/image_bootstrap.c
index 32b211be..fa6424a0 100644
--- a/util/image_bootstrap.c
+++ b/util/image_bootstrap.c
@@ -45,14 +45,14 @@ static int bootstrap_parse(FILE *file, struct shirudo_image_bootstrap *boot,
{
size_t capacity = 0;
char *line = NULL;
- int got, rc = 0;
+ int got, ret = 0;
while ((got = read_text_line(file, &line, &capacity,
PATH_MAX + 127)) != 0) {
char *key, *value;
if (got < 0) {
- rc = got;
+ ret = got;
break;
}
key = trim(line);
@@ -60,7 +60,7 @@ static int bootstrap_parse(FILE *file, struct shirudo_image_bootstrap *boot,
continue;
value = strchr(key, '=');
if (!value) {
- rc = -EINVAL;
+ ret = -EINVAL;
break;
}
*value++ = 0;
@@ -69,53 +69,53 @@ static int bootstrap_parse(FILE *file, struct shirudo_image_bootstrap *boot,
if (!strcmp(key, "runtime.root_hash")) {
if (!initial || boot->have_root ||
hex_decode(value, boot->runtime_root, 32)) {
- rc = -EINVAL;
+ ret = -EINVAL;
break;
}
boot->have_root = true;
} else if (!strcmp(key, "runtime.image") && initial) {
if (!shirudo_image_path_valid(value) ||
boot->runtime[0])
- rc = -EINVAL;
+ ret = -EINVAL;
else if (strscpy(boot->runtime, value,
sizeof(boot->runtime)) < 0)
- rc = -ENAMETOOLONG;
+ ret = -ENAMETOOLONG;
} else if (!strcmp(key, "config.image")) {
if (!shirudo_image_path_valid(value))
- rc = -EINVAL;
+ ret = -EINVAL;
else if (strscpy(boot->config, value,
sizeof(boot->config)) < 0)
- rc = -ENAMETOOLONG;
+ ret = -ENAMETOOLONG;
} else if (!strcmp(key, "config.verification_key")) {
if (strncmp(value, RUNTIME_DIR "/",
sizeof(RUNTIME_DIR)) ||
!shirudo_image_path_valid(value))
- rc = -EPERM;
+ ret = -EPERM;
else if (strscpy(boot->certificate, value,
sizeof(boot->certificate)) < 0)
- rc = -ENAMETOOLONG;
+ ret = -ENAMETOOLONG;
} else if (!strcmp(key, "config.pcr")) {
__u64 pcr;
if (parse_u64(value, strlen(value), 23, &pcr) ||
shirudo_config_measure_pcr_valid(pcr)) {
- rc = -EINVAL;
+ ret = -EINVAL;
} else {
boot->pcr = pcr;
boot->have_pcr = true;
}
} else if (!strncmp(key, "config.", 7) ||
!strncmp(key, "runtime.", 8)) {
- rc = -EINVAL;
+ ret = -EINVAL;
}
- if (rc)
+ if (ret)
break;
}
- if (ferror(file) && !rc)
- rc = -EIO;
+ if (ferror(file) && !ret)
+ ret = -EIO;
libc_free(line);
fclose(file);
- return rc;
+ return ret;
}
int shirudo_image_bootstrap_read(const char *path,
@@ -134,22 +134,22 @@ int shirudo_image_bootstrap_read_fd(int fd,
struct shirudo_image_bootstrap *boot,
bool initial)
{
- int copy, rc;
+ int copy, ret;
FILE *file;
copy = fcntl(fd, F_DUPFD_CLOEXEC, 3);
if (copy < 0)
return -errno;
if (lseek(copy, 0, SEEK_SET) < 0) {
- rc = -errno;
+ ret = -errno;
close(copy);
- return rc;
+ return ret;
}
file = fdopen(copy, "r");
if (!file) {
- rc = -errno;
+ ret = -errno;
close(copy);
- return rc;
+ return ret;
}
return bootstrap_parse(file, boot, initial);
}
diff --git a/util/image_cache.c b/util/image_cache.c
index 7472419a..be8a59e9 100644
--- a/util/image_cache.c
+++ b/util/image_cache.c
@@ -36,7 +36,7 @@ static size_t download_write(char *data, size_t size, size_t count, void *ctx)
{
struct image_download *download = ctx;
size_t bytes;
- int rc;
+ int ret;
if (size && count > SIZE_MAX / size) {
download->err = -EFBIG;
@@ -47,9 +47,9 @@ static size_t download_write(char *data, size_t size, size_t count, void *ctx)
download->err = -EFBIG;
return 0;
}
- rc = write_complete(download->fd, data, bytes);
- if (rc) {
- download->err = rc;
+ ret = write_complete(download->fd, data, bytes);
+ if (ret) {
+ download->err = ret;
return 0;
}
download->written += bytes;
@@ -60,13 +60,13 @@ static int download_https(const char *source, struct image_download *download)
{
CURLcode result;
CURL *curl;
- int rc;
+ int ret;
curl = curl_easy_init();
if (!curl)
return -ENOMEM;
- rc = tls_curl_policy(curl, NULL);
- if (rc)
+ ret = tls_curl_policy(curl, NULL);
+ if (ret)
goto out;
curl_easy_setopt(curl, CURLOPT_URL, source);
curl_easy_setopt(curl, CURLOPT_PROTOCOLS_STR, "https");
@@ -81,10 +81,10 @@ static int download_https(const char *source, struct image_download *download)
curl_easy_setopt(curl, CURLOPT_WRITEDATA, download);
result = curl_easy_perform(curl);
if (result != CURLE_OK)
- rc = download->err ? download->err : -EIO;
+ ret = download->err ? download->err : -EIO;
out:
curl_easy_cleanup(curl);
- return rc;
+ return ret;
}
static int copy_local(const char *source, struct image_download *download)
@@ -92,57 +92,57 @@ static int copy_local(const char *source, struct image_download *download)
char buffer[65536];
struct stat st;
ssize_t n;
- int fd, rc = 0;
+ int fd, ret = 0;
fd = open(source, O_RDONLY | O_CLOEXEC | O_NOFOLLOW | O_NONBLOCK);
if (fd < 0)
return -errno;
if (fstat(fd, &st)) {
- rc = -errno;
+ ret = -errno;
goto out;
}
if (!S_ISREG(st.st_mode) || st.st_size < 0 ||
(__u64)st.st_size > download->limit) {
- rc = -EINVAL;
+ ret = -EINVAL;
goto out;
}
while ((n = read(fd, buffer, sizeof(buffer))) != 0) {
if (n < 0) {
if (errno == EINTR)
continue;
- rc = -errno;
+ ret = -errno;
break;
}
if (download_write(buffer, 1, n, download) != (size_t)n) {
- rc = download->err;
+ ret = download->err;
break;
}
}
out:
close(fd);
- return rc;
+ return ret;
}
static int fetch_file(const char *source, const char *destination, __u64 max)
{
struct image_download download = { .limit = max };
- int fd, rc;
+ int fd, ret;
fd = open(destination,
O_WRONLY | O_CREAT | O_EXCL | O_CLOEXEC | O_NOFOLLOW, 0600);
if (fd < 0)
return -errno;
download.fd = fd;
- rc = fsetxattr(fd, XATTR_NAME, SEAL_LABEL,
- strlen(SEAL_LABEL), 0) ? -errno : 0;
- if (!rc)
- rc = !strncmp(source, "https://", 8) ?
+ ret = fsetxattr(fd, XATTR_NAME, SEAL_LABEL,
+ strlen(SEAL_LABEL), 0) ? -errno : 0;
+ if (!ret)
+ ret = !strncmp(source, "https://", 8) ?
download_https(source, &download) :
copy_local(source, &download);
- if (!rc && fsync(fd))
- rc = -errno;
+ if (!ret && fsync(fd))
+ ret = -errno;
close(fd);
- return rc;
+ return ret;
}
/* Verify downloads before publishing their root-hash-named cache files. */
@@ -153,21 +153,21 @@ static int verify_incoming(const struct shirudo_config_image_open *opened,
.data_loop_fd = -1,
.hash_loop_fd = -1,
};
- int rc, cleanup;
+ int ret, cleanup;
char name[128];
if (strsprintf(name, sizeof(name), "shirudo-verify-%s", strrchr(staging, '/') + 1) < 0)
return -ENAMETOOLONG;
- rc = shirudo_dm_verity_create(opened, name, &device);
- if (rc)
- return rc;
- rc = shirudo_dm_verity_verify(&device, opened);
+ ret = shirudo_dm_verity_create(opened, name, &device);
+ if (ret)
+ return ret;
+ ret = shirudo_dm_verity_verify(&device, opened);
cleanup = shirudo_dm_verity_remove(&device, true);
if (cleanup)
pr_warn("image: cannot remove incoming mapping: %s",
strerror(-cleanup));
shirudo_dm_verity_close(&device);
- return rc ? rc : cleanup;
+ return ret ? ret : cleanup;
}
int shirudo_image_cache_fetch(const char *source,
@@ -186,63 +186,63 @@ int shirudo_image_cache_fetch(const char *source,
char staging[] = IMAGE_CACHE_DIR "/incoming-XXXXXX";
char incoming[PATH_MAX], from[PATH_MAX], to[PATH_MAX];
char hex[65];
- int dir = -1, rc;
+ int dir = -1, ret;
size_t i;
if (!mkdtemp(staging))
return -errno;
- rc = seal_label(staging);
- if (rc)
+ ret = seal_label(staging);
+ if (ret)
goto out;
if (strsprintf(incoming, sizeof(incoming), "%s/image", staging) < 0) {
- rc = -ENAMETOOLONG;
+ ret = -ENAMETOOLONG;
goto out;
}
for (i = 0; i < ARRAY_SIZE(files); i++) {
if (strsprintf(from, sizeof(from), "%s%s", source, files[i].suffix) < 0 ||
strsprintf(to, sizeof(to), "%s%s", incoming, files[i].suffix) < 0) {
- rc = -ENAMETOOLONG;
+ ret = -ENAMETOOLONG;
goto out;
}
- rc = fetch_file(from, to, files[i].max_bytes);
- if (rc)
+ ret = fetch_file(from, to, files[i].max_bytes);
+ if (ret)
goto out;
}
- rc = shirudo_config_image_open(incoming, &opened);
- if (rc)
+ ret = shirudo_config_image_open(incoming, &opened);
+ if (ret)
goto out;
- rc = verify_incoming(&opened, staging);
- if (!rc) {
+ ret = verify_incoming(&opened, staging);
+ if (!ret) {
memcpy(target->root_hash, opened.image.root_hash, 32);
hex_encode(target->root_hash, 32, hex);
if (strsprintf(target->prefix, sizeof(target->prefix), "%s/%s",
IMAGE_CACHE_DIR, hex) < 0)
- rc = -ENAMETOOLONG;
+ ret = -ENAMETOOLONG;
}
shirudo_config_image_close(&opened);
- if (rc)
+ if (ret)
goto out;
for (i = 0; i < ARRAY_SIZE(files); i++) {
if (strsprintf(from, sizeof(from), "%s%s", incoming, files[i].suffix) < 0 ||
strsprintf(to, sizeof(to), "%s%s", target->prefix, files[i].suffix) < 0) {
- rc = -ENAMETOOLONG;
+ ret = -ENAMETOOLONG;
goto out;
}
if (link(from, to) && errno != EEXIST) {
- rc = -errno;
+ ret = -errno;
goto out;
}
}
dir = open(IMAGE_CACHE_DIR,
O_RDONLY | O_DIRECTORY | O_CLOEXEC | O_NOFOLLOW);
if (dir < 0 || fsync(dir)) {
- rc = -errno;
+ ret = -errno;
goto out;
}
- rc = shirudo_config_image_open(target->prefix, &opened);
- if (!rc) {
+ ret = shirudo_config_image_open(target->prefix, &opened);
+ if (!ret) {
if (memcmp(opened.image.root_hash, target->root_hash, 32))
- rc = -EKEYREJECTED;
+ ret = -EKEYREJECTED;
shirudo_config_image_close(&opened);
}
out:
@@ -253,5 +253,5 @@ out:
unlink(to);
}
rmdir(staging);
- return rc;
+ return ret;
}
diff --git a/util/image_config.c b/util/image_config.c
index 41461cd1..a6638861 100644
--- a/util/image_config.c
+++ b/util/image_config.c
@@ -73,14 +73,14 @@ int shirudo_image_open_relative(const char *path, int flags)
/* The image's shirudo.conf, read through its root. */
static int config_load_root(struct shirudo_config *cfg, int root_fd)
{
- int fd, rc;
+ int fd, ret;
fd = open_beneath(root_fd, "etc/shirudo/shirudo.conf", O_RDONLY);
if (fd < 0)
return fd;
- rc = config_load_fd(cfg, fd, "config image shirudo.conf");
+ ret = config_load_fd(cfg, fd, "config image shirudo.conf");
close(fd);
- return rc;
+ return ret;
}
static int validate_tree(int root_fd, dev_t device, __u32 depth,
@@ -89,7 +89,7 @@ static int validate_tree(int root_fd, dev_t device, __u32 depth,
struct dirent *entry;
struct stat st;
DIR *dir;
- int fd, rc = 0;
+ int fd, ret = 0;
if (depth > 32)
return -ELOOP;
@@ -98,25 +98,25 @@ static int validate_tree(int root_fd, dev_t device, __u32 depth,
return -errno;
dir = fdopendir(fd);
if (!dir) {
- rc = -errno;
+ ret = -errno;
close(fd);
- return rc;
+ return ret;
}
errno = 0;
while ((entry = readdir(dir)) != NULL) {
if (!strcmp(entry->d_name, ".") || !strcmp(entry->d_name, ".."))
continue;
if (++*entries > 65536) {
- rc = -E2BIG;
+ ret = -E2BIG;
break;
}
if (fstatat(fd, entry->d_name, &st, AT_SYMLINK_NOFOLLOW)) {
- rc = -errno;
+ ret = -errno;
break;
}
if (st.st_dev != device ||
(!S_ISREG(st.st_mode) && !S_ISDIR(st.st_mode))) {
- rc = -EPERM;
+ ret = -EPERM;
break;
}
if (S_ISDIR(st.st_mode)) {
@@ -125,20 +125,20 @@ static int validate_tree(int root_fd, dev_t device, __u32 depth,
O_NOFOLLOW);
if (child < 0) {
- rc = -errno;
+ ret = -errno;
break;
}
- rc = validate_tree(child, device, depth + 1, entries);
+ ret = validate_tree(child, device, depth + 1, entries);
close(child);
- if (rc)
+ if (ret)
break;
}
errno = 0;
}
- if (!entry && errno && !rc)
- rc = -errno;
+ if (!entry && errno && !ret)
+ ret = -errno;
closedir(dir);
- return rc;
+ return ret;
}
static int validate_settings(int root_fd)
@@ -147,7 +147,7 @@ static int validate_settings(int root_fd)
size_t capacity = 0;
FILE *file;
ssize_t length;
- int fd, rc = 0;
+ int fd, ret = 0;
fd = openat(root_fd, "etc/shirudo/shirudo.conf",
O_RDONLY | O_CLOEXEC | O_NOFOLLOW);
@@ -155,15 +155,15 @@ static int validate_settings(int root_fd)
return -errno;
file = fdopen(fd, "r");
if (!file) {
- rc = -errno;
+ ret = -errno;
close(fd);
- return rc;
+ return ret;
}
while ((length = getline(&line, &capacity, file)) >= 0) {
char *p = line, *end, *value;
if (length > 1023 || strlen(line) != (size_t)length) {
- rc = -E2BIG;
+ ret = -E2BIG;
break;
}
while (*p == ' ' || *p == '\t')
@@ -172,7 +172,7 @@ static int validate_settings(int root_fd)
continue;
value = strchr(p, '=');
if (!value) {
- rc = -EINVAL;
+ ret = -EINVAL;
break;
}
*value++ = 0;
@@ -191,19 +191,19 @@ static int validate_settings(int root_fd)
end[-1] == '\n'))
end--;
if (parse_u64(value, end - value, ~0ULL, &bytes)) {
- rc = -EINVAL;
+ ret = -EINVAL;
break;
}
} else if (strncmp(p, "map_export.", 11)) {
- rc = -EPERM;
+ ret = -EPERM;
break;
}
}
- if (ferror(file) && !rc)
- rc = -EIO;
+ if (ferror(file) && !ret)
+ ret = -EIO;
libc_free(line);
fclose(file);
- return rc;
+ return ret;
}
int shirudo_image_config_validate(int root_fd)
@@ -211,44 +211,44 @@ int shirudo_image_config_validate(int root_fd)
struct shirudo_config candidate;
__u32 entries = 0;
struct stat st;
- int rc;
+ int ret;
if (fstat(root_fd, &st))
return -errno;
if (!S_ISDIR(st.st_mode))
return -ENOTDIR;
- rc = validate_tree(root_fd, st.st_dev, 0, &entries);
- if (!rc)
- rc = validate_settings(root_fd);
- if (!rc) {
- rc = config_load_root(&candidate, root_fd);
- if (!rc && (!candidate.map_export_valid ||
- !candidate.tls_classical_hosts_valid))
- rc = -EINVAL;
+ ret = validate_tree(root_fd, st.st_dev, 0, &entries);
+ if (!ret)
+ ret = validate_settings(root_fd);
+ if (!ret) {
+ ret = config_load_root(&candidate, root_fd);
+ if (!ret && (!candidate.map_export_valid ||
+ !candidate.tls_classical_hosts_valid))
+ ret = -EINVAL;
explicit_bzero(&candidate, sizeof(candidate));
}
- return rc;
+ return ret;
}
int shirudo_image_config_set(const struct shirudo_config *bootstrap,
int root_fd)
{
struct shirudo_config candidate;
- int fd = -1, rc;
+ int fd = -1, ret;
candidate = *bootstrap;
if (root_fd >= 0) {
- rc = shirudo_image_config_validate(root_fd);
- if (rc)
- return rc;
+ ret = shirudo_image_config_validate(root_fd);
+ if (ret)
+ return ret;
fd = fcntl(root_fd, F_DUPFD_CLOEXEC, 3);
if (fd < 0)
return -errno;
- rc = config_load_root(&candidate, fd);
- if (rc || !candidate.map_export_valid ||
+ ret = config_load_root(&candidate, fd);
+ if (ret || !candidate.map_export_valid ||
!candidate.tls_classical_hosts_valid) {
close(fd);
- return rc ? rc : -EINVAL;
+ return ret ? ret : -EINVAL;
}
memcpy(candidate.tpm_owner_auth, bootstrap->tpm_owner_auth,
sizeof(candidate.tpm_owner_auth));
diff --git a/util/image_guards.c b/util/image_guards.c
index 1c56fead..043850f8 100644
--- a/util/image_guards.c
+++ b/util/image_guards.c
@@ -167,7 +167,7 @@ int shirudo_config_root_begin(const __u8 root[32],
struct shirudo_expected_root previous = {}, expected = { .valid = 1 };
const struct shirudo_guard_map *map =
&shirudo_guard_maps[SHIRUDO_GUARD_ROOTS];
- int mode, rc;
+ int mode, ret;
*guard = (struct shirudo_config_root_guard) {
.map_fd = -1,
@@ -183,22 +183,22 @@ int shirudo_config_root_begin(const __u8 root[32],
return -errno;
guard->task_fd = syscall(SYS_pidfd_open, getpid(), 0);
if (guard->task_fd < 0) {
- rc = -errno;
+ ret = -errno;
goto fail;
}
if (bpf_map_lookup_elem(guard->map_fd, &guard->task_fd, &previous)) {
if (errno != ENOENT) {
- rc = -errno;
+ ret = -errno;
goto fail;
}
} else if (previous.valid) {
- rc = -EBUSY;
+ ret = -EBUSY;
goto fail;
}
memcpy(expected.root, root, sizeof(expected.root));
if (bpf_map_update_elem(guard->map_fd, &guard->task_fd, &expected,
BPF_ANY)) {
- rc = -errno;
+ ret = -errno;
goto fail;
}
return 0;
@@ -208,25 +208,25 @@ fail:
close(guard->map_fd);
guard->map_fd = -1;
guard->task_fd = -1;
- return rc;
+ return ret;
}
/* Clear through retained FDs on every exit; report failure to clear. */
int shirudo_config_root_end(struct shirudo_config_root_guard *guard)
{
struct shirudo_expected_root empty = {};
- int rc = 0;
+ int ret = 0;
if (guard->map_fd < 0)
return 0;
if (bpf_map_update_elem(guard->map_fd, &guard->task_fd, &empty,
BPF_ANY))
- rc = -errno;
+ ret = -errno;
close(guard->task_fd);
close(guard->map_fd);
guard->map_fd = -1;
guard->task_fd = -1;
- return rc;
+ return ret;
}
static int guard_map_ids(__u32 ids[SHIRUDO_GUARD_MAP_COUNT])
@@ -234,7 +234,7 @@ static int guard_map_ids(__u32 ids[SHIRUDO_GUARD_MAP_COUNT])
struct bpf_map_info info;
__u32 length;
__u32 i;
- int fd, rc;
+ int fd, ret;
for (i = 0; i < SHIRUDO_GUARD_MAP_COUNT; i++) {
const struct shirudo_guard_map *expected =
@@ -245,9 +245,9 @@ static int guard_map_ids(__u32 ids[SHIRUDO_GUARD_MAP_COUNT])
return -errno;
memset(&info, 0, sizeof(info));
length = sizeof(info);
- rc = bpf_map_get_info_by_fd(fd, &info, &length);
- if (rc)
- rc = -errno;
+ ret = bpf_map_get_info_by_fd(fd, &info, &length);
+ if (ret)
+ ret = -errno;
else if (!info.id || info.type != expected->type ||
info.key_size != expected->key_size ||
info.value_size != expected->value_size ||
@@ -256,12 +256,12 @@ static int guard_map_ids(__u32 ids[SHIRUDO_GUARD_MAP_COUNT])
info.name[sizeof(info.name) - 1] ||
strncmp(info.name, expected->name,
sizeof(info.name) - 1))
- rc = -EPROTO;
+ ret = -EPROTO;
close(fd);
- if (rc) {
+ if (ret) {
pr_err("image: invalid guard map %s: %s", expected->pin,
- strerror(-rc));
- return rc;
+ strerror(-ret));
+ return ret;
}
ids[i] = info.id;
}
@@ -275,7 +275,7 @@ static int guard_program_maps(const struct bpf_prog_info *program,
struct bpf_map_info info;
__u32 i, j;
__u32 length;
- int fd, rc;
+ int fd, ret;
for (i = 0; i < program->nr_map_ids; i++) {
fd = bpf_map_get_fd_by_id(map_ids[i]);
@@ -283,12 +283,12 @@ static int guard_program_maps(const struct bpf_prog_info *program,
return -errno;
memset(&info, 0, sizeof(info));
length = sizeof(info);
- rc = bpf_map_get_info_by_fd(fd, &info, &length);
- if (rc)
- rc = -errno;
+ ret = bpf_map_get_info_by_fd(fd, &info, &length);
+ if (ret)
+ ret = -errno;
close(fd);
- if (rc)
- return rc;
+ if (ret)
+ return ret;
for (j = 0; j < SHIRUDO_GUARD_MAP_COUNT; j++) {
if (strncmp(info.name, shirudo_guard_maps[j].name,
sizeof(info.name) - 1))
@@ -306,27 +306,27 @@ static int guard_kernel_btf(__u32 id, struct btf **result)
__u32 length = sizeof(info);
char name[16] = {};
struct btf *btf;
- int fd, rc;
+ int fd, ret;
fd = bpf_btf_get_fd_by_id(id);
if (fd < 0)
return -errno;
info.name = (uintptr_t)name;
info.name_len = sizeof(name);
- rc = bpf_btf_get_info_by_fd(fd, &info, &length);
- if (rc)
- rc = -errno;
+ ret = bpf_btf_get_info_by_fd(fd, &info, &length);
+ if (ret)
+ ret = -errno;
else if (!info.kernel_btf ||
!memchr(name, '\0', sizeof(name)) ||
strcmp(name, "vmlinux"))
- rc = -EPROTO;
+ ret = -EPROTO;
close(fd);
- if (rc)
- return rc;
+ if (ret)
+ return ret;
btf = btf__load_from_kernel_by_id(id);
- rc = libbpf_get_error(btf);
- if (rc)
- return rc;
+ ret = libbpf_get_error(btf);
+ if (ret)
+ return ret;
*result = btf;
return 0;
}
@@ -341,34 +341,34 @@ static int guard_link(const struct shirudo_image_guard *guard,
char function[96];
__u32 length;
const char *suffix;
- int fd, prog, rc, type_id;
+ int fd, prog, ret, type_id;
fd = bpf_obj_get(guard->pin);
if (fd < 0)
return -errno;
length = sizeof(link);
- rc = bpf_link_get_info_by_fd(fd, &link, &length);
- if (rc)
- rc = -errno;
+ ret = bpf_link_get_info_by_fd(fd, &link, &length);
+ if (ret)
+ ret = -errno;
else if (link.type != BPF_LINK_TYPE_TRACING ||
!link.id || !link.prog_id ||
link.tracing.attach_type != BPF_LSM_MAC)
- rc = -EPROTO;
+ ret = -EPROTO;
close(fd);
- if (rc)
- return rc;
+ if (ret)
+ return ret;
prog = bpf_prog_get_fd_by_id(link.prog_id);
if (prog < 0)
return -errno;
program.map_ids = (uintptr_t)map_ids;
program.nr_map_ids = ARRAY_SIZE(map_ids);
length = sizeof(program);
- rc = bpf_prog_get_info_by_fd(prog, &program, &length);
- if (rc)
- rc = -errno;
+ ret = bpf_prog_get_info_by_fd(prog, &program, &length);
+ if (ret)
+ ret = -errno;
close(prog);
- if (rc)
- return rc;
+ if (ret)
+ return ret;
if (program.type != BPF_PROG_TYPE_LSM || !program.attach_btf_id ||
!program.attach_btf_obj_id || program.id != link.prog_id ||
program.nr_map_ids > ARRAY_SIZE(map_ids) ||
@@ -377,9 +377,9 @@ static int guard_link(const struct shirudo_image_guard *guard,
link.tracing.target_btf_id != program.attach_btf_id)
return -EPROTO;
if (!*kernel) {
- rc = guard_kernel_btf(program.attach_btf_obj_id, kernel);
- if (rc)
- return rc;
+ ret = guard_kernel_btf(program.attach_btf_obj_id, kernel);
+ if (ret)
+ return ret;
*kernel_id = program.attach_btf_obj_id;
}
if (*kernel_id != program.attach_btf_obj_id)
@@ -430,25 +430,25 @@ int shirudo_image_guards_ready(void)
struct btf *kernel = NULL;
__u32 kernel_id = 0;
__u32 i, j;
- int rc;
+ int ret;
- rc = guard_map_ids(map_ids);
- if (rc)
- return rc;
+ ret = guard_map_ids(map_ids);
+ if (ret)
+ return ret;
for (i = 0; i < ARRAY_SIZE(groups); i++) {
for (j = 0; j < groups[i].count; j++) {
const struct shirudo_image_guard *guard =
&groups[i].guards[j];
- rc = guard_link(guard, map_ids, &kernel, &kernel_id);
- if (rc) {
+ ret = guard_link(guard, map_ids, &kernel, &kernel_id);
+ if (ret) {
pr_err("image: missing or invalid guard %s: %s",
- guard->pin, strerror(-rc));
+ guard->pin, strerror(-ret));
goto out;
}
}
}
out:
btf__free(kernel);
- return rc;
+ return ret;
}
diff --git a/util/image_keys.c b/util/image_keys.c
index ae31fc5a..5253934e 100644
--- a/util/image_keys.c
+++ b/util/image_keys.c
@@ -26,7 +26,7 @@ static int revocations(int root_fd, bool apply, bool boot)
{
struct dirent *entry;
struct stat root, st;
- int keys_fd, dir_fd, rc = 0;
+ int keys_fd, dir_fd, ret = 0;
DIR *dir;
if (fstat(root_fd, &root))
@@ -42,9 +42,9 @@ static int revocations(int root_fd, bool apply, bool boot)
return errno == ENOENT ? 0 : -errno;
dir = fdopendir(dir_fd);
if (!dir) {
- rc = -errno;
+ ret = -errno;
close(dir_fd);
- return rc;
+ return ret;
}
errno = 0;
while ((entry = readdir(dir)) != NULL) {
@@ -58,74 +58,74 @@ static int revocations(int root_fd, bool apply, bool boot)
continue;
if (strlen(entry->d_name) != 68 ||
strcmp(entry->d_name + 64, ".der")) {
- rc = -EINVAL;
+ ret = -EINVAL;
break;
}
memcpy(name, entry->d_name, 64);
name[64] = 0;
- rc = hex_decode(name, expected, 32);
- if (rc)
+ ret = hex_decode(name, expected, 32);
+ if (ret)
break;
hex_encode(expected, 32, canonical);
memcpy(canonical + 64, ".der", 5);
if (strcmp(canonical, entry->d_name)) {
- rc = -EINVAL;
+ ret = -EINVAL;
break;
}
fd = openat(dir_fd, entry->d_name,
O_RDONLY | O_NONBLOCK | O_CLOEXEC | O_NOFOLLOW);
if (fd < 0) {
- rc = -errno;
+ ret = -errno;
break;
}
- rc = fstat(fd, &st) ? -errno : 0;
- if (!rc && (!S_ISREG(st.st_mode) || st.st_dev != root.st_dev ||
- st.st_size <= 0 ||
- st.st_size > KEYS_DER_MAX))
- rc = -EINVAL;
- if (!rc)
- rc = keys_read_der_fd(fd, &der, &size);
+ ret = fstat(fd, &st) ? -errno : 0;
+ if (!ret && (!S_ISREG(st.st_mode) || st.st_dev != root.st_dev ||
+ st.st_size <= 0 ||
+ st.st_size > KEYS_DER_MAX))
+ ret = -EINVAL;
+ if (!ret)
+ ret = keys_read_der_fd(fd, &der, &size);
close(fd);
- if (!rc)
- rc = keys_digest_der(der, size, digest,
- fingerprint);
- if (!rc && memcmp(expected, fingerprint, 32))
- rc = -EKEYREJECTED;
- if (!rc && apply)
- rc = shirudo_keys_revoke_image(der, size, boot);
+ if (!ret)
+ ret = keys_digest_der(der, size, digest,
+ fingerprint);
+ if (!ret && memcmp(expected, fingerprint, 32))
+ ret = -EKEYREJECTED;
+ if (!ret && apply)
+ ret = shirudo_keys_revoke_image(der, size, boot);
xfree(der, size);
- if (rc)
+ if (ret)
break;
errno = 0;
}
- if (!entry && errno && !rc)
- rc = -errno;
+ if (!entry && errno && !ret)
+ ret = -errno;
closedir(dir);
- return rc;
+ return ret;
}
int shirudo_keys_validate_image_set(const char *primary, int root_fd,
struct shirudo_trusted_set *set)
{
- int rc;
+ int ret;
- rc = shirudo_image_config_validate(root_fd);
- if (rc) {
+ ret = shirudo_image_config_validate(root_fd);
+ if (ret) {
pr_err("image trust set: validate config image: %s",
- strerror(-rc));
- return rc;
+ strerror(-ret));
+ return ret;
}
- rc = revocations(root_fd, false, false);
- if (rc) {
+ ret = revocations(root_fd, false, false);
+ if (ret) {
pr_err("image trust set: validate revocations: %s",
- strerror(-rc));
- return rc;
+ strerror(-ret));
+ return ret;
}
- rc = shirudo_keys_load_image_root(primary, root_fd, true, set);
- if (rc) {
+ ret = shirudo_keys_load_image_root(primary, root_fd, true, set);
+ if (ret) {
pr_err("image trust set: load certificates: %s",
- strerror(-rc));
- return rc;
+ strerror(-ret));
+ return ret;
}
if (!set->n || set->n_unvouched) {
pr_err("image trust set: reject set with %zu certificates and %zu unvouched",
@@ -139,7 +139,7 @@ int shirudo_keys_check_image_set(const struct shirudo_trusted_set *set)
{
key_serial_t keyring;
size_t i;
- int rc;
+ int ret;
keyring = keyring_bpf_serial();
if (keyring < 0)
@@ -148,12 +148,12 @@ int shirudo_keys_check_image_set(const struct shirudo_trusted_set *set)
const __u8 *der = NULL;
size_t size = 0;
- rc = keys_cert_der(&set->certs[i], &der, &size);
- if (rc)
- return rc;
- rc = keyring_holds_cert(keyring, der, size);
- if (rc != 1)
- return rc < 0 ? rc : -ENOKEY;
+ ret = keys_cert_der(&set->certs[i], &der, &size);
+ if (ret)
+ return ret;
+ ret = keyring_holds_cert(keyring, der, size);
+ if (ret != 1)
+ return ret < 0 ? ret : -ENOKEY;
}
return 0;
}
@@ -161,17 +161,17 @@ int shirudo_keys_check_image_set(const struct shirudo_trusted_set *set)
int shirudo_keys_validate_image(int root_fd)
{
struct shirudo_trusted_set set;
- int rc;
+ int ret;
- rc = shirudo_keys_validate_image_set(RUNTIME_CERT_PATH,
- root_fd, &set);
- return rc ? rc : shirudo_keys_check_image_set(&set);
+ ret = shirudo_keys_validate_image_set(RUNTIME_CERT_PATH,
+ root_fd, &set);
+ return ret ? ret : shirudo_keys_check_image_set(&set);
}
int shirudo_keys_apply_image(int root_fd, bool boot)
{
- int rc;
+ int ret;
- rc = shirudo_keys_validate_image(root_fd);
- return rc ? rc : revocations(root_fd, true, boot);
+ ret = shirudo_keys_validate_image(root_fd);
+ return ret ? ret : revocations(root_fd, true, boot);
}
diff --git a/util/image_runtime.c b/util/image_runtime.c
index 0133b63b..aec15980 100644
--- a/util/image_runtime.c
+++ b/util/image_runtime.c
@@ -106,41 +106,41 @@ static int reject_overrides(void)
int shirudo_image_bootstrap_load(void)
{
struct shirudo_identity identity;
- int mode, rc;
+ int mode, ret;
if (image.loaded)
return 1;
mode = shirudo_enforcement_active();
if (mode < 0)
return mode;
- rc = identity_read(&identity);
- if (mode && rc)
- return rc;
- if (!rc && !mode)
+ ret = identity_read(&identity);
+ if (mode && ret)
+ return ret;
+ if (!ret && !mode)
return -EPROTO;
- if (!rc) {
+ if (!ret) {
memcpy(image.bootstrap.runtime_root, identity.runtime_root, 32);
image.bootstrap.have_root = true;
- rc = load_runtime_config(false);
+ ret = load_runtime_config(false);
} else {
- rc = shirudo_image_bootstrap_read(CONF_PATH,
- &image.bootstrap, true);
- if (!rc &&
+ ret = shirudo_image_bootstrap_read(CONF_PATH,
+ &image.bootstrap, true);
+ if (!ret &&
(!image.bootstrap.runtime[0] || !image.bootstrap.have_root))
- rc = -EINVAL;
- if (!rc)
- rc = config_load_path(&image.bootstrap_config,
- CONF_PATH);
+ ret = -EINVAL;
+ if (!ret)
+ ret = config_load_path(&image.bootstrap_config,
+ CONF_PATH);
}
- if (rc)
- return rc;
- rc = reject_overrides();
- if (rc)
- return rc;
- rc = shirudo_image_config_set(&image.bootstrap_config, -1);
- if (!rc)
+ if (ret)
+ return ret;
+ ret = reject_overrides();
+ if (ret)
+ return ret;
+ ret = shirudo_image_config_set(&image.bootstrap_config, -1);
+ if (!ret)
image.loaded = true;
- return rc ? rc : 1;
+ return ret ? ret : 1;
}
const __u8 *shirudo_image_runtime_root(void)
@@ -178,7 +178,7 @@ static int device_observed(dev_t device, const __u8 root[32], __u32 kind)
__u64 key, next, diskseq;
struct stat st;
char path[64];
- int fd, block, rc = -EACCES;
+ int fd, block, ret = -EACCES;
if (strsprintf(path, sizeof(path), "/dev/dm-%u", minor(device)) < 0)
return -ENAMETOOLONG;
@@ -187,13 +187,13 @@ static int device_observed(dev_t device, const __u8 root[32], __u32 kind)
return -errno;
if (fstat(block, &st) || !S_ISBLK(st.st_mode) || st.st_rdev != device ||
ioctl(block, BLKGETDISKSEQ, &diskseq)) {
- rc = errno ? -errno : -EPERM;
+ ret = errno ? -errno : -EPERM;
close(block);
- return rc;
+ return ret;
}
fd = bpf_obj_get(BPFFS_DIR "/devices");
if (fd < 0) {
- rc = -errno;
+ ret = -errno;
goto out_block;
}
if (bpf_map_get_next_key(fd, NULL, &key))
@@ -203,7 +203,7 @@ static int device_observed(dev_t device, const __u8 root[32], __u32 kind)
entry.dev == dev && entry.kind == kind &&
entry.diskseq == diskseq &&
(!root || !memcmp(entry.root, root, 32))) {
- rc = 0;
+ ret = 0;
break;
}
if (bpf_map_get_next_key(fd, &key, &next))
@@ -214,7 +214,7 @@ out:
close(fd);
out_block:
close(block);
- return rc;
+ return ret;
}
static int runtime_observed(dev_t device)
@@ -238,17 +238,17 @@ static int mount_flags(int fd, bool executable)
static int open_runtime_file(const char *path, dev_t device)
{
struct stat st;
- int fd, rc;
+ int fd, ret;
fd = open(path, O_RDONLY | O_CLOEXEC | O_NOFOLLOW);
if (fd < 0)
return -errno;
- rc = fstat(fd, &st) ? -errno : 0;
- if (!rc && (!S_ISREG(st.st_mode) || st.st_dev != device))
- rc = -EPERM;
- if (rc) {
+ ret = fstat(fd, &st) ? -errno : 0;
+ if (!ret && (!S_ISREG(st.st_mode) || st.st_dev != device))
+ ret = -EPERM;
+ if (ret) {
close(fd);
- return rc;
+ return ret;
}
return fd;
}
@@ -256,37 +256,37 @@ static int open_runtime_file(const char *path, dev_t device)
static int load_runtime_config(bool trusted_boot)
{
struct stat root;
- int fd, rc;
+ int fd, ret;
if (!trusted_boot) {
- rc = shirudo_image_guards_ready();
- if (rc)
- return rc;
+ ret = shirudo_image_guards_ready();
+ if (ret)
+ return ret;
}
if (stat(RUNTIME_DIR, &root))
return -errno;
if (!trusted_boot) {
- rc = runtime_observed(root.st_dev);
- if (rc)
- return rc;
+ ret = runtime_observed(root.st_dev);
+ if (ret)
+ return ret;
}
fd = open_runtime_file(RUNTIME_CONF_PATH, root.st_dev);
if (fd < 0)
return fd;
- rc = shirudo_image_bootstrap_read_fd(fd, &image.bootstrap, false);
- if (!rc)
- rc = config_load_fd(&image.bootstrap_config, fd,
- RUNTIME_CONF_PATH);
+ ret = shirudo_image_bootstrap_read_fd(fd, &image.bootstrap, false);
+ if (!ret)
+ ret = config_load_fd(&image.bootstrap_config, fd,
+ RUNTIME_CONF_PATH);
close(fd);
- if (rc)
- return rc;
+ if (ret)
+ return ret;
if (!image.bootstrap.config[0] || !image.bootstrap.certificate[0] ||
!image.bootstrap.have_pcr)
return -EINVAL;
- rc = shirudo_image_config_set(&image.bootstrap_config, -1);
- if (rc)
- return rc;
+ ret = shirudo_image_config_set(&image.bootstrap_config, -1);
+ if (ret)
+ return ret;
fd = open_runtime_file(image.bootstrap.certificate, root.st_dev);
if (fd < 0)
@@ -298,10 +298,10 @@ static int load_runtime_config(bool trusted_boot)
fd = open_runtime_file(RUNTIME_CERT_PATH, root.st_dev);
if (fd < 0)
return fd;
- rc = mount_flags(fd, true);
+ ret = mount_flags(fd, true);
close(fd);
- if (rc)
- return rc;
+ if (ret)
+ return ret;
/* The verified config certificate stays open through key enrollment. */
return 0;
@@ -321,7 +321,7 @@ static int mount_runtime(bool trusted_boot)
.hash_loop_fd = -1,
};
bool created = false;
- int rc, cleanup;
+ int ret, cleanup;
struct stat st;
if (!image.loaded)
@@ -329,53 +329,53 @@ static int mount_runtime(bool trusted_boot)
if (!trusted_boot && !stat(RUNTIME_DIR, &st) &&
!runtime_observed(st.st_dev))
return load_runtime_config(trusted_boot);
- rc = shirudo_config_image_open_root(image.bootstrap.runtime,
- image.bootstrap.runtime_root,
- &opened);
- if (!rc) {
+ ret = shirudo_config_image_open_root(image.bootstrap.runtime,
+ image.bootstrap.runtime_root,
+ &opened);
+ if (!ret) {
step = "prepare runtime mountpoint";
- rc = mkdir_owned(RUNTIME_DIR);
+ ret = mkdir_owned(RUNTIME_DIR);
}
- if (!rc) {
+ if (!ret) {
step = "create runtime dm-verity mapping";
- rc = shirudo_dm_verity_create(&opened, "shirudo-runtime",
- &device);
- created = !rc;
+ ret = shirudo_dm_verity_create(&opened, "shirudo-runtime",
+ &device);
+ created = !ret;
}
- if (rc == -EEXIST) {
+ if (ret == -EEXIST) {
step = "inspect runtime dm-verity mapping";
- rc = shirudo_dm_verity_inspect("shirudo-runtime", &opened.image,
- &device);
+ ret = shirudo_dm_verity_inspect("shirudo-runtime", &opened.image,
+ &device);
}
- if (!rc) {
+ if (!ret) {
step = "verify runtime image";
- rc = shirudo_dm_verity_verify(&device, &opened);
+ ret = shirudo_dm_verity_verify(&device, &opened);
}
- if (!rc) {
+ if (!ret) {
step = "mount runtime image";
- rc = shirudo_dm_verity_mount(&device, RUNTIME_DIR,
- true);
+ ret = shirudo_dm_verity_mount(&device, RUNTIME_DIR,
+ true);
}
- if (rc && created) {
+ if (ret && created) {
cleanup = shirudo_dm_verity_remove(&device, false);
if (cleanup)
pr_warn("image: cannot remove runtime mapping: %s",
strerror(-cleanup));
}
shirudo_dm_verity_close(&device);
- if (!rc && trusted_boot)
+ if (!ret && trusted_boot)
image.boot_runtime = device;
shirudo_config_image_close(&opened);
- if (!rc) {
+ if (!ret) {
step = "load runtime config";
- rc = load_runtime_config(trusted_boot);
- if (rc && umount2(RUNTIME_DIR, MNT_DETACH))
+ ret = load_runtime_config(trusted_boot);
+ if (ret && umount2(RUNTIME_DIR, MNT_DETACH))
pr_warn("image: cannot unmount the runtime: %s",
strerror(errno));
}
- if (rc)
- pr_err("image: %s: %s", step, strerror(-rc));
- return rc;
+ if (ret)
+ pr_err("image: %s: %s", step, strerror(-ret));
+ return ret;
}
int shirudo_image_runtime_mount(void)
@@ -420,7 +420,7 @@ static int collect_mapping(const char *name, dev_t device, void *ctx)
.hash_loop_fd = -1,
};
const dev_t *active = ctx;
- int rc;
+ int ret;
if (device == *active ||
device_observed(device, NULL, DEVICE_CONFIG))
@@ -429,10 +429,10 @@ static int collect_mapping(const char *name, dev_t device, void *ctx)
return -ENAMETOOLONG;
strscpy(retired.name, name, sizeof(retired.name));
retired.device = device;
- rc = shirudo_dm_verity_remove(&retired, false);
- if (rc && rc != -EBUSY && rc != -ENXIO && rc != -ENODEV)
+ ret = shirudo_dm_verity_remove(&retired, false);
+ if (ret && ret != -EBUSY && ret != -ENXIO && ret != -ENODEV)
pr_warn("image: cannot remove retired mapping %s: %s", name,
- strerror(-rc));
+ strerror(-ret));
return 0;
}
@@ -440,16 +440,16 @@ static void collect_mappings(void)
{
struct stat st;
dev_t active = 0;
- int rc;
+ int ret;
if (image.update.lock_fd < 0)
return;
if (!stat(CONFIG_IMAGE_DIR, &st))
active = st.st_dev;
- rc = shirudo_dm_verity_list(collect_mapping, &active);
- if (rc)
+ ret = shirudo_dm_verity_list(collect_mapping, &active);
+ if (ret)
pr_warn("image: cannot collect retired mappings: %s",
- strerror(-rc));
+ strerror(-ret));
}
static void close_candidate(void)
@@ -469,27 +469,27 @@ static void close_candidate(void)
static int remove_candidate(struct shirudo_dm_verity *device)
{
__u32 attempt;
- int rc;
+ int ret;
for (attempt = 0; attempt < 100; attempt++) {
- rc = shirudo_dm_verity_remove(device, false);
- if (rc != -EBUSY)
- return rc;
+ ret = shirudo_dm_verity_remove(device, false);
+ if (ret != -EBUSY)
+ return ret;
if (attempt < 99)
usleep(10000);
}
- return rc;
+ return ret;
}
static int candidate_keys(int fd)
{
- int rc;
+ int ret;
- rc = shirudo_keys_validate_image(fd);
- if (rc == -ENOKEY)
+ ret = shirudo_keys_validate_image(fd);
+ if (ret == -ENOKEY)
pr_err("image: BPF signer was not enrolled at boot; "
"reboot with the new trusted key set required");
- return rc;
+ return ret;
}
static int mount_candidate(struct image_context *current)
@@ -497,7 +497,7 @@ static int mount_candidate(struct image_context *current)
struct shirudo_dm_verity *device = &current->candidate_device;
const char *mountpoint = CONFIG_CANDIDATE_DIR;
struct stat st;
- int rc;
+ int ret;
if (!stat(CONFIG_IMAGE_DIR, &st) &&
st.st_dev == current->candidate_device.device) {
@@ -507,11 +507,11 @@ static int mount_candidate(struct image_context *current)
if (umount2(mountpoint, MNT_DETACH) &&
errno != EINVAL && errno != ENOENT)
return -errno;
- rc = mkdir_owned(mountpoint);
- if (!rc)
- rc = shirudo_dm_verity_mount(device, mountpoint, false);
- if (rc)
- return rc;
+ ret = mkdir_owned(mountpoint);
+ if (!ret)
+ ret = shirudo_dm_verity_mount(device, mountpoint, false);
+ if (ret)
+ return ret;
current->candidate_fd = open(mountpoint,
O_PATH | O_DIRECTORY | O_CLOEXEC);
}
@@ -524,7 +524,7 @@ static int prepare_config(struct image_context *current,
{
struct shirudo_dm_verity *device = &current->candidate_device;
bool created = false;
- int rc, cleanup;
+ int ret, cleanup;
char name[128];
close_candidate();
@@ -534,83 +534,83 @@ static int prepare_config(struct image_context *current,
sizeof(IMAGE_CACHE_DIR)) ||
!shirudo_image_path_valid(target->prefix))
return -EPERM;
- rc = shirudo_config_image_open(target->prefix, &current->candidate);
- if (rc)
- return rc;
+ ret = shirudo_config_image_open(target->prefix, &current->candidate);
+ if (ret)
+ return ret;
if (memcmp(target->root_hash, current->candidate.image.root_hash, 32))
return -EKEYREJECTED;
- rc = mapping_name(target->root_hash, name);
- if (rc)
- return rc;
- rc = shirudo_dm_verity_inspect(name, &current->candidate.image,
- device);
- if (rc == -ENXIO || rc == -ENODEV || rc == -ENOENT) {
- rc = shirudo_dm_verity_create(&current->candidate, name,
- device);
- created = !rc;
+ ret = mapping_name(target->root_hash, name);
+ if (ret)
+ return ret;
+ ret = shirudo_dm_verity_inspect(name, &current->candidate.image,
+ device);
+ if (ret == -ENXIO || ret == -ENODEV || ret == -ENOENT) {
+ ret = shirudo_dm_verity_create(&current->candidate, name,
+ device);
+ created = !ret;
}
- if (!rc)
- rc = shirudo_dm_verity_verify(device, &current->candidate);
- if (!rc && !trusted_boot)
- rc = device_observed(current->candidate_device.device,
- current->candidate.image.root_hash,
- DEVICE_CONFIG);
- if (rc)
+ if (!ret)
+ ret = shirudo_dm_verity_verify(device, &current->candidate);
+ if (!ret && !trusted_boot)
+ ret = device_observed(current->candidate_device.device,
+ current->candidate.image.root_hash,
+ DEVICE_CONFIG);
+ if (ret)
goto out;
- rc = mount_candidate(current);
- if (rc)
+ ret = mount_candidate(current);
+ if (ret)
goto out;
- rc = mount_flags(current->candidate_fd, false);
- if (!rc)
- rc = shirudo_image_config_validate(current->candidate_fd);
- if (!rc && !trusted_boot)
- rc = candidate_keys(current->candidate_fd);
+ ret = mount_flags(current->candidate_fd, false);
+ if (!ret)
+ ret = shirudo_image_config_validate(current->candidate_fd);
+ if (!ret && !trusted_boot)
+ ret = candidate_keys(current->candidate_fd);
out:
- if (rc && created) {
+ if (ret && created) {
close_candidate();
cleanup = remove_candidate(device);
if (cleanup && cleanup != -ENXIO && cleanup != -ENODEV)
pr_warn("image: cannot remove rejected mapping %s: %s",
device->name, strerror(-cleanup));
}
- return rc;
+ return ret;
}
static int activate_config(struct image_context *current, bool boot)
{
struct stat st;
- int fd, rc;
-
- rc = shirudo_keys_apply_image(current->candidate_fd, boot);
- if (rc)
- return rc;
- rc = mkdir_owned(CONFIG_IMAGE_DIR);
- if (rc)
- return rc;
+ int fd, ret;
+
+ ret = shirudo_keys_apply_image(current->candidate_fd, boot);
+ if (ret)
+ return ret;
+ ret = mkdir_owned(CONFIG_IMAGE_DIR);
+ if (ret)
+ return ret;
if (stat(CONFIG_IMAGE_DIR, &st))
return -errno;
if (st.st_dev != current->candidate_device.device) {
if (umount2(CONFIG_IMAGE_DIR, MNT_DETACH) &&
errno != EINVAL)
return -errno;
- rc = shirudo_dm_verity_mount(&current->candidate_device,
- CONFIG_IMAGE_DIR, false);
- if (rc)
- return rc;
+ ret = shirudo_dm_verity_mount(&current->candidate_device,
+ CONFIG_IMAGE_DIR, false);
+ if (ret)
+ return ret;
}
fd = open(CONFIG_IMAGE_DIR, O_PATH | O_DIRECTORY | O_CLOEXEC);
if (fd < 0)
return -errno;
if (fstat(fd, &st))
- rc = -errno;
+ ret = -errno;
else if (st.st_dev != current->candidate_device.device)
- rc = -ESTALE;
+ ret = -ESTALE;
else
- rc = mount_flags(fd, false);
- if (!rc)
- rc = shirudo_image_config_set(&current->bootstrap_config, fd);
+ ret = mount_flags(fd, false);
+ if (!ret)
+ ret = shirudo_image_config_set(&current->bootstrap_config, fd);
close(fd);
- return rc;
+ return ret;
}
static int prepare_update(void *ctx,
@@ -654,20 +654,20 @@ static const struct shirudo_config_update_ops boot_ops = {
static int open_update(void)
{
- int rc;
+ int ret;
if (image.update.lock_fd >= 0)
return 0;
- rc = mkdir_owned(CONFIG_UPDATE_DIR);
- if (!rc)
- rc = tpm_open(&image.tpm);
- if (!rc)
- rc = chain_tpm_bound(image.tpm);
- if (!rc)
- rc = shirudo_config_update_open(CONFIG_UPDATE_DIR,
- &update_ops, &image,
- &image.update);
- return rc;
+ ret = mkdir_owned(CONFIG_UPDATE_DIR);
+ if (!ret)
+ ret = tpm_open(&image.tpm);
+ if (!ret)
+ ret = chain_tpm_bound(image.tpm);
+ if (!ret)
+ ret = shirudo_config_update_open(CONFIG_UPDATE_DIR,
+ &update_ops, &image,
+ &image.update);
+ return ret;
}
static int boot_target(struct shirudo_config_update_target *target)
@@ -676,31 +676,31 @@ static int boot_target(struct shirudo_config_update_target *target)
struct shirudo_config_image_open opened;
const char *prefix;
bool selected;
- int rc;
+ int ret;
- rc = shirudo_config_update_read(&image.update, &previous);
- selected = !rc;
+ ret = shirudo_config_update_read(&image.update, &previous);
+ selected = !ret;
prefix = selected ? previous.target.prefix : image.bootstrap.config;
- if (rc && rc != -ENOENT)
- return rc;
- rc = shirudo_config_image_open(prefix, &opened);
- if (rc)
- return rc;
+ if (ret && ret != -ENOENT)
+ return ret;
+ ret = shirudo_config_image_open(prefix, &opened);
+ if (ret)
+ return ret;
if (selected && memcmp(previous.target.root_hash,
opened.image.root_hash, 32)) {
- rc = -EKEYREJECTED;
+ ret = -EKEYREJECTED;
} else {
strscpy(target->prefix, prefix, sizeof(target->prefix));
memcpy(target->root_hash, opened.image.root_hash, 32);
}
shirudo_config_image_close(&opened);
- return rc;
+ return ret;
}
-static int boot_keys_error(const char *step, int rc)
+static int boot_keys_error(const char *step, int ret)
{
- pr_err("initrd boot keys: %s: %s", step, strerror(-rc));
- return rc;
+ pr_err("initrd boot keys: %s: %s", step, strerror(-ret));
+ return ret;
}
/*
@@ -712,7 +712,7 @@ static int seal_config_key(key_serial_t ring, const __u8 *der, size_t size)
{
struct keyring_cert cert = { .der = der, .len = size };
key_serial_t key;
- int rc;
+ int ret;
key = shirudo_keyring_dm_verity_add_cert(der, size);
if (key < 0 && key != -EPERM && key != -EACCES)
@@ -723,19 +723,19 @@ static int seal_config_key(key_serial_t ring, const __u8 *der, size_t size)
"boot with dm_verity.keyring_unsealed=1",
-ENOKEY);
if (key >= 0) {
- rc = shirudo_keyring_dm_verity_seal();
- if (rc == -EEXIST)
+ ret = shirudo_keyring_dm_verity_seal();
+ if (ret == -EEXIST)
return boot_keys_error("seal dm-verity keyring restricted "
"by another task (tampered)",
-EKEYREJECTED);
- if (rc)
- return boot_keys_error("seal dm-verity keyring", rc);
+ if (ret)
+ return boot_keys_error("seal dm-verity keyring", ret);
}
- rc = keyring_holds_exactly(ring, &cert, 1);
- if (rc <= 0)
+ ret = keyring_holds_exactly(ring, &cert, 1);
+ if (ret <= 0)
return boot_keys_error("check dm-verity keyring holds only the "
"config certificate",
- rc ? rc : -EKEYREJECTED);
+ ret ? ret : -EKEYREJECTED);
return 0;
}
@@ -744,21 +744,21 @@ static int enroll_config_key(void)
__u8 *der = NULL;
key_serial_t ring;
size_t size = 0;
- int rc;
+ int ret;
- rc = image.certificate_fd < 0 ? -EBADF :
+ ret = image.certificate_fd < 0 ? -EBADF :
keys_read_der_fd(image.certificate_fd, &der, &size);
- if (rc)
- return boot_keys_error("read config verification certificate", rc);
+ if (ret)
+ return boot_keys_error("read config verification certificate", ret);
ring = shirudo_keyring_dm_verity_serial();
if (ring < 0) {
- rc = (int)ring;
+ ret = (int)ring;
xfree(der, size);
- return boot_keys_error("lookup dm-verity keyring", rc);
+ return boot_keys_error("lookup dm-verity keyring", ret);
}
- rc = seal_config_key(ring, der, size);
+ ret = seal_config_key(ring, der, size);
xfree(der, size);
- return rc;
+ return ret;
}
/* The authenticated initrd validates the boot set before installing guards. */
@@ -766,35 +766,35 @@ int shirudo_image_boot_keys(struct shirudo_trusted_set *set)
{
struct shirudo_trusted_cert primary = { .primary = true };
size_t i;
- int rc;
+ int ret;
/* These temporary mounts are released before loading the guards. */
image.boot_keys_open = true;
- rc = mount_runtime(true);
- if (rc)
- return boot_keys_error("mount runtime", rc);
- rc = enroll_config_key();
- if (rc)
- return boot_keys_error("enrol config certificate", rc);
- rc = open_update();
- if (rc)
- return boot_keys_error("open config update state", rc);
- rc = boot_target(&image.boot_target);
- if (rc)
- return boot_keys_error("select boot config", rc);
- rc = prepare_config(&image, &image.boot_target, true);
- if (rc)
- return boot_keys_error("prepare boot config", rc);
- rc = shirudo_keys_validate_image_set(RUNTIME_CERT_PATH,
- image.candidate_fd, set);
- if (rc)
- return boot_keys_error("validate BPF trust set", rc);
+ ret = mount_runtime(true);
+ if (ret)
+ return boot_keys_error("mount runtime", ret);
+ ret = enroll_config_key();
+ if (ret)
+ return boot_keys_error("enrol config certificate", ret);
+ ret = open_update();
+ if (ret)
+ return boot_keys_error("open config update state", ret);
+ ret = boot_target(&image.boot_target);
+ if (ret)
+ return boot_keys_error("select boot config", ret);
+ ret = prepare_config(&image, &image.boot_target, true);
+ if (ret)
+ return boot_keys_error("prepare boot config", ret);
+ ret = shirudo_keys_validate_image_set(RUNTIME_CERT_PATH,
+ image.candidate_fd, set);
+ if (ret)
+ return boot_keys_error("validate BPF trust set", ret);
/* Guard loaders need the initial signer until activation. */
strscpy(primary.path, RUNTIME_CERT_PATH, sizeof(primary.path));
- rc = keys_digest_file(primary.path, primary.sha256,
- primary.fingerprint);
- if (rc)
- return boot_keys_error("digest primary certificate", rc);
+ ret = keys_digest_file(primary.path, primary.sha256,
+ primary.fingerprint);
+ if (ret)
+ return boot_keys_error("digest primary certificate", ret);
for (i = 0; i < set->n; i++)
if (!memcmp(set->certs[i].sha256, primary.sha256, 32))
break;
@@ -810,7 +810,7 @@ int shirudo_image_boot_keys(struct shirudo_trusted_set *set)
int shirudo_image_boot_keys_close(void)
{
- int rc = 0, err;
+ int ret = 0, err;
if (!image.boot_keys_open)
return 0;
@@ -823,48 +823,48 @@ int shirudo_image_boot_keys_close(void)
image.certificate_fd = -1;
if (umount(CONFIG_CANDIDATE_DIR) && errno != EINVAL &&
errno != ENOENT)
- rc = -errno;
+ ret = -errno;
if (image.candidate_device.name[0]) {
err = shirudo_dm_verity_remove(&image.candidate_device, false);
- if (!rc && err && err != -ENXIO && err != -ENODEV)
- rc = err;
+ if (!ret && err && err != -ENXIO && err != -ENODEV)
+ ret = err;
}
shirudo_config_image_close(&image.candidate);
if (umount(RUNTIME_DIR) && errno != EINVAL && errno != ENOENT &&
- !rc)
- rc = -errno;
+ !ret)
+ ret = -errno;
if (image.boot_runtime.name[0]) {
err = shirudo_dm_verity_remove(&image.boot_runtime, false);
- if (!rc && err && err != -ENXIO && err != -ENODEV)
- rc = err;
+ if (!ret && err && err != -ENXIO && err != -ENODEV)
+ ret = err;
}
image.boot_keys_open = false;
- return rc;
+ return ret;
}
int shirudo_image_boot(void)
{
struct shirudo_config_update_target target = {};
- int rc;
+ int ret;
- rc = open_update();
- if (rc)
- return rc;
+ ret = open_update();
+ if (ret)
+ return ret;
if (image.boot_target_valid) {
target = image.boot_target;
} else {
- rc = boot_target(&target);
- if (rc)
- return rc;
+ ret = boot_target(&target);
+ if (ret)
+ return ret;
}
/* Boot and live updates record key revocations differently. */
image.update.ops = &boot_ops;
- rc = shirudo_config_update_boot(&image.update, &target,
- image.bootstrap.pcr);
+ ret = shirudo_config_update_boot(&image.update, &target,
+ image.bootstrap.pcr);
image.update.ops = &update_ops;
- if (rc == -EINPROGRESS)
+ if (ret == -EINPROGRESS)
pr_err("image: activation is pending; further changes are blocked");
- return rc;
+ return ret;
}
static int config_mount_check(const struct shirudo_config_update_record *record)
@@ -873,64 +873,64 @@ static int config_mount_check(const struct shirudo_config_update_record *record)
struct shirudo_dm_verity device;
struct stat st;
char name[128];
- int fd, rc;
+ int fd, ret;
- rc = shirudo_config_image_open(record->target.prefix, &opened);
- if (rc)
- return rc;
+ ret = shirudo_config_image_open(record->target.prefix, &opened);
+ if (ret)
+ return ret;
if (memcmp(record->target.root_hash, opened.image.root_hash, 32))
- rc = -EKEYREJECTED;
- if (!rc)
- rc = mapping_name(record->target.root_hash, name);
- if (!rc)
- rc = shirudo_dm_verity_inspect(name, &opened.image, &device);
+ ret = -EKEYREJECTED;
+ if (!ret)
+ ret = mapping_name(record->target.root_hash, name);
+ if (!ret)
+ ret = shirudo_dm_verity_inspect(name, &opened.image, &device);
shirudo_config_image_close(&opened);
- if (rc)
- return rc;
+ if (ret)
+ return ret;
if (stat(CONFIG_IMAGE_DIR, &st) || st.st_dev != device.device) {
- rc = -EUCLEAN;
+ ret = -EUCLEAN;
goto out;
}
- rc = device_observed(device.device, record->target.root_hash,
- DEVICE_CONFIG);
- if (rc)
+ ret = device_observed(device.device, record->target.root_hash,
+ DEVICE_CONFIG);
+ if (ret)
goto out;
fd = open(CONFIG_IMAGE_DIR, O_PATH | O_DIRECTORY | O_CLOEXEC);
if (fd < 0) {
- rc = -errno;
+ ret = -errno;
goto out;
}
- rc = mount_flags(fd, false);
- if (!rc)
- rc = shirudo_image_config_set(&image.bootstrap_config, fd);
+ ret = mount_flags(fd, false);
+ if (!ret)
+ ret = shirudo_image_config_set(&image.bootstrap_config, fd);
close(fd);
out:
shirudo_dm_verity_close(&device);
- return rc;
+ return ret;
}
int shirudo_image_boot_complete(void)
{
struct shirudo_config_update_record record;
- int rc;
-
- rc = shirudo_config_update_read(&image.update, &record);
- if (!rc)
- rc = config_mount_check(&record);
- if (!rc)
- rc = shirudo_config_update_complete_boot(&image.update);
- return rc;
+ int ret;
+
+ ret = shirudo_config_update_read(&image.update, &record);
+ if (!ret)
+ ret = config_mount_check(&record);
+ if (!ret)
+ ret = shirudo_config_update_complete_boot(&image.update);
+ return ret;
}
static int current_config(void)
{
struct shirudo_config_update_record record;
- int rc;
+ int ret;
- rc = open_update();
- if (!rc)
- rc = shirudo_config_update_check(&image.update, &record);
- return rc ? rc : config_mount_check(&record);
+ ret = open_update();
+ if (!ret)
+ ret = shirudo_config_update_check(&image.update, &record);
+ return ret ? ret : config_mount_check(&record);
}
/*
@@ -953,7 +953,7 @@ static int status_config(int state)
int shirudo_image_enter(const char *command, int argc, const char **argv)
{
struct shirudo_identity identity;
- int mode, rc;
+ int mode, ret;
if (!strcmp(command, "image") && argc > 1 &&
(!strcmp(argv[1], "build") || !strcmp(argv[1], "verify") ||
@@ -967,19 +967,19 @@ int shirudo_image_enter(const char *command, int argc, const char **argv)
mode = shirudo_enforcement_active();
if (mode < 0)
return mode;
- rc = identity_read(&identity);
- if (mode && rc)
- return rc;
- if (rc)
- return rc == -ENOENT || rc == -EPERM || rc == -EACCES ? 0 : rc;
+ ret = identity_read(&identity);
+ if (mode && ret)
+ return ret;
+ if (ret)
+ return ret == -ENOENT || ret == -EPERM || ret == -EACCES ? 0 : ret;
if (!mode)
return -EPROTO;
- rc = shirudo_image_bootstrap_load();
- if (rc < 0)
- return rc;
- rc = load_runtime_config(false);
- if (rc)
- return rc;
+ ret = shirudo_image_bootstrap_load();
+ if (ret < 0)
+ return ret;
+ ret = load_runtime_config(false);
+ if (ret)
+ return ret;
for (int i = 1; i < argc; i++) {
if (!strncmp(argv[i], "--keys-dir", 10) ||
!strncmp(argv[i], "--cert", 6) ||
@@ -988,12 +988,12 @@ int shirudo_image_enter(const char *command, int argc, const char **argv)
}
if (!strcmp(command, "image"))
return open_update();
- rc = current_config();
+ ret = current_config();
if (!strcmp(command, "status") &&
- (rc == -EINPROGRESS || rc == -EUCLEAN || rc == -ESTALE ||
- rc == -EKEYREJECTED))
- return status_config(rc);
- return rc;
+ (ret == -EINPROGRESS || ret == -EUCLEAN || ret == -ESTALE ||
+ ret == -EKEYREJECTED))
+ return status_config(ret);
+ return ret;
}
int shirudo_image_config_state(__u8 root[32])
@@ -1017,15 +1017,15 @@ int shirudo_image_status(void)
.buf = buffer,
.cap = sizeof(buffer),
};
- int rc;
+ int ret;
if (image.update.lock_fd < 0)
return -ENODEV;
- rc = shirudo_config_update_read(&image.update, &record);
- if (rc)
- return rc;
+ ret = shirudo_config_update_read(&image.update, &record);
+ if (ret)
+ return ret;
hex_encode(record.target.root_hash, 32, root);
- rc = record.pending ? -EINPROGRESS : current_config();
+ ret = record.pending ? -EINPROGRESS : current_config();
json_obj_open(&emit);
json_kv_string(&emit, "root_hash", root);
json_kv_int(&emit, "pcr", record.pcr);
@@ -1033,12 +1033,12 @@ int shirudo_image_status(void)
json_kv_int(&emit, "reset_count", record.reset_count);
json_kv_int(&emit, "restart_count", record.restart_count);
json_kv_bool(&emit, "pending", record.pending);
- json_kv_bool(&emit, "consistent", !rc);
+ json_kv_bool(&emit, "consistent", !ret);
json_obj_close(&emit);
if (emit.err)
return emit.err;
puts(buffer);
- return rc;
+ return ret;
}
void shirudo_image_leave(void)
@@ -1060,17 +1060,17 @@ void shirudo_image_leave(void)
int shirudo_image_update(const char *prefix)
{
struct shirudo_config_update_target target = {};
- int rc;
+ int ret;
if (image.update.lock_fd < 0)
return -ENODEV;
- rc = current_config();
- if (!rc)
- rc = mkdir_owned(IMAGE_CACHE_DIR);
- if (!rc)
- rc = shirudo_image_cache_fetch(prefix, &target);
- if (!rc)
- rc = shirudo_config_update_begin(&image.update, &target,
- image.bootstrap.pcr);
- return rc;
+ ret = current_config();
+ if (!ret)
+ ret = mkdir_owned(IMAGE_CACHE_DIR);
+ if (!ret)
+ ret = shirudo_image_cache_fetch(prefix, &target);
+ if (!ret)
+ ret = shirudo_config_update_begin(&image.update, &target,
+ image.bootstrap.pcr);
+ return ret;
}
diff --git a/util/io.c b/util/io.c
index c4075630..24d03aa4 100644
--- a/util/io.c
+++ b/util/io.c
@@ -72,15 +72,15 @@ int read_fd(int fd, const char *label, size_t max, void *out, size_t *len)
char *buf, *p;
size_t left;
off_t off;
- int rc;
+ int ret;
if (fstat(fd, &st) != 0)
return -errno;
if (!S_ISREG(st.st_mode))
return -EINVAL;
- rc = check_trusted(fd, label, false);
- if (rc)
- return rc;
+ ret = check_trusted(fd, label, false);
+ if (ret)
+ return ret;
if ((uintmax_t)st.st_size > max)
return -EFBIG;
buf = xmalloc((size_t)st.st_size + 1);
@@ -128,7 +128,7 @@ int read_text_line(FILE *f, char **line, size_t *cap, size_t max)
int read_file(const char *path, size_t max, void *out, size_t *len)
{
- int fd, rc;
+ int fd, ret;
if (under(path, VAR_LIB)) {
fd = seal_open_read(path);
@@ -139,9 +139,9 @@ int read_file(const char *path, size_t max, void *out, size_t *len)
if (fd < 0)
return -errno;
}
- rc = read_fd(fd, path, max, out, len);
+ ret = read_fd(fd, path, max, out, len);
close(fd);
- return rc;
+ return ret;
}
static bool under(const char *path, const char *dir)
diff --git a/util/json.c b/util/json.c
index 53515f88..fca0eedd 100644
--- a/util/json.c
+++ b/util/json.c
@@ -329,28 +329,28 @@ static int emit_byte(char *dst, size_t cap, size_t *len, __u8 b)
static int utf8_emit(char *dst, size_t cap, size_t *len, __u32 cp)
{
- int rc;
+ int ret;
if (cp < 0x80) {
return emit_byte(dst, cap, len, cp);
} else if (cp < 0x800) {
- rc = emit_byte(dst, cap, len, 0xC0 | (cp >> 6));
- if (!rc)
- rc = emit_byte(dst, cap, len, 0x80 | (cp & 0x3F));
- return rc;
+ ret = emit_byte(dst, cap, len, 0xC0 | (cp >> 6));
+ if (!ret)
+ ret = emit_byte(dst, cap, len, 0x80 | (cp & 0x3F));
+ return ret;
}
- rc = emit_byte(dst, cap, len, 0xE0 | (cp >> 12));
- if (!rc)
- rc = emit_byte(dst, cap, len, 0x80 | ((cp >> 6) & 0x3F));
- if (!rc)
- rc = emit_byte(dst, cap, len, 0x80 | (cp & 0x3F));
- return rc;
+ ret = emit_byte(dst, cap, len, 0xE0 | (cp >> 12));
+ if (!ret)
+ ret = emit_byte(dst, cap, len, 0x80 | ((cp >> 6) & 0x3F));
+ if (!ret)
+ ret = emit_byte(dst, cap, len, 0x80 | (cp & 0x3F));
+ return ret;
}
static int parse_string(struct pctx *c, char *dst, size_t cap)
{
size_t len = 0;
- int rc;
+ int ret;
if (c->p >= c->end || *c->p != '"')
return -EINVAL;
@@ -371,28 +371,28 @@ static int parse_string(struct pctx *c, char *dst, size_t cap)
e = *c->p++;
switch (e) {
case '"':
- rc = emit_byte(dst, cap, &len, '"');
+ ret = emit_byte(dst, cap, &len, '"');
break;
case '\\':
- rc = emit_byte(dst, cap, &len, '\\');
+ ret = emit_byte(dst, cap, &len, '\\');
break;
case '/':
- rc = emit_byte(dst, cap, &len, '/');
+ ret = emit_byte(dst, cap, &len, '/');
break;
case 'b':
- rc = emit_byte(dst, cap, &len, '\b');
+ ret = emit_byte(dst, cap, &len, '\b');
break;
case 'f':
- rc = emit_byte(dst, cap, &len, '\f');
+ ret = emit_byte(dst, cap, &len, '\f');
break;
case 'n':
- rc = emit_byte(dst, cap, &len, '\n');
+ ret = emit_byte(dst, cap, &len, '\n');
break;
case 'r':
- rc = emit_byte(dst, cap, &len, '\r');
+ ret = emit_byte(dst, cap, &len, '\r');
break;
case 't':
- rc = emit_byte(dst, cap, &len, '\t');
+ ret = emit_byte(dst, cap, &len, '\t');
break;
case 'u': {
int cp, lo;
@@ -420,33 +420,33 @@ static int parse_string(struct pctx *c, char *dst, size_t cap)
return -EINVAL; /* lone low surrogate */
}
if (cp < 0x10000) {
- rc = utf8_emit(dst, cap, &len, cp);
+ ret = utf8_emit(dst, cap, &len, cp);
} else {
- rc = emit_byte(dst, cap, &len,
- 0xF0 | (cp >> 18));
- if (!rc)
- rc = emit_byte(dst, cap, &len,
- 0x80 | ((cp >> 12) & 0x3F));
- if (!rc)
- rc = emit_byte(dst, cap, &len,
- 0x80 | ((cp >> 6) & 0x3F));
- if (!rc)
- rc = emit_byte(dst, cap, &len,
- 0x80 | (cp & 0x3F));
+ ret = emit_byte(dst, cap, &len,
+ 0xF0 | (cp >> 18));
+ if (!ret)
+ ret = emit_byte(dst, cap, &len,
+ 0x80 | ((cp >> 12) & 0x3F));
+ if (!ret)
+ ret = emit_byte(dst, cap, &len,
+ 0x80 | ((cp >> 6) & 0x3F));
+ if (!ret)
+ ret = emit_byte(dst, cap, &len,
+ 0x80 | (cp & 0x3F));
}
break;
}
default:
return -EINVAL;
}
- if (rc)
- return rc;
+ if (ret)
+ return ret;
} else if (ch < 0x20) {
return -EINVAL; /* unescaped control char */
} else {
- rc = emit_byte(dst, cap, &len, ch);
- if (rc)
- return rc;
+ ret = emit_byte(dst, cap, &len, ch);
+ if (ret)
+ return ret;
}
}
if (dst)
@@ -459,7 +459,7 @@ static int parse_value(struct pctx *c, struct shirudo_json_field *f);
static int parse_object(struct pctx *c)
{
char key[256];
- int rc;
+ int ret;
if (++c->depth > JSON_MAX_DEPTH)
return -E2BIG;
@@ -475,9 +475,9 @@ static int parse_object(struct pctx *c)
size_t i;
skip_ws(c);
- rc = parse_string(c, key, sizeof(key));
- if (rc)
- return rc;
+ ret = parse_string(c, key, sizeof(key));
+ if (ret)
+ return ret;
skip_ws(c);
if (c->p >= c->end || *c->p != ':')
return -EINVAL;
@@ -488,9 +488,9 @@ static int parse_object(struct pctx *c)
break;
}
}
- rc = parse_value(c, f);
- if (rc)
- return rc;
+ ret = parse_value(c, f);
+ if (ret)
+ return ret;
skip_ws(c);
if (c->p >= c->end)
return -EINVAL;
@@ -510,7 +510,7 @@ static int parse_object(struct pctx *c)
static int parse_array(struct pctx *c)
{
- int rc;
+ int ret;
if (++c->depth > JSON_MAX_DEPTH)
return -E2BIG;
@@ -522,9 +522,9 @@ static int parse_array(struct pctx *c)
return 0;
}
for (;;) {
- rc = parse_value(c, NULL); /* elements never dispatched */
- if (rc)
- return rc;
+ ret = parse_value(c, NULL); /* elements never dispatched */
+ if (ret)
+ return ret;
skip_ws(c);
if (c->p >= c->end)
return -EINVAL;
@@ -545,7 +545,7 @@ static int parse_array(struct pctx *c)
static int parse_array_into(struct pctx *c, struct shirudo_json_field *f)
{
struct shirudo_json_array *sink = f->dst;
- int rc;
+ int ret;
if (++c->depth > JSON_MAX_DEPTH)
return -E2BIG;
@@ -571,18 +571,18 @@ static int parse_array_into(struct pctx *c, struct shirudo_json_field *f)
c->fields = f->sub;
c->n_fields = f->n_sub;
- rc = parse_object(c);
+ ret = parse_object(c);
c->fields = save_f;
c->n_fields = save_n;
} else {
- rc = parse_value(c, f->n_sub ? &f->sub[0] : NULL);
+ ret = parse_value(c, f->n_sub ? &f->sub[0] : NULL);
}
- if (rc)
- return rc;
+ if (ret)
+ return ret;
if (sink && sink->on_elem) {
- rc = sink->on_elem(sink->ctx);
- if (rc)
- return rc;
+ ret = sink->on_elem(sink->ctx);
+ if (ret)
+ return ret;
}
skip_ws(c);
if (c->p >= c->end)
@@ -668,7 +668,7 @@ static int parse_value(struct pctx *c, struct shirudo_json_field *f)
case '{': {
struct shirudo_json_field *save_f = c->fields;
size_t save_n = c->n_fields;
- int rc;
+ int ret;
if (f) {
if (f->type != SHIRUDO_JSON_T_OBJECT)
@@ -684,11 +684,11 @@ static int parse_value(struct pctx *c, struct shirudo_json_field *f)
c->fields = NULL;
c->n_fields = 0;
}
- rc = parse_object(c);
+ ret = parse_object(c);
c->fields = save_f;
c->n_fields = save_n;
- if (rc)
- return rc;
+ if (ret)
+ return ret;
if (f)
f->seen = 1;
return 0;
@@ -702,13 +702,13 @@ static int parse_value(struct pctx *c, struct shirudo_json_field *f)
return parse_array(c);
case '"':
if (f) {
- int rc;
+ int ret;
if (f->type != SHIRUDO_JSON_T_STRING)
return -EINVAL;
- rc = parse_string(c, f->dst, f->dst_cap);
- if (rc)
- return rc;
+ ret = parse_string(c, f->dst, f->dst_cap);
+ if (ret)
+ return ret;
f->seen = 1;
return 0;
}
@@ -750,7 +750,7 @@ int json_parse(const char *data, size_t len,
.fields = fields, .n_fields = n_fields,
};
size_t i;
- int rc;
+ int ret;
if (len > JSON_MAX_BYTES)
return -E2BIG;
@@ -760,9 +760,9 @@ int json_parse(const char *data, size_t len,
skip_ws(&c);
if (c.p >= c.end || *c.p != '{')
return -EINVAL;
- rc = parse_object(&c);
- if (rc)
- return rc;
+ ret = parse_object(&c);
+ if (ret)
+ return ret;
skip_ws(&c);
if (c.p != c.end)
return -EINVAL; /* trailing garbage */
diff --git a/util/kernel_abi.c b/util/kernel_abi.c
index 62f34080..2ce5e5a0 100644
--- a/util/kernel_abi.c
+++ b/util/kernel_abi.c
@@ -198,7 +198,7 @@ int kernel_abi_check(char *detail, size_t detail_sz)
{
struct btf *btf;
long err;
- int rc;
+ int ret;
if (detail && detail_sz)
detail[0] = '\0';
@@ -209,7 +209,7 @@ int kernel_abi_check(char *detail, size_t detail_sz)
"cannot read target kernel BTF: %s; boot a Shirudo-patched kernel",
strerror((int)-err));
- rc = kernel_abi_validate_btf(btf, detail, detail_sz);
+ ret = kernel_abi_validate_btf(btf, detail, detail_sz);
btf__free(btf);
- return rc;
+ return ret;
}
diff --git a/util/kernel_build_id.c b/util/kernel_build_id.c
index 7420da88..7861a4bd 100644
--- a/util/kernel_build_id.c
+++ b/util/kernel_build_id.c
@@ -69,7 +69,7 @@ int kernel_build_id_read(char out[KERNEL_BUILD_ID_STRING_MAX])
{
__u8 notes[KERNEL_NOTES_MAX];
size_t len = 0;
- int fd, rc;
+ int fd, ret;
if (!out)
return -EINVAL;
@@ -80,16 +80,16 @@ int kernel_build_id_read(char out[KERNEL_BUILD_ID_STRING_MAX])
ssize_t n = read(fd, notes + len, sizeof(notes) - len);
if (n < 0) {
- rc = -errno;
+ ret = -errno;
goto out;
}
if (!n)
break;
len += (size_t)n;
}
- rc = len == sizeof(notes) ? -E2BIG :
+ ret = len == sizeof(notes) ? -E2BIG :
kernel_build_id_from_notes(notes, len, out);
out:
close(fd);
- return rc;
+ return ret;
}
diff --git a/util/keyring.c b/util/keyring.c
index 9d248398..9726a605 100644
--- a/util/keyring.c
+++ b/util/keyring.c
@@ -124,11 +124,11 @@ int keyring_list(key_serial_t keyring,
{
key_serial_t *serials = NULL;
size_t n = 0, cap = 0, i;
- int rc;
+ int ret;
- rc = read_links(keyring, &serials, &n, &cap);
- if (rc)
- return rc;
+ ret = read_links(keyring, &serials, &n, &cap);
+ if (ret)
+ return ret;
for (i = 0; i < n; i++) {
const char *type, *description;
char desc[KEYRING_DESC_MAX];
@@ -148,11 +148,11 @@ int keyring_links(key_serial_t keyring, struct keyring_link **links,
struct keyring_link *out = NULL;
key_serial_t *serials = NULL;
size_t count = 0, cap = 0, i;
- int rc;
+ int ret;
- rc = read_links(keyring, &serials, &count, &cap);
- if (rc)
- return rc;
+ ret = read_links(keyring, &serials, &count, &cap);
+ if (ret)
+ return ret;
if (count) {
out = xcalloc(count, sizeof(*out));
if (!out) {
@@ -186,16 +186,16 @@ int keyring_cert_description(const __u8 *der, size_t der_len,
const char *type, *description;
char desc[KEYRING_DESC_MAX];
long probe;
- int rc;
+ int ret;
probe = sys_add_key("asymmetric", NULL, der, der_len,
KEY_SPEC_THREAD_KEYRING);
if (probe < 0)
return -errno;
- rc = describe_key((key_serial_t)probe, desc, sizeof(desc));
+ ret = describe_key((key_serial_t)probe, desc, sizeof(desc));
sys_keyctl(KEYCTL_UNLINK, probe, KEY_SPEC_THREAD_KEYRING, 0, 0);
- if (rc)
- return rc;
+ if (ret)
+ return ret;
split_describe(desc, &type, &description);
return strscpy(out, description, KEYRING_DESC_MAX) < 0 ? -ERANGE : 0;
}
@@ -222,13 +222,13 @@ int keyring_holds_cert(key_serial_t keyring,
const __u8 *der, size_t der_len)
{
struct holds_cert_ctx ctx = {};
- int rc;
+ int ret;
- rc = keyring_cert_description(der, der_len, ctx.want);
- if (!rc)
- rc = keyring_list(keyring, holds_cert_cb, &ctx);
- if (rc)
- return rc;
+ ret = keyring_cert_description(der, der_len, ctx.want);
+ if (!ret)
+ ret = keyring_list(keyring, holds_cert_cb, &ctx);
+ if (ret)
+ return ret;
return ctx.found ? 1 : 0;
}
@@ -237,13 +237,13 @@ key_serial_t keyring_find_cert(key_serial_t keyring,
size_t der_len)
{
struct holds_cert_ctx ctx = {};
- int rc;
+ int ret;
- rc = keyring_cert_description(der, der_len, ctx.want);
- if (!rc)
- rc = keyring_list(keyring, holds_cert_cb, &ctx);
- if (rc)
- return rc;
+ ret = keyring_cert_description(der, der_len, ctx.want);
+ if (!ret)
+ ret = keyring_list(keyring, holds_cert_cb, &ctx);
+ if (ret)
+ return ret;
return ctx.found ? ctx.serial : -ENOKEY;
}
@@ -259,7 +259,7 @@ int keyring_holds_exactly(key_serial_t keyring,
size_t links = 0, cap = 0, i, j;
key_serial_t *serials = NULL;
bool *matched = NULL;
- int rc = -ENOMEM;
+ int ret = -ENOMEM;
if (n) {
want = xcalloc(n, sizeof(*want));
@@ -268,13 +268,13 @@ int keyring_holds_exactly(key_serial_t keyring,
goto out;
}
for (i = 0; i < n; i++) {
- rc = keyring_cert_description(certs[i].der, certs[i].len,
- want[i]);
- if (rc)
+ ret = keyring_cert_description(certs[i].der, certs[i].len,
+ want[i]);
+ if (ret)
goto out;
}
- rc = read_links(keyring, &serials, &links, &cap);
- if (rc)
+ ret = read_links(keyring, &serials, &links, &cap);
+ if (ret)
goto out;
if (links != n)
goto out;
@@ -294,7 +294,7 @@ int keyring_holds_exactly(key_serial_t keyring,
goto out;
matched[j] = true;
}
- rc = 1;
+ ret = 1;
out:
if (serials)
xfree(serials, cap);
@@ -302,7 +302,7 @@ out:
xfree(want, n * sizeof(*want));
if (matched)
xfree(matched, n * sizeof(*matched));
- return rc;
+ return ret;
}
int keyring_unlink_key(key_serial_t keyring, key_serial_t key)
diff --git a/util/keys.c b/util/keys.c
index f183ddf5..fdec272f 100644
--- a/util/keys.c
+++ b/util/keys.c
@@ -42,27 +42,27 @@ struct keys_candidate {
int keys_read_der_fd(int fd, __u8 **out, size_t *out_sz)
{
- int rc = read_fd(fd, "certificate", KEYS_DER_MAX, out, out_sz);
+ int ret = read_fd(fd, "certificate", KEYS_DER_MAX, out, out_sz);
- if (!rc && !*out_sz) {
+ if (!ret && !*out_sz) {
xfree(*out, 1);
*out = NULL;
return -EINVAL;
}
- return rc;
+ return ret;
}
static int keys_read_der_at(int dirfd, const char *name, __u8 **out,
size_t *out_sz)
{
- int fd, rc;
+ int fd, ret;
fd = open_beneath(dirfd, name, O_RDONLY);
if (fd < 0)
return fd;
- rc = keys_read_der_fd(fd, out, out_sz);
+ ret = keys_read_der_fd(fd, out, out_sz);
close(fd);
- return rc;
+ return ret;
}
int keys_read_der(const char *path, __u8 **out,
@@ -77,10 +77,10 @@ int keys_read_der(const char *path, __u8 **out,
if (fd < 0)
return -errno;
if (fstat(fd, &st) < 0) {
- int rc = -errno;
+ int ret = -errno;
close(fd);
- return rc;
+ return ret;
}
if (!S_ISREG(st.st_mode) || st.st_size <= 0 ||
st.st_size > KEYS_DER_MAX) {
@@ -111,17 +111,17 @@ int keys_digest_der(const __u8 *der, size_t der_sz,
__u8 sha256[32], __u8 fingerprint[32])
{
struct shirudo_cert cert = {};
- int rc;
-
- rc = sha256_buffer(der, der_sz, sha256);
- if (rc)
- return rc;
- rc = cert_read_der(der, der_sz, &cert);
- if (rc)
- return rc;
- rc = cert_pubkey_digest(&cert, fingerprint);
+ int ret;
+
+ ret = sha256_buffer(der, der_sz, sha256);
+ if (ret)
+ return ret;
+ ret = cert_read_der(der, der_sz, &cert);
+ if (ret)
+ return ret;
+ ret = cert_pubkey_digest(&cert, fingerprint);
cert_free(&cert);
- return rc;
+ return ret;
}
/*
@@ -181,10 +181,10 @@ int keys_cert_read(const struct shirudo_trusted_cert *c,
{
const __u8 *der;
size_t len;
- int rc;
+ int ret;
- rc = keys_cert_der(c, &der, &len);
- return rc ? rc : cert_read_der(der, len, cert);
+ ret = keys_cert_der(c, &der, &len);
+ return ret ? ret : cert_read_der(der, len, cert);
}
/* The certificate at path, its digests, and its bytes kept for the set. */
@@ -193,16 +193,16 @@ static int keys_take_file(const char *path, __u8 sha256[32],
{
size_t der_sz = 0;
__u8 *der = NULL;
- int rc;
-
- rc = keys_read_der(path, &der, &der_sz);
- if (rc)
- return rc;
- rc = keys_digest_der(der, der_sz, sha256, fingerprint);
- if (!rc)
- rc = der_keep(sha256, der, der_sz);
+ int ret;
+
+ ret = keys_read_der(path, &der, &der_sz);
+ if (ret)
+ return ret;
+ ret = keys_digest_der(der, der_sz, sha256, fingerprint);
+ if (!ret)
+ ret = der_keep(sha256, der, der_sz);
xfree(der, der_sz);
- return rc;
+ return ret;
}
int keys_digest_file(const char *path, __u8 sha256[32],
@@ -210,14 +210,14 @@ int keys_digest_file(const char *path, __u8 sha256[32],
{
size_t der_sz = 0;
__u8 *der = NULL;
- int rc;
+ int ret;
- rc = keys_read_der(path, &der, &der_sz);
- if (rc)
- return rc;
- rc = keys_digest_der(der, der_sz, sha256, fingerprint);
+ ret = keys_read_der(path, &der, &der_sz);
+ if (ret)
+ return ret;
+ ret = keys_digest_der(der, der_sz, sha256, fingerprint);
xfree(der, der_sz);
- return rc;
+ return ret;
}
/* <dir>/<fingerprint hex><suffix>, the name a certificate has in a set. */
@@ -278,13 +278,13 @@ int keys_verify_vouch(const struct shirudo_trusted_set *set,
{
size_t payload_sz = 0, i;
__u8 *payload = NULL;
- int rc;
+ int ret;
- rc = keys_vouch_payload(der, der_sz, &payload, &payload_sz);
- if (rc)
- return rc;
- rc = -EKEYREJECTED;
- for (i = 0; i < set->n && rc; i++) {
+ ret = keys_vouch_payload(der, der_sz, &payload, &payload_sz);
+ if (ret)
+ return ret;
+ ret = -EKEYREJECTED;
+ for (i = 0; i < set->n && ret; i++) {
struct shirudo_cert cert = {};
if (keys_cert_read(&set->certs[i], &cert))
@@ -292,12 +292,12 @@ int keys_verify_vouch(const struct shirudo_trusted_set *set,
if (verify_detached(payload, payload_sz, sig, sig_sz,
&cert) == 0) {
memcpy(voucher, set->certs[i].fingerprint, 32);
- rc = 0;
+ ret = 0;
}
cert_free(&cert);
}
xfree(payload, payload_sz);
- return rc;
+ return ret;
}
static int cert_cmp(const void *a, const void *b)
@@ -323,14 +323,14 @@ static int set_add(struct shirudo_trusted_set *set, const char *path,
const __u8 voucher[32], const __u8 *der, size_t der_sz)
{
struct shirudo_trusted_cert *c;
- int rc;
+ int ret;
if (set->n >= KEYS_MAX)
return -E2BIG;
if (der) {
- rc = der_keep(sha256, der, der_sz);
- if (rc)
- return rc;
+ ret = der_keep(sha256, der, der_sz);
+ if (ret)
+ return ret;
}
c = &set->certs[set->n];
memset(c, 0, sizeof(*c));
@@ -410,7 +410,7 @@ static int admit_vouched(struct shirudo_trusted_set *set,
size_t sig_sz = 0;
__u8 *sig = NULL;
__u8 voucher[32];
- int rc;
+ int ret;
if (c->done)
continue;
@@ -424,15 +424,15 @@ static int admit_vouched(struct shirudo_trusted_set *set,
keys_read_der_at(c->dirfd, vouch, &sig, &sig_sz) :
keys_read_der(vouch, &sig, &sig_sz)))
continue;
- rc = keys_verify_vouch(set, c->der, c->der_sz,
- sig, sig_sz, voucher);
+ ret = keys_verify_vouch(set, c->der, c->der_sz,
+ sig, sig_sz, voucher);
xfree(sig, sig_sz);
- if (rc)
+ if (ret)
continue;
- rc = set_add(set, c->path, c->sha256, c->fingerprint,
- voucher, c->der, c->der_sz);
- if (rc)
- return rc;
+ ret = set_add(set, c->path, c->sha256, c->fingerprint,
+ voucher, c->der, c->der_sz);
+ if (ret)
+ return ret;
c->done = true;
progress = true;
}
@@ -465,32 +465,32 @@ static int scan_trusted(const char *keys_dir, const char *revoked_dir,
{
struct dirent **names = NULL;
char dir[PATH_MAX];
- int n, i, rc = 0;
+ int n, i, ret = 0;
if (strsprintf(dir, sizeof(dir), "%s/trusted", keys_dir) < 0)
return -ENAMETOOLONG;
n = scandir(dir, &names, select_der, alphasort);
if (n < 0)
return errno == ENOENT ? 0 : -errno;
- for (i = 0; i < n && !rc; i++) {
+ for (i = 0; i < n && !ret; i++) {
struct keys_candidate *c = &cand[*n_cand];
if (*n_cand >= KEYS_SCAN_MAX) {
- rc = -E2BIG;
+ ret = -E2BIG;
break;
}
c->dirfd = -1;
if (strsprintf(c->path, sizeof(c->path), "%s/%s", dir,
names[i]->d_name) < 0) {
- rc = -ENAMETOOLONG;
+ ret = -ENAMETOOLONG;
break;
}
- rc = keys_read_der(c->path, &c->der, &c->der_sz);
- if (rc)
+ ret = keys_read_der(c->path, &c->der, &c->der_sz);
+ if (ret)
break;
- rc = keys_digest_der(c->der, c->der_sz, c->sha256,
- c->fingerprint);
- if (rc) {
+ ret = keys_digest_der(c->der, c->der_sz, c->sha256,
+ c->fingerprint);
+ if (ret) {
xfree(c->der, c->der_sz);
c->der = NULL;
break;
@@ -505,7 +505,7 @@ static int scan_trusted(const char *keys_dir, const char *revoked_dir,
for (i = 0; i < n; i++)
libc_free(names[i]);
libc_free(names);
- return rc;
+ return ret;
}
/*
@@ -518,7 +518,7 @@ static int scan_trusted_at(int keys_fd, const char *display,
int *trusted_fd)
{
struct dirent **names = NULL;
- int n, i, rc = 0;
+ int n, i, ret = 0;
*trusted_fd = open_beneath(keys_fd, "trusted", O_RDONLY | O_DIRECTORY);
if (*trusted_fd == -ENOENT)
@@ -528,27 +528,27 @@ static int scan_trusted_at(int keys_fd, const char *display,
n = scandirat(*trusted_fd, ".", &names, select_der, alphasort);
if (n < 0)
return -errno;
- for (i = 0; i < n && !rc; i++) {
+ for (i = 0; i < n && !ret; i++) {
struct keys_candidate *c = &cand[*n_cand];
if (*n_cand >= KEYS_SCAN_MAX) {
- rc = -E2BIG;
+ ret = -E2BIG;
break;
}
c->dirfd = *trusted_fd;
if (strscpy(c->name, names[i]->d_name, sizeof(c->name)) < 0 ||
strsprintf(c->path, sizeof(c->path), "%s/trusted/%s",
display, names[i]->d_name) < 0) {
- rc = -ENAMETOOLONG;
+ ret = -ENAMETOOLONG;
break;
}
- rc = keys_read_der_at(*trusted_fd, c->name, &c->der,
- &c->der_sz);
- if (rc)
+ ret = keys_read_der_at(*trusted_fd, c->name, &c->der,
+ &c->der_sz);
+ if (ret)
break;
- rc = keys_digest_der(c->der, c->der_sz, c->sha256,
- c->fingerprint);
- if (rc) {
+ ret = keys_digest_der(c->der, c->der_sz, c->sha256,
+ c->fingerprint);
+ if (ret) {
xfree(c->der, c->der_sz);
c->der = NULL;
break;
@@ -558,7 +558,7 @@ static int scan_trusted_at(int keys_fd, const char *display,
for (i = 0; i < n; i++)
libc_free(names[i]);
libc_free(names);
- return rc;
+ return ret;
}
static int load_set(const char *primary, const char *keys_dir,
@@ -569,7 +569,7 @@ static int load_set(const char *primary, const char *keys_dir,
__u8 sha256[32], fingerprint[32];
char revoked[PATH_MAX];
size_t n_cand = 0;
- int rc;
+ int ret;
memset(set, 0, sizeof(*set));
if (!revoked_dir) {
@@ -578,13 +578,13 @@ static int load_set(const char *primary, const char *keys_dir,
return -ENAMETOOLONG;
revoked_dir = revoked;
}
- rc = keys_take_file(primary, sha256, fingerprint);
- if (rc)
- return rc;
+ ret = keys_take_file(primary, sha256, fingerprint);
+ if (ret)
+ return ret;
if (!keys_is_revoked(revoked_dir, fingerprint)) {
- rc = set_add(set, primary, sha256, fingerprint, NULL, NULL, 0);
- if (rc)
- return rc;
+ ret = set_add(set, primary, sha256, fingerprint, NULL, NULL, 0);
+ if (ret)
+ return ret;
}
set->n_revoked = count_der(revoked_dir);
if (!with_trusted)
@@ -593,12 +593,12 @@ static int load_set(const char *primary, const char *keys_dir,
cand = xcalloc(KEYS_SCAN_MAX, sizeof(*cand));
if (!cand)
return -ENOMEM;
- rc = scan_trusted(keys_dir, revoked_dir, set, cand, &n_cand);
- if (!rc)
- rc = admit_vouched(set, cand, n_cand);
+ ret = scan_trusted(keys_dir, revoked_dir, set, cand, &n_cand);
+ if (!ret)
+ ret = admit_vouched(set, cand, n_cand);
candidates_free(cand, n_cand);
- if (rc)
- return rc;
+ if (ret)
+ return ret;
sort:
if (set->n > 1)
qsort(set->certs, set->n, sizeof(set->certs[0]), cert_cmp);
@@ -618,15 +618,15 @@ static int load_set_at(const char *primary, int keys_fd, const char *display,
__u8 sha256[32], fingerprint[32];
int revoked_fd, trusted_fd = -1;
size_t n_cand = 0, i, kept = 0;
- int rc;
+ int ret;
memset(set, 0, sizeof(*set));
- rc = keys_take_file(primary, sha256, fingerprint);
- if (rc)
- return rc;
- rc = set_add(set, primary, sha256, fingerprint, NULL, NULL, 0);
- if (rc)
- return rc;
+ ret = keys_take_file(primary, sha256, fingerprint);
+ if (ret)
+ return ret;
+ ret = set_add(set, primary, sha256, fingerprint, NULL, NULL, 0);
+ if (ret)
+ return ret;
if (keys_fd == -ENOENT)
return 0;
revoked_fd = open_beneath(keys_fd, "revoked", O_RDONLY | O_DIRECTORY);
@@ -634,15 +634,15 @@ static int load_set_at(const char *primary, int keys_fd, const char *display,
if (with_trusted) {
cand = xcalloc(KEYS_SCAN_MAX, sizeof(*cand));
if (!cand) {
- rc = -ENOMEM;
+ ret = -ENOMEM;
goto out;
}
- rc = scan_trusted_at(keys_fd, display, cand, &n_cand,
- &trusted_fd);
- if (!rc)
- rc = admit_vouched(set, cand, n_cand);
+ ret = scan_trusted_at(keys_fd, display, cand, &n_cand,
+ &trusted_fd);
+ if (!ret)
+ ret = admit_vouched(set, cand, n_cand);
candidates_free(cand, n_cand);
- if (rc)
+ if (ret)
goto out;
}
for (i = 0; i < set->n; i++)
@@ -656,7 +656,7 @@ out:
close(trusted_fd);
if (revoked_fd >= 0)
close(revoked_fd);
- return rc;
+ return ret;
}
int shirudo_keys_load_image_at(const char *primary, int keys_fd,
@@ -670,7 +670,7 @@ int shirudo_keys_load_image_root(const char *primary, int root_fd,
bool with_trusted,
struct shirudo_trusted_set *set)
{
- int keys_fd, rc;
+ int keys_fd, ret;
keys_fd = open_beneath(root_fd, "keys", O_RDONLY | O_DIRECTORY);
if (keys_fd < 0 && keys_fd != -ENOENT) {
@@ -678,10 +678,10 @@ int shirudo_keys_load_image_root(const char *primary, int root_fd,
strerror(-keys_fd));
return keys_fd;
}
- rc = shirudo_keys_load_image_at(primary, keys_fd, with_trusted, set);
+ ret = shirudo_keys_load_image_at(primary, keys_fd, with_trusted, set);
if (keys_fd >= 0)
close(keys_fd);
- return rc;
+ return ret;
}
int keys_load(const char *keys_dir, const char *revoked_dir,
@@ -710,7 +710,7 @@ int keys_anchor_digest(const __u8 sha256[][32], size_t n,
{
__u8 sorted[KEYS_MAX][32];
size_t i;
- int rc;
+ int ret;
if (n == 1) {
memcpy(out, sha256[0], 32);
@@ -722,10 +722,10 @@ int keys_anchor_digest(const __u8 sha256[][32], size_t n,
for (i = 0; i < n; i++)
memcpy(sorted[i], sha256[i], 32);
qsort(sorted, n, 32, digest_cmp);
- rc = sha256_buffer(sorted, n * 32, out);
- if (rc)
+ ret = sha256_buffer(sorted, n * 32, out);
+ if (ret)
memset(out, 0, 32);
- return rc;
+ return ret;
}
int keys_set_digest(const struct shirudo_trusted_set *set,
@@ -751,27 +751,27 @@ int keys_install(const char *keys_dir, const __u8 *der,
__u8 sha256[32], fingerprint[32];
char vouch[PATH_MAX];
char dir[PATH_MAX];
- int rc;
+ int ret;
- rc = keys_digest_der(der, der_sz, sha256, fingerprint);
- if (rc)
- return rc;
+ ret = keys_digest_der(der, der_sz, sha256, fingerprint);
+ if (ret)
+ return ret;
if (strsprintf(dir, sizeof(dir), "%s/trusted", keys_dir) < 0)
return -ENAMETOOLONG;
- rc = seal_mkdir_p(dir, 0700);
- if (rc)
- return rc;
- rc = keys_path_for(dir, fingerprint, ".der", out, cap);
- if (!rc)
- rc = keys_path_for(dir, fingerprint, ".vouch", vouch,
- sizeof(vouch));
- if (rc)
- return rc;
- rc = keys_write_file(vouch, sig, sig_sz);
- if (rc)
- return rc;
- rc = keys_write_file(out, der, der_sz);
- if (rc)
+ ret = seal_mkdir_p(dir, 0700);
+ if (ret)
+ return ret;
+ ret = keys_path_for(dir, fingerprint, ".der", out, cap);
+ if (!ret)
+ ret = keys_path_for(dir, fingerprint, ".vouch", vouch,
+ sizeof(vouch));
+ if (ret)
+ return ret;
+ ret = keys_write_file(vouch, sig, sig_sz);
+ if (ret)
+ return ret;
+ ret = keys_write_file(out, der, der_sz);
+ if (ret)
unlink(vouch);
- return rc;
+ return ret;
}
diff --git a/util/kmodules.c b/util/kmodules.c
index faad40a2..3e9ae096 100644
--- a/util/kmodules.c
+++ b/util/kmodules.c
@@ -116,7 +116,7 @@ int kmodules_parse(char *buf, struct shirudo_kmod_set *set)
struct edge { __u16 user, dep; } *edges = NULL;
char *line, *end;
size_t i, j;
- int rc;
+ int ret;
memset(set, 0, sizeof(*set));
end = buf + strlen(buf);
@@ -129,7 +129,7 @@ int kmodules_parse(char *buf, struct shirudo_kmod_set *set)
set->deps = xmalloc(deps_cap * sizeof(*set->deps));
edges = xmalloc(edge_cap * sizeof(*edges));
if (!set->mods || !set->deps || !edges) {
- rc = -ENOMEM;
+ ret = -ENOMEM;
goto out;
}
@@ -158,7 +158,7 @@ int kmodules_parse(char *buf, struct shirudo_kmod_set *set)
sizeof(*set->mods));
if (!np) {
- rc = -ENOMEM;
+ ret = -ENOMEM;
goto out;
}
set->mods = np;
@@ -229,7 +229,7 @@ int kmodules_parse(char *buf, struct shirudo_kmod_set *set)
sizeof(*edges));
if (!np) {
- rc = -ENOMEM;
+ ret = -ENOMEM;
goto out;
}
edges = np;
@@ -253,7 +253,7 @@ int kmodules_parse(char *buf, struct shirudo_kmod_set *set)
sizeof(*set->deps));
if (!np) {
- rc = -ENOMEM;
+ ret = -ENOMEM;
goto out;
}
set->deps = np;
@@ -264,31 +264,31 @@ int kmodules_parse(char *buf, struct shirudo_kmod_set *set)
}
}
- rc = 0;
+ ret = 0;
out:
xfree(edges, edge_cap * sizeof(*edges));
- if (rc) {
+ if (ret) {
xfree(set->mods, mod_cap * sizeof(*set->mods));
xfree(set->deps, deps_cap * sizeof(*set->deps));
memset(set, 0, sizeof(*set));
}
- return rc;
+ return ret;
}
int kmodules_read(struct shirudo_kmod_set *set)
{
size_t buf_cap = 0, i;
char *buf = NULL;
- int rc;
+ int ret;
memset(set, 0, sizeof(*set));
- rc = slurp(&buf, &buf_cap);
- if (rc)
- return rc;
- rc = kmodules_parse(buf, set);
+ ret = slurp(&buf, &buf_cap);
+ if (ret)
+ return ret;
+ ret = kmodules_parse(buf, set);
xfree(buf, buf_cap);
- if (rc)
- return rc;
+ if (ret)
+ return ret;
/*
* Stat each /sys/module/<name>/ for its kernfs mtime, which the
diff --git a/util/paths.c b/util/paths.c
index 11674438..8266e847 100644
--- a/util/paths.c
+++ b/util/paths.c
@@ -46,12 +46,12 @@ int key_paths(const char *keys_dir,
char *pkey_path, size_t pkey_sz,
char *cert_path, size_t cert_sz)
{
- int rc;
+ int ret;
- rc = shirudo_key_path(pkey_path, pkey_sz, keys_dir,
- SIGNING_KEY_FILE);
- if (rc)
- return rc;
+ ret = shirudo_key_path(pkey_path, pkey_sz, keys_dir,
+ SIGNING_KEY_FILE);
+ if (ret)
+ return ret;
return shirudo_key_path(cert_path, cert_sz, keys_dir,
CERT_FILE);
}
diff --git a/util/preflight.c b/util/preflight.c
index d775c698..1acd7f90 100644
--- a/util/preflight.c
+++ b/util/preflight.c
@@ -220,15 +220,15 @@ static void check_cert_algorithm(struct shirudo_preflight_result *r)
for (i = 0; i < set.n; i++) {
struct shirudo_cert cert = {};
char name[64];
- int rc;
+ int ret;
if (keys_cert_read(&set.certs[i], &cert)) {
fail(r, c, "%s: cannot parse", set.certs[i].path);
return;
}
- rc = cert_key_algorithm(&cert, name, sizeof(name));
+ ret = cert_key_algorithm(&cert, name, sizeof(name));
cert_free(&cert);
- if (rc) {
+ if (ret) {
fail(r, c, "%s: cannot determine public-key algorithm",
set.certs[i].path);
return;
@@ -270,28 +270,28 @@ static void check_cert_kernel_algo(struct shirudo_preflight_result *r)
const __u8 *der = NULL;
size_t der_sz = 0;
long key;
- int rc;
+ int ret;
- rc = keys_cert_der(&set.certs[i], &der, &der_sz);
- if (rc) {
- fail(r, c, "%s: %s", set.certs[i].path, strerror(-rc));
+ ret = keys_cert_der(&set.certs[i], &der, &der_sz);
+ if (ret) {
+ fail(r, c, "%s: %s", set.certs[i].path, strerror(-ret));
return;
}
key = syscall(__NR_add_key, "asymmetric", "", der, der_sz,
(long)KEY_SPEC_THREAD_KEYRING);
- rc = key < 0 ? errno : 0;
+ ret = key < 0 ? errno : 0;
syscall(__NR_keyctl, KEYCTL_CLEAR,
(long)KEY_SPEC_THREAD_KEYRING, 0L, 0L, 0L);
- if (!rc)
+ if (!ret)
continue;
- if (rc == ENOENT || rc == ENOPKG)
+ if (ret == ENOENT || ret == ENOPKG)
fail(r, c,
"kernel cannot verify the public-key algorithm of %s (ML-DSA certs need CONFIG_CRYPTO_MLDSA=y and CONFIG_CRYPTO_SHA512=y)",
set.certs[i].path);
else
fail(r, c, "kernel rejected %s: %s "
"(add_key asymmetric)", set.certs[i].path,
- strerror(rc));
+ strerror(ret));
return;
}
pass(c);
diff --git a/util/report.c b/util/report.c
index 95b40146..cd157105 100644
--- a/util/report.c
+++ b/util/report.c
@@ -32,7 +32,7 @@ int report_emit(const char *path, const struct shirudo_op_report *r)
const char *vlog = r->verifier_log ? r->verifier_log : "";
size_t loglen = strlen(vlog);
size_t cap = loglen * 6 + 16384; /* worst-case escape + slack */
- int fd, rc = 0;
+ int fd, ret = 0;
char *buf;
if (strsprintf(nv_index, sizeof(nv_index), "0x%08X",
@@ -102,17 +102,17 @@ int report_emit(const char *path, const struct shirudo_op_report *r)
xfree(buf, cap);
return fd;
}
- rc = write_complete(fd, buf, strlen(buf));
- if (!rc)
- rc = write_complete(fd, "\n", 1);
- if (close(fd) != 0 && !rc)
- rc = -errno;
- if (rc) {
- pr_err("report: write %s: %s", path, strerror(-rc));
+ ret = write_complete(fd, buf, strlen(buf));
+ if (!ret)
+ ret = write_complete(fd, "\n", 1);
+ if (close(fd) != 0 && !ret)
+ ret = -errno;
+ if (ret) {
+ pr_err("report: write %s: %s", path, strerror(-ret));
unlink(path);
}
xfree(buf, cap);
- return rc;
+ return ret;
}
void report_set_log(struct shirudo_op_report *r, const char *log)
diff --git a/util/seal.c b/util/seal.c
index 71e6ec49..495df39f 100644
--- a/util/seal.c
+++ b/util/seal.c
@@ -55,7 +55,7 @@ static int seal_label_cb(const char *path, const struct stat *sb,
int typeflag, struct FTW *ftwbuf)
{
char label[SEAL_LABEL_LEN];
- int rc;
+ int ret;
(void)typeflag;
(void)ftwbuf;
@@ -78,10 +78,10 @@ static int seal_label_cb(const char *path, const struct stat *sb,
"ignored", path);
return 0;
}
- rc = seal_label(path);
- if (rc) {
- pr_err("seal: label %s: %s", path, strerror(-rc));
- seal_walk_error = rc;
+ ret = seal_label(path);
+ if (ret) {
+ pr_err("seal: label %s: %s", path, strerror(-ret));
+ seal_walk_error = ret;
return 1;
}
return 0;
@@ -170,7 +170,7 @@ static int seal_same(int dfd, int fd)
static int seal_open_dir(const char *path, bool create, mode_t mode)
{
char buf[PATH_MAX], *comp, *save;
- int dfd, nfd, rc = 0;
+ int dfd, nfd, ret = 0;
bool created;
if (strscpy(buf, path, sizeof(buf)) < 0)
@@ -183,31 +183,31 @@ static int seal_open_dir(const char *path, bool create, mode_t mode)
comp = strtok_r(NULL, "/", &save)) {
created = create && mkdirat(dfd, comp, mode) == 0;
if (create && !created && errno != EEXIST) {
- rc = -errno;
+ ret = -errno;
break;
}
nfd = openat(dfd, comp, O_RDONLY | O_DIRECTORY | O_NOFOLLOW |
O_CLOEXEC);
if (nfd < 0) {
- rc = -errno;
- if (rc == -ELOOP || rc == -ENOTDIR)
+ ret = -errno;
+ if (ret == -ELOOP || ret == -ENOTDIR)
pr_err("%s: %s is not a directory of shirudo's "
"(foreign entry in sealed state)", path,
comp);
break;
}
- rc = created ? seal_inherit(dfd, nfd) : seal_same(dfd, nfd);
- if (rc == -EPERM)
+ ret = created ? seal_inherit(dfd, nfd) : seal_same(dfd, nfd);
+ if (ret == -EPERM)
pr_err("%s: %s carries no label (foreign entry in "
"sealed state); refusing", path, comp);
close(dfd);
dfd = nfd;
- if (rc)
+ if (ret)
break;
}
- if (rc) {
+ if (ret) {
close(dfd);
- return rc;
+ return ret;
}
return dfd;
}
@@ -310,33 +310,33 @@ int seal_output_open(const char *path, int flags, mode_t mode)
{
const char *name;
struct stat st;
- int dfd, fd, rc;
+ int dfd, fd, ret;
dfd = seal_open_parent(path, &name);
if (dfd < 0)
return dfd;
- rc = seal_fsealed(dfd);
- if (rc)
+ ret = seal_fsealed(dfd);
+ if (ret)
goto out_dir;
fd = openat(dfd, name, (flags & ~O_TRUNC) | O_NOFOLLOW | O_CLOEXEC,
mode);
if (fd < 0) {
- rc = -errno;
+ ret = -errno;
goto out_dir;
}
if (fstat(fd, &st)) {
- rc = -errno;
+ ret = -errno;
goto out_fd;
}
if (!S_ISREG(st.st_mode)) {
- rc = -EINVAL;
+ ret = -EINVAL;
goto out_fd;
}
- rc = seal_fsealed(fd);
- if (rc)
+ ret = seal_fsealed(fd);
+ if (ret)
goto out_fd;
if ((flags & O_TRUNC) && ftruncate(fd, 0)) {
- rc = -errno;
+ ret = -errno;
goto out_fd;
}
close(dfd);
@@ -345,17 +345,17 @@ out_fd:
close(fd);
out_dir:
close(dfd);
- if (rc > 0) {
+ if (ret > 0) {
pr_err("%s: refusing to write sealed state", path);
- rc = -EPERM;
+ ret = -EPERM;
}
- return rc;
+ return ret;
}
int seal_open(const char *path, int flags, mode_t mode)
{
const char *name;
- int dfd, fd, rc;
+ int dfd, fd, ret;
dfd = seal_open_parent(path, &name);
if (dfd < 0)
@@ -364,32 +364,32 @@ int seal_open(const char *path, int flags, mode_t mode)
O_NONBLOCK | O_CLOEXEC, mode);
if (fd >= 0) {
if (flags & O_EXCL) {
- rc = -EEXIST;
+ ret = -EEXIST;
} else {
- rc = seal_regular(fd);
- if (!rc)
- rc = seal_same(dfd, fd);
- if (rc == -EPERM)
+ ret = seal_regular(fd);
+ if (!ret)
+ ret = seal_same(dfd, fd);
+ if (ret == -EPERM)
pr_err("%s: carries no label (foreign entry "
"in sealed state); refusing", path);
- if (!rc && (flags & O_TRUNC) && ftruncate(fd, 0))
- rc = -errno;
+ if (!ret && (flags & O_TRUNC) && ftruncate(fd, 0))
+ ret = -errno;
}
} else if (errno == ENOENT && (flags & O_CREAT)) {
fd = openat(dfd, name, flags | O_EXCL | O_NOFOLLOW | O_CLOEXEC,
mode);
- rc = fd < 0 ? -errno : seal_inherit(dfd, fd);
+ ret = fd < 0 ? -errno : seal_inherit(dfd, fd);
} else {
- rc = -errno;
- if (rc == -ELOOP)
+ ret = -errno;
+ if (ret == -ELOOP)
pr_err("%s: is a symbolic link (foreign entry in "
"sealed state); refusing", path);
}
close(dfd);
- if (rc) {
+ if (ret) {
if (fd >= 0)
close(fd);
- return rc;
+ return ret;
}
return fd;
}
@@ -397,23 +397,23 @@ int seal_open(const char *path, int flags, mode_t mode)
int seal_open_read(const char *path)
{
const char *name;
- int dfd, fd, rc;
+ int dfd, fd, ret;
dfd = seal_open_parent(path, &name);
if (dfd < 0)
return dfd;
fd = openat(dfd, name, O_RDONLY | O_NOFOLLOW | O_NONBLOCK | O_CLOEXEC);
- rc = fd < 0 ? -errno : seal_regular(fd);
- if (!rc)
- rc = seal_same(dfd, fd);
+ ret = fd < 0 ? -errno : seal_regular(fd);
+ if (!ret)
+ ret = seal_same(dfd, fd);
close(dfd);
- if (rc) {
+ if (ret) {
if (fd >= 0)
close(fd);
- if (rc == -EPERM || rc == -ELOOP)
+ if (ret == -EPERM || ret == -ELOOP)
pr_err("%s: not shirudo's own (foreign entry in sealed "
"state); refusing to read it", path);
- return rc;
+ return ret;
}
return fd;
}
@@ -443,7 +443,7 @@ int seal_write_file(const char *path, const void *data, size_t len,
{
char tmp[NAME_MAX + 1];
const char *name;
- int dfd, fd, rc;
+ int dfd, fd, ret;
dfd = seal_open_parent(path, &name);
if (dfd < 0)
@@ -455,23 +455,23 @@ int seal_write_file(const char *path, const void *data, size_t len,
fd = openat(dfd, tmp, O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC |
O_NOFOLLOW, mode);
if (fd < 0) {
- rc = -errno;
+ ret = -errno;
close(dfd);
- return rc;
+ return ret;
}
- rc = seal_inherit(dfd, fd);
- if (!rc)
- rc = write_complete(fd, data, len);
- if (!rc && fsync(fd))
- rc = -errno;
- if (close(fd) && !rc)
- rc = -errno;
- if (!rc && renameat(dfd, tmp, dfd, name))
- rc = -errno;
- if (!rc && fsync(dfd))
- rc = -errno;
- if (rc)
+ ret = seal_inherit(dfd, fd);
+ if (!ret)
+ ret = write_complete(fd, data, len);
+ if (!ret && fsync(fd))
+ ret = -errno;
+ if (close(fd) && !ret)
+ ret = -errno;
+ if (!ret && renameat(dfd, tmp, dfd, name))
+ ret = -errno;
+ if (!ret && fsync(dfd))
+ ret = -errno;
+ if (ret)
unlinkat(dfd, tmp, 0);
close(dfd);
- return rc;
+ return ret;
}
diff --git a/util/serializer.c b/util/serializer.c
index 915708d9..2a489d55 100644
--- a/util/serializer.c
+++ b/util/serializer.c
@@ -20,13 +20,13 @@ int serializer_lock_acquire_at(const char *dir, __u32 map_id)
{
char name[64];
struct stat st;
- int dir_fd, fd, rc;
+ int dir_fd, fd, ret;
if (!dir || !dir[0] || map_id == 0)
return -EINVAL;
- rc = seal_mkdir_p(dir, 0700);
- if (rc)
- return rc;
+ ret = seal_mkdir_p(dir, 0700);
+ if (ret)
+ return ret;
dir_fd = open(dir, O_RDONLY | O_DIRECTORY | O_CLOEXEC | O_NOFOLLOW);
if (dir_fd < 0)
return -errno;
@@ -36,20 +36,20 @@ int serializer_lock_acquire_at(const char *dir, __u32 map_id)
}
fd = openat(dir_fd, name, O_CREAT | O_RDWR | O_CLOEXEC | O_NOFOLLOW, 0600);
if (fd < 0) {
- rc = -errno;
+ ret = -errno;
close(dir_fd);
- return rc;
+ return ret;
}
- rc = seal_inherit(dir_fd, fd);
+ ret = seal_inherit(dir_fd, fd);
close(dir_fd);
- if (rc) {
+ if (ret) {
close(fd);
- return rc;
+ return ret;
}
if (fstat(fd, &st) != 0) {
- rc = -errno;
+ ret = -errno;
close(fd);
- return rc;
+ return ret;
}
if (!S_ISREG(st.st_mode)) {
close(fd);
@@ -57,9 +57,9 @@ int serializer_lock_acquire_at(const char *dir, __u32 map_id)
}
/* The open fd owns the lock; callers release it with close(). */
if (flock(fd, LOCK_EX | LOCK_NB) != 0) {
- rc = (errno == EWOULDBLOCK || errno == EAGAIN) ? -EBUSY : -errno;
+ ret = (errno == EWOULDBLOCK || errno == EAGAIN) ? -EBUSY : -errno;
close(fd);
- return rc;
+ return ret;
}
return fd;
}
diff --git a/util/sign.c b/util/sign.c
index a617e605..01dcd3b3 100644
--- a/util/sign.c
+++ b/util/sign.c
@@ -70,21 +70,21 @@ static void display_openssl_errors(void)
int open_signing_key(const char *pkey_path)
{
struct stat st;
- int fd, rc;
+ int fd, ret;
/* A FIFO in its place would block open() before fstat() refuses it. */
fd = open(pkey_path, O_RDONLY | O_CLOEXEC | O_NONBLOCK);
if (fd < 0) {
- rc = -errno;
+ ret = -errno;
pr_err("open private key %s: %s", pkey_path, strerror(errno));
- return rc;
+ return ret;
}
if (fstat(fd, &st)) {
- rc = -errno;
+ ret = -errno;
pr_err("stat private key %s: %s", pkey_path, strerror(errno));
goto err;
}
- rc = -EPERM;
+ ret = -EPERM;
if (!S_ISREG(st.st_mode)) {
pr_err("signing key %s is not a regular file", pkey_path);
goto err;
@@ -98,7 +98,7 @@ int open_signing_key(const char *pkey_path)
return fd;
err:
close(fd);
- return rc;
+ return ret;
}
static EVP_PKEY *read_private_key(const char *pkey_path)
diff --git a/util/string.c b/util/string.c
index de1c08ca..28e8e771 100644
--- a/util/string.c
+++ b/util/string.c
@@ -76,12 +76,12 @@ int parse_s64(const char *s, size_t len, __s64 min, __s64 max, __s64 *out)
bool neg = len && s[0] == '-';
__u64 v;
__s64 r;
- int rc;
+ int ret;
- rc = parse_base(s + neg, len - neg, 10,
- neg ? (__u64)INT64_MAX + 1 : (__u64)INT64_MAX, &v);
- if (rc)
- return rc;
+ ret = parse_base(s + neg, len - neg, 10,
+ neg ? (__u64)INT64_MAX + 1 : (__u64)INT64_MAX, &v);
+ if (ret)
+ return ret;
if (!neg)
r = (__s64)v;
else if (v == (__u64)INT64_MAX + 1)
diff --git a/util/tamper.c b/util/tamper.c
index bd4c5d91..fea68cb3 100644
--- a/util/tamper.c
+++ b/util/tamper.c
@@ -112,29 +112,29 @@ int tamper_read(struct shirudo_tamper_counts *out)
{
struct bpf_map_info info = {};
__u32 len = sizeof(info);
- int fd, rc;
+ int fd, ret;
__u32 key;
memset(out, 0, sizeof(*out));
fd = bpf_obj_get(TAMPER_PIN);
if (fd < 0)
return -errno;
- rc = bpf_map_get_info_by_fd(fd, &info, &len);
- if (rc) {
- rc = -errno;
+ ret = bpf_map_get_info_by_fd(fd, &info, &len);
+ if (ret) {
+ ret = -errno;
} else if (info.max_entries != SHIRUDO_TAMPER_MAX ||
info.value_size != sizeof(out->count[0])) {
- rc = -EPROTO;
+ ret = -EPROTO;
} else {
for (key = 0; key < SHIRUDO_TAMPER_MAX; key++) {
- rc = bpf_map_lookup_elem(fd, &key, &out->count[key]);
- if (rc) {
- rc = -errno;
+ ret = bpf_map_lookup_elem(fd, &key, &out->count[key]);
+ if (ret) {
+ ret = -errno;
break;
}
out->total += out->count[key];
}
}
close(fd);
- return rc;
+ return ret;
}
diff --git a/util/tpm.c b/util/tpm.c
index d5126e4f..365dcabc 100644
--- a/util/tpm.c
+++ b/util/tpm.c
@@ -57,7 +57,7 @@ static int open_tpm(struct shirudo_tpm **out, bool quiet)
{
char tcti[TPM_TCTI_MAX];
struct shirudo_tpm *t;
- TSS2_RC rc;
+ TSS2_RC ret;
int err;
/*
@@ -81,18 +81,18 @@ static int open_tpm(struct shirudo_tpm **out, bool quiet)
t = xcalloc(1, sizeof(*t));
if (!t)
return -ENOMEM;
- rc = Tss2_TctiLdr_Initialize(tcti, &t->tcti);
- if (rc != TSS2_RC_SUCCESS) {
+ ret = Tss2_TctiLdr_Initialize(tcti, &t->tcti);
+ if (ret != TSS2_RC_SUCCESS) {
if (!quiet)
pr_err("tpm: TctiLdr_Initialize(%s): rc=0x%08x", tcti,
- (__u32)rc);
+ (__u32)ret);
xfree(t, sizeof(*t));
return -EIO;
}
- rc = Esys_Initialize(&t->esys, t->tcti, NULL);
- if (rc != TSS2_RC_SUCCESS) {
+ ret = Esys_Initialize(&t->esys, t->tcti, NULL);
+ if (ret != TSS2_RC_SUCCESS) {
if (!quiet)
- pr_err("tpm: Esys_Initialize: rc=0x%08x", (__u32)rc);
+ pr_err("tpm: Esys_Initialize: rc=0x%08x", (__u32)ret);
Tss2_TctiLdr_Finalize(&t->tcti);
xfree(t, sizeof(*t));
return -EIO;
@@ -136,20 +136,20 @@ int tpm_nv_set_writer(struct shirudo_tpm *t,
return 0;
}
-static bool rc_is(TSS2_RC rc, TSS2_RC code)
+static bool rc_is(TSS2_RC ret, TSS2_RC code)
{
- if ((rc & 0xFFFF0000u) != 0)
+ if ((ret & 0xFFFF0000u) != 0)
return false; /* not a TPM-layer code */
- if (rc & TPM2_RC_FMT1)
- return (rc & 0x0BFu) == (code & 0x0BFu);
- return (rc & 0xFFFu) == code;
+ if (ret & TPM2_RC_FMT1)
+ return (ret & 0x0BFu) == (code & 0x0BFu);
+ return (ret & 0xFFFu) == code;
}
-static bool rc_is_auth_failure(TSS2_RC rc)
+static bool rc_is_auth_failure(TSS2_RC ret)
{
- return rc_is(rc, TPM2_RC_BAD_AUTH) || rc_is(rc, TPM2_RC_AUTH_FAIL) ||
- rc_is(rc, TPM2_RC_NV_AUTHORIZATION) ||
- rc_is(rc, TPM2_RC_POLICY_FAIL);
+ return rc_is(ret, TPM2_RC_BAD_AUTH) || rc_is(ret, TPM2_RC_AUTH_FAIL) ||
+ rc_is(ret, TPM2_RC_NV_AUTHORIZATION) ||
+ rc_is(ret, TPM2_RC_POLICY_FAIL);
}
static void pcr_selection(__u32 mask, TPML_PCR_SELECTION *sel)
@@ -169,15 +169,15 @@ int tpm_pcr_read(struct shirudo_tpm *t, __u32 pcr,
TPML_PCR_SELECTION sel;
TPML_DIGEST *values = NULL;
UINT32 counter;
- TSS2_RC rc;
+ TSS2_RC ret;
if (pcr >= 24)
return -EINVAL;
pcr_selection(1u << pcr, &sel);
- rc = Esys_PCR_Read(t->esys, ESYS_TR_NONE, ESYS_TR_NONE, ESYS_TR_NONE,
- &sel, &counter, NULL, &values);
- if (rc != TSS2_RC_SUCCESS) {
- pr_err("tpm: PCR_Read(%u): rc=0x%08x", pcr, (__u32)rc);
+ ret = Esys_PCR_Read(t->esys, ESYS_TR_NONE, ESYS_TR_NONE, ESYS_TR_NONE,
+ &sel, &counter, NULL, &values);
+ if (ret != TSS2_RC_SUCCESS) {
+ pr_err("tpm: PCR_Read(%u): rc=0x%08x", pcr, (__u32)ret);
return -EIO;
}
if (values->count != 1 || values->digests[0].size != 32) {
@@ -194,16 +194,16 @@ int tpm_pcr_extend(struct shirudo_tpm *t, __u32 pcr,
const __u8 digest[32])
{
TPML_DIGEST_VALUES dv = { .count = 1 };
- TSS2_RC rc;
+ TSS2_RC ret;
if (pcr >= 24)
return -EINVAL;
dv.digests[0].hashAlg = TPM2_ALG_SHA256;
memcpy(dv.digests[0].digest.sha256, digest, 32);
- rc = Esys_PCR_Extend(t->esys, ESYS_TR_PCR0 + pcr, ESYS_TR_PASSWORD,
- ESYS_TR_NONE, ESYS_TR_NONE, &dv);
- if (rc != TSS2_RC_SUCCESS) {
- pr_err("tpm: PCR_Extend(%u): rc=0x%08x", pcr, (__u32)rc);
+ ret = Esys_PCR_Extend(t->esys, ESYS_TR_PCR0 + pcr, ESYS_TR_PASSWORD,
+ ESYS_TR_NONE, ESYS_TR_NONE, &dv);
+ if (ret != TSS2_RC_SUCCESS) {
+ pr_err("tpm: PCR_Extend(%u): rc=0x%08x", pcr, (__u32)ret);
return -EIO;
}
return 0;
@@ -213,14 +213,14 @@ int shirudo_tpm_boot_identity(struct shirudo_tpm *t, __u32 *reset,
__u32 *restart)
{
TPMS_TIME_INFO *info = NULL;
- TSS2_RC rc;
+ TSS2_RC ret;
if (!t || !reset || !restart)
return -EINVAL;
- rc = Esys_ReadClock(t->esys, ESYS_TR_NONE, ESYS_TR_NONE, ESYS_TR_NONE,
- &info);
- if (rc != TSS2_RC_SUCCESS) {
- pr_err("tpm: ReadClock: rc=0x%08x", (__u32)rc);
+ ret = Esys_ReadClock(t->esys, ESYS_TR_NONE, ESYS_TR_NONE, ESYS_TR_NONE,
+ &info);
+ if (ret != TSS2_RC_SUCCESS) {
+ pr_err("tpm: ReadClock: rc=0x%08x", (__u32)ret);
return -EIO;
}
*reset = info->clockInfo.resetCount;
@@ -232,12 +232,12 @@ int shirudo_tpm_boot_identity(struct shirudo_tpm *t, __u32 *reset,
int tpm_reset_count(struct shirudo_tpm *t, __u32 *out)
{
TPMS_TIME_INFO *info = NULL;
- TSS2_RC rc;
+ TSS2_RC ret;
- rc = Esys_ReadClock(t->esys, ESYS_TR_NONE, ESYS_TR_NONE, ESYS_TR_NONE,
- &info);
- if (rc != TSS2_RC_SUCCESS) {
- pr_err("tpm: ReadClock: rc=0x%08x", (__u32)rc);
+ ret = Esys_ReadClock(t->esys, ESYS_TR_NONE, ESYS_TR_NONE, ESYS_TR_NONE,
+ &info);
+ if (ret != TSS2_RC_SUCCESS) {
+ pr_err("tpm: ReadClock: rc=0x%08x", (__u32)ret);
return -EIO;
}
*out = info->clockInfo.resetCount;
@@ -247,15 +247,15 @@ int tpm_reset_count(struct shirudo_tpm *t, __u32 *out)
static int nv_handle(struct shirudo_tpm *t, __u32 index, ESYS_TR *out)
{
- TSS2_RC rc;
+ TSS2_RC ret;
- rc = Esys_TR_FromTPMPublic(t->esys, index, ESYS_TR_NONE, ESYS_TR_NONE,
- ESYS_TR_NONE, out);
- if (rc_is(rc, TPM2_RC_HANDLE))
+ ret = Esys_TR_FromTPMPublic(t->esys, index, ESYS_TR_NONE, ESYS_TR_NONE,
+ ESYS_TR_NONE, out);
+ if (rc_is(ret, TPM2_RC_HANDLE))
return -ENOENT; /* quiet: undefined is normal */
- if (rc != TSS2_RC_SUCCESS) {
+ if (ret != TSS2_RC_SUCCESS) {
pr_err("tpm: TR_FromTPMPublic(0x%08x): rc=0x%08x", index,
- (__u32)rc);
+ (__u32)ret);
return -EIO;
}
return 0;
@@ -267,7 +267,7 @@ int tpm_nv_info(struct shirudo_tpm *t, __u32 index,
TPM2B_NV_PUBLIC *pub = NULL;
TPM2B_NAME *name = NULL;
ESYS_TR nv;
- TSS2_RC rc;
+ TSS2_RC ret;
int err;
memset(info, 0, sizeof(*info));
@@ -276,12 +276,12 @@ int tpm_nv_info(struct shirudo_tpm *t, __u32 index,
return 0;
if (err)
return err;
- rc = Esys_NV_ReadPublic(t->esys, nv, ESYS_TR_NONE, ESYS_TR_NONE,
- ESYS_TR_NONE, &pub, &name);
+ ret = Esys_NV_ReadPublic(t->esys, nv, ESYS_TR_NONE, ESYS_TR_NONE,
+ ESYS_TR_NONE, &pub, &name);
Esys_TR_Close(t->esys, &nv);
- if (rc != TSS2_RC_SUCCESS) {
+ if (ret != TSS2_RC_SUCCESS) {
pr_err("tpm: NV_ReadPublic(0x%08x): rc=0x%08x", index,
- (__u32)rc);
+ (__u32)ret);
return -EIO;
}
info->defined = true;
@@ -302,7 +302,7 @@ int tpm_nv_info(struct shirudo_tpm *t, __u32 index,
static int owner_auth_set(struct shirudo_tpm *t, const void *auth, size_t len)
{
TPM2B_AUTH owner = {};
- TSS2_RC rc;
+ TSS2_RC ret;
if (len > sizeof(owner.buffer))
return -EINVAL;
@@ -310,10 +310,10 @@ static int owner_auth_set(struct shirudo_tpm *t, const void *auth, size_t len)
memcpy(owner.buffer, auth, len);
owner.size = (__u16)len;
}
- rc = Esys_TR_SetAuth(t->esys, ESYS_TR_RH_OWNER, &owner);
+ ret = Esys_TR_SetAuth(t->esys, ESYS_TR_RH_OWNER, &owner);
explicit_bzero(owner.buffer, sizeof(owner.buffer));
- if (rc != TSS2_RC_SUCCESS) {
- pr_err("tpm: TR_SetAuth(owner): rc=0x%08x", (__u32)rc);
+ if (ret != TSS2_RC_SUCCESS) {
+ pr_err("tpm: TR_SetAuth(owner): rc=0x%08x", (__u32)ret);
return -EIO;
}
return 0;
@@ -326,17 +326,17 @@ static void owner_auth_clear(struct shirudo_tpm *t)
Esys_TR_SetAuth(t->esys, ESYS_TR_RH_OWNER, &empty);
}
-static int owner_auth_error(const char *op, __u32 index, TSS2_RC rc)
+static int owner_auth_error(const char *op, __u32 index, TSS2_RC ret)
{
- if (rc_is_auth_failure(rc)) {
+ if (rc_is_auth_failure(ret)) {
pr_err("tpm: %s(0x%08x): owner-hierarchy authorization "
"failed (rc=0x%08x). This TPM has owner auth set; "
"supply it via tpm.owner_auth in %s (or "
"SHIRUDO_TPM_OWNER_AUTH), or clear the TPM owner "
- "auth.", op, index, (__u32)rc, CONF_PATH);
+ "auth.", op, index, (__u32)ret, CONF_PATH);
return -EACCES;
}
- pr_err("tpm: %s(0x%08x): rc=0x%08x", op, index, (__u32)rc);
+ pr_err("tpm: %s(0x%08x): rc=0x%08x", op, index, (__u32)ret);
return -EIO;
}
@@ -347,7 +347,7 @@ int tpm_nv_define(struct shirudo_tpm *t, __u32 index,
TPM2B_NV_PUBLIC pub = {};
TPM2B_AUTH nv_auth = {};
ESYS_TR nv = ESYS_TR_NONE;
- TSS2_RC rc;
+ TSS2_RC ret;
int err;
err = owner_auth_set(t, owner_auth, owner_auth_len);
@@ -359,12 +359,12 @@ int tpm_nv_define(struct shirudo_tpm *t, __u32 index,
pub.nvPublic.authPolicy.size = 32;
memcpy(pub.nvPublic.authPolicy.buffer, policy, 32);
pub.nvPublic.dataSize = TPM_NV_DIGEST_LEN;
- rc = Esys_NV_DefineSpace(t->esys, ESYS_TR_RH_OWNER, ESYS_TR_PASSWORD,
- ESYS_TR_NONE, ESYS_TR_NONE, &nv_auth, &pub,
- &nv);
+ ret = Esys_NV_DefineSpace(t->esys, ESYS_TR_RH_OWNER, ESYS_TR_PASSWORD,
+ ESYS_TR_NONE, ESYS_TR_NONE, &nv_auth, &pub,
+ &nv);
owner_auth_clear(t);
- if (rc != TSS2_RC_SUCCESS)
- return owner_auth_error("NV_DefineSpace", index, rc);
+ if (ret != TSS2_RC_SUCCESS)
+ return owner_auth_error("NV_DefineSpace", index, ret);
Esys_TR_Close(t->esys, &nv);
return 0;
}
@@ -373,7 +373,7 @@ int tpm_nv_undefine(struct shirudo_tpm *t, __u32 index,
const void *owner_auth, size_t owner_auth_len)
{
ESYS_TR nv;
- TSS2_RC rc;
+ TSS2_RC ret;
int err;
err = nv_handle(t, index, &nv);
@@ -384,13 +384,13 @@ int tpm_nv_undefine(struct shirudo_tpm *t, __u32 index,
Esys_TR_Close(t->esys, &nv);
return err;
}
- rc = Esys_NV_UndefineSpace(t->esys, ESYS_TR_RH_OWNER, nv,
- ESYS_TR_PASSWORD, ESYS_TR_NONE,
- ESYS_TR_NONE);
+ ret = Esys_NV_UndefineSpace(t->esys, ESYS_TR_RH_OWNER, nv,
+ ESYS_TR_PASSWORD, ESYS_TR_NONE,
+ ESYS_TR_NONE);
owner_auth_clear(t);
- if (rc != TSS2_RC_SUCCESS) {
+ if (ret != TSS2_RC_SUCCESS) {
Esys_TR_Close(t->esys, &nv);
- return owner_auth_error("NV_UndefineSpace", index, rc);
+ return owner_auth_error("NV_UndefineSpace", index, ret);
}
return 0;
}
@@ -399,19 +399,19 @@ int tpm_nv_read(struct shirudo_tpm *t, __u32 index, __u8 out[32])
{
TPM2B_MAX_NV_BUFFER *data = NULL;
ESYS_TR nv;
- TSS2_RC rc;
+ TSS2_RC ret;
int err;
err = nv_handle(t, index, &nv);
if (err)
return err;
- rc = Esys_NV_Read(t->esys, nv, nv, ESYS_TR_PASSWORD, ESYS_TR_NONE,
- ESYS_TR_NONE, TPM_NV_DIGEST_LEN, 0, &data);
+ ret = Esys_NV_Read(t->esys, nv, nv, ESYS_TR_PASSWORD, ESYS_TR_NONE,
+ ESYS_TR_NONE, TPM_NV_DIGEST_LEN, 0, &data);
Esys_TR_Close(t->esys, &nv);
- if (rc_is(rc, TPM2_RC_NV_UNINITIALIZED))
+ if (rc_is(ret, TPM2_RC_NV_UNINITIALIZED))
return -ENODATA; /* quiet: nothing written this boot */
- if (rc != TSS2_RC_SUCCESS) {
- pr_err("tpm: NV_Read(0x%08x): rc=0x%08x", index, (__u32)rc);
+ if (ret != TSS2_RC_SUCCESS) {
+ pr_err("tpm: NV_Read(0x%08x): rc=0x%08x", index, (__u32)ret);
return -EIO;
}
if (data->size != TPM_NV_DIGEST_LEN) {
@@ -428,14 +428,14 @@ int tpm_nv_read(struct shirudo_tpm *t, __u32 index, __u8 out[32])
int tpm_policy_session_start(struct shirudo_tpm *t, ESYS_TR *session)
{
TPMT_SYM_DEF sym = { .algorithm = TPM2_ALG_NULL };
- TSS2_RC rc;
-
- rc = Esys_StartAuthSession(t->esys, ESYS_TR_NONE, ESYS_TR_NONE,
- ESYS_TR_NONE, ESYS_TR_NONE, ESYS_TR_NONE,
- NULL, TPM2_SE_POLICY, &sym, TPM2_ALG_SHA256,
- session);
- if (rc != TSS2_RC_SUCCESS) {
- pr_err("tpm: StartAuthSession: rc=0x%08x", (__u32)rc);
+ TSS2_RC ret;
+
+ ret = Esys_StartAuthSession(t->esys, ESYS_TR_NONE, ESYS_TR_NONE,
+ ESYS_TR_NONE, ESYS_TR_NONE, ESYS_TR_NONE,
+ NULL, TPM2_SE_POLICY, &sym, TPM2_ALG_SHA256,
+ session);
+ if (ret != TSS2_RC_SUCCESS) {
+ pr_err("tpm: StartAuthSession: rc=0x%08x", (__u32)ret);
return -EIO;
}
return 0;
@@ -453,7 +453,7 @@ int tpm_writer_prepare(struct shirudo_tpm *t, ESYS_TR session,
struct tpm_writer_authorization *authorization)
{
TPM2B_NONCE *nonce = NULL;
- TSS2_RC rc;
+ TSS2_RC ret;
int err;
authorization->cphash.size = TPM_DIGEST_LEN;
@@ -462,9 +462,9 @@ int tpm_writer_prepare(struct shirudo_tpm *t, ESYS_TR session,
pr_err("tpm: compute NV_Extend command hash: %s", strerror(-err));
return err;
}
- rc = Esys_TRSess_GetNonceTPM(t->esys, session, &nonce);
- if (rc != TSS2_RC_SUCCESS || !nonce) {
- pr_err("tpm: NV writer PolicySigned: rc=0x%08x", (__u32)rc);
+ ret = Esys_TRSess_GetNonceTPM(t->esys, session, &nonce);
+ if (ret != TSS2_RC_SUCCESS || !nonce) {
+ pr_err("tpm: NV writer PolicySigned: rc=0x%08x", (__u32)ret);
Esys_Free(nonce);
return -EACCES;
}
@@ -498,7 +498,7 @@ static int tpm_writer_primary(struct shirudo_tpm *t,
TPM2B_NAME *name = NULL;
TPM2B_DATA outside = {};
TPMT_PUBLIC *p;
- TSS2_RC rc;
+ TSS2_RC ret;
int err;
*key = ESYS_TR_NONE;
@@ -520,14 +520,14 @@ static int tpm_writer_primary(struct shirudo_tpm *t,
explicit_bzero(&cfg, sizeof(cfg));
if (err)
return err;
- rc = Esys_CreatePrimary(t->esys, ESYS_TR_RH_OWNER,
- ESYS_TR_PASSWORD, ESYS_TR_NONE, ESYS_TR_NONE,
- &sensitive, &in_pub, &outside, &creation_pcr,
- key, &out_pub, NULL, NULL, NULL);
+ ret = Esys_CreatePrimary(t->esys, ESYS_TR_RH_OWNER,
+ ESYS_TR_PASSWORD, ESYS_TR_NONE, ESYS_TR_NONE,
+ &sensitive, &in_pub, &outside, &creation_pcr,
+ key, &out_pub, NULL, NULL, NULL);
owner_auth_clear(t);
- if (rc != TSS2_RC_SUCCESS) {
- pr_err("tpm: CreatePrimary(NV writer): rc=0x%08x", (__u32)rc);
- err = rc_is_auth_failure(rc) ? -EACCES : -EIO;
+ if (ret != TSS2_RC_SUCCESS) {
+ pr_err("tpm: CreatePrimary(NV writer): rc=0x%08x", (__u32)ret);
+ err = rc_is_auth_failure(ret) ? -EACCES : -EIO;
goto cleanup;
}
if (!out_pub) {
@@ -556,8 +556,8 @@ static int tpm_writer_primary(struct shirudo_tpm *t,
err = tpm_object_name(public_area, sizeof(public_area), computed);
if (err)
goto out;
- rc = Esys_TR_GetName(t->esys, *key, &name);
- if (rc != TSS2_RC_SUCCESS || !name ||
+ ret = Esys_TR_GetName(t->esys, *key, &name);
+ if (ret != TSS2_RC_SUCCESS || !name ||
name->size != sizeof(computed) ||
memcmp(name->name, computed, sizeof(computed)))
err = -EPROTO;
@@ -609,15 +609,15 @@ static int tpm_writer_sign(struct shirudo_tpm *t, ESYS_TR key,
TPM2B_DIGEST digest = {
.size = TPM_DIGEST_LEN,
};
- TSS2_RC rc;
+ TSS2_RC ret;
int err = 0;
memcpy(digest.buffer, hash, TPM_DIGEST_LEN);
scheme.details.rsassa.hashAlg = TPM2_ALG_SHA256;
- rc = Esys_Sign(t->esys, key, ESYS_TR_PASSWORD, ESYS_TR_NONE,
- ESYS_TR_NONE, &digest, &scheme, &validation, &signature);
- if (rc != TSS2_RC_SUCCESS) {
- pr_err("tpm: Sign(NV writer): rc=0x%08x", (__u32)rc);
+ ret = Esys_Sign(t->esys, key, ESYS_TR_PASSWORD, ESYS_TR_NONE,
+ ESYS_TR_NONE, &digest, &scheme, &validation, &signature);
+ if (ret != TSS2_RC_SUCCESS) {
+ pr_err("tpm: Sign(NV writer): rc=0x%08x", (__u32)ret);
err = -EACCES;
} else if (!signature || signature->sigAlg != TPM2_ALG_RSASSA ||
signature->signature.rsassa.hash != TPM2_ALG_SHA256 ||
@@ -639,18 +639,18 @@ TSS2_RC tpm_writer_authorize(struct shirudo_tpm *t, ESYS_TR key, ESYS_TR session
TPMT_SIGNATURE sig = { .sigAlg = TPM2_ALG_RSASSA };
TPM2B_TIMEOUT *timeout = NULL;
TPMT_TK_AUTH *ticket = NULL;
- TSS2_RC rc;
+ TSS2_RC ret;
sig.signature.rsassa.hash = TPM2_ALG_SHA256;
sig.signature.rsassa.sig.size = TPM_NV_RSA_BYTES;
memcpy(sig.signature.rsassa.sig.buffer, signature, TPM_NV_RSA_BYTES);
memcpy(ref.buffer, TPM_NV_POLICY_REF, ref.size);
- rc = Esys_PolicySigned(t->esys, key, session, ESYS_TR_NONE,
- ESYS_TR_NONE, ESYS_TR_NONE, &authorization->nonce,
- &authorization->cphash, &ref, 0, &sig, &timeout, &ticket);
+ ret = Esys_PolicySigned(t->esys, key, session, ESYS_TR_NONE,
+ ESYS_TR_NONE, ESYS_TR_NONE, &authorization->nonce,
+ &authorization->cphash, &ref, 0, &sig, &timeout, &ticket);
Esys_Free(timeout);
Esys_Free(ticket);
- return rc;
+ return ret;
}
static int policy_writer_signed(struct shirudo_tpm *t, ESYS_TR session,
@@ -661,7 +661,7 @@ static int policy_writer_signed(struct shirudo_tpm *t, ESYS_TR session,
__u8 public[TPM_NV_RSA_BYTES];
ESYS_TR key = ESYS_TR_NONE;
struct tpm_nv_info nv;
- TSS2_RC rc;
+ TSS2_RC ret;
int err;
if (!t->writer_set)
@@ -682,9 +682,9 @@ static int policy_writer_signed(struct shirudo_tpm *t, ESYS_TR session,
err = tpm_writer_sign(t, key, authorization.digest, signature);
if (err)
goto out;
- rc = tpm_writer_authorize(t, key, session, &authorization, signature);
- if (rc != TSS2_RC_SUCCESS) {
- pr_err("tpm: NV writer PolicySigned: rc=0x%08x", (__u32)rc);
+ ret = tpm_writer_authorize(t, key, session, &authorization, signature);
+ if (ret != TSS2_RC_SUCCESS) {
+ pr_err("tpm: NV writer PolicySigned: rc=0x%08x", (__u32)ret);
err = -EACCES;
}
out:
@@ -697,21 +697,21 @@ int tpm_policy_session_finish(struct shirudo_tpm *t, ESYS_TR session,
const __u8 expected[TPM_DIGEST_LEN])
{
TPM2B_DIGEST *digest = NULL;
- TSS2_RC rc;
+ TSS2_RC ret;
int err = 0;
- rc = Esys_PolicyCommandCode(t->esys, session, ESYS_TR_NONE,
- ESYS_TR_NONE, ESYS_TR_NONE, TPM2_CC_NV_Extend);
- if (rc != TSS2_RC_SUCCESS) {
- pr_err("tpm: register policy assertion: rc=0x%08x", (__u32)rc);
+ ret = Esys_PolicyCommandCode(t->esys, session, ESYS_TR_NONE,
+ ESYS_TR_NONE, ESYS_TR_NONE, TPM2_CC_NV_Extend);
+ if (ret != TSS2_RC_SUCCESS) {
+ pr_err("tpm: register policy assertion: rc=0x%08x", (__u32)ret);
return -EACCES;
}
- rc = Esys_PolicyGetDigest(t->esys, session, ESYS_TR_NONE,
- ESYS_TR_NONE, ESYS_TR_NONE, &digest);
- if (rc != TSS2_RC_SUCCESS || !digest || digest->size != TPM_DIGEST_LEN ||
+ ret = Esys_PolicyGetDigest(t->esys, session, ESYS_TR_NONE,
+ ESYS_TR_NONE, ESYS_TR_NONE, &digest);
+ if (ret != TSS2_RC_SUCCESS || !digest || digest->size != TPM_DIGEST_LEN ||
memcmp(digest->buffer, expected, TPM_DIGEST_LEN)) {
pr_err("tpm: register policy digest does not match the "
- "computed policy (rc=0x%08x)", (__u32)rc);
+ "computed policy (rc=0x%08x)", (__u32)ret);
err = -EPROTO;
}
Esys_Free(digest);
@@ -732,7 +732,7 @@ static int policy_session_register(struct shirudo_tpm *t, bool init,
{
TPML_DIGEST branches = { .count = 2 };
__u8 expected[32];
- TSS2_RC rc;
+ TSS2_RC ret;
int err;
if (!t->writer_set) {
@@ -742,25 +742,25 @@ static int policy_session_register(struct shirudo_tpm *t, bool init,
err = tpm_policy_session_start(t, session);
if (err)
return err;
- rc = Esys_PolicyNvWritten(t->esys, *session, ESYS_TR_NONE, ESYS_TR_NONE,
- ESYS_TR_NONE, init ? TPM2_NO : TPM2_YES);
- if (rc == TSS2_RC_SUCCESS && init) {
+ ret = Esys_PolicyNvWritten(t->esys, *session, ESYS_TR_NONE, ESYS_TR_NONE,
+ ESYS_TR_NONE, init ? TPM2_NO : TPM2_YES);
+ if (ret == TSS2_RC_SUCCESS && init) {
TPM2B_DIGEST live = {};
TPML_PCR_SELECTION sel;
pcr_selection(pcr_mask, &sel);
- rc = Esys_PolicyPCR(t->esys, *session, ESYS_TR_NONE,
- ESYS_TR_NONE, ESYS_TR_NONE, &live, &sel);
+ ret = Esys_PolicyPCR(t->esys, *session, ESYS_TR_NONE,
+ ESYS_TR_NONE, ESYS_TR_NONE, &live, &sel);
}
- if (rc == TSS2_RC_SUCCESS) {
+ if (ret == TSS2_RC_SUCCESS) {
branches.digests[0].size = 32;
memcpy(branches.digests[0].buffer, branch_written, 32);
branches.digests[1].size = 32;
memcpy(branches.digests[1].buffer, branch_init, 32);
- rc = Esys_PolicyOR(t->esys, *session, ESYS_TR_NONE,
- ESYS_TR_NONE, ESYS_TR_NONE, &branches);
+ ret = Esys_PolicyOR(t->esys, *session, ESYS_TR_NONE,
+ ESYS_TR_NONE, ESYS_TR_NONE, &branches);
}
- if (rc == TSS2_RC_SUCCESS) {
+ if (ret == TSS2_RC_SUCCESS) {
err = policy_writer_signed(t, *session, index, event);
if (err) {
session_flush(t, *session);
@@ -768,13 +768,13 @@ static int policy_session_register(struct shirudo_tpm *t, bool init,
return err;
}
}
- if (rc != TSS2_RC_SUCCESS) {
- if (rc_is(rc, TPM2_RC_VALUE) && init)
+ if (ret != TSS2_RC_SUCCESS) {
+ if (rc_is(ret, TPM2_RC_VALUE) && init)
pr_err("tpm: the anchoring PCR moved; the register "
"can only be initialised in the boot window");
else
pr_err("tpm: register policy assertion: rc=0x%08x",
- (__u32)rc);
+ (__u32)ret);
session_flush(t, *session);
*session = ESYS_TR_NONE;
return -EACCES;
@@ -796,20 +796,20 @@ static int nv_extend_session(struct shirudo_tpm *t, __u32 index,
{
TPM2B_MAX_NV_BUFFER data = { .size = TPM_NV_DIGEST_LEN };
ESYS_TR nv;
- TSS2_RC rc;
+ TSS2_RC ret;
int err;
err = nv_handle(t, index, &nv);
if (err)
return err;
memcpy(data.buffer, event, TPM_NV_DIGEST_LEN);
- rc = Esys_NV_Extend(t->esys, nv, nv, session, ESYS_TR_NONE,
- ESYS_TR_NONE, &data);
+ ret = Esys_NV_Extend(t->esys, nv, nv, session, ESYS_TR_NONE,
+ ESYS_TR_NONE, &data);
Esys_TR_Close(t->esys, &nv);
- if (rc != TSS2_RC_SUCCESS) {
+ if (ret != TSS2_RC_SUCCESS) {
pr_err("tpm: NV_Extend(0x%08x): rc=0x%08x", index,
- (__u32)rc);
- return rc_is_auth_failure(rc) ? -EACCES : -EIO;
+ (__u32)ret);
+ return rc_is_auth_failure(ret) ? -EACCES : -EIO;
}
return 0;
}
@@ -935,22 +935,22 @@ static int endorsement_primary(struct shirudo_tpm *t,
TPM2B_DATA outside = {};
__u8 computed[TPM_NAME_LEN];
ESYS_TR handle;
- TSS2_RC rc;
+ TSS2_RC ret;
int err;
memset(key, 0, sizeof(*key));
- rc = Esys_CreatePrimary(t->esys, ESYS_TR_RH_ENDORSEMENT,
- ESYS_TR_PASSWORD, ESYS_TR_NONE, ESYS_TR_NONE,
- &sensitive, in_pub, &outside, &creation_pcr,
- &handle, &out_pub, NULL, NULL, NULL);
- if (rc != TSS2_RC_SUCCESS) {
- if (rc_is_auth_failure(rc))
+ ret = Esys_CreatePrimary(t->esys, ESYS_TR_RH_ENDORSEMENT,
+ ESYS_TR_PASSWORD, ESYS_TR_NONE, ESYS_TR_NONE,
+ &sensitive, in_pub, &outside, &creation_pcr,
+ &handle, &out_pub, NULL, NULL, NULL);
+ if (ret != TSS2_RC_SUCCESS) {
+ if (rc_is_auth_failure(ret))
pr_err("tpm: CreatePrimary(%s): the endorsement "
"hierarchy has an auth value (rc=0x%08x)", what,
- (__u32)rc);
+ (__u32)ret);
else
pr_err("tpm: CreatePrimary(%s): rc=0x%08x", what,
- (__u32)rc);
+ (__u32)ret);
return -EIO;
}
key->handle = handle;
@@ -961,8 +961,8 @@ static int endorsement_primary(struct shirudo_tpm *t,
err = tpm_object_name(key->public, key->public_len,
computed);
if (!err) {
- rc = Esys_TR_GetName(t->esys, handle, &name);
- if (rc != TSS2_RC_SUCCESS || name->size != sizeof(computed) ||
+ ret = Esys_TR_GetName(t->esys, handle, &name);
+ if (ret != TSS2_RC_SUCCESS || name->size != sizeof(computed) ||
memcmp(name->name, computed, sizeof(computed)) != 0) {
pr_err("tpm: %s name does not match its marshalled "
"public area", what);
@@ -1063,7 +1063,7 @@ int tpm_quote(struct shirudo_tpm *t, const struct shirudo_tpm_key *ak,
TPM2B_ATTEST *quoted = NULL;
TPML_PCR_SELECTION sel;
TPM2B_DATA qual = {};
- TSS2_RC rc;
+ TSS2_RC ret;
int err;
if (nonce_len > sizeof(qual.buffer))
@@ -1071,10 +1071,10 @@ int tpm_quote(struct shirudo_tpm *t, const struct shirudo_tpm_key *ak,
memcpy(qual.buffer, nonce, nonce_len);
qual.size = (__u16)nonce_len;
pcr_selection(pcr_mask, &sel);
- rc = Esys_Quote(t->esys, ak->handle, ESYS_TR_PASSWORD, ESYS_TR_NONE,
- ESYS_TR_NONE, &qual, &scheme, &sel, &quoted, &sig);
- if (rc != TSS2_RC_SUCCESS) {
- pr_err("tpm: Quote: rc=0x%08x", (__u32)rc);
+ ret = Esys_Quote(t->esys, ak->handle, ESYS_TR_PASSWORD, ESYS_TR_NONE,
+ ESYS_TR_NONE, &qual, &scheme, &sel, &quoted, &sig);
+ if (ret != TSS2_RC_SUCCESS) {
+ pr_err("tpm: Quote: rc=0x%08x", (__u32)ret);
return -EIO;
}
err = attestation_copy(quoted, sig, out);
@@ -1093,7 +1093,7 @@ int tpm_nv_certify(struct shirudo_tpm *t,
TPM2B_ATTEST *info = NULL;
TPM2B_DATA qual = {};
ESYS_TR nv;
- TSS2_RC rc;
+ TSS2_RC ret;
int err;
if (nonce_len > sizeof(qual.buffer))
@@ -1103,14 +1103,14 @@ int tpm_nv_certify(struct shirudo_tpm *t,
err = nv_handle(t, index, &nv);
if (err)
return err;
- rc = Esys_NV_Certify(t->esys, ak->handle, nv, nv, ESYS_TR_PASSWORD,
- ESYS_TR_PASSWORD, ESYS_TR_NONE, &qual, &scheme,
- TPM_NV_DIGEST_LEN, 0, &info, &sig);
+ ret = Esys_NV_Certify(t->esys, ak->handle, nv, nv, ESYS_TR_PASSWORD,
+ ESYS_TR_PASSWORD, ESYS_TR_NONE, &qual, &scheme,
+ TPM_NV_DIGEST_LEN, 0, &info, &sig);
Esys_TR_Close(t->esys, &nv);
- if (rc != TSS2_RC_SUCCESS) {
+ if (ret != TSS2_RC_SUCCESS) {
pr_err("tpm: NV_Certify(0x%08x): rc=0x%08x", index,
- (__u32)rc);
- return rc_is(rc, TPM2_RC_NV_UNINITIALIZED) ? -ENODATA : -EIO;
+ (__u32)ret);
+ return rc_is(ret, TPM2_RC_NV_UNINITIALIZED) ? -ENODATA : -EIO;
}
err = attestation_copy(info, sig, out);
Esys_Free(info);
@@ -1129,7 +1129,7 @@ int tpm_activate_credential(struct shirudo_tpm *t,
TPM2B_DIGEST *cert_info = NULL;
ESYS_TR session = ESYS_TR_NONE;
TPM2B_ID_OBJECT id = {};
- TSS2_RC rc;
+ TSS2_RC ret;
int err;
if (blob_len > sizeof(id.credential) || secret_len > sizeof(sec.secret))
@@ -1142,22 +1142,22 @@ int tpm_activate_credential(struct shirudo_tpm *t,
if (err)
return err;
/* The endorsement key's policy: the hierarchy's own authorisation. */
- rc = Esys_PolicySecret(t->esys, ESYS_TR_RH_ENDORSEMENT, session,
- ESYS_TR_PASSWORD, ESYS_TR_NONE, ESYS_TR_NONE,
- NULL, NULL, NULL, 0, NULL, NULL);
- if (rc != TSS2_RC_SUCCESS) {
+ ret = Esys_PolicySecret(t->esys, ESYS_TR_RH_ENDORSEMENT, session,
+ ESYS_TR_PASSWORD, ESYS_TR_NONE, ESYS_TR_NONE,
+ NULL, NULL, NULL, 0, NULL, NULL);
+ if (ret != TSS2_RC_SUCCESS) {
pr_err("tpm: PolicySecret(endorsement): rc=0x%08x",
- (__u32)rc);
+ (__u32)ret);
session_flush(t, session);
return -EACCES;
}
- rc = Esys_ActivateCredential(t->esys, ak->handle, ek->handle,
- ESYS_TR_PASSWORD, session, ESYS_TR_NONE,
- &id, &sec, &cert_info);
+ ret = Esys_ActivateCredential(t->esys, ak->handle, ek->handle,
+ ESYS_TR_PASSWORD, session, ESYS_TR_NONE,
+ &id, &sec, &cert_info);
session_flush(t, session);
- if (rc != TSS2_RC_SUCCESS) {
- pr_err("tpm: ActivateCredential: rc=0x%08x", (__u32)rc);
- return (rc & 0xFFFF0000u) == 0 ? -EKEYREJECTED : -EIO;
+ if (ret != TSS2_RC_SUCCESS) {
+ pr_err("tpm: ActivateCredential: rc=0x%08x", (__u32)ret);
+ return (ret & 0xFFFF0000u) == 0 ? -EKEYREJECTED : -EIO;
}
if (cert_info->size > cap) {
Esys_Free(cert_info);
@@ -1175,15 +1175,15 @@ static int nv_read_all(struct shirudo_tpm *t, __u32 index, __u8 *out,
TPM2B_NV_PUBLIC *pub = NULL;
size_t off = 0, total;
ESYS_TR nv;
- TSS2_RC rc;
+ TSS2_RC ret;
int err;
err = nv_handle(t, index, &nv);
if (err)
return err;
- rc = Esys_NV_ReadPublic(t->esys, nv, ESYS_TR_NONE, ESYS_TR_NONE,
- ESYS_TR_NONE, &pub, NULL);
- if (rc != TSS2_RC_SUCCESS) {
+ ret = Esys_NV_ReadPublic(t->esys, nv, ESYS_TR_NONE, ESYS_TR_NONE,
+ ESYS_TR_NONE, &pub, NULL);
+ if (ret != TSS2_RC_SUCCESS) {
Esys_TR_Close(t->esys, &nv);
return -EIO;
}
@@ -1199,10 +1199,10 @@ static int nv_read_all(struct shirudo_tpm *t, __u32 index, __u8 *out,
if (want > NV_READ_CHUNK)
want = NV_READ_CHUNK;
- rc = Esys_NV_Read(t->esys, nv, nv, ESYS_TR_PASSWORD,
- ESYS_TR_NONE, ESYS_TR_NONE, (UINT16)want,
- (UINT16)off, &data);
- if (rc != TSS2_RC_SUCCESS) {
+ ret = Esys_NV_Read(t->esys, nv, nv, ESYS_TR_PASSWORD,
+ ESYS_TR_NONE, ESYS_TR_NONE, (UINT16)want,
+ (UINT16)off, &data);
+ if (ret != TSS2_RC_SUCCESS) {
Esys_TR_Close(t->esys, &nv);
return -EIO;
}
diff --git a/util/tpm_wire.c b/util/tpm_wire.c
index a46bd02b..678c9002 100644
--- a/util/tpm_wire.c
+++ b/util/tpm_wire.c
@@ -207,16 +207,16 @@ int tpm_policy_signed(const __u8 prev[32],
__u8 public[TPM_NV_RSA_PUBLIC_AREA_LEN];
__u8 bytes[32 + sizeof(TPM_NV_POLICY_REF) - 1];
__u8 name[TPM_NAME_LEN];
- int rc;
+ int ret;
tpm_writer_public(writer_public, public);
- rc = tpm_object_name(public, sizeof(public), name);
- if (rc)
- return rc;
- rc = policy_hash(prev, TPM_CC_POLICY_SIGNED, name, sizeof(name), NULL,
- 0, out);
- if (rc)
- return rc;
+ ret = tpm_object_name(public, sizeof(public), name);
+ if (ret)
+ return ret;
+ ret = policy_hash(prev, TPM_CC_POLICY_SIGNED, name, sizeof(name), NULL,
+ 0, out);
+ if (ret)
+ return ret;
memcpy(bytes, out, 32);
memcpy(bytes + 32, TPM_NV_POLICY_REF,
sizeof(TPM_NV_POLICY_REF) - 1);
@@ -238,15 +238,15 @@ int tpm_register_policy_final(const __u8 branch_written[32],
const __u8 writer_public[TPM_NV_RSA_BYTES],
__u8 policy[32])
{
- int rc;
-
- rc = tpm_policy_or(branch_written, branch_init, policy);
- if (!rc)
- rc = tpm_policy_signed(policy, writer_public, policy);
- if (!rc)
- rc = tpm_policy_command_code(policy, TPM_CC_NV_EXTEND,
- policy);
- return rc;
+ int ret;
+
+ ret = tpm_policy_or(branch_written, branch_init, policy);
+ if (!ret)
+ ret = tpm_policy_signed(policy, writer_public, policy);
+ if (!ret)
+ ret = tpm_policy_command_code(policy, TPM_CC_NV_EXTEND,
+ policy);
+ return ret;
}
int tpm_register_policy(__u32 pcr_mask,
@@ -257,18 +257,18 @@ int tpm_register_policy(__u32 pcr_mask,
{
static const __u8 zero[32];
__u8 pcr_digest[32], unwritten[32];
- int rc;
-
- rc = tpm_policy_nv_written(zero, true, branch_written);
- if (!rc)
- rc = tpm_policy_nv_written(zero, false, unwritten);
- if (!rc)
- rc = sha256_buffer(pcr_values, 32 * n_values, pcr_digest);
- if (!rc)
- rc = tpm_policy_pcr(unwritten, pcr_mask, pcr_digest,
- branch_init);
- if (rc)
- return rc;
+ int ret;
+
+ ret = tpm_policy_nv_written(zero, true, branch_written);
+ if (!ret)
+ ret = tpm_policy_nv_written(zero, false, unwritten);
+ if (!ret)
+ ret = sha256_buffer(pcr_values, 32 * n_values, pcr_digest);
+ if (!ret)
+ ret = tpm_policy_pcr(unwritten, pcr_mask, pcr_digest,
+ branch_init);
+ if (ret)
+ return ret;
return tpm_register_policy_final(branch_written, branch_init,
writer_public, policy);
}
@@ -433,12 +433,12 @@ int tpm_ecc_public_parse(const __u8 *buf, size_t len,
struct shirudo_tpm_ecc_public *out)
{
struct shirudo_tpm_public pub;
- int rc;
+ int ret;
memset(out, 0, sizeof(*out));
- rc = tpm_public_parse(buf, len, &pub);
- if (rc)
- return rc;
+ ret = tpm_public_parse(buf, len, &pub);
+ if (ret)
+ return ret;
if (pub.type != TPM_ALG_ECC ||
pub.sym_alg != TPM_ALG_NULL ||
pub.scheme != TPM_ALG_ECDSA)
@@ -523,7 +523,7 @@ int tpm_credential_protect(const __u8 seed[32],
__u8 plain[2 + TPM_CREDENTIAL_LEN], enc[sizeof(plain)];
__u8 mac_in[sizeof(enc) + TPM_NAME_LEN], mac[32];
__u8 sym_key[16], hmac_key[32];
- int rc = -EIO;
+ int ret = -EIO;
if (tpm_kdfa(seed, 32, "STORAGE", name, TPM_NAME_LEN,
NULL, 0, sym_key, sizeof(sym_key)))
@@ -542,12 +542,12 @@ int tpm_credential_protect(const __u8 seed[32],
put_be16(out, 32);
memcpy(out + 2, mac, 32);
memcpy(out + 34, enc, sizeof(enc));
- rc = 0;
+ ret = 0;
out:
explicit_bzero(plain, sizeof(plain));
explicit_bzero(sym_key, sizeof(sym_key));
explicit_bzero(hmac_key, sizeof(hmac_key));
- return rc;
+ return ret;
}
int tpm_ecdsa_signature_parse(const __u8 *buf, size_t len,
diff --git a/util/upatch.c b/util/upatch.c
index 6df4d520..a34e5e02 100644
--- a/util/upatch.c
+++ b/util/upatch.c
@@ -266,25 +266,25 @@ reject:
static int upatch_parse(const void *data, size_t size,
struct shirudo_upatch *out)
{
- int rc;
+ int ret;
memset(out, 0, sizeof(*out));
if (!data || !size || size > UPATCH_FILE_MAX)
return -EINVAL;
out->map = data;
out->map_size = size;
- rc = parse_header(out->map, out->map_size, &out->hdr);
- if (rc)
+ ret = parse_header(out->map, out->map_size, &out->hdr);
+ if (ret)
goto err;
out->rodata_offset_valid = true;
- rc = validate_bounds(&out->hdr, out->map_size);
- if (rc)
+ ret = validate_bounds(&out->hdr, out->map_size);
+ if (ret)
goto err;
parse_signed_sections(out);
return 0;
err:
memset(out, 0, sizeof(*out));
- return rc;
+ return ret;
}
int upatch_open_memory(const void *data, size_t size,
@@ -297,7 +297,7 @@ int upatch_open_fd(int fd, struct shirudo_upatch *out)
{
struct stat st;
void *m;
- int rc;
+ int ret;
memset(out, 0, sizeof(*out));
if (fstat(fd, &st) != 0)
@@ -312,10 +312,10 @@ int upatch_open_fd(int fd, struct shirudo_upatch *out)
if (m == MAP_FAILED)
return -errno;
- rc = upatch_parse(m, (size_t)st.st_size, out);
- if (rc) {
+ ret = upatch_parse(m, (size_t)st.st_size, out);
+ if (ret) {
munmap(m, (size_t)st.st_size);
- return rc;
+ return ret;
}
out->mapped = true;
return 0;
@@ -323,15 +323,15 @@ int upatch_open_fd(int fd, struct shirudo_upatch *out)
int upatch_open(const char *path, struct shirudo_upatch *out)
{
- int fd, rc;
+ int fd, ret;
memset(out, 0, sizeof(*out));
fd = open(path, O_RDONLY | O_CLOEXEC);
if (fd < 0)
return -errno;
- rc = upatch_open_fd(fd, out);
+ ret = upatch_open_fd(fd, out);
close(fd);
- return rc;
+ return ret;
}
void upatch_close(struct shirudo_upatch *u)
@@ -482,7 +482,7 @@ int prog_specs_parse(const void *metadata, __u32 metadata_len,
const __u8 *cursor, *end;
size_t base_len;
__u32 magic, version, count, i, nr_uprobes = 0;
- int rc = -EINVAL;
+ int ret = -EINVAL;
*out = NULL;
if (!metadata || metadata_len < sizeof(__u32))
@@ -648,7 +648,7 @@ int prog_specs_parse(const void *metadata, __u32 metadata_len,
spec->uprobe_path = xstrndup((const char *)cursor,
path_len);
if (!spec->uprobe_path) {
- rc = -ENOMEM;
+ ret = -ENOMEM;
goto out;
}
spec->uprobe_path_len = path_len;
@@ -659,7 +659,7 @@ int prog_specs_parse(const void *metadata, __u32 metadata_len,
spec->uprobe_offsets =
xcalloc(nr_offsets, sizeof(*spec->uprobe_offsets));
if (!spec->uprobe_offsets) {
- rc = -ENOMEM;
+ ret = -ENOMEM;
goto out;
}
spec->nr_uprobe_offsets = nr_offsets;
@@ -683,5 +683,5 @@ int prog_specs_parse(const void *metadata, __u32 metadata_len,
return 0;
out:
prog_specs_free(specs, nr_progs);
- return rc;
+ return ret;
}
diff --git a/util/upatch_decode.c b/util/upatch_decode.c
index 1738a9f9..0e587018 100644
--- a/util/upatch_decode.c
+++ b/util/upatch_decode.c
@@ -817,7 +817,7 @@ static int lua_shirudo_page_slots(lua_State *L)
__u8 *data = NULL;
size_t hex_len, data_len = 0, off = 0, per_chunk;
__u64 chunks;
- int slot_size, n = 0, rc;
+ int slot_size, n = 0, ret;
luaL_checktype(L, 1, LUA_TTABLE);
slot_size = lua_check_c_int(L, 2);
@@ -831,8 +831,8 @@ static int lua_shirudo_page_slots(lua_State *L)
lua_newtable(L);
return 1;
}
- rc = hex_decode_push(L, hex, hex_len, &data, &data_len);
- if (rc)
+ ret = hex_decode_push(L, hex, hex_len, &data, &data_len);
+ if (ret)
return luaL_error(L, "invalid page data_hex");
per_chunk = SERIAL_CHUNK_PAYLOAD / (size_t)slot_size;
lua_newtable(L);
@@ -860,11 +860,11 @@ static int lua_check_u64_string(lua_State *L, int arg, __u64 *out)
{
size_t len;
const char *s = luaL_checklstring(L, arg, &len);
- int rc = parse_u64(s, len, UINT64_MAX, out);
+ int ret = parse_u64(s, len, UINT64_MAX, out);
- if (rc == -ERANGE)
+ if (ret == -ERANGE)
return luaL_argerror(L, arg, "u64 string out of range");
- if (rc)
+ if (ret)
return luaL_argerror(L, arg, "expected a decimal u64 string");
return 0;
}
@@ -938,7 +938,7 @@ static int lua_shirudo_fixed_records(lua_State *L)
__u8 *data = NULL;
__u64 cursor, chunks;
size_t hex_len, data_len = 0;
- int rc;
+ int ret;
lua_rawgeti(L, pages_idx, (int)i);
if (!lua_istable(L, -1)) {
@@ -953,8 +953,8 @@ static int lua_shirudo_fixed_records(lua_State *L)
lua_pop(L, 2);
continue;
}
- rc = hex_decode_push(L, hex, hex_len, &data, &data_len);
- if (rc) {
+ ret = hex_decode_push(L, hex, hex_len, &data, &data_len);
+ if (ret) {
lua_pop(L, 2);
return luaL_error(L, "invalid page data_hex");
}
@@ -1209,7 +1209,7 @@ static int run_lua_decoder(const struct upatch_decoder_view *d,
};
struct json_out jo = {};
lua_State *L;
- int rc = 0;
+ int ret = 0;
L = lua_newstate(lua_limited_alloc, &memory);
if (!L)
@@ -1231,11 +1231,11 @@ static int run_lua_decoder(const struct upatch_decoder_view *d,
lua_pcall(L, 0, 1, 0)) {
fprintf(stderr, "upatch map: decoder load failed: %s\n",
lua_error_message(L));
- rc = -EINVAL;
+ ret = -EINVAL;
goto out_close;
}
- rc = lua_get_decoder_entrypoint(L, d->entrypoint);
- if (rc) {
+ ret = lua_get_decoder_entrypoint(L, d->entrypoint);
+ if (ret) {
fprintf(stderr, "upatch map: decoder entrypoint '%s' not found\n",
d->entrypoint);
goto out_close;
@@ -1247,18 +1247,18 @@ static int run_lua_decoder(const struct upatch_decoder_view *d,
if (lua_pcall(L, 0, 1, 0)) {
fprintf(stderr, "upatch map: decoder failed: %s\n",
lua_error_message(L));
- rc = -EINVAL;
+ ret = -EINVAL;
goto out_close;
}
- rc = otel ? lua_otel_emit_value(L, -1, &jo, 0) :
+ ret = otel ? lua_otel_emit_value(L, -1, &jo, 0) :
lua_json_emit_value(L, -1, &jo, 0);
- if (rc) {
+ if (ret) {
fprintf(stderr, "upatch map: decoder encode failed: %s\n",
- strerror(-rc));
+ strerror(-ret));
goto out_close;
}
if (jo.err) {
- rc = jo.err;
+ ret = jo.err;
goto out_close;
}
*out = jo.buf;
@@ -1273,7 +1273,7 @@ out_close:
lua_sethook(L, NULL, 0, 0);
current_lua_budget = NULL;
lua_close(L);
- return rc;
+ return ret;
}
static int decoder_matches(const struct upatch_decoder_view *d,
@@ -1301,16 +1301,16 @@ static int decoder_matches(const struct upatch_decoder_view *d,
static int archive_open(const char *path, bool archived,
struct shirudo_upatch *u)
{
- int fd, rc;
+ int fd, ret;
if (!archived)
return upatch_open(path, u);
fd = seal_open_read(path);
if (fd < 0)
return fd;
- rc = upatch_open_fd(fd, u);
+ ret = upatch_open_fd(fd, u);
close(fd);
- return rc;
+ return ret;
}
static int decode_map_open(const char *path, bool archived,
@@ -1320,7 +1320,7 @@ static int decode_map_open(const char *path, bool archived,
{
struct shirudo_upatch u;
__u32 i;
- int rc;
+ int ret;
if (!path || !v || !out || !out_len)
return -EINVAL;
@@ -1328,10 +1328,10 @@ static int decode_map_open(const char *path, bool archived,
*out_len = 0;
if (!upatch_name_valid(v->upatch))
return -EINVAL;
- rc = archive_open(path, archived, &u);
- if (rc)
- return rc == -ENOENT ? -ENOENT : rc;
- rc = -ENODATA;
+ ret = archive_open(path, archived, &u);
+ if (ret)
+ return ret == -ENOENT ? -ENOENT : ret;
+ ret = -ENODATA;
for (i = 0; i < u.nr_decoders; i++) {
struct upatch_decoder_view d;
@@ -1339,11 +1339,11 @@ static int decode_map_open(const char *path, bool archived,
continue;
if (!decoder_matches(&d, v))
continue;
- rc = run_lua_decoder(&d, v, otel, max_bytes, out, out_len);
+ ret = run_lua_decoder(&d, v, otel, max_bytes, out, out_len);
break;
}
upatch_close(&u);
- return rc;
+ return ret;
}
static int decode_map_file(const char *path, const struct shirudo_map_view *v,
@@ -1359,17 +1359,17 @@ int upatch_decode_map_signal(const struct shirudo_map_view *v,
struct shirudo_upatch u;
char path[PATH_MAX];
__u32 i;
- int rc;
+ int ret;
if (!v || !signal_out || !upatch_name_valid(v->upatch))
return -EINVAL;
if (strsprintf(path, sizeof(path), "%s/%s.upatch", UPATCHES_DIR,
v->upatch) < 0)
return -ENAMETOOLONG;
- rc = archive_open(path, true, &u);
- if (rc)
- return rc == -ENOENT ? -ENOENT : rc;
- rc = -ENODATA;
+ ret = archive_open(path, true, &u);
+ if (ret)
+ return ret == -ENOENT ? -ENOENT : ret;
+ ret = -ENODATA;
for (i = 0; i < u.nr_decoders; i++) {
struct upatch_decoder_view d;
@@ -1377,11 +1377,11 @@ int upatch_decode_map_signal(const struct shirudo_map_view *v,
!decoder_matches(&d, v))
continue;
*signal_out = d.export_signal;
- rc = 0;
+ ret = 0;
break;
}
upatch_close(&u);
- return rc;
+ return ret;
}
static int decode_map(const struct shirudo_map_view *v, bool otel,
diff --git a/util/upatch_maps.c b/util/upatch_maps.c
index 374ec7e9..091a8b7f 100644
--- a/util/upatch_maps.c
+++ b/util/upatch_maps.c
@@ -848,24 +848,24 @@ static int read_serial_page(int serial_fd,
__u32 page_index, flags;
__u64 cursor, next_cursor;
__u8 *data = NULL;
- int rc;
+ int ret;
chunk = xmalloc(sizeof(*chunk));
if (!chunk)
return -ENOMEM;
key = 0;
if (bpf_map_lookup_elem(serial_fd, &key, chunk) != 0) {
- rc = -errno;
+ ret = -errno;
goto out_chunk;
}
if (chunk->magic != SERIAL_MAGIC ||
chunk->version != SERIAL_VERSION ||
chunk->invocation_id != invocation_id) {
- rc = -EBADMSG;
+ ret = -EBADMSG;
goto out_chunk;
}
if (chunk->status != 0) {
- rc = chunk->status < 0 ? chunk->status : -EIO;
+ ret = chunk->status < 0 ? chunk->status : -EIO;
goto out_chunk;
}
total_chunks = chunk->total_chunks;
@@ -878,37 +878,37 @@ static int read_serial_page(int serial_fd,
total_chunks > SERIAL_MAX_CHUNKS ||
bytes_total > SERIAL_MAX_BYTES ||
bytes_total > total_chunks * SERIAL_CHUNK_PAYLOAD) {
- rc = -EBADMSG;
+ ret = -EBADMSG;
goto out_chunk;
}
if (page_index != want_page_index || cursor != want_cursor ||
next_cursor < cursor) {
- rc = -EBADMSG;
+ ret = -EBADMSG;
goto out_chunk;
}
data = bytes_total ? xmalloc(bytes_total) : NULL;
if (bytes_total && !data) {
- rc = -ENOMEM;
+ ret = -ENOMEM;
goto out_chunk;
}
for (key = 0; key < total_chunks; key++) {
if (key != 0 &&
bpf_map_lookup_elem(serial_fd, &key, chunk) != 0) {
- rc = -errno;
+ ret = -errno;
goto out_data;
}
- rc = serial_chunk_validate(chunk, key, total_chunks,
- page_index, cursor,
- next_cursor, invocation_id);
- if (rc)
+ ret = serial_chunk_validate(chunk, key, total_chunks,
+ page_index, cursor,
+ next_cursor, invocation_id);
+ if (ret)
goto out_data;
if (chunk->status != 0) {
- rc = chunk->status < 0 ? chunk->status : -EIO;
+ ret = chunk->status < 0 ? chunk->status : -EIO;
goto out_data;
}
if (chunk->bytes_total != bytes_total ||
copied + chunk->bytes_in_chunk > bytes_total) {
- rc = -EBADMSG;
+ ret = -EBADMSG;
goto out_data;
}
if (chunk->bytes_in_chunk)
@@ -917,7 +917,7 @@ static int read_serial_page(int serial_fd,
copied += chunk->bytes_in_chunk;
}
if (copied != bytes_total) {
- rc = -EBADMSG;
+ ret = -EBADMSG;
goto out_data;
}
@@ -937,7 +937,7 @@ out_data:
xfree(data, bytes_total);
out_chunk:
xfree(chunk, sizeof(*chunk));
- return rc;
+ return ret;
}
static int try_read_serialized(const char *upatch, const char *map,
@@ -946,7 +946,7 @@ static int try_read_serialized(const char *upatch, const char *map,
struct bpf_map_info serial_info = {};
__u64 cursor = 0, bytes_total = 0, invocation_id;
__u32 page_index;
- int prog_fd = -1, serial_fd = -1, lock_fd = -1, rc;
+ int prog_fd = -1, serial_fd = -1, lock_fd = -1, ret;
if (strcmp(map, SERIAL_MAP_NAME) == 0)
return 0;
@@ -956,12 +956,12 @@ static int try_read_serialized(const char *upatch, const char *map,
return 0;
return prog_fd;
}
- rc = open_map_pin(upatch, SERIAL_MAP_NAME,
- &serial_fd, &serial_info);
- if (rc)
+ ret = open_map_pin(upatch, SERIAL_MAP_NAME,
+ &serial_fd, &serial_info);
+ if (ret)
goto out;
- rc = validate_serial_map(&serial_info);
- if (rc)
+ ret = validate_serial_map(&serial_info);
+ if (ret)
goto out;
/*
* Clearing, running and reading are one transaction. Key the lock by
@@ -970,12 +970,12 @@ static int try_read_serialized(const char *upatch, const char *map,
*/
lock_fd = serializer_lock_acquire(serial_info.id);
if (lock_fd < 0) {
- rc = lock_fd;
+ ret = lock_fd;
lock_fd = -1;
goto out;
}
- rc = serializer_new_invocation_id(&invocation_id);
- if (rc)
+ ret = serializer_new_invocation_id(&invocation_id);
+ if (ret)
goto out;
for (page_index = 0; page_index < SERIAL_MAX_PAGES;
@@ -984,8 +984,8 @@ static int try_read_serialized(const char *upatch, const char *map,
struct shirudo_serial_page page = {};
__u32 retval = 0;
- rc = clear_serial_map(serial_fd, &serial_info);
- if (rc)
+ ret = clear_serial_map(serial_fd, &serial_info);
+ if (ret)
goto out;
ctx.magic = SERIAL_MAGIC;
@@ -998,11 +998,11 @@ static int try_read_serialized(const char *upatch, const char *map,
ctx.cursor = cursor;
ctx.invocation_id = invocation_id;
- rc = prog_test_run(prog_fd, &ctx, sizeof(ctx), &retval);
- if (rc)
+ ret = prog_test_run(prog_fd, &ctx, sizeof(ctx), &retval);
+ if (ret)
goto out;
if ((__s32)retval < 0) {
- rc = (__s32)retval;
+ ret = (__s32)retval;
goto out;
}
if (ctx.magic != SERIAL_MAGIC ||
@@ -1010,22 +1010,22 @@ static int try_read_serialized(const char *upatch, const char *map,
ctx.page_index != page_index ||
ctx.cursor != cursor ||
ctx.invocation_id != invocation_id) {
- rc = -EBADMSG;
+ ret = -EBADMSG;
goto out;
}
- rc = read_serial_page(serial_fd, &serial_info, page_index,
- cursor, invocation_id, &page);
- if (rc)
+ ret = read_serial_page(serial_fd, &serial_info, page_index,
+ cursor, invocation_id, &page);
+ if (ret)
goto out;
if (bytes_total + page.bytes > SERIAL_MAX_TOTAL_BYTES) {
xfree(page.data, page.bytes);
- rc = -E2BIG;
+ ret = -E2BIG;
goto out;
}
bytes_total += page.bytes;
- rc = append_serial_page(out, &page);
- if (rc) {
+ ret = append_serial_page(out, &page);
+ if (ret) {
xfree(page.data, page.bytes);
goto out;
}
@@ -1034,14 +1034,14 @@ static int try_read_serialized(const char *upatch, const char *map,
if (page.done)
break;
if (page.next_cursor == cursor) {
- rc = -EBADMSG;
+ ret = -EBADMSG;
goto out;
}
cursor = page.next_cursor;
}
if (out->n_serial_pages == 0 ||
!out->serial_pages[out->n_serial_pages - 1].done) {
- rc = -E2BIG;
+ ret = -E2BIG;
goto out;
}
@@ -1053,7 +1053,7 @@ static int try_read_serialized(const char *upatch, const char *map,
return 1;
out:
- if (rc < 0 && out->serial_pages) {
+ if (ret < 0 && out->serial_pages) {
__u32 i;
for (i = 0; i < out->n_serial_pages; i++)
@@ -1071,7 +1071,7 @@ out:
close(lock_fd);
if (prog_fd >= 0)
close(prog_fd);
- return rc;
+ return ret;
}
static int read_entries(int fd, struct shirudo_map_view *v,
@@ -1235,16 +1235,16 @@ int upatch_maps_read(const char *upatch, const char *map,
char bpffs_name[UPATCH_BPFFS_NAME_MAX + 1];
struct stat upatch_st;
int fd = -1;
- int rc;
+ int ret;
memset(out, 0, sizeof(*out));
if (strscpy(out->upatch, upatch, sizeof(out->upatch)) < 0 ||
strscpy(out->name, map, sizeof(out->name)) < 0)
return -ENAMETOOLONG;
- rc = open_map_pin(upatch, map, &fd, &info);
- if (rc)
- return rc;
+ ret = open_map_pin(upatch, map, &fd, &info);
+ if (ret)
+ return ret;
out->type = info.type;
out->type_name = map_type_name(info.type);
out->key_size = info.key_size;
@@ -1270,12 +1270,12 @@ int upatch_maps_read(const char *upatch, const char *map,
(__u64)upatch_st.st_ctim.tv_sec * 1000000000ULL +
(__u64)upatch_st.st_ctim.tv_nsec;
- rc = try_read_serialized(upatch, map, flags, out);
- if (rc < 0) {
+ ret = try_read_serialized(upatch, map, flags, out);
+ if (ret < 0) {
close(fd);
- return rc;
+ return ret;
}
- if (rc > 0) {
+ if (ret > 0) {
close(fd);
return 0;
}
@@ -1309,10 +1309,10 @@ int upatch_maps_read(const char *upatch, const char *map,
sizeof(out->value_type_def), &off, 0);
}
- rc = read_entries(fd, out, max_entries_cap);
+ ret = read_entries(fd, out, max_entries_cap);
close(fd);
- return rc;
+ return ret;
}
static void summary_append(struct shirudo_map_summary **list, size_t *n,
@@ -1350,14 +1350,14 @@ static void scan_upatch_maps(const char *upatch,
while ((e = readdir(d))) {
struct bpf_map_info info = {};
struct shirudo_map_summary one = {};
- int fd, rc;
+ int fd, ret;
if (e->d_name[0] == '.')
continue;
if (strcmp(e->d_name, SERIAL_MAP_NAME) == 0)
continue;
- rc = open_map_pin(upatch, e->d_name, &fd, &info);
- if (rc)
+ ret = open_map_pin(upatch, e->d_name, &fd, &info);
+ if (ret)
continue;
close(fd);
strscpy(one.upatch, upatch, sizeof(one.upatch));
diff --git a/util/upatch_maps_otel.c b/util/upatch_maps_otel.c
index 9a5500b8..eb94475c 100644
--- a/util/upatch_maps_otel.c
+++ b/util/upatch_maps_otel.c
@@ -153,7 +153,7 @@ int shirudo_upatch_maps_otel_classify(const struct shirudo_map_view *v,
char *reason, size_t reason_sz)
{
struct metric_type mt;
- int rc;
+ int ret;
if (!v || !signal)
return -EINVAL;
@@ -171,8 +171,8 @@ int shirudo_upatch_maps_otel_classify(const struct shirudo_map_view *v,
strscpy(reason, "map is not per-CPU", reason_sz);
return 0;
}
- rc = metric_type_from_view(v, &mt);
- if (rc) {
+ ret = metric_type_from_view(v, &mt);
+ if (ret) {
strscpy(reason, "value is not a BTF integer scalar", reason_sz);
return 0;
}
@@ -410,7 +410,7 @@ static int json_anyvalue_emit(struct json_anyvalue_ctx *c,
static int json_anyvalue_object(struct json_anyvalue_ctx *c,
struct shirudo_json_emit *e, bool wrap)
{
- int rc;
+ int ret;
if (c->depth++ >= JSON_MAX_DEPTH) {
c->depth--;
@@ -435,35 +435,35 @@ static int json_anyvalue_object(struct json_anyvalue_ctx *c,
const char *key;
size_t key_len;
- rc = json_anyvalue_string(c, &key, &key_len);
- if (rc)
+ ret = json_anyvalue_string(c, &key, &key_len);
+ if (ret)
break;
json_anyvalue_skip_ws(c);
if (c->p >= c->end || *c->p++ != ':') {
- rc = -EINVAL;
+ ret = -EINVAL;
break;
}
json_anyvalue_skip_ws(c);
json_obj_open(e);
json_kv_raw(e, "key", key, key_len);
json_obj_open_key(e, "value");
- rc = json_anyvalue_emit_contents(c, e);
+ ret = json_anyvalue_emit_contents(c, e);
json_obj_close(e);
json_obj_close(e);
- if (rc)
+ if (ret)
break;
json_anyvalue_skip_ws(c);
if (c->p >= c->end) {
- rc = -EINVAL;
+ ret = -EINVAL;
break;
}
if (*c->p == '}') {
c->p++;
- rc = 0;
+ ret = 0;
break;
}
if (*c->p++ != ',') {
- rc = -EINVAL;
+ ret = -EINVAL;
break;
}
json_anyvalue_skip_ws(c);
@@ -473,13 +473,13 @@ static int json_anyvalue_object(struct json_anyvalue_ctx *c,
if (wrap)
json_obj_close(e);
c->depth--;
- return rc;
+ return ret;
}
static int json_anyvalue_array(struct json_anyvalue_ctx *c,
struct shirudo_json_emit *e, bool wrap)
{
- int rc = 0;
+ int ret = 0;
if (c->depth++ >= JSON_MAX_DEPTH) {
c->depth--;
@@ -496,12 +496,12 @@ static int json_anyvalue_array(struct json_anyvalue_ctx *c,
} else {
for (;;) {
json_anyvalue_skip_ws(c);
- rc = json_anyvalue_emit(c, e);
- if (rc)
+ ret = json_anyvalue_emit(c, e);
+ if (ret)
break;
json_anyvalue_skip_ws(c);
if (c->p >= c->end) {
- rc = -EINVAL;
+ ret = -EINVAL;
break;
}
if (*c->p == ']') {
@@ -509,7 +509,7 @@ static int json_anyvalue_array(struct json_anyvalue_ctx *c,
break;
}
if (*c->p++ != ',') {
- rc = -EINVAL;
+ ret = -EINVAL;
break;
}
}
@@ -519,7 +519,7 @@ static int json_anyvalue_array(struct json_anyvalue_ctx *c,
if (wrap)
json_obj_close(e);
c->depth--;
- return rc;
+ return ret;
}
static int json_anyvalue_emit_contents(struct json_anyvalue_ctx *c,
@@ -527,7 +527,7 @@ static int json_anyvalue_emit_contents(struct json_anyvalue_ctx *c,
{
const char *start;
size_t len;
- int rc;
+ int ret;
json_anyvalue_skip_ws(c);
if (c->p >= c->end)
@@ -538,27 +538,27 @@ static int json_anyvalue_emit_contents(struct json_anyvalue_ctx *c,
case '[':
return json_anyvalue_array(c, e, false);
case '"':
- rc = json_anyvalue_string(c, &start, &len);
- if (rc)
- return rc;
+ ret = json_anyvalue_string(c, &start, &len);
+ if (ret)
+ return ret;
json_kv_raw(e, "stringValue", start, len);
return 0;
case 't':
- rc = json_anyvalue_literal(c, "true");
- if (rc)
- return rc;
+ ret = json_anyvalue_literal(c, "true");
+ if (ret)
+ return ret;
json_kv_bool(e, "boolValue", true);
return 0;
case 'f':
- rc = json_anyvalue_literal(c, "false");
- if (rc)
- return rc;
+ ret = json_anyvalue_literal(c, "false");
+ if (ret)
+ return ret;
json_kv_bool(e, "boolValue", false);
return 0;
case 'n':
- rc = json_anyvalue_literal(c, "null");
- if (rc)
- return rc;
+ ret = json_anyvalue_literal(c, "null");
+ if (ret)
+ return ret;
/* An empty AnyValue is the OTLP JSON representation of null. */
return 0;
default:
@@ -569,12 +569,12 @@ static int json_anyvalue_emit_contents(struct json_anyvalue_ctx *c,
static int json_anyvalue_emit(struct json_anyvalue_ctx *c,
struct shirudo_json_emit *e)
{
- int rc;
+ int ret;
json_obj_open(e);
- rc = json_anyvalue_emit_contents(c, e);
+ ret = json_anyvalue_emit_contents(c, e);
json_obj_close(e);
- return rc;
+ return ret;
}
static int json_anyvalue_from_document(struct shirudo_json_emit *e,
@@ -584,14 +584,14 @@ static int json_anyvalue_from_document(struct shirudo_json_emit *e,
.p = json,
.end = json + len,
};
- int rc;
+ int ret;
if (!wrap && (c.p >= c.end || *c.p != '{'))
return -EINVAL;
- rc = wrap ? json_anyvalue_emit(&c, e) :
+ ret = wrap ? json_anyvalue_emit(&c, e) :
json_anyvalue_object(&c, e, false);
- if (rc)
- return rc;
+ if (ret)
+ return ret;
json_anyvalue_skip_ws(&c);
return c.p == c.end ? 0 : -EINVAL;
}
@@ -865,13 +865,13 @@ static int build_metric_decoded_payload(const char *path,
struct shirudo_json_emit e = {};
char *decoded = NULL, *decoded_buf, *buf;
size_t decoded_len = 0, decoded_alloc_len;
- int rc;
+ int ret;
- rc = path ? upatch_decode_map_file_json(path, v,
+ ret = path ? upatch_decode_map_file_json(path, v,
&decoded, &decoded_len) :
upatch_decode_map_json(v, &decoded, &decoded_len);
- if (rc)
- return rc;
+ if (ret)
+ return ret;
decoded_buf = decoded;
decoded_alloc_len = decoded_len;
while (decoded_len && isspace((__u8)decoded[0])) {
@@ -1002,7 +1002,7 @@ static int validate_endpoint_security(struct otel_state *st)
CURLU *url = curl_url();
char *scheme = NULL, *host = NULL, *user = NULL, *password = NULL;
CURLUcode uc;
- int rc = 0;
+ int ret = 0;
if (!url)
return -ENOMEM;
@@ -1011,22 +1011,22 @@ static int validate_endpoint_security(struct otel_state *st)
return curl_url_cleanup(url), -EINVAL;
if (curl_url_get(url, CURLUPART_SCHEME, &scheme, 0) ||
curl_url_get(url, CURLUPART_HOST, &host, 0)) {
- rc = -EINVAL;
+ ret = -EINVAL;
goto out;
}
(void)curl_url_get(url, CURLUPART_USER, &user, 0);
(void)curl_url_get(url, CURLUPART_PASSWORD, &password, 0);
if ((user && user[0]) || (password && password[0])) {
- rc = -EINVAL;
+ ret = -EINVAL;
goto out;
}
if (strscpy(st->host, host, sizeof(st->host)) < 0) {
- rc = -ENAMETOOLONG;
+ ret = -ENAMETOOLONG;
goto out;
}
if (strcmp(scheme, "http") == 0) {
if (!loopback_host(host) && !st->opts.allow_insecure) {
- rc = -EPERM;
+ ret = -EPERM;
goto out;
}
if (st->opts.allow_insecure)
@@ -1040,7 +1040,7 @@ static int validate_endpoint_security(struct otel_state *st)
"and hostname verification for %s; the Collector's "
"identity is not verified\n", host);
} else {
- rc = -EPROTONOSUPPORT;
+ ret = -EPROTONOSUPPORT;
}
out:
curl_free(scheme);
@@ -1048,7 +1048,7 @@ out:
curl_free(user);
curl_free(password);
curl_url_cleanup(url);
- return rc;
+ return ret;
}
int shirudo_upatch_maps_otel_build_metric_file(const char *path,
@@ -1123,7 +1123,7 @@ static int add_configured_headers(struct otel_state *st, const char *input)
char *copy, *save = NULL, *pair;
size_t total = input ? strlen(input) : 0;
bool tenant_seen = false;
- int rc = 0;
+ int ret = 0;
if (!input)
return 0;
@@ -1140,7 +1140,7 @@ static int add_configured_headers(struct otel_state *st, const char *input)
size_t n;
if (!eq) {
- rc = -EINVAL;
+ ret = -EINVAL;
break;
}
*eq = '\0';
@@ -1157,14 +1157,14 @@ static int add_configured_headers(struct otel_state *st, const char *input)
if (!name[0] || reserved_header(name) ||
percent_decode(value) != 0 || strpbrk(name, "\r\n:") ||
strpbrk(value, "\r\n")) {
- rc = -EINVAL;
+ ret = -EINVAL;
break;
}
if (tenant) {
if (st->opts.tenant_id)
continue;
if (tenant_seen || !tenant_id_valid(value)) {
- rc = -EINVAL;
+ ret = -EINVAL;
break;
}
tenant_seen = true;
@@ -1173,19 +1173,19 @@ static int add_configured_headers(struct otel_state *st, const char *input)
n = strlen(name) + strlen(value) + 3;
line = xmalloc(n);
if (!line) {
- rc = -ENOMEM;
+ ret = -ENOMEM;
break;
}
- rc = strsprintf(line, n, "%s: %s", name, value) < 0 ? -E2BIG :
+ ret = strsprintf(line, n, "%s: %s", name, value) < 0 ? -E2BIG :
append_header(st, line);
explicit_bzero(line, n);
xfree(line, n);
- if (rc)
+ if (ret)
break;
}
explicit_bzero(copy, total);
xfree(copy, total + 1);
- return rc;
+ return ret;
}
static int configure_state(struct otel_state *st, const char *spec,
@@ -1194,7 +1194,7 @@ static int configure_state(struct otel_state *st, const char *spec,
const char *protocol = otel_env(st->signal, "PROTOCOL");
const char *compression = otel_env(st->signal, "COMPRESSION");
const char *headers = otel_env(st->signal, "HEADERS");
- int rc;
+ int ret;
if (protocol && strcmp(protocol, "http/json") != 0)
return -EPROTONOSUPPORT;
@@ -1207,26 +1207,26 @@ static int configure_state(struct otel_state *st, const char *spec,
st->client_key = otel_env(st->signal, "CLIENT_KEY");
if (!!st->client_cert != !!st->client_key)
return -EINVAL;
- rc = parse_timeout(otel_env(st->signal, "TIMEOUT"), &st->timeout_ms);
- if (rc)
- return rc;
- rc = resolve_endpoint(st, spec, spec_is_base);
- if (rc)
- return rc;
- rc = validate_endpoint_security(st);
- if (rc)
- return rc;
- rc = append_header(st, "Content-Type: application/json");
- if (rc)
- return rc;
+ ret = parse_timeout(otel_env(st->signal, "TIMEOUT"), &st->timeout_ms);
+ if (ret)
+ return ret;
+ ret = resolve_endpoint(st, spec, spec_is_base);
+ if (ret)
+ return ret;
+ ret = validate_endpoint_security(st);
+ if (ret)
+ return ret;
+ ret = append_header(st, "Content-Type: application/json");
+ if (ret)
+ return ret;
if (st->gzip) {
- rc = append_header(st, "Content-Encoding: gzip");
- if (rc)
- return rc;
+ ret = append_header(st, "Content-Encoding: gzip");
+ if (ret)
+ return ret;
}
- rc = add_configured_headers(st, headers);
- if (rc || !st->opts.tenant_id)
- return rc;
+ ret = add_configured_headers(st, headers);
+ if (ret || !st->opts.tenant_id)
+ return ret;
if (!tenant_id_valid(st->opts.tenant_id))
return -EINVAL;
{
@@ -1427,12 +1427,12 @@ static int check_partial_success(enum shirudo_otel_signal signal,
partial, ARRAY_SIZE(partial) },
};
__s64 rejected = 0;
- int rc;
+ int ret;
if (len == 0)
return 0;
- rc = json_parse(body, len, root, ARRAY_SIZE(root));
- if (rc) {
+ ret = json_parse(body, len, root, ARRAY_SIZE(root));
+ if (ret) {
partial[0] = (struct shirudo_json_field){
count, SHIRUDO_JSON_T_INT, &rejected, 0, 0, NULL, 0 };
if (json_parse(body, len, root, ARRAY_SIZE(root)))
@@ -1492,15 +1492,15 @@ static int otel_post(struct otel_state *st, const char *json, size_t json_len)
const void *body = json;
size_t body_len = json_len, compressed_cap = 0;
__u32 attempt, max_attempts = st->opts.retries + 1;
- int rc = -EIO;
+ int ret = -EIO;
if (!st->s3_reference && st->opts.otlp_max_bytes &&
json_len > st->opts.otlp_max_bytes)
return -E2BIG;
if (st->gzip) {
- rc = gzip_data(json, json_len, &compressed, &body_len);
- if (rc)
- return rc;
+ ret = gzip_data(json, json_len, &compressed, &body_len);
+ if (ret)
+ return ret;
body = compressed;
compressed_cap = compressBound(json_len) + 32;
}
@@ -1512,7 +1512,7 @@ static int otel_post(struct otel_state *st, const char *json, size_t json_len)
bool retry;
if (!curl) {
- rc = -ENOMEM;
+ ret = -ENOMEM;
break;
}
curl_easy_setopt(curl, CURLOPT_URL, st->endpoint);
@@ -1535,7 +1535,7 @@ static int otel_post(struct otel_state *st, const char *json, size_t json_len)
st->insecure_tls ? 0L : 2L);
if (tls_curl_policy(curl, NULL)) {
curl_easy_cleanup(curl);
- rc = -EINVAL;
+ ret = -EINVAL;
break;
}
if (st->ca_file)
@@ -1548,8 +1548,8 @@ static int otel_post(struct otel_state *st, const char *json, size_t json_len)
if (cc == CURLE_OK)
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &status);
if (cc == CURLE_OK && status == 200) {
- rc = check_partial_success(st->signal, response.buf,
- response.len);
+ ret = check_partial_success(st->signal, response.buf,
+ response.len);
curl_easy_cleanup(curl);
break;
}
@@ -1561,7 +1561,7 @@ static int otel_post(struct otel_state *st, const char *json, size_t json_len)
else
fprintf(stderr, "otel: export attempt %u/%u received HTTP %ld\n",
attempt + 1, max_attempts, status);
- rc = cc == CURLE_OPERATION_TIMEDOUT ? -ETIMEDOUT :
+ ret = cc == CURLE_OPERATION_TIMEDOUT ? -ETIMEDOUT :
cc != CURLE_OK ? -EHOSTUNREACH : -EREMOTEIO;
curl_easy_cleanup(curl);
if (!retry || attempt + 1 == max_attempts)
@@ -1571,7 +1571,7 @@ static int otel_post(struct otel_state *st, const char *json, size_t json_len)
}
if (compressed)
xfree(compressed, compressed_cap);
- return rc;
+ return ret;
}
static int otel_open_transport(enum shirudo_otel_signal signal,
@@ -1580,7 +1580,7 @@ static int otel_open_transport(enum shirudo_otel_signal signal,
const char *decoder_path, void **state)
{
struct otel_state *st;
- int rc;
+ int ret;
if (!state)
return -EINVAL;
@@ -1599,12 +1599,12 @@ static int otel_open_transport(enum shirudo_otel_signal signal,
MAP_EXPORT_LOG_RECORD_MAX_DEFAULT;
st->decoder_path = decoder_path;
if (curl_global_init(CURL_GLOBAL_DEFAULT) != CURLE_OK) {
- rc = -EIO;
+ ret = -EIO;
goto err;
}
/* Explicit CLI/config endpoints are base URLs for the selected signal. */
- rc = configure_state(st, spec, true);
- if (rc)
+ ret = configure_state(st, spec, true);
+ if (ret)
goto err_global;
*state = st;
return 0;
@@ -1614,7 +1614,7 @@ err_global:
err:
curl_slist_free_all(st->headers);
xfree(st, sizeof(*st));
- return rc;
+ return ret;
}
static int otel_open_common(const char *spec, const struct shirudo_map_view *v,
@@ -1624,15 +1624,15 @@ static int otel_open_common(const char *spec, const struct shirudo_map_view *v,
{
enum shirudo_otel_signal signal;
char reason[160];
- int rc;
+ int ret;
if (!v || !state)
return -EINVAL;
if (automatic) {
- rc = shirudo_upatch_maps_otel_classify(v, &signal,
- reason, sizeof(reason));
- if (rc)
- return rc;
+ ret = shirudo_upatch_maps_otel_classify(v, &signal,
+ reason, sizeof(reason));
+ if (ret)
+ return ret;
fprintf(stderr, "otel: selected %s for %s map %s: %s\n",
signal == SHIRUDO_OTEL_LOG ? "log" : "metric",
v->type_name, v->name, reason);
@@ -1647,22 +1647,22 @@ static int otel_emit(void *state, const struct shirudo_map_view *v)
struct otel_state *st = state;
char *payload = NULL;
size_t len = 0;
- int rc;
+ int ret;
if (!st || !v)
return -EINVAL;
if (st->signal == SHIRUDO_OTEL_LOG)
- rc = build_log_payload(st->decoder_path, v,
- st->opts.log_record_max_bytes,
- &payload, &len);
+ ret = build_log_payload(st->decoder_path, v,
+ st->opts.log_record_max_bytes,
+ &payload, &len);
else
- rc = build_metric_decoded_payload(st->decoder_path, v,
- &payload, &len);
- if (rc)
- return rc;
- rc = otel_post(st, payload, len);
+ ret = build_metric_decoded_payload(st->decoder_path, v,
+ &payload, &len);
+ if (ret)
+ return ret;
+ ret = otel_post(st, payload, len);
xfree(payload, JSON_MAX_BYTES);
- return rc;
+ return ret;
}
static int otel_close(void *state)
@@ -1696,7 +1696,7 @@ static int build_generic_log_payload(const char *scope_name,
{
struct shirudo_json_emit e = {};
char *buf;
- int rc;
+ int ret;
size_t cap;
if (!scope_name || !event_name || !severity_text || !body_json ||
@@ -1713,11 +1713,11 @@ static int build_generic_log_payload(const char *scope_name,
log_open(&e, scope_name, severity_number, severity_text, event_name);
json_obj_open_key(&e, "body");
- rc = json_anyvalue_from_document(&e, body_json, body_len, false);
+ ret = json_anyvalue_from_document(&e, body_json, body_len, false);
json_obj_close(&e);
- if (rc) {
+ if (ret) {
xfree(buf, cap);
- return rc;
+ return ret;
}
json_arr_open(&e, "attributes");
if (status)
@@ -1751,24 +1751,24 @@ int shirudo_otel_send_log_json(const struct shirudo_otel_opts *opts,
char *payload = NULL;
void *state = NULL;
size_t payload_len = 0, alloc_len = 0;
- int rc;
-
- rc = otel_open_transport(SHIRUDO_OTEL_LOG,
- opts ? opts->endpoint : NULL, opts, NULL, &state);
- if (rc)
- return rc;
- rc = build_generic_log_payload(scope_name, event_name,
- severity_number, severity_text,
- status, version_id,
- tamper_attempts,
- body_json, body_len,
- &payload, &payload_len, &alloc_len);
- if (!rc)
- rc = otel_post(state, payload, payload_len);
+ int ret;
+
+ ret = otel_open_transport(SHIRUDO_OTEL_LOG,
+ opts ? opts->endpoint : NULL, opts, NULL, &state);
+ if (ret)
+ return ret;
+ ret = build_generic_log_payload(scope_name, event_name,
+ severity_number, severity_text,
+ status, version_id,
+ tamper_attempts,
+ body_json, body_len,
+ &payload, &payload_len, &alloc_len);
+ if (!ret)
+ ret = otel_post(state, payload, payload_len);
if (payload)
xfree(payload, alloc_len);
otel_close(state);
- return rc;
+ return ret;
}
struct snapshot_writer {
@@ -1797,24 +1797,24 @@ static int snapshot_temp_file(FILE **out)
if (fd < 0)
return -errno;
if (fchmod(fd, 0600) != 0) {
- int rc = -errno;
+ int ret = -errno;
unlink(path);
close(fd);
- return rc;
+ return ret;
}
if (unlink(path) != 0) {
- int rc = -errno;
+ int ret = -errno;
close(fd);
- return rc;
+ return ret;
}
file = fdopen(fd, "w+b");
if (!file) {
- int rc = -errno;
+ int ret = -errno;
close(fd);
- return rc;
+ return ret;
}
*out = file;
return 0;
@@ -1877,7 +1877,7 @@ static int snapshot_json_sink(void *ctx, const char *data, size_t len)
w->z.avail_in = chunk;
while (w->z.avail_in) {
size_t produced;
- int rc, zr;
+ int ret, zr;
w->z.next_out = out;
w->z.avail_out = sizeof(out);
@@ -1885,9 +1885,9 @@ static int snapshot_json_sink(void *ctx, const char *data, size_t len)
if (zr != Z_OK)
return -EIO;
produced = sizeof(out) - w->z.avail_out;
- rc = snapshot_write_compressed(w, out, produced);
- if (rc)
- return rc;
+ ret = snapshot_write_compressed(w, out, produced);
+ if (ret)
+ return ret;
}
data += chunk;
len -= chunk;
@@ -1899,7 +1899,7 @@ static int snapshot_writer_finish(struct snapshot_writer *w,
struct s3_snapshot *snapshot)
{
__u8 out[S3_GZIP_BUFFER_SIZE];
- int zr, rc;
+ int zr, ret;
do {
size_t produced;
@@ -1910,9 +1910,9 @@ static int snapshot_writer_finish(struct snapshot_writer *w,
if (zr != Z_OK && zr != Z_STREAM_END)
return -EIO;
produced = sizeof(out) - w->z.avail_out;
- rc = snapshot_write_compressed(w, out, produced);
- if (rc)
- return rc;
+ ret = snapshot_write_compressed(w, out, produced);
+ if (ret)
+ return ret;
} while (zr != Z_STREAM_END);
if (deflateEnd(&w->z) != Z_OK)
return -EIO;
@@ -1940,38 +1940,38 @@ static int build_s3_snapshot(const char *decoder_path,
struct snapshot_writer writer;
char *decoded = NULL;
size_t decoded_len = 0;
- int rc;
+ int ret;
memset(snapshot, 0, sizeof(*snapshot));
/* S3 stores exactly the canonical value returned by the signed decoder. */
if (decoder_path)
- rc = upatch_decode_map_file_json_limit(decoder_path, v,
- S3_DECODER_JSON_MAX_BYTES,
- &decoded,
- &decoded_len);
+ ret = upatch_decode_map_file_json_limit(decoder_path, v,
+ S3_DECODER_JSON_MAX_BYTES,
+ &decoded,
+ &decoded_len);
else
- rc = upatch_decode_map_json_limit(v,
- S3_DECODER_JSON_MAX_BYTES,
- &decoded,
- &decoded_len);
- if (rc)
- return rc;
- rc = snapshot_temp_file(&snapshot->file);
- if (rc) {
+ ret = upatch_decode_map_json_limit(v,
+ S3_DECODER_JSON_MAX_BYTES,
+ &decoded,
+ &decoded_len);
+ if (ret)
+ return ret;
+ ret = snapshot_temp_file(&snapshot->file);
+ if (ret) {
xfree(decoded, decoded_len + 1);
- return rc;
+ return ret;
}
- rc = snapshot_writer_init(&writer, snapshot->file);
- if (rc) {
+ ret = snapshot_writer_init(&writer, snapshot->file);
+ if (ret) {
xfree(decoded, decoded_len + 1);
goto err_writer;
}
- rc = snapshot_json_sink(&writer, decoded, decoded_len);
+ ret = snapshot_json_sink(&writer, decoded, decoded_len);
xfree(decoded, decoded_len + 1);
- if (rc)
+ if (ret)
goto err_writer;
- rc = snapshot_writer_finish(&writer, snapshot);
- if (rc)
+ ret = snapshot_writer_finish(&writer, snapshot);
+ if (ret)
goto err_writer;
return 0;
@@ -1979,7 +1979,7 @@ err_writer:
snapshot_writer_abort(&writer);
fclose(snapshot->file);
snapshot->file = NULL;
- return rc;
+ return ret;
}
static bool valid_bucket(const char *bucket, size_t len)
@@ -2098,7 +2098,7 @@ static int validate_s3_endpoint(struct otel_s3_state *st)
{
CURLU *url;
char *scheme = NULL, *host = NULL, *user = NULL, *password = NULL;
- int rc = 0;
+ int ret = 0;
if (!st->custom_endpoint) {
if (st->opts.allow_insecure) {
@@ -2114,27 +2114,27 @@ static int validate_s3_endpoint(struct otel_s3_state *st)
if (curl_url_set(url, CURLUPART_URL, st->endpoint, 0) ||
curl_url_get(url, CURLUPART_SCHEME, &scheme, 0) ||
curl_url_get(url, CURLUPART_HOST, &host, 0)) {
- rc = -EINVAL;
+ ret = -EINVAL;
goto out;
}
(void)curl_url_get(url, CURLUPART_USER, &user, 0);
(void)curl_url_get(url, CURLUPART_PASSWORD, &password, 0);
if ((user && user[0]) || (password && password[0]) ||
strchr(st->endpoint, '?') || strchr(st->endpoint, '#')) {
- rc = -EINVAL;
+ ret = -EINVAL;
goto out;
}
if (strlen(host) >= sizeof(st->host)) {
- rc = -ENAMETOOLONG;
+ ret = -ENAMETOOLONG;
goto out;
}
if (strscpy(st->host, host, sizeof(st->host)) < 0) {
- rc = -ENAMETOOLONG;
+ ret = -ENAMETOOLONG;
goto out;
}
if (strcmp(scheme, "http") == 0) {
if (!loopback_host(host) && !st->opts.allow_insecure) {
- rc = -EPERM;
+ ret = -EPERM;
goto out;
}
if (st->opts.allow_insecure)
@@ -2146,7 +2146,7 @@ static int validate_s3_endpoint(struct otel_s3_state *st)
fprintf(stderr, "WARNING: --otel-insecure disables TLS certificate "
"and hostname verification for S3 endpoint %s\n", host);
} else {
- rc = -EPROTONOSUPPORT;
+ ret = -EPROTONOSUPPORT;
}
out:
curl_free(scheme);
@@ -2154,7 +2154,7 @@ out:
curl_free(user);
curl_free(password);
curl_url_cleanup(url);
- return rc;
+ return ret;
}
static void safe_key_segment(char *segment)
@@ -2197,7 +2197,7 @@ static int build_s3_urls(const struct otel_s3_state *st,
{
char hostname[256] = "unknown";
char key[S3_URL_MAX], escaped[S3_URL_MAX];
- int n, rc;
+ int n, ret;
if (gethostname(hostname, sizeof(hostname)) != 0)
strscpy(hostname, "unknown", sizeof(hostname));
@@ -2208,9 +2208,9 @@ static int build_s3_urls(const struct otel_s3_state *st,
v->upatch, v->name, snapshot->sha256_hex);
if (n < 0 || (size_t)n > S3_KEY_MAX)
return -ENAMETOOLONG;
- rc = escape_s3_path(key, escaped, sizeof(escaped));
- if (rc)
- return rc;
+ ret = escape_s3_path(key, escaped, sizeof(escaped));
+ if (ret)
+ return ret;
if (strsprintf(uri, uri_sz, "s3://%s/%s", st->bucket, escaped) < 0)
return -ENAMETOOLONG;
if (st->custom_endpoint)
@@ -2253,7 +2253,7 @@ static int s3_headers(const struct otel_s3_state *st,
upatch,
map,
};
- int rc;
+ int ret;
if (strsprintf(sha256, sizeof(sha256), "x-amz-content-sha256: %s",
snapshot->sha256_hex) < 0 ||
@@ -2265,9 +2265,9 @@ static int s3_headers(const struct otel_s3_state *st,
v->name) < 0)
return -E2BIG;
for (size_t i = 0; i < ARRAY_SIZE(lines); i++) {
- rc = s3_header(out, lines[i]);
- if (rc)
- return rc;
+ ret = s3_header(out, lines[i]);
+ if (ret)
+ return ret;
}
/* STS session tokens run well past a kilobyte. */
if (st->session_token) {
@@ -2277,12 +2277,12 @@ static int s3_headers(const struct otel_s3_state *st,
if (!token)
return -ENOMEM;
- rc = strsprintf(token, len, "x-amz-security-token: %s",
- st->session_token) < 0 ? -E2BIG :
+ ret = strsprintf(token, len, "x-amz-security-token: %s",
+ st->session_token) < 0 ? -E2BIG :
s3_header(out, token);
xfree(token, len);
- if (rc)
- return rc;
+ if (ret)
+ return ret;
}
return 0;
}
@@ -2301,16 +2301,16 @@ static int s3_put(struct otel_s3_state *st,
struct curl_slist *headers = NULL;
char sigv4[128];
__u32 max_attempts = st->opts.retries + 1;
- int rc;
+ int ret;
*already_present = false;
- rc = s3_headers(st, v, snapshot, &headers);
- if (rc) {
+ ret = s3_headers(st, v, snapshot, &headers);
+ if (ret) {
curl_slist_free_all(headers);
- return rc;
+ return ret;
}
if (strsprintf(sigv4, sizeof(sigv4), "aws:amz:%s:s3", st->region) < 0) {
- rc = -ENAMETOOLONG;
+ ret = -ENAMETOOLONG;
goto out;
}
for (__u32 attempt = 0; attempt < max_attempts; attempt++) {
@@ -2321,13 +2321,13 @@ static int s3_put(struct otel_s3_state *st,
bool retry;
if (!curl) {
- rc = -ENOMEM;
+ ret = -ENOMEM;
break;
}
clearerr(snapshot->file);
if (fseeko(snapshot->file, 0, SEEK_SET) != 0) {
curl_easy_cleanup(curl);
- rc = -EIO;
+ ret = -EIO;
break;
}
curl_easy_setopt(curl, CURLOPT_URL, url);
@@ -2353,7 +2353,7 @@ static int s3_put(struct otel_s3_state *st,
st->insecure_tls ? 0L : 2L);
if (tls_curl_policy(curl, NULL)) {
curl_easy_cleanup(curl);
- rc = -EINVAL;
+ ret = -EINVAL;
break;
}
if (st->ca_file)
@@ -2365,7 +2365,7 @@ static int s3_put(struct otel_s3_state *st,
(status == 200 || status == 201 || status == 204 ||
status == 412)) {
*already_present = status == 412;
- rc = 0;
+ ret = 0;
curl_easy_cleanup(curl);
break;
}
@@ -2377,7 +2377,7 @@ static int s3_put(struct otel_s3_state *st,
else
fprintf(stderr, "otel.s3: upload attempt %u/%u received HTTP %ld\n",
attempt + 1, max_attempts, status);
- rc = cc == CURLE_OPERATION_TIMEDOUT ? -ETIMEDOUT :
+ ret = cc == CURLE_OPERATION_TIMEDOUT ? -ETIMEDOUT :
cc != CURLE_OK ? -EHOSTUNREACH : -EREMOTEIO;
curl_easy_cleanup(curl);
if (!retry || attempt + 1 == max_attempts)
@@ -2387,7 +2387,7 @@ static int s3_put(struct otel_s3_state *st,
}
out:
curl_slist_free_all(headers);
- return rc;
+ return ret;
}
static int build_s3_reference(const struct shirudo_map_view *v,
@@ -2458,7 +2458,7 @@ static int otel_s3_open(const char *spec, const struct shirudo_map_view *v,
{
struct otel_s3_state *st;
void *otel = NULL;
- int rc;
+ int ret;
if (!v || !state || !spec || !spec[0])
return -EINVAL;
@@ -2472,15 +2472,15 @@ static int otel_s3_open(const char *spec, const struct shirudo_map_view *v,
st->opts.retries = 3;
if (opts)
st->opts = *opts;
- rc = parse_s3_spec(st, spec);
- if (rc)
+ ret = parse_s3_spec(st, spec);
+ if (ret)
goto err;
- rc = validate_s3_endpoint(st);
- if (rc)
+ ret = validate_s3_endpoint(st);
+ if (ret)
goto err;
- rc = otel_open_common(st->opts.endpoint, v, &st->opts, false,
- SHIRUDO_OTEL_LOG, decoder_path, &otel);
- if (rc)
+ ret = otel_open_common(st->opts.endpoint, v, &st->opts, false,
+ SHIRUDO_OTEL_LOG, decoder_path, &otel);
+ if (ret)
goto err;
st->otel = otel;
st->otel->s3_reference = true;
@@ -2488,7 +2488,7 @@ static int otel_s3_open(const char *spec, const struct shirudo_map_view *v,
return 0;
err:
otel_s3_state_free(st);
- return rc;
+ return ret;
}
static int otel_s3_emit(void *state, const struct shirudo_map_view *v)
@@ -2499,34 +2499,34 @@ static int otel_s3_emit(void *state, const struct shirudo_map_view *v)
char *payload = NULL;
size_t payload_len = 0;
bool already_present;
- int rc;
+ int ret;
if (!st || !v)
return -EINVAL;
- rc = build_s3_snapshot(st->otel ? st->otel->decoder_path : NULL,
- v, &snapshot);
- if (rc)
- return rc;
- rc = build_s3_urls(st, v, &snapshot, url, sizeof(url), uri,
- sizeof(uri));
- if (rc)
+ ret = build_s3_snapshot(st->otel ? st->otel->decoder_path : NULL,
+ v, &snapshot);
+ if (ret)
+ return ret;
+ ret = build_s3_urls(st, v, &snapshot, url, sizeof(url), uri,
+ sizeof(uri));
+ if (ret)
goto out;
- rc = s3_put(st, v, &snapshot, url, &already_present);
- if (rc)
+ ret = s3_put(st, v, &snapshot, url, &already_present);
+ if (ret)
goto out;
fprintf(stderr, "otel.s3: %s %s (%llu bytes)\n",
already_present ? "found" : "uploaded", uri,
snapshot.object_bytes);
- rc = build_s3_reference(v, &snapshot, uri, &payload, &payload_len);
- if (rc)
+ ret = build_s3_reference(v, &snapshot, uri, &payload, &payload_len);
+ if (ret)
goto out;
- rc = otel_post(st->otel, payload, payload_len);
+ ret = otel_post(st->otel, payload, payload_len);
out:
if (payload)
xfree(payload, S3_REFERENCE_MAX);
if (snapshot.file)
fclose(snapshot.file);
- return rc;
+ return ret;
}
static int otel_s3_close(void *state)
@@ -2544,17 +2544,17 @@ int shirudo_upatch_maps_otel_send_file(const char *decoder_path,
bool automatic = mode == SHIRUDO_OTEL_AUTO;
enum shirudo_otel_signal signal;
void *state = NULL;
- int rc, close_rc;
+ int ret, close_rc;
if (mode == SHIRUDO_OTEL_S3) {
if (!opts || !opts->s3_uri)
return -EINVAL;
- rc = otel_s3_open(opts->s3_uri, v, opts, decoder_path, &state);
- if (rc)
- return rc;
- rc = otel_s3_emit(state, v);
+ ret = otel_s3_open(opts->s3_uri, v, opts, decoder_path, &state);
+ if (ret)
+ return ret;
+ ret = otel_s3_emit(state, v);
close_rc = otel_s3_close(state);
- return rc ? rc : close_rc;
+ return ret ? ret : close_rc;
}
if (mode == SHIRUDO_OTEL_FORCE_LOG)
signal = SHIRUDO_OTEL_LOG;
@@ -2564,13 +2564,13 @@ int shirudo_upatch_maps_otel_send_file(const char *decoder_path,
signal = SHIRUDO_OTEL_LOG;
else
return -EINVAL;
- rc = otel_open_common(endpoint, v, opts, automatic, signal,
- decoder_path, &state);
- if (rc)
- return rc;
- rc = otel_emit(state, v);
+ ret = otel_open_common(endpoint, v, opts, automatic, signal,
+ decoder_path, &state);
+ if (ret)
+ return ret;
+ ret = otel_emit(state, v);
close_rc = otel_close(state);
- return rc ? rc : close_rc;
+ return ret ? ret : close_rc;
}
int shirudo_upatch_maps_otel_send(const struct shirudo_map_view *v,
@@ -2584,17 +2584,17 @@ int shirudo_upatch_maps_otel_send_decoded(const struct shirudo_map_view *v,
enum shirudo_otel_signal signal,
const struct shirudo_otel_opts *opts)
{
- int rc;
+ int ret;
if (signal == SHIRUDO_OTEL_LOG)
- rc = shirudo_upatch_maps_otel_send(v, SHIRUDO_OTEL_FORCE_LOG,
- opts);
+ ret = shirudo_upatch_maps_otel_send(v, SHIRUDO_OTEL_FORCE_LOG,
+ opts);
else if (signal == SHIRUDO_OTEL_METRIC)
- rc = shirudo_upatch_maps_otel_send(v, SHIRUDO_OTEL_FORCE_METRIC,
- opts);
+ ret = shirudo_upatch_maps_otel_send(v, SHIRUDO_OTEL_FORCE_METRIC,
+ opts);
else
return -EINVAL;
- if (rc == -E2BIG && opts && opts->s3_uri)
+ if (ret == -E2BIG && opts && opts->s3_uri)
return shirudo_upatch_maps_otel_send(v, SHIRUDO_OTEL_S3, opts);
- return rc;
+ return ret;
}
diff --git a/util/upatch_resolve.c b/util/upatch_resolve.c
index da5e97f9..f287a8a8 100644
--- a/util/upatch_resolve.c
+++ b/util/upatch_resolve.c
@@ -95,7 +95,7 @@ int upatch_resolve_location(struct btf *vbtf, const char *name,
struct bpf_link_info linfo = {};
struct bpf_prog_info info = {};
const char *attach_name = NULL;
- int link_fd, prog_fd, rc;
+ int link_fd, prog_fd, ret;
__u32 attach_type = 0;
const char *prefix;
__u32 len;
@@ -105,10 +105,10 @@ int upatch_resolve_location(struct btf *vbtf, const char *name,
if (link_fd < 0)
return link_fd;
len = sizeof(linfo);
- rc = bpf_link_get_info_by_fd(link_fd, &linfo, &len);
- if (rc != 0 || linfo.prog_id == 0) {
+ ret = bpf_link_get_info_by_fd(link_fd, &linfo, &len);
+ if (ret != 0 || linfo.prog_id == 0) {
close(link_fd);
- return rc ? -errno : -EINVAL;
+ return ret ? -errno : -EINVAL;
}
if (linfo.type == BPF_LINK_TYPE_UPROBE_MULTI) {
struct bpf_link_info detail = {};
@@ -128,21 +128,21 @@ int upatch_resolve_location(struct btf *vbtf, const char *name,
detail.uprobe_multi.path = ptr_to_u64(path);
detail.uprobe_multi.path_size = path_size;
len = sizeof(detail);
- rc = bpf_link_get_info_by_fd(link_fd, &detail, &len);
+ ret = bpf_link_get_info_by_fd(link_fd, &detail, &len);
close(link_fd);
- if (rc != 0) {
- rc = -errno;
+ if (ret != 0) {
+ ret = -errno;
xfree(path, path_size);
- return rc;
+ return ret;
}
if (!memchr(path, '\0', path_size)) {
xfree(path, path_size);
return -EINVAL;
}
- rc = strsprintf(out, cap, "uprobe.multi/%s (%u funcs)", path,
- count) < 0 ? -E2BIG : 0;
+ ret = strsprintf(out, cap, "uprobe.multi/%s (%u funcs)", path,
+ count) < 0 ? -E2BIG : 0;
xfree(path, path_size);
- return rc;
+ return ret;
}
close(link_fd);
if (linfo.type == BPF_LINK_TYPE_TRACING)
@@ -159,9 +159,9 @@ int upatch_resolve_location(struct btf *vbtf, const char *name,
if (prog_fd < 0)
return -errno;
len = sizeof(info);
- rc = bpf_prog_get_info_by_fd(prog_fd, &info, &len);
+ ret = bpf_prog_get_info_by_fd(prog_fd, &info, &len);
close(prog_fd);
- if (rc != 0)
+ if (ret != 0)
return -errno;
if (vbtf && info.attach_btf_id &&
diff --git a/util/upatch_rodata.c b/util/upatch_rodata.c
index fd03f7b0..a37d000c 100644
--- a/util/upatch_rodata.c
+++ b/util/upatch_rodata.c
@@ -163,7 +163,7 @@ static int find_rodata_data(const struct shirudo_upatch *u,
struct rodata_map maps[RODATA_MAPS_MAX] = {};
size_t count = u->hdr.loader_insns_len / sizeof(*insns), i;
__u32 sec_size;
- int rc = -ENODATA;
+ int ret = -ENODATA;
if (!sec || BTF_INFO_KIND(sec->info) != BTF_KIND_DATASEC ||
u->hdr.loader_insns_len % sizeof(*insns))
@@ -228,7 +228,7 @@ static int find_rodata_data(const struct shirudo_upatch *u,
return 0;
}
}
- return rc;
+ return ret;
}
static int btf_rodata_btf(const struct shirudo_upatch *u,
@@ -317,15 +317,15 @@ static int btf_rodata_btf(const struct shirudo_upatch *u,
int upatch_rodata_data_offset(const struct shirudo_upatch *u, __u32 *offset)
{
struct rodata_view view = {};
- int rc;
+ int ret;
if (!u || !offset)
return -EINVAL;
- rc = btf_rodata_btf(u, &view);
- if (!rc)
+ ret = btf_rodata_btf(u, &view);
+ if (!ret)
*offset = view.data_offset;
btf__free(view.btf);
- return rc;
+ return ret;
}
int upatch_rodata_symbol_range(const struct shirudo_upatch *u,
@@ -337,18 +337,18 @@ int upatch_rodata_symbol_range(const struct shirudo_upatch *u,
const struct btf_var_secinfo *vars;
bool found = false;
__u32 i;
- int rc;
+ int ret;
if (!u || !symbol || !symbol[0] || !range)
return -EINVAL;
- rc = btf_rodata_btf(u, &view);
- if (rc) {
+ ret = btf_rodata_btf(u, &view);
+ if (ret) {
btf__free(view.btf);
- return rc;
+ return ret;
}
sec = btf__type_by_id(view.btf, view.type_id);
if (!sec || BTF_INFO_KIND(sec->info) != BTF_KIND_DATASEC) {
- rc = -EINVAL;
+ ret = -EINVAL;
goto out;
}
vars = (const struct btf_var_secinfo *)(sec + 1);
@@ -366,7 +366,7 @@ int upatch_rodata_symbol_range(const struct shirudo_upatch *u,
if (strcmp(name, symbol))
continue;
if (found) {
- rc = -EEXIST;
+ ret = -EEXIST;
goto out;
}
offset = vars[i].offset;
@@ -375,17 +375,17 @@ int upatch_rodata_symbol_range(const struct shirudo_upatch *u,
view.data_offset > u->hdr.data_len ||
offset > u->hdr.data_len - view.data_offset ||
size > u->hdr.data_len - view.data_offset - offset) {
- rc = -EINVAL;
+ ret = -EINVAL;
goto out;
}
range->offset = view.data_offset + offset;
range->size = size;
found = true;
}
- rc = found ? 0 : -ENOENT;
+ ret = found ? 0 : -ENOENT;
out:
btf__free(view.btf);
- return rc;
+ return ret;
}
static __u32 btf_unwrap(const struct btf *btf, __u32 id)
@@ -576,7 +576,7 @@ static int json_btf_value(struct shirudo_json_emit *e, const struct btf *btf,
{
const struct btf_type *t;
__u16 kind;
- int rc;
+ int ret;
if (depth >= RODATA_JSON_MAX_DEPTH || !type_id || !bytes)
return -EINVAL;
@@ -589,9 +589,9 @@ static int json_btf_value(struct shirudo_json_emit *e, const struct btf *btf,
__u64 value;
bool sign, boolean;
- rc = btf_integer(t, bytes, size, &value, &sign, &boolean);
- if (rc)
- return rc;
+ ret = btf_integer(t, bytes, size, &value, &sign, &boolean);
+ if (ret)
+ return ret;
if (boolean)
json_raw_value(e, value ? "true" : "false", value ? 4 : 5);
else
@@ -697,12 +697,12 @@ static int json_btf_value(struct shirudo_json_emit *e, const struct btf *btf,
if (member_size < 0 || byte_off > size ||
(size_t)member_size > size - byte_off)
return -EINVAL;
- rc = json_btf_value(e, btf, m[i].type,
- bytes + byte_off,
- (size_t)member_size,
- depth + 1);
- if (rc)
- return rc;
+ ret = json_btf_value(e, btf, m[i].type,
+ bytes + byte_off,
+ (size_t)member_size,
+ depth + 1);
+ if (ret)
+ return ret;
}
}
json_obj_close(e);
@@ -721,11 +721,11 @@ static int json_btf_value(struct shirudo_json_emit *e, const struct btf *btf,
for (i = 0; i < a->nelems && !e->err; i++) {
if (!elem_size)
return -EINVAL;
- rc = json_btf_value(e, btf, a->type,
- bytes + (size_t)i * elem_size,
- (size_t)elem_size, depth + 1);
- if (rc)
- return rc;
+ ret = json_btf_value(e, btf, a->type,
+ bytes + (size_t)i * elem_size,
+ (size_t)elem_size, depth + 1);
+ if (ret)
+ return ret;
}
json_arr_close(e);
return e->err;
@@ -792,7 +792,7 @@ static int print_rodata_text(const struct shirudo_upatch *u,
(const struct btf_var_secinfo *)(sec + 1);
__u32 i, vlen = BTF_INFO_VLEN(sec->info);
char name[UPATCH_NAME_MAX + 1];
- int rc = 0;
+ int ret = 0;
memcpy(name, u->hdr.name, UPATCH_NAME_MAX);
name[UPATCH_NAME_MAX] = '\0';
@@ -810,26 +810,26 @@ static int print_rodata_text(const struct shirudo_upatch *u,
if (!var_name || !var_name[0] ||
btf_var_type(view->btf, &vars[i], &type_id)) {
- rc = -EINVAL;
+ ret = -EINVAL;
goto out;
}
- rc = append_type_name(view->btf, type_id, type,
- sizeof(type), &type_off, 0);
- if (rc)
+ ret = append_type_name(view->btf, type_id, type,
+ sizeof(type), &type_off, 0);
+ if (ret)
goto out;
if (vars[i].offset > view->size ||
vars[i].size > view->size - vars[i].offset) {
- rc = -EINVAL;
+ ret = -EINVAL;
goto out;
}
printf("\n%s: %s, size=%u, rodata+%u, data+%u, file+%u = ",
var_name, type, vars[i].size, vars[i].offset,
view->data_offset + vars[i].offset,
u->hdr.data_off + view->data_offset + vars[i].offset);
- rc = btf_dump__dump_type_data(dump, type_id,
- view->bytes + vars[i].offset,
- vars[i].size, &opts);
- if (rc < 0)
+ ret = btf_dump__dump_type_data(dump, type_id,
+ view->bytes + vars[i].offset,
+ vars[i].size, &opts);
+ if (ret < 0)
goto out;
putchar('\n');
}
@@ -838,7 +838,7 @@ static int print_rodata_text(const struct shirudo_upatch *u,
return 0;
out:
btf_dump__free(dump);
- return rc;
+ return ret;
}
static int print_rodata_json(const struct shirudo_upatch *u,
@@ -852,7 +852,7 @@ static int print_rodata_json(const struct shirudo_upatch *u,
char *buf = xmalloc(JSON_MAX_BYTES);
struct shirudo_json_emit e = {};
__u32 i, vlen = BTF_INFO_VLEN(sec->info);
- int rc = 0;
+ int ret = 0;
if (!buf)
return -ENOMEM;
@@ -877,16 +877,16 @@ static int print_rodata_json(const struct shirudo_upatch *u,
if (!var_name || !var_name[0] ||
btf_var_type(view->btf, &vars[i], &type_id)) {
- rc = -EINVAL;
+ ret = -EINVAL;
break;
}
- rc = append_type_name(view->btf, type_id, type,
- sizeof(type), &type_off, 0);
- if (rc)
+ ret = append_type_name(view->btf, type_id, type,
+ sizeof(type), &type_off, 0);
+ if (ret)
break;
if (vars[i].offset > view->size ||
vars[i].size > view->size - vars[i].offset) {
- rc = -EINVAL;
+ ret = -EINVAL;
break;
}
json_obj_open(&e);
@@ -899,42 +899,42 @@ static int print_rodata_json(const struct shirudo_upatch *u,
json_kv_int(&e, "file_offset",
u->hdr.data_off + view->data_offset + vars[i].offset);
json_key(&e, "value");
- rc = json_btf_value(&e, view->btf, type_id,
- view->bytes + vars[i].offset,
- vars[i].size, 0);
+ ret = json_btf_value(&e, view->btf, type_id,
+ view->bytes + vars[i].offset,
+ vars[i].size, 0);
json_obj_close(&e);
- if (rc)
+ if (ret)
break;
}
json_arr_close(&e);
json_obj_close(&e);
- if (!rc && e.err)
- rc = e.err;
- if (!rc)
- rc = write_complete(STDOUT_FILENO, buf, e.len);
- if (!rc)
- rc = write_complete(STDOUT_FILENO, "\n", 1);
- if (rc == -ENOSPC)
+ if (!ret && e.err)
+ ret = e.err;
+ if (!ret)
+ ret = write_complete(STDOUT_FILENO, buf, e.len);
+ if (!ret)
+ ret = write_complete(STDOUT_FILENO, "\n", 1);
+ if (ret == -ENOSPC)
pr_err("BTF JSON output exceeds %u bytes", JSON_MAX_BYTES);
xfree(buf, JSON_MAX_BYTES);
- return rc;
+ return ret;
}
int upatch_rodata_print(const struct shirudo_upatch *u, const char *path,
bool json)
{
struct rodata_view view = {};
- int rc;
+ int ret;
if (upatch_is_unload(u))
return -EINVAL;
- rc = btf_rodata_btf(u, &view);
- if (rc)
+ ret = btf_rodata_btf(u, &view);
+ if (ret)
goto out;
- rc = json ? print_rodata_json(u, path, &view) :
+ ret = json ? print_rodata_json(u, path, &view) :
print_rodata_text(u, path, &view);
out:
if (view.btf)
btf__free(view.btf);
- return rc;
+ return ret;
}