mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-09-18 22:19:30 +02:00
fsverity: Fix silent truncation in bpf_get_fsverity_digest()
bpf_get_fsverity_digest() silently truncates the digest if the provided
buffer is too small. This is a footgun, and it doesn't match the
semantics of the equivalent UAPI (FS_IOC_MEASURE_VERITY).
Change it to return -EOVERFLOW instead, matching FS_IOC_MEASURE_VERITY.
Fixes: 67814c00de ("bpf, fsverity: Add kfunc bpf_get_fsverity_digest")
Signed-off-by: Eric Biggers <ebiggers@kernel.org>
Acked-by: Song Liu <song@kernel.org>
Cc: stable@vger.kernel.org
Link: https://lore.kernel.org/bpf/20260803181232.14743-3-ebiggers@kernel.org
Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
This commit is contained in:
+5
-4
@@ -144,14 +144,15 @@ __bpf_kfunc int bpf_get_fsverity_digest(struct file *file, const struct bpf_dynp
|
||||
|
||||
hash_alg = vi->tree_params.hash_alg;
|
||||
|
||||
out_digest_sz = dynptr_sz - sizeof(struct fsverity_digest);
|
||||
if (out_digest_sz < hash_alg->digest_size)
|
||||
return -EOVERFLOW;
|
||||
|
||||
arg->digest_algorithm = hash_alg - fsverity_hash_algs;
|
||||
arg->digest_size = hash_alg->digest_size;
|
||||
|
||||
out_digest_sz = dynptr_sz - sizeof(struct fsverity_digest);
|
||||
|
||||
/* copy digest */
|
||||
memcpy(arg->digest, vi->file_digest,
|
||||
min(hash_alg->digest_size, out_digest_sz));
|
||||
memcpy(arg->digest, vi->file_digest, hash_alg->digest_size);
|
||||
|
||||
/* fill the extra buffer with zeros */
|
||||
if (out_digest_sz > hash_alg->digest_size)
|
||||
|
||||
Reference in New Issue
Block a user