* [PATCH bpf v2 0/2] Fixes for bpf_get_fsverity_digest()
@ 2026-08-03 18:12 Eric Biggers
2026-08-03 18:12 ` [PATCH bpf v2 1/2] fsverity: Fix bpf_get_fsverity_digest() dynptr assumptions Eric Biggers
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Eric Biggers @ 2026-08-03 18:12 UTC (permalink / raw)
To: bpf
Cc: fsverity, linux-kernel, Alexei Starovoitov, Daniel Borkmann,
Andrii Nakryiko, Eduard Zingerman, Kumar Kartikeya Dwivedi,
Martin KaFai Lau, Song Liu, Yonghong Song, Emil Tsalapatis,
Jiri Olsa, Eric Biggers, stable
Two fixes for bpf_get_fsverity_digest().
Changed in v2:
- Added patch to fix silent truncation.
- Updated commit message to clarify that the size > INT_MAX case
seems to be unreachable currently.
- Added Acked-bys
Eric Biggers (2):
fsverity: Fix bpf_get_fsverity_digest() dynptr assumptions
fsverity: Fix silent truncation in bpf_get_fsverity_digest()
fs/verity/measure.c | 15 +++++++++------
1 file changed, 9 insertions(+), 6 deletions(-)
base-commit: e5fd3f514e27db1f05fbd72ba615d74941e23c51
--
2.55.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH bpf v2 1/2] fsverity: Fix bpf_get_fsverity_digest() dynptr assumptions
2026-08-03 18:12 [PATCH bpf v2 0/2] Fixes for bpf_get_fsverity_digest() Eric Biggers
@ 2026-08-03 18:12 ` Eric Biggers
2026-08-03 18:12 ` [PATCH bpf v2 2/2] fsverity: Fix silent truncation in bpf_get_fsverity_digest() Eric Biggers
2026-08-04 7:30 ` [PATCH bpf v2 0/2] Fixes for bpf_get_fsverity_digest() patchwork-bot+netdevbpf
2 siblings, 0 replies; 5+ messages in thread
From: Eric Biggers @ 2026-08-03 18:12 UTC (permalink / raw)
To: bpf
Cc: fsverity, linux-kernel, Alexei Starovoitov, Daniel Borkmann,
Andrii Nakryiko, Eduard Zingerman, Kumar Kartikeya Dwivedi,
Martin KaFai Lau, Song Liu, Yonghong Song, Emil Tsalapatis,
Jiri Olsa, Eric Biggers, stable
The BPF verifier and the dynptr abstraction ensure that the memory space
referenced by a dynptr remains valid. They do not, however, provide any
guarantee that the contents of the memory are stable. kfuncs are
expected to remain memory-safe even if concurrent modifications occur.
bpf_get_fsverity_digest() didn't follow that: it could crash if
arg->digest_size was concurrently modified.
Fix that by using the known-good value hash_alg->digest_size instead.
Also widen 'dynptr_sz' and 'out_digest_sz' to u64 to match the return
type of __bpf_dynptr_size(). It doesn't appear that it can actually be
more than INT_MAX currently (since __bpf_dynptr_data_rw() excludes
file-based pointers), but the correct type might as well be used.
Fixes: 67814c00de31 ("bpf, fsverity: Add kfunc bpf_get_fsverity_digest")
Cc: stable@vger.kernel.org
Acked-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
Acked-by: Song Liu <song@kernel.org>
Signed-off-by: Eric Biggers <ebiggers@kernel.org>
---
fs/verity/measure.c | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/fs/verity/measure.c b/fs/verity/measure.c
index cfe2d5e535f9..f8b3526af004 100644
--- a/fs/verity/measure.c
+++ b/fs/verity/measure.c
@@ -122,11 +122,11 @@ __bpf_kfunc int bpf_get_fsverity_digest(struct file *file, const struct bpf_dynp
{
const struct bpf_dynptr_kern *digest_ptr = (struct bpf_dynptr_kern *)digest_p;
const struct inode *inode = file_inode(file);
- u32 dynptr_sz = __bpf_dynptr_size(digest_ptr);
+ u64 dynptr_sz = __bpf_dynptr_size(digest_ptr);
struct fsverity_digest *arg;
const struct fsverity_info *vi;
const struct fsverity_hash_alg *hash_alg;
- int out_digest_sz;
+ u64 out_digest_sz;
if (dynptr_sz < sizeof(struct fsverity_digest))
return -EINVAL;
@@ -150,11 +150,13 @@ __bpf_kfunc int bpf_get_fsverity_digest(struct file *file, const struct bpf_dynp
out_digest_sz = dynptr_sz - sizeof(struct fsverity_digest);
/* copy digest */
- memcpy(arg->digest, vi->file_digest, min_t(int, hash_alg->digest_size, out_digest_sz));
+ memcpy(arg->digest, vi->file_digest,
+ min(hash_alg->digest_size, out_digest_sz));
/* fill the extra buffer with zeros */
if (out_digest_sz > hash_alg->digest_size)
- memset(arg->digest + arg->digest_size, 0, out_digest_sz - hash_alg->digest_size);
+ memset(arg->digest + hash_alg->digest_size, 0,
+ out_digest_sz - hash_alg->digest_size);
return 0;
}
--
2.55.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH bpf v2 2/2] fsverity: Fix silent truncation in bpf_get_fsverity_digest()
2026-08-03 18:12 [PATCH bpf v2 0/2] Fixes for bpf_get_fsverity_digest() Eric Biggers
2026-08-03 18:12 ` [PATCH bpf v2 1/2] fsverity: Fix bpf_get_fsverity_digest() dynptr assumptions Eric Biggers
@ 2026-08-03 18:12 ` Eric Biggers
2026-08-04 5:41 ` Song Liu
2026-08-04 7:30 ` [PATCH bpf v2 0/2] Fixes for bpf_get_fsverity_digest() patchwork-bot+netdevbpf
2 siblings, 1 reply; 5+ messages in thread
From: Eric Biggers @ 2026-08-03 18:12 UTC (permalink / raw)
To: bpf
Cc: fsverity, linux-kernel, Alexei Starovoitov, Daniel Borkmann,
Andrii Nakryiko, Eduard Zingerman, Kumar Kartikeya Dwivedi,
Martin KaFai Lau, Song Liu, Yonghong Song, Emil Tsalapatis,
Jiri Olsa, Eric Biggers, stable
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: 67814c00de31 ("bpf, fsverity: Add kfunc bpf_get_fsverity_digest")
Cc: stable@vger.kernel.org
Signed-off-by: Eric Biggers <ebiggers@kernel.org>
---
fs/verity/measure.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/fs/verity/measure.c b/fs/verity/measure.c
index f8b3526af004..68dfccb69772 100644
--- a/fs/verity/measure.c
+++ b/fs/verity/measure.c
@@ -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)
--
2.55.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH bpf v2 2/2] fsverity: Fix silent truncation in bpf_get_fsverity_digest()
2026-08-03 18:12 ` [PATCH bpf v2 2/2] fsverity: Fix silent truncation in bpf_get_fsverity_digest() Eric Biggers
@ 2026-08-04 5:41 ` Song Liu
0 siblings, 0 replies; 5+ messages in thread
From: Song Liu @ 2026-08-04 5:41 UTC (permalink / raw)
To: Eric Biggers
Cc: bpf, fsverity, linux-kernel, Alexei Starovoitov, Daniel Borkmann,
Andrii Nakryiko, Eduard Zingerman, Kumar Kartikeya Dwivedi,
Martin KaFai Lau, Yonghong Song, Emil Tsalapatis, Jiri Olsa,
stable
On Mon, Aug 3, 2026 at 11:13 AM Eric Biggers <ebiggers@kernel.org> wrote:
>
> 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: 67814c00de31 ("bpf, fsverity: Add kfunc bpf_get_fsverity_digest")
> Cc: stable@vger.kernel.org
> Signed-off-by: Eric Biggers <ebiggers@kernel.org>
Acked-by: Song Liu <song@kernel.org>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH bpf v2 0/2] Fixes for bpf_get_fsverity_digest()
2026-08-03 18:12 [PATCH bpf v2 0/2] Fixes for bpf_get_fsverity_digest() Eric Biggers
2026-08-03 18:12 ` [PATCH bpf v2 1/2] fsverity: Fix bpf_get_fsverity_digest() dynptr assumptions Eric Biggers
2026-08-03 18:12 ` [PATCH bpf v2 2/2] fsverity: Fix silent truncation in bpf_get_fsverity_digest() Eric Biggers
@ 2026-08-04 7:30 ` patchwork-bot+netdevbpf
2 siblings, 0 replies; 5+ messages in thread
From: patchwork-bot+netdevbpf @ 2026-08-04 7:30 UTC (permalink / raw)
To: Eric Biggers
Cc: bpf, fsverity, linux-kernel, ast, daniel, andrii, eddyz87, memxor,
martin.lau, song, yonghong.song, emil, jolsa, stable
Hello:
This series was applied to bpf/bpf.git (master)
by Kumar Kartikeya Dwivedi <memxor@gmail.com>:
On Mon, 3 Aug 2026 11:12:30 -0700 you wrote:
> Two fixes for bpf_get_fsverity_digest().
>
> Changed in v2:
> - Added patch to fix silent truncation.
> - Updated commit message to clarify that the size > INT_MAX case
> seems to be unreachable currently.
> - Added Acked-bys
>
> [...]
Here is the summary with links:
- [bpf,v2,1/2] fsverity: Fix bpf_get_fsverity_digest() dynptr assumptions
https://git.kernel.org/bpf/bpf/c/3e8ec7c03872
- [bpf,v2,2/2] fsverity: Fix silent truncation in bpf_get_fsverity_digest()
https://git.kernel.org/bpf/bpf/c/7c68ed5c5ad4
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-08-04 7:30 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-03 18:12 [PATCH bpf v2 0/2] Fixes for bpf_get_fsverity_digest() Eric Biggers
2026-08-03 18:12 ` [PATCH bpf v2 1/2] fsverity: Fix bpf_get_fsverity_digest() dynptr assumptions Eric Biggers
2026-08-03 18:12 ` [PATCH bpf v2 2/2] fsverity: Fix silent truncation in bpf_get_fsverity_digest() Eric Biggers
2026-08-04 5:41 ` Song Liu
2026-08-04 7:30 ` [PATCH bpf v2 0/2] Fixes for bpf_get_fsverity_digest() patchwork-bot+netdevbpf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox