Linux fsverity development list
 help / color / mirror / Atom feed
From: Yichong Chen <chenyichong@uniontech.com>
To: ebiggers@kernel.org, tytso@mit.edu
Cc: ast@kernel.org, song@kernel.org, fsverity@lists.linux.dev,
	bpf@vger.kernel.org, linux-kernel@vger.kernel.org,
	Yichong Chen <chenyichong@uniontech.com>
Subject: [PATCH] fsverity: reject short BPF digest buffers
Date: Wed,  5 Aug 2026 15:56:55 +0800	[thread overview]
Message-ID: <20260805075655.950308-1-chenyichong@uniontech.com> (raw)

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


             reply	other threads:[~2026-08-05  7:57 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-05  7:56 Yichong Chen [this message]
2026-08-05 19:50 ` [PATCH] fsverity: reject short BPF digest buffers Eric Biggers

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=20260805075655.950308-1-chenyichong@uniontech.com \
    --to=chenyichong@uniontech.com \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=ebiggers@kernel.org \
    --cc=fsverity@lists.linux.dev \
    --cc=linux-kernel@vger.kernel.org \
    --cc=song@kernel.org \
    --cc=tytso@mit.edu \
    /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