The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH] fsverity: reject short BPF digest buffers
@ 2026-08-05  7:56 Yichong Chen
  2026-08-05 19:50 ` Eric Biggers
  0 siblings, 1 reply; 2+ messages in thread
From: Yichong Chen @ 2026-08-05  7:56 UTC (permalink / raw)
  To: ebiggers, tytso; +Cc: ast, song, fsverity, bpf, linux-kernel, Yichong Chen

bpf_get_fsverity_digest() reports the digest size as the full hash digest
size.  However, when the provided dynptr only has room for part of the
digest, the helper currently copies the truncated digest and still returns
success.

Returning success with a digest_size that is larger than the actual copied
digest is misleading for integrity policy code.  Match the ioctl
measurement path and reject too-small output buffers with -EOVERFLOW.

Fixes: 67814c00de31 ("bpf, fsverity: Add kfunc bpf_get_fsverity_digest")
Signed-off-by: Yichong Chen <chenyichong@uniontech.com>
---
 fs/verity/measure.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/fs/verity/measure.c b/fs/verity/measure.c
index cfe2d5e535f9..4cfadba95488 100644
--- a/fs/verity/measure.c
+++ b/fs/verity/measure.c
@@ -148,9 +148,11 @@ __bpf_kfunc int bpf_get_fsverity_digest(struct file *file, const struct bpf_dynp
 	arg->digest_size = hash_alg->digest_size;
 
 	out_digest_sz = dynptr_sz - sizeof(struct fsverity_digest);
+	if (out_digest_sz < hash_alg->digest_size)
+		return -EOVERFLOW;
 
 	/* copy digest */
-	memcpy(arg->digest, vi->file_digest,  min_t(int, 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)
-- 
2.51.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] fsverity: reject short BPF digest buffers
  2026-08-05  7:56 [PATCH] fsverity: reject short BPF digest buffers Yichong Chen
@ 2026-08-05 19:50 ` Eric Biggers
  0 siblings, 0 replies; 2+ messages in thread
From: Eric Biggers @ 2026-08-05 19:50 UTC (permalink / raw)
  To: Yichong Chen; +Cc: tytso, ast, song, fsverity, bpf, linux-kernel

On Wed, Aug 05, 2026 at 03:56:55PM +0800, Yichong Chen wrote:
> bpf_get_fsverity_digest() reports the digest size as the full hash digest
> size.  However, when the provided dynptr only has room for part of the
> digest, the helper currently copies the truncated digest and still returns
> success.
> 
> Returning success with a digest_size that is larger than the actual copied
> digest is misleading for integrity policy code.  Match the ioctl
> measurement path and reject too-small output buffers with -EOVERFLOW.
> 
> Fixes: 67814c00de31 ("bpf, fsverity: Add kfunc bpf_get_fsverity_digest")
> Signed-off-by: Yichong Chen <chenyichong@uniontech.com>
> ---
>  fs/verity/measure.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)

Already handled by https://lore.kernel.org/bpf/20260803181232.14743-1-ebiggers@kernel.org/

- Eric

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-08-05 19:50 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-05  7:56 [PATCH] fsverity: reject short BPF digest buffers Yichong Chen
2026-08-05 19:50 ` Eric Biggers

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox