git: ec213d186be9 - stable/14 - kern_module.c: add kern_ implementations
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Mon, 16 Nov 2026 18:12:49 UTC
The branch stable/14 has been updated by brooks:
URL: https://cgit.FreeBSD.org/src/commit/?id=ec213d186be9c954ce786c76d4623941ac142ee1
commit ec213d186be9c954ce786c76d4623941ac142ee1
Author: Brooks Davis <brooks@FreeBSD.org>
AuthorDate: 2026-11-10 11:49:20 +0000
Commit: Brooks Davis <brooks@FreeBSD.org>
CommitDate: 2026-11-16 15:57:41 +0000
kern_module.c: add kern_ implementations
In the case of modstat(2) use a cast to access the name member of the
old struct version so the compiler see the right array size. This
addresses a sub-object bounds bug.
Effort: CHERI upstreaming
Sponsored by: DARPA, AFRL, Innovate UK
Pull Request: https://github.com/freebsd/freebsd-src/pull/2284
(cherry picked from commit b96dc2c04fb4f504ad0c752c5d4b074c5bfbf7e0)
---
sys/kern/kern_module.c | 29 ++++++++++++++++++++++-------
sys/sys/syscallsubr.h | 3 +++
2 files changed, 25 insertions(+), 7 deletions(-)
diff --git a/sys/kern/kern_module.c b/sys/kern/kern_module.c
index 5568ff57a860..aba5cc02dc50 100644
--- a/sys/kern/kern_module.c
+++ b/sys/kern/kern_module.c
@@ -32,8 +32,9 @@
#include <sys/systm.h>
#include <sys/eventhandler.h>
#include <sys/malloc.h>
-#include <sys/sysproto.h>
+#include <sys/syscallsubr.h>
#include <sys/sysent.h>
+#include <sys/sysproto.h>
#include <sys/proc.h>
#include <sys/lock.h>
#include <sys/mutex.h>
@@ -374,18 +375,23 @@ struct module_stat_v2 {
int
sys_modstat(struct thread *td, struct modstat_args *uap)
+{
+ return (kern_modstat(td, uap->modid, uap->stat));
+}
+
+int
+kern_modstat(struct thread *td, int modid, struct module_stat *stat)
{
module_t mod;
modspecific_t data;
int error = 0;
int id, namelen, refs, version;
- struct module_stat *stat;
struct module_stat_v2 *stat_v2;
- char *name;
+ char *name, *user_namep;
bool is_v1v2;
MOD_SLOCK;
- mod = module_lookupbyid(uap->modid);
+ mod = module_lookupbyid(modid);
if (mod == NULL) {
MOD_SUNLOCK;
return (ENOENT);
@@ -395,7 +401,6 @@ sys_modstat(struct thread *td, struct modstat_args *uap)
name = mod->name;
data = mod->data;
MOD_SUNLOCK;
- stat = uap->stat;
/*
* Check the version of the user's structure.
@@ -406,12 +411,16 @@ sys_modstat(struct thread *td, struct modstat_args *uap)
version == sizeof(struct module_stat_v2));
if (!is_v1v2 && version != sizeof(struct module_stat))
return (EINVAL);
+ if (is_v1v2)
+ user_namep = ((struct module_stat_v1 *)stat)->name;
+ else
+ user_namep = stat->name;
namelen = strlen(mod->name) + 1;
if (is_v1v2 && namelen > MAXMODNAMEV1V2)
namelen = MAXMODNAMEV1V2;
else if (namelen > MAXMODNAMEV3)
namelen = MAXMODNAMEV3;
- if ((error = copyout(name, &stat->name[0], namelen)) != 0)
+ if ((error = copyout(name, user_namep, namelen)) != 0)
return (error);
/* Extending MAXMODNAME gives an offset change for v3. */
@@ -446,12 +455,18 @@ sys_modstat(struct thread *td, struct modstat_args *uap)
int
sys_modfind(struct thread *td, struct modfind_args *uap)
+{
+ return (kern_modfind(td, uap->name));
+}
+
+int
+kern_modfind(struct thread *td, const char *uname)
{
int error = 0;
char name[MAXMODNAMEV3];
module_t mod;
- if ((error = copyinstr(uap->name, name, sizeof name, 0)) != 0)
+ if ((error = copyinstr(uname, name, sizeof name, 0)) != 0)
return (error);
MOD_SLOCK;
diff --git a/sys/sys/syscallsubr.h b/sys/sys/syscallsubr.h
index ab56b22978c2..e88bbcc995f9 100644
--- a/sys/sys/syscallsubr.h
+++ b/sys/sys/syscallsubr.h
@@ -50,6 +50,7 @@ struct kevent_copyops;
struct kld_file_stat;
struct ksiginfo;
struct mbuf;
+struct module_stat;
struct msghdr;
struct msqid_ds;
struct pollfd;
@@ -239,6 +240,8 @@ int kern_mmap(struct thread *td, const struct mmap_req *mrp);
int kern_mmap_racct_check(struct thread *td, struct vm_map *map,
vm_size_t size);
int kern_mmap_maxprot(struct proc *p, int prot);
+int kern_modfind(struct thread *td, const char *uname);
+int kern_modstat(struct thread *td, int modid, struct module_stat *stat);
int kern_mprotect(struct thread *td, uintptr_t addr, size_t size,
int prot, int flags);
int kern_msgctl(struct thread *, int, int, struct msqid_ds *);