<feed xmlns='http://www.w3.org/2005/Atom'>
<title>linux.git/kernel/module/dups.c, branch v7.3-rc2</title>
<subtitle>Linux kernel source tree</subtitle>
<link rel='alternate' type='text/html' href='https://git.tavy.me/linux.git/'/>
<entry>
<title>module/dups: Clean up includes</title>
<updated>2026-08-06T11:29:03+00:00</updated>
<author>
<name>Petr Pavlu</name>
<email>petr.pavlu@suse.com</email>
</author>
<published>2026-08-06T09:10:20+00:00</published>
<link rel='alternate' type='text/html' href='https://git.tavy.me/linux.git/commit/?id=2a7ecc5fbde76fd48f37c2878e52c50ae8928e0a'/>
<id>2a7ecc5fbde76fd48f37c2878e52c50ae8928e0a</id>
<content type='text'>
The kernel/module/dups.c file relies on the following definitions and
associated functions:

* module_param() -&gt; linux/moduleparam.h,
* DEFINE_MUTEX() -&gt; linux/mutex.h,
* LIST_HEAD(), list_for_each_entry(), ... -&gt; linux/list.h,
* refcount_t, refcount_inc(), ... -&gt; linux/refcount.h,
* MODULE_NAME_LEN -&gt; linux/module.h,
* completion, complete_all(), ... -&gt; linux/completion.h,
* delayed_work, work_struct, ... -&gt; linux/workqueue.h,
* lockdep_assert_held() -&gt; linux/lockdep.h,
* strcmp(), memcpy() -&gt; linux/string.h,
* container_of() -&gt; linux/container_of.h,
* DEFINE_FREE(), __free(), scoped_guard() -&gt; linux/cleanup.h,
* kzalloc_obj(), kfree() -&gt; linux/slab.h,
* pr_debug(), pr_warn() -&gt; linux/printk.h,
* WARN() -&gt; linux/bug.h,
* TASK_KILLABLE -&gt; linux/sched.h,
* HZ -&gt; linux/param.h.

Update the file's include list accordingly.

Signed-off-by: Petr Pavlu &lt;petr.pavlu@suse.com&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
The kernel/module/dups.c file relies on the following definitions and
associated functions:

* module_param() -&gt; linux/moduleparam.h,
* DEFINE_MUTEX() -&gt; linux/mutex.h,
* LIST_HEAD(), list_for_each_entry(), ... -&gt; linux/list.h,
* refcount_t, refcount_inc(), ... -&gt; linux/refcount.h,
* MODULE_NAME_LEN -&gt; linux/module.h,
* completion, complete_all(), ... -&gt; linux/completion.h,
* delayed_work, work_struct, ... -&gt; linux/workqueue.h,
* lockdep_assert_held() -&gt; linux/lockdep.h,
* strcmp(), memcpy() -&gt; linux/string.h,
* container_of() -&gt; linux/container_of.h,
* DEFINE_FREE(), __free(), scoped_guard() -&gt; linux/cleanup.h,
* kzalloc_obj(), kfree() -&gt; linux/slab.h,
* pr_debug(), pr_warn() -&gt; linux/printk.h,
* WARN() -&gt; linux/bug.h,
* TASK_KILLABLE -&gt; linux/sched.h,
* HZ -&gt; linux/param.h.

Update the file's include list accordingly.

Signed-off-by: Petr Pavlu &lt;petr.pavlu@suse.com&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>module/dups: Use strcmp() to compare module names</title>
<updated>2026-08-06T11:29:03+00:00</updated>
<author>
<name>Petr Pavlu</name>
<email>petr.pavlu@suse.com</email>
</author>
<published>2026-08-06T09:10:19+00:00</published>
<link rel='alternate' type='text/html' href='https://git.tavy.me/linux.git/commit/?id=cc6e79b2080da3310dbf9749c6ee61ae1641ec70'/>
<id>cc6e79b2080da3310dbf9749c6ee61ae1641ec70</id>
<content type='text'>
Use strcmp() instead of strlen()+memcmp() to compare module names in
kmod_dup_request_lookup(), since all strings are NUL-terminated.

Reviewed-by: Aaron Tomlin &lt;atomlin@atomlin.com&gt;
Signed-off-by: Petr Pavlu &lt;petr.pavlu@suse.com&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Use strcmp() instead of strlen()+memcmp() to compare module names in
kmod_dup_request_lookup(), since all strings are NUL-terminated.

Reviewed-by: Aaron Tomlin &lt;atomlin@atomlin.com&gt;
Signed-off-by: Petr Pavlu &lt;petr.pavlu@suse.com&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>module/dups: Use scope-based cleanup helpers</title>
<updated>2026-08-06T11:29:03+00:00</updated>
<author>
<name>Petr Pavlu</name>
<email>petr.pavlu@suse.com</email>
</author>
<published>2026-08-06T09:10:18+00:00</published>
<link rel='alternate' type='text/html' href='https://git.tavy.me/linux.git/commit/?id=c85e76535b6d66cf89e6895721d36cf63b233c6a'/>
<id>c85e76535b6d66cf89e6895721d36cf63b233c6a</id>
<content type='text'>
Use scope-based cleanup helpers for kmod_dup_mutex and kmod_req to shorten
the code and to clarify where the lock is taken in
kmod_dup_request_exists_wait().

Signed-off-by: Petr Pavlu &lt;petr.pavlu@suse.com&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Use scope-based cleanup helpers for kmod_dup_mutex and kmod_req to shorten
the code and to clarify where the lock is taken in
kmod_dup_request_exists_wait().

Signed-off-by: Petr Pavlu &lt;petr.pavlu@suse.com&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>module/dups: Avoid unnecessary kmod_dup_req allocations</title>
<updated>2026-08-06T11:29:03+00:00</updated>
<author>
<name>Petr Pavlu</name>
<email>petr.pavlu@suse.com</email>
</author>
<published>2026-08-06T09:10:17+00:00</published>
<link rel='alternate' type='text/html' href='https://git.tavy.me/linux.git/commit/?id=96e6f752fc25af366de2b3f8aa09c93963d00d2a'/>
<id>96e6f752fc25af366de2b3f8aa09c93963d00d2a</id>
<content type='text'>
The kmod dups code preallocates kmod_dup_req before taking kmod_dup_mutex
to avoid allocating memory while holding the lock. This provides little
benefit, since the allocation is fast and can safely be done under the
lock. On the other hand, it leads to unnecessary allocations when the
request turns out to be a duplicate and slightly complicates the code.

Allocate kmod_dup_req only when needed and introduce a helper function
alloc_kmod_req() to initialize the structure.

Reviewed-by: Aaron Tomlin &lt;atomlin@atomlin.com&gt;
Signed-off-by: Petr Pavlu &lt;petr.pavlu@suse.com&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
The kmod dups code preallocates kmod_dup_req before taking kmod_dup_mutex
to avoid allocating memory while holding the lock. This provides little
benefit, since the allocation is fast and can safely be done under the
lock. On the other hand, it leads to unnecessary allocations when the
request turns out to be a duplicate and slightly complicates the code.

Allocate kmod_dup_req only when needed and introduce a helper function
alloc_kmod_req() to initialize the structure.

Reviewed-by: Aaron Tomlin &lt;atomlin@atomlin.com&gt;
Signed-off-by: Petr Pavlu &lt;petr.pavlu@suse.com&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>module/dups: Fix use-after-free in kmod_dup_req lifetime handling</title>
<updated>2026-08-06T11:29:03+00:00</updated>
<author>
<name>Petr Pavlu</name>
<email>petr.pavlu@suse.com</email>
</author>
<published>2026-08-06T09:10:16+00:00</published>
<link rel='alternate' type='text/html' href='https://git.tavy.me/linux.git/commit/?id=5eecb11b543f9f417bcf0dea239ff99c6af65dbd'/>
<id>5eecb11b543f9f417bcf0dea239ff99c6af65dbd</id>
<content type='text'>
The kmod dups code uses RCU to ensure that a kmod_dup_req instance is freed
only after it is no longer referenced. When releasing an instance, the
kmod_dup_request_delete() function removes the kmod_dup_req from the
dup_kmod_reqs list, waits via synchronize_rcu() and finally frees it.
However, this doesn't work correctly because parallel users referencing the
instance in kmod_dup_request_exists_wait() don't enter an RCU read-side
critical section. This can result in a use-after-free.

The kmod_dup_request_exists_wait() function may need to hold a valid
reference to a kmod_dup_req instance across a blocking wait until the
corresponding modprobe command completes. This makes it unsuitable for RCU.

Fix the issue by changing the lifecycle management of kmod_dup_req to use
reference counting.

Fixes: 8660484ed1cf ("module: add debugging auto-load duplicate module support")
Reviewed-by: Aaron Tomlin &lt;atomlin@atomlin.com&gt;
Signed-off-by: Petr Pavlu &lt;petr.pavlu@suse.com&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
The kmod dups code uses RCU to ensure that a kmod_dup_req instance is freed
only after it is no longer referenced. When releasing an instance, the
kmod_dup_request_delete() function removes the kmod_dup_req from the
dup_kmod_reqs list, waits via synchronize_rcu() and finally frees it.
However, this doesn't work correctly because parallel users referencing the
instance in kmod_dup_request_exists_wait() don't enter an RCU read-side
critical section. This can result in a use-after-free.

The kmod_dup_request_exists_wait() function may need to hold a valid
reference to a kmod_dup_req instance across a blocking wait until the
corresponding modprobe command completes. This makes it unsuitable for RCU.

Fix the issue by changing the lifecycle management of kmod_dup_req to use
reference counting.

Fixes: 8660484ed1cf ("module: add debugging auto-load duplicate module support")
Reviewed-by: Aaron Tomlin &lt;atomlin@atomlin.com&gt;
Signed-off-by: Petr Pavlu &lt;petr.pavlu@suse.com&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>module/dups: Inform duplicate requests about the result directly</title>
<updated>2026-08-06T11:29:03+00:00</updated>
<author>
<name>Petr Pavlu</name>
<email>petr.pavlu@suse.com</email>
</author>
<published>2026-08-06T09:10:15+00:00</published>
<link rel='alternate' type='text/html' href='https://git.tavy.me/linux.git/commit/?id=d258ed8a86bb46bbbbc84fb914478259a1e694a4'/>
<id>d258ed8a86bb46bbbbc84fb914478259a1e694a4</id>
<content type='text'>
When kmod_dup_request_announce() announces the completion of
a request_module() call to duplicate waiters, it queues a work item to
invoke kmod_dup_request_complete(), and only that function calls
complete_all().

This adds an arbitrary delay that is unnecessary and provides little
benefit. Call complete_all() directly from kmod_dup_request_announce()
instead.

Signed-off-by: Petr Pavlu &lt;petr.pavlu@suse.com&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
When kmod_dup_request_announce() announces the completion of
a request_module() call to duplicate waiters, it queues a work item to
invoke kmod_dup_request_complete(), and only that function calls
complete_all().

This adds an arbitrary delay that is unnecessary and provides little
benefit. Call complete_all() directly from kmod_dup_request_announce()
instead.

Signed-off-by: Petr Pavlu &lt;petr.pavlu@suse.com&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>module: use strscpy() to copy module names in stats and dup tracking</title>
<updated>2026-08-06T11:29:02+00:00</updated>
<author>
<name>Naveen Kumar Chaudhary</name>
<email>naveen.osdev@gmail.com</email>
</author>
<published>2026-06-04T17:45:02+00:00</published>
<link rel='alternate' type='text/html' href='https://git.tavy.me/linux.git/commit/?id=93c29ebd1622fb0670701e1c1b3a978a5cac08b7'/>
<id>93c29ebd1622fb0670701e1c1b3a978a5cac08b7</id>
<content type='text'>
Both try_add_failed_module() and kmod_dup_request_exists_wait() use
memcpy() with strlen() to copy module names into fixed-size
char[MODULE_NAME_LEN] buffers. Neither performs a bounds check on the
copy. Current callers always pass names originating from
mod-&gt;name (itself char[MODULE_NAME_LEN]), so this is not exploitable
today. However both functions accept a plain const char * with no
documented length contract, making them latent buffer overflows if a
future caller passes a longer string.

Replace memcpy() with strscpy() in both sites, which bounds the copy
to MODULE_NAME_LEN and always NUL-terminates.

Signed-off-by: Naveen Kumar Chaudhary &lt;naveen.osdev@gmail.com&gt;
Reviewed-by: Petr Pavlu &lt;petr.pavlu@suse.com&gt;
Signed-off-by: Petr Pavlu &lt;petr.pavlu@suse.com&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Both try_add_failed_module() and kmod_dup_request_exists_wait() use
memcpy() with strlen() to copy module names into fixed-size
char[MODULE_NAME_LEN] buffers. Neither performs a bounds check on the
copy. Current callers always pass names originating from
mod-&gt;name (itself char[MODULE_NAME_LEN]), so this is not exploitable
today. However both functions accept a plain const char * with no
documented length contract, making them latent buffer overflows if a
future caller passes a longer string.

Replace memcpy() with strscpy() in both sites, which bounds the copy
to MODULE_NAME_LEN and always NUL-terminates.

Signed-off-by: Naveen Kumar Chaudhary &lt;naveen.osdev@gmail.com&gt;
Reviewed-by: Petr Pavlu &lt;petr.pavlu@suse.com&gt;
Signed-off-by: Petr Pavlu &lt;petr.pavlu@suse.com&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>Convert 'alloc_obj' family to use the new default GFP_KERNEL argument</title>
<updated>2026-02-22T01:09:51+00:00</updated>
<author>
<name>Linus Torvalds</name>
<email>torvalds@linux-foundation.org</email>
</author>
<published>2026-02-22T00:37:42+00:00</published>
<link rel='alternate' type='text/html' href='https://git.tavy.me/linux.git/commit/?id=bf4afc53b77aeaa48b5409da5c8da6bb4eff7f43'/>
<id>bf4afc53b77aeaa48b5409da5c8da6bb4eff7f43</id>
<content type='text'>
This was done entirely with mindless brute force, using

    git grep -l '\&lt;k[vmz]*alloc_objs*(.*, GFP_KERNEL)' |
        xargs sed -i 's/\(alloc_objs*(.*\), GFP_KERNEL)/\1)/'

to convert the new alloc_obj() users that had a simple GFP_KERNEL
argument to just drop that argument.

Note that due to the extreme simplicity of the scripting, any slightly
more complex cases spread over multiple lines would not be triggered:
they definitely exist, but this covers the vast bulk of the cases, and
the resulting diff is also then easier to check automatically.

For the same reason the 'flex' versions will be done as a separate
conversion.

Signed-off-by: Linus Torvalds &lt;torvalds@linux-foundation.org&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
This was done entirely with mindless brute force, using

    git grep -l '\&lt;k[vmz]*alloc_objs*(.*, GFP_KERNEL)' |
        xargs sed -i 's/\(alloc_objs*(.*\), GFP_KERNEL)/\1)/'

to convert the new alloc_obj() users that had a simple GFP_KERNEL
argument to just drop that argument.

Note that due to the extreme simplicity of the scripting, any slightly
more complex cases spread over multiple lines would not be triggered:
they definitely exist, but this covers the vast bulk of the cases, and
the resulting diff is also then easier to check automatically.

For the same reason the 'flex' versions will be done as a separate
conversion.

Signed-off-by: Linus Torvalds &lt;torvalds@linux-foundation.org&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>treewide: Replace kmalloc with kmalloc_obj for non-scalar types</title>
<updated>2026-02-21T09:02:28+00:00</updated>
<author>
<name>Kees Cook</name>
<email>kees@kernel.org</email>
</author>
<published>2026-02-21T07:49:23+00:00</published>
<link rel='alternate' type='text/html' href='https://git.tavy.me/linux.git/commit/?id=69050f8d6d075dc01af7a5f2f550a8067510366f'/>
<id>69050f8d6d075dc01af7a5f2f550a8067510366f</id>
<content type='text'>
This is the result of running the Coccinelle script from
scripts/coccinelle/api/kmalloc_objs.cocci. The script is designed to
avoid scalar types (which need careful case-by-case checking), and
instead replace kmalloc-family calls that allocate struct or union
object instances:

Single allocations:	kmalloc(sizeof(TYPE), ...)
are replaced with:	kmalloc_obj(TYPE, ...)

Array allocations:	kmalloc_array(COUNT, sizeof(TYPE), ...)
are replaced with:	kmalloc_objs(TYPE, COUNT, ...)

Flex array allocations:	kmalloc(struct_size(PTR, FAM, COUNT), ...)
are replaced with:	kmalloc_flex(*PTR, FAM, COUNT, ...)

(where TYPE may also be *VAR)

The resulting allocations no longer return "void *", instead returning
"TYPE *".

Signed-off-by: Kees Cook &lt;kees@kernel.org&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
This is the result of running the Coccinelle script from
scripts/coccinelle/api/kmalloc_objs.cocci. The script is designed to
avoid scalar types (which need careful case-by-case checking), and
instead replace kmalloc-family calls that allocate struct or union
object instances:

Single allocations:	kmalloc(sizeof(TYPE), ...)
are replaced with:	kmalloc_obj(TYPE, ...)

Array allocations:	kmalloc_array(COUNT, sizeof(TYPE), ...)
are replaced with:	kmalloc_objs(TYPE, COUNT, ...)

Flex array allocations:	kmalloc(struct_size(PTR, FAM, COUNT), ...)
are replaced with:	kmalloc_flex(*PTR, FAM, COUNT, ...)

(where TYPE may also be *VAR)

The resulting allocations no longer return "void *", instead returning
"TYPE *".

Signed-off-by: Kees Cook &lt;kees@kernel.org&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>module: replace use of system_wq with system_dfl_wq</title>
<updated>2025-12-22T16:35:53+00:00</updated>
<author>
<name>Marco Crivellari</name>
<email>marco.crivellari@suse.com</email>
</author>
<published>2025-11-11T09:50:49+00:00</published>
<link rel='alternate' type='text/html' href='https://git.tavy.me/linux.git/commit/?id=581ac2d4a58b81669cc6abf645a558bce5cf14ab'/>
<id>581ac2d4a58b81669cc6abf645a558bce5cf14ab</id>
<content type='text'>
Currently if a user enqueues a work item using schedule_delayed_work() the
used wq is "system_wq" (per-cpu wq) while queue_delayed_work() use
WORK_CPU_UNBOUND (used when a cpu is not specified). The same applies to
schedule_work() that is using system_wq and queue_work(), that makes use
again of WORK_CPU_UNBOUND.

This lack of consistency cannot be addressed without refactoring the API.

This continues the effort to refactor workqueue APIs, which began with
the introduction of new workqueues and a new alloc_workqueue flag in:

commit 128ea9f6ccfb ("workqueue: Add system_percpu_wq and system_dfl_wq")
commit 930c2ea566af ("workqueue: Add new WQ_PERCPU flag")

Switch to using system_dfl_wq, the new unbound workqueue, because the
users do not benefit from a per-cpu workqueue.

Suggested-by: Tejun Heo &lt;tj@kernel.org&gt;
Signed-off-by: Marco Crivellari &lt;marco.crivellari@suse.com&gt;
Reviewed-by: Petr Pavlu &lt;petr.pavlu@suse.com&gt;
Signed-off-by: Sami Tolvanen &lt;samitolvanen@google.com&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Currently if a user enqueues a work item using schedule_delayed_work() the
used wq is "system_wq" (per-cpu wq) while queue_delayed_work() use
WORK_CPU_UNBOUND (used when a cpu is not specified). The same applies to
schedule_work() that is using system_wq and queue_work(), that makes use
again of WORK_CPU_UNBOUND.

This lack of consistency cannot be addressed without refactoring the API.

This continues the effort to refactor workqueue APIs, which began with
the introduction of new workqueues and a new alloc_workqueue flag in:

commit 128ea9f6ccfb ("workqueue: Add system_percpu_wq and system_dfl_wq")
commit 930c2ea566af ("workqueue: Add new WQ_PERCPU flag")

Switch to using system_dfl_wq, the new unbound workqueue, because the
users do not benefit from a per-cpu workqueue.

Suggested-by: Tejun Heo &lt;tj@kernel.org&gt;
Signed-off-by: Marco Crivellari &lt;marco.crivellari@suse.com&gt;
Reviewed-by: Petr Pavlu &lt;petr.pavlu@suse.com&gt;
Signed-off-by: Sami Tolvanen &lt;samitolvanen@google.com&gt;
</pre>
</div>
</content>
</entry>
</feed>
