From nobody Fri Oct 2 07:44:58 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 99CE935E94E; Mon, 3 Aug 2026 18:13:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785780805; cv=none; b=G/oKhfqeqbIIVuNrC4YzBBbyhVXIujgqGRrm8INo2+KrorCRzrvBNFdL0jXHEzb7di1iJD51Xk07ZBZ753pN+db3Xnwd/umepBiWjCURUP3oWUUJqgirf3lnclE5vDcDupJiTFK8C8u4gc+/P0Zbq+wOaTXXo15pCI0g0fAwKy0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785780805; c=relaxed/simple; bh=Q/dZi5hA8K+90LfLFO+8KUhUpOlrWMKbGN5SGqZx6xM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZxMsmp5GWKCr2+X1yTKl//a901kwiNXBQ4R5o8gjbhk8oierkIAlXFP1t7+gIiNTB37a5eWIbhwa1Xpa437ktzWE1NY1/Ibkv066JnuNjoVupn8/aaYvxCfoEgpwiuhU1yuwvhw2QrveIYwX9+XsPyouR6rsVZDciZznJfr/VWQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ByOk3Meo; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="ByOk3Meo" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C1E491F00A3D; Mon, 3 Aug 2026 18:13:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1785780804; bh=RFgr9FRC1IjAIMhstc7EK8DGLKbN4/UtrRJfKSRkdJw=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=ByOk3MeoSRiFLCLtdJom3R5VislGhactY42OwBmNp8TcPkscyn/S2qNnME5HPVVsn p0GknCleJnvhga4WSp54YUZO9TjPwIUBuYIo+M0VjQg7HOZkdDBl/kqU9CShwRxIe3 uIsDQ+87EyhyZwPqWfJ8nR8uUbQ7k+GxUlCKGV0kqw7PPvbycjhYfoBctuR9HFAV6d iqnPdu/AlJGruVyc7JWa55VPHf9uI/qqYJFrpahVlnmaCV31vMst8ujumgoVhVWUgl mA16a7CxSyzNTfSPARvia4wY1YJee0YU7Tu725lHph2NL/GcmHT9r2rJfD+zrXRI4L Ep/F7sNYDB78g== From: Eric Biggers To: bpf@vger.kernel.org Cc: fsverity@lists.linux.dev, linux-kernel@vger.kernel.org, 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@vger.kernel.org Subject: [PATCH bpf v2 1/2] fsverity: Fix bpf_get_fsverity_digest() dynptr assumptions Date: Mon, 3 Aug 2026 11:12:31 -0700 Message-ID: <20260803181232.14743-2-ebiggers@kernel.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260803181232.14743-1-ebiggers@kernel.org> References: <20260803181232.14743-1-ebiggers@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 Acked-by: Song Liu Signed-off-by: Eric Biggers --- 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 =3D (struct bpf_dynptr_kern *)di= gest_p; const struct inode *inode =3D file_inode(file); - u32 dynptr_sz =3D __bpf_dynptr_size(digest_ptr); + u64 dynptr_sz =3D __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; =20 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 =3D dynptr_sz - sizeof(struct fsverity_digest); =20 /* copy digest */ - memcpy(arg->digest, vi->file_digest, min_t(int, hash_alg->digest_size, o= ut_digest_sz)); + memcpy(arg->digest, vi->file_digest, + min(hash_alg->digest_size, out_digest_sz)); =20 /* 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->dige= st_size); + memset(arg->digest + hash_alg->digest_size, 0, + out_digest_sz - hash_alg->digest_size); =20 return 0; } --=20 2.55.0 From nobody Fri Oct 2 07:44:58 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F420741D20B; Mon, 3 Aug 2026 18:13:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785780806; cv=none; b=KC3J4Rh1vuKJVXy0lz4qVB1Yrgwu55hr3Lo5K1n+vD1fTN9FoJLLcLOpynVGiDaHXBj/hD64BkDMbUN0iTsGhKGRpgee2znk75AyUL4rOz2XgbZvfRVYEsVubu/W81EOIoNbMy3Kzz3ndzHRescDVnSPFDvcyUCtd2eppddBtMM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785780806; c=relaxed/simple; bh=t204v6IkJFOLWcsbZpo6q1sU+xH6NxOUQi54boeo3ao=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WZbutAskyGVZGhtDHU+fI7S/jl/JYfkzaikXhimjLvcFz/Nm77n+Su3ncs0K7/hDv8XN4/Y9IirBpFKg7CfDSZjH559RVNah6+NyN6qgU50UJfS6gSp7ZS0o4lBAn3ecqs//++daa7mGFkCWmQFqswlQei068oiKSV5wxP1XC+w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=hgxB9j6t; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="hgxB9j6t" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6B1C31F00A3A; Mon, 3 Aug 2026 18:13:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1785780804; bh=M++mqAzNlFzgVh8y1H7yy6racbyWVV1Hx6y+OsOYWKI=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=hgxB9j6tfiLskWRkxk16CwZ60Y0rcV6+42+wCGdAHOowSlGGKkccF/t6f7twRqU8s dhXny1DbG3+pjHKXdPoLFl/OLmsj5+vhhnakOu9+CQDl65yfdKBT8KUD0I6yF7wU5/ g0Xmap5dPBF5naD51JQjoWAOfnXJostrklCryCvSSE4E0KsonuEfNNt8/mCPdXMh/C JjmOZhSM2793U2UzzlZ4F1qgA2DlSqHwVgYh1rrsd6VebpA550Zb1l2WYsv/VqvUT2 bKo0LAv+A6u8w3y3sI/ynDJaCBzn6LEl88MlVX9WJ870eevhq0qpMUBExuM2dcAk+/ 2/lFh8sGpq6qg== From: Eric Biggers To: bpf@vger.kernel.org Cc: fsverity@lists.linux.dev, linux-kernel@vger.kernel.org, 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@vger.kernel.org Subject: [PATCH bpf v2 2/2] fsverity: Fix silent truncation in bpf_get_fsverity_digest() Date: Mon, 3 Aug 2026 11:12:32 -0700 Message-ID: <20260803181232.14743-3-ebiggers@kernel.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260803181232.14743-1-ebiggers@kernel.org> References: <20260803181232.14743-1-ebiggers@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 Acked-by: Song Liu --- 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 =20 hash_alg =3D vi->tree_params.hash_alg; =20 + out_digest_sz =3D dynptr_sz - sizeof(struct fsverity_digest); + if (out_digest_sz < hash_alg->digest_size) + return -EOVERFLOW; + arg->digest_algorithm =3D hash_alg - fsverity_hash_algs; arg->digest_size =3D hash_alg->digest_size; =20 - out_digest_sz =3D 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); =20 /* fill the extra buffer with zeros */ if (out_digest_sz > hash_alg->digest_size) --=20 2.55.0