All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Yichong Chen" <chenyichong@uniontech.com>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH] fsverity: reject short BPF digest buffers
Date: Wed, 05 Aug 2026 08:07:24 +0000	[thread overview]
Message-ID: <20260805080725.0E4411F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <20260805075655.950308-1-chenyichong@uniontech.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [High] Out-of-bounds write (TOCTOU) due to use of shared memory in pointer arithmetic.
--

--- Patch [1]: [PATCH] fsverity: reject short BPF digest buffers ---
commit f40b6203fcacca3140ba489474dd88b289d0ffc4
Author: Yichong Chen <chenyichong@uniontech.com>

fsverity: reject short BPF digest buffers

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. This changes it to return -EOVERFLOW instead to match the ioctl
measurement path.

> diff --git a/fs/verity/measure.c b/fs/verity/measure.c
> index cfe2d5e535f96..4cfadba95488b 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)

[Severity: High]
This is a pre-existing issue, but can the arg->digest_size field be modified
concurrently after it is initialized?

Looking at bpf_get_fsverity_digest(), the memset() operation directly following
this hunk uses arg->digest_size to compute the destination pointer:

    if (out_digest_sz > hash_alg->digest_size)
        memset(arg->digest + arg->digest_size, 0,
               out_digest_sz - hash_alg->digest_size);

Since arg is a pointer into a dynptr that might be backed by shared memory,
if an attacker overwrites arg->digest_size with a large value before the
memset() executes, could this cause an out-of-bounds write of zeros into
kernel memory?

Would it be safer to use hash_alg->digest_size instead of re-reading
arg->digest_size when calculating the pointer offset for the memset?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260805075655.950308-1-chenyichong@uniontech.com?part=1

  reply	other threads:[~2026-08-05  8:07 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-05  7:56 [PATCH] fsverity: reject short BPF digest buffers Yichong Chen
2026-08-05  8:07 ` sashiko-bot [this message]
2026-08-05 19:50 ` 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=20260805080725.0E4411F00A3A@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=chenyichong@uniontech.com \
    --cc=sashiko-reviews@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.