From 90d4f48592909fa73e0aa127eaa5f0674c210df8 Mon Sep 17 00:00:00 2001 From: Isa Date: Sun, 23 Nov 2025 15:23:05 +0200 Subject: [PATCH 1/2] cdev: Replace deprecated copystr with copyout The example cdev module used copystr() inside mydev_read(), which is deprecated according to COPY(9). Although the code compiles, invoking the module causes a kernel page fault. A crash dump larger than 1 GB was generated on 14.3-RELEASE-p5 (amd64 GENERIC). Replacing copystr() with copyout() resolves the issue and the module now behaves as expected. --- share/examples/kld/cdev/module/cdev.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/share/examples/kld/cdev/module/cdev.c b/share/examples/kld/cdev/module/cdev.c index 9d10e8d03f983c..227fbcf2f163db 100644 --- a/share/examples/kld/cdev/module/cdev.c +++ b/share/examples/kld/cdev/module/cdev.c @@ -176,7 +176,7 @@ mydev_read(struct cdev *dev, struct uio *uio, int ioflag) if (len <= 0) { err = -1; } else { /* copy buf to userland */ - copystr(&buf, uio->uio_iov->iov_base, 513, &len); + copyout(&buf, uio->uio_iov->iov_base, 513); } return(err); } From 89aedc8918ec1cba532da373ee19ec1a6a62162d Mon Sep 17 00:00:00 2001 From: Isa Date: Tue, 25 Nov 2025 20:03:43 +0200 Subject: [PATCH 2/2] cdev: Use len variable instead of hardcoded buffer size Replaced the hardcoded byte count with the len variable in mydev_read(), ensuring the buffer size is used correctly. This follows best practices and prevents potential issues. Signed-off-by: Isa Isoux --- share/examples/kld/cdev/module/cdev.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/share/examples/kld/cdev/module/cdev.c b/share/examples/kld/cdev/module/cdev.c index 227fbcf2f163db..055bd7e71a31b3 100644 --- a/share/examples/kld/cdev/module/cdev.c +++ b/share/examples/kld/cdev/module/cdev.c @@ -176,7 +176,7 @@ mydev_read(struct cdev *dev, struct uio *uio, int ioflag) if (len <= 0) { err = -1; } else { /* copy buf to userland */ - copyout(&buf, uio->uio_iov->iov_base, 513); + copyout(&buf, uio->uio_iov->iov_base, len); } return(err); }