git: 300d7db00a37 - releng/15.2 - kern_module.c: add kern_ implementations
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Tue, 17 Nov 2026 19:51:55 UTC
The branch releng/15.2 has been updated by cperciva:
URL: https://cgit.FreeBSD.org/src/commit/?id=300d7db00a3730b48839c9d92dec462f1844f834
commit 300d7db00a3730b48839c9d92dec462f1844f834
Author: Brooks Davis <brooks@FreeBSD.org>
AuthorDate: 2026-11-10 11:49:20 +0000
Commit: Colin Percival <cperciva@FreeBSD.org>
CommitDate: 2026-11-17 19:51:12 +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.
Approved by: re (cperciva)
Effort: CHERI upstreaming
Sponsored by: DARPA, AFRL, Innovate UK
Pull Request: https://github.com/freebsd/freebsd-src/pull/2284
(cherry picked from commit b96dc2c04fb4f504ad0c752c5d4b074c5bfbf7e0)
(cherry picked from commit 5c7d799c53ccb2f0a886566750f8226ea0c7f02f)
---
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 6298f06fdba7..de2df96bdbf8 100644
--- a/sys/kern/kern_module.c
+++ b/sys/kern/kern_module.c
@@ -31,8 +31,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>
@@ -373,18 +374,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);
@@ -394,7 +400,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.
@@ -405,12 +410,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. */
@@ -445,12 +454,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 8061ea65e978..36538eda5034 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 mq_attr;
struct msghdr;
struct msqid_ds;
@@ -252,6 +253,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 *);