From: sashiko-bot@kernel.org
To: "Blaise Boscaccy" <bboscaccy@linux.microsoft.com>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH v5 07/10] hornet: Introduce gen_sig
Date: Tue, 21 Apr 2026 03:03:05 +0000 [thread overview]
Message-ID: <20260421030305.957A9C19425@smtp.kernel.org> (raw)
In-Reply-To: <20260420212653.438685-8-bboscaccy@linux.microsoft.com>
Sashiko AI review found 5 potential issue(s):
- [High] Infinite loop during argument parsing on architectures with unsigned char.
- [Medium] Ignored return value of `sha256()` causes use of uninitialized memory.
- [Medium] Stack buffer overflow when parsing '--add' arguments.
- [Medium] Missing NULL pointer checks for OpenSSL allocations.
- [Medium] Unchecked return value of `ASN1_item_i2d()`.
--
commit 72bf19e54c723e2a7111cbc219bbeb6e98977318
Author: Blaise Boscaccy <bboscaccy@linux.microsoft.com>
hornet: Introduce gen_sig
This commit introduces the gen_sig tool. It creates a pkcs#7 signature of a
data payload and appends a signed attribute containing a set of hashes.
> diff --git a/scripts/hornet/gen_sig.c b/scripts/hornet/gen_sig.c
> index 0000000000000..f966516ebc99b
> --- /dev/null
> +++ b/scripts/hornet/gen_sig.c
[ ... ]
> +static void add_hash(MAP_SET *set, unsigned char *buffer, int buffer_len, int index)
> +{
> + HORNET_MAP *map = NULL;
> +
> + map = HORNET_MAP_new();
> + ASN1_INTEGER_set(map->index, index);
map is allocated via HORNET_MAP_new(), but the return value is not checked
for NULL before dereferencing it in ASN1_INTEGER_set(). Should we handle
potential allocation failures here?
[ ... ]
> +int main(int argc, char **argv)
> +{
[ ... ]
> + int i;
> + char opt;
> +
> + const char *short_opts = "C:K:P:O:A:Sh";
> +
> + static const struct option long_opts[] = {
> + {"cert", required_argument, 0, 'C'},
> + {"key", required_argument, 0, 'K'},
> + {"pass", required_argument, 0, 'P'},
> + {"out", required_argument, 0, 'O'},
> + {"data", required_argument, 0, 'D'},
> + {"add", required_argument, 0, 'A'},
> + {"help", no_argument, 0, 'h'},
> + {0, 0, 0, 0}
> + };
> +
> + while ((opt = getopt_long_only(argc, argv, short_opts, long_opts, NULL)) != -1) {
getopt_long_only() returns an int. If it returns -1, and opt is a char,
architectures where char is unsigned by default (like ARM or PowerPC) will
evaluate opt as 255.
Since 255 != -1, will this cause an infinite loop during argument parsing on
those platforms?
> + switch (opt) {
> + case 'C':
> + cert_path = optarg;
> + break;
[ ... ]
> + case 'A':
> + if (strchr(optarg, ':')) {
> + hashes[hash_count].file = strsep(&optarg, ":");
> + hashes[hash_count].index = atoi(optarg);
> + hash_count++;
The hashes array is defined with a fixed size of MAX_HASHES. Does this code
need to check if hash_count is less than MAX_HASHES before writing to the
array to prevent a stack buffer overflow if too many arguments are provided?
[ ... ]
> + si = CMS_add1_signer(cms_out, signer, pkey, EVP_sha256(), flags);
> + ERR(!si, "add signer failed");
> +
> + set = MAP_SET_new();
> + set->maps = sk_HORNET_MAP_new_null();
MAP_SET_new() and sk_HORNET_MAP_new_null() can return NULL if memory
allocation fails. Since set->maps dereferences set immediately, can this
result in a segmentation fault under memory pressure?
> +
> + for (i = 0; i < hash_count; i++) {
> + sha256(hashes[i].file, hash_buffer, &hash_len);
> + add_hash(set, hash_buffer, hash_len, hashes[i].index);
> + }
The return value of sha256() is ignored here. If the file cannot be opened,
sha256() will fail, leaving hash_buffer and hash_len uninitialized.
Will this lead to an out-of-bounds read of uninitialized stack memory when
passed to add_hash()?
> +
> + oid = OBJ_txt2obj("2.25.316487325684022475439036912669789383960", 1);
> + if (!oid) {
> + ERR_print_errors_fp(stderr);
> + DIE("create oid failed");
> + }
> +
> + der_len = ASN1_item_i2d((ASN1_VALUE *)set, &der, ASN1_ITEM_rptr(MAP_SET));
> + CMS_signed_add1_attr_by_OBJ(si, oid, V_ASN1_SEQUENCE, der, der_len);
ASN1_item_i2d() returns a negative value on failure. Since der_len is passed
directly to CMS_signed_add1_attr_by_OBJ() without checking for errors, could
this cause issues by passing a negative length to the OpenSSL routine?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260420212653.438685-1-bboscaccy@linux.microsoft.com?part=7
next prev parent reply other threads:[~2026-04-21 3:03 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-20 21:26 [PATCH v5 00/10] Reintroduce Hornet LSM Blaise Boscaccy
2026-04-20 21:26 ` [PATCH v5 01/10] crypto: pkcs7: add flag for validated trust on a signed info block Blaise Boscaccy
2026-04-21 1:17 ` sashiko-bot
2026-04-20 21:26 ` [PATCH v5 02/10] crypto: pkcs7: add ability to extract signed attributes by OID Blaise Boscaccy
2026-04-21 1:49 ` sashiko-bot
2026-04-20 21:26 ` [PATCH v5 03/10] crypto: pkcs7: add tests for pkcs7_get_authattr Blaise Boscaccy
2026-04-21 2:06 ` sashiko-bot
2026-04-20 21:26 ` [PATCH v5 04/10] lsm: framework for BPF integrity verification Blaise Boscaccy
2026-04-20 21:26 ` [PATCH v5 05/10] lsm: security: Add additional enum values for bpf integrity checks Blaise Boscaccy
2026-04-20 21:26 ` [PATCH v5 06/10] security: Hornet LSM Blaise Boscaccy
2026-04-21 0:08 ` Fan Wu
2026-04-21 4:29 ` sashiko-bot
2026-04-20 21:26 ` [PATCH v5 07/10] hornet: Introduce gen_sig Blaise Boscaccy
2026-04-21 0:18 ` Fan Wu
2026-04-21 3:03 ` sashiko-bot [this message]
2026-04-20 21:26 ` [PATCH v5 08/10] hornet: Add a light skeleton data extractor scripts Blaise Boscaccy
2026-04-21 3:06 ` sashiko-bot
2026-04-20 21:26 ` [PATCH v5 09/10] selftests/hornet: Add a selftest for the Hornet LSM Blaise Boscaccy
2026-04-21 3:04 ` sashiko-bot
2026-04-20 21:26 ` [PATCH v5 10/10] ipe: Add BPF program load policy enforcement via Hornet integration Blaise Boscaccy
2026-04-21 0:27 ` Fan Wu
2026-04-21 3:23 ` sashiko-bot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260421030305.957A9C19425@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=bboscaccy@linux.microsoft.com \
--cc=bpf@vger.kernel.org \
--cc=sashiko@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox