* [PATCH 1/2] hwrng: virtio - use min() in copy_data()
@ 2026-09-26 5:58 Thorsten Blum
2026-09-26 5:58 ` [PATCH 2/2] hwrng: virtio - use snprintf() in probe_common() Thorsten Blum
0 siblings, 1 reply; 2+ messages in thread
From: Thorsten Blum @ 2026-09-26 5:58 UTC (permalink / raw)
To: Laurent Vivier, Olivia Mackall, Herbert Xu
Cc: Thorsten Blum, virtualization, linux-crypto, linux-kernel
Use the simpler min() macro since all values are unsigned and
compatible. The subtraction avail - vi->data_idx is also guaranteed to
be positive by the preceding check.
Signed-off-by: Thorsten Blum <blum@kernel.org>
---
drivers/char/hw_random/virtio-rng.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/char/hw_random/virtio-rng.c b/drivers/char/hw_random/virtio-rng.c
index 5e83ffa105e4..5b1b23b5596a 100644
--- a/drivers/char/hw_random/virtio-rng.c
+++ b/drivers/char/hw_random/virtio-rng.c
@@ -81,13 +81,13 @@ static unsigned int copy_data(struct virtrng_info *vi, void *buf,
* steered into adjacent slab memory, including under
* speculation.
*/
- avail = min_t(unsigned int, vi->data_avail, sizeof(vi->data));
+ avail = min(vi->data_avail, sizeof(vi->data));
if (vi->data_idx >= avail) {
vi->data_avail = 0;
request_entropy(vi);
return 0;
}
- size = min_t(unsigned int, size, avail - vi->data_idx);
+ size = min(size, avail - vi->data_idx);
idx = array_index_nospec(vi->data_idx, sizeof(vi->data));
memcpy(buf, vi->data + idx, size);
vi->data_idx += size;
^ permalink raw reply [flat|nested] 2+ messages in thread* [PATCH 2/2] hwrng: virtio - use snprintf() in probe_common()
2026-09-26 5:58 [PATCH 1/2] hwrng: virtio - use min() in copy_data() Thorsten Blum
@ 2026-09-26 5:58 ` Thorsten Blum
0 siblings, 0 replies; 2+ messages in thread
From: Thorsten Blum @ 2026-09-26 5:58 UTC (permalink / raw)
To: Laurent Vivier, Olivia Mackall, Herbert Xu
Cc: Thorsten Blum, virtualization, linux-crypto, linux-kernel
While the current code works correctly, replace the unbounded sprintf()
with the safer snprintf() to follow secure coding best practices.
Signed-off-by: Thorsten Blum <blum@kernel.org>
---
drivers/char/hw_random/virtio-rng.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/char/hw_random/virtio-rng.c b/drivers/char/hw_random/virtio-rng.c
index 5b1b23b5596a..f9982217247d 100644
--- a/drivers/char/hw_random/virtio-rng.c
+++ b/drivers/char/hw_random/virtio-rng.c
@@ -162,7 +162,7 @@ static int probe_common(struct virtio_device *vdev)
err = index;
goto err_ida;
}
- sprintf(vi->name, "virtio_rng.%d", index);
+ snprintf(vi->name, sizeof(vi->name), "virtio_rng.%d", vi->index);
init_completion(&vi->have_data);
vi->hwrng = (struct hwrng) {
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-09-26 5:59 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-26 5:58 [PATCH 1/2] hwrng: virtio - use min() in copy_data() Thorsten Blum
2026-09-26 5:58 ` [PATCH 2/2] hwrng: virtio - use snprintf() in probe_common() Thorsten Blum
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®