Skip to content

Commit 39d3f1d

Browse files
committed
composefs: Ensure buffer is suitably aligned for struct fsverity_digest
struct fsverity_digest starts with a __u16, so it will normally require 16-bit alignment, which is not guaranteed for a char array. Resolves: #3339 Signed-off-by: Simon McVittie <smcv@debian.org>
1 parent 8705495 commit 39d3f1d

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

src/libostree/ostree-repo-composefs.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -327,19 +327,22 @@ checkout_one_composefs_file_at (OstreeRepo *repo, OtTristate verity, const char
327327
* This is the typical case when we're pulled into the target
328328
* system repo with verity on and are recreating the composefs
329329
* image during deploy. */
330-
char buf[sizeof (struct fsverity_digest) + OSTREE_SHA256_DIGEST_LEN];
330+
union
331+
{
332+
struct fsverity_digest d;
333+
char buf[sizeof (struct fsverity_digest) + OSTREE_SHA256_DIGEST_LEN];
334+
} result;
331335
guchar *known_digest = NULL;
332336

333337
if (G_IS_UNIX_INPUT_STREAM (input))
334338
{
335339
int content_fd = g_unix_input_stream_get_fd (G_UNIX_INPUT_STREAM (input));
336-
struct fsverity_digest *d = (struct fsverity_digest *)&buf;
337-
d->digest_size = OSTREE_SHA256_DIGEST_LEN;
340+
result.d->digest_size = OSTREE_SHA256_DIGEST_LEN;
338341

339-
if (ioctl (content_fd, FS_IOC_MEASURE_VERITY, d) == 0
340-
&& d->digest_size == OSTREE_SHA256_DIGEST_LEN
341-
&& d->digest_algorithm == FS_VERITY_HASH_ALG_SHA256)
342-
known_digest = d->digest;
342+
if (ioctl (content_fd, FS_IOC_MEASURE_VERITY, &result) == 0
343+
&& result.d->digest_size == OSTREE_SHA256_DIGEST_LEN
344+
&& result.d->digest_algorithm == FS_VERITY_HASH_ALG_SHA256)
345+
known_digest = result.d->digest;
343346
}
344347
#endif
345348

0 commit comments

Comments
 (0)