aboutsummaryrefslogtreecommitdiffstats
path: root/module/icp/algs/blake3/blake3_impl.c
diff options
context:
space:
mode:
authorRichard Yao <[email protected]>2022-11-28 16:49:58 -0500
committerGitHub <[email protected]>2022-11-28 13:49:58 -0800
commit303678350a7253c7bee9d6a3347ee1bcdf9cc177 (patch)
tree9575523aa56dc94e8075ed976fa62a9c3e2f251d /module/icp/algs/blake3/blake3_impl.c
parentd27a00283faf4ec2b997ff2376dee4a080e1ca7b (diff)
Convert some sprintf() calls to kmem_scnprintf()
These `sprintf()` calls are used repeatedly to write to a buffer. There is no protection against overflow other than reviewers explicitly checking to see if the buffers are big enough. However, such issues are easily missed during review and when they are missed, we would rather stop printing rather than have a buffer overflow, so we convert these functions to use `kmem_scnprintf()`. The Linux kernel provides an entire page for module parameters, so we are safe to write up to PAGE_SIZE. Removing `sprintf()` from these functions removes the last instances of `sprintf()` usage in our platform-independent kernel code. This improves XNU kernel compatibility because the XNU kernel does not support (removed support for?) `sprintf()`. Reviewed-by: Brian Behlendorf <[email protected]> Reviewed-by: Jorgen Lundman <[email protected]> Signed-off-by: Richard Yao <[email protected]> Closes #14209
Diffstat (limited to 'module/icp/algs/blake3/blake3_impl.c')
-rw-r--r--module/icp/algs/blake3/blake3_impl.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/module/icp/algs/blake3/blake3_impl.c b/module/icp/algs/blake3/blake3_impl.c
index 1692916ce..7bc4db2c9 100644
--- a/module/icp/algs/blake3/blake3_impl.c
+++ b/module/icp/algs/blake3/blake3_impl.c
@@ -282,16 +282,16 @@ blake3_param_get(char *buffer, zfs_kernel_param_t *unused)
/* cycling */
fmt = IMPL_FMT(impl, IMPL_CYCLE);
- cnt += sprintf(buffer + cnt, fmt, "cycle");
+ cnt += kmem_scnprintf(buffer + cnt, PAGE_SIZE - cnt, fmt, "cycle");
/* list fastest */
fmt = IMPL_FMT(impl, IMPL_FASTEST);
- cnt += sprintf(buffer + cnt, fmt, "fastest");
+ cnt += kmem_scnprintf(buffer + cnt, PAGE_SIZE - cnt, fmt, "fastest");
/* list all supported implementations */
for (uint32_t i = 0; i < blake3_supp_impls_cnt; ++i) {
fmt = IMPL_FMT(impl, i);
- cnt += sprintf(buffer + cnt, fmt,
+ cnt += kmem_scnprintf(buffer + cnt, PAGE_SIZE - cnt, fmt,
blake3_supp_impls[i]->name);
}