Re: git: 7f8c2056db1e - main - modstat: avoid copying from freed memory
- In reply to: Brooks Davis : "git: 7f8c2056db1e - main - modstat: avoid copying from freed memory"
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Wed, 11 Nov 2026 10:18:25 UTC
On Wed, Nov 11, 2026 at 09:58:12AM +0000, Brooks Davis wrote: > The branch main has been updated by brooks: > > URL: https://cgit.FreeBSD.org/src/commit/?id=7f8c2056db1e39e44c3eda15aa4e53f7fc971cd8 > > commit 7f8c2056db1e39e44c3eda15aa4e53f7fc971cd8 > Author: Brooks Davis <brooks@FreeBSD.org> > AuthorDate: 2026-11-11 09:40:40 +0000 > Commit: Brooks Davis <brooks@FreeBSD.org> > CommitDate: 2026-11-11 09:40:40 +0000 > > modstat: avoid copying from freed memory > > If a module is unloaded after the module is looked up in kern_modstat, > but before one of the copyout's occurs, then the memory being copied > might be freed and reused leading to an information disclosure. > > The LLM was particularly concerned about a TOCTOU issue in the length > of the name, but it seems likely that there are issues with all the > copyout's. As such, hold the shared lock throughout. As noted in the review, this change is suboptimal in that it holds the module lock too long, potenially over a page fault, but it's a minor performance issue in an administrative command. If kern_modstat only handled one version of struct module_stat I'd probably have done a more agressive refactor, but the compat bits make it more complicated than I wanted to deal with. This is an excellent example of why we should not version structures and instead add new system calls. I'd have had to edit more functions, but they would have been simple, linear things not this mess of ifs. -- Brooks