Linux Modules
 help / color / mirror / Atom feed
* [PATCH] module: procfs: fix signed integer overflow in module_total_size()
@ 2026-06-03 16:24 Naveen Kumar Chaudhary
  2026-06-05 20:52 ` Sami Tolvanen
  0 siblings, 1 reply; 6+ messages in thread
From: Naveen Kumar Chaudhary @ 2026-06-03 16:24 UTC (permalink / raw)
  To: mcgrof, petr.pavlu, da.gomez, samitolvanen
  Cc: atomlin, linux-modules, linux-kernel

module_total_size() accumulates unsigned section sizes into a signed int
before returning as unsigned int. If the total exceeds INT_MAX, this is
signed integer overflow.

Change the accumulator to unsigned int to match the return type.

Signed-off-by: Naveen Kumar Chaudhary <naveen.osdev@gmail.com>
---
 kernel/module/procfs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/module/procfs.c b/kernel/module/procfs.c
index 0a4841e88adb..90712aa9dd13 100644
--- a/kernel/module/procfs.c
+++ b/kernel/module/procfs.c
@@ -64,7 +64,7 @@ static void m_stop(struct seq_file *m, void *p)
 
 static unsigned int module_total_size(struct module *mod)
 {
-	int size = 0;
+	unsigned int size = 0;
 
 	for_each_mod_mem_type(type)
 		size += mod->mem[type].size;
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] module: procfs: fix signed integer overflow in module_total_size()
  2026-06-03 16:24 [PATCH] module: procfs: fix signed integer overflow in module_total_size() Naveen Kumar Chaudhary
@ 2026-06-05 20:52 ` Sami Tolvanen
  2026-06-07  4:18   ` [PATCH v2] " Naveen Kumar Chaudhary
  0 siblings, 1 reply; 6+ messages in thread
From: Sami Tolvanen @ 2026-06-05 20:52 UTC (permalink / raw)
  To: Naveen Kumar Chaudhary
  Cc: mcgrof, petr.pavlu, da.gomez, atomlin, linux-modules,
	linux-kernel

On Wed, Jun 03, 2026 at 09:54:11PM +0530, Naveen Kumar Chaudhary wrote:
> module_total_size() accumulates unsigned section sizes into a signed int
> before returning as unsigned int. If the total exceeds INT_MAX, this is
> signed integer overflow.

This doesn't sound accurate to me. The compiler performs an implicit
type conversion, but there's no signed integer overflow:

https://godbolt.org/z/hzGrYMsPW

> Change the accumulator to unsigned int to match the return type.
> 
> Signed-off-by: Naveen Kumar Chaudhary <naveen.osdev@gmail.com>
> ---
>  kernel/module/procfs.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/kernel/module/procfs.c b/kernel/module/procfs.c
> index 0a4841e88adb..90712aa9dd13 100644
> --- a/kernel/module/procfs.c
> +++ b/kernel/module/procfs.c
> @@ -64,7 +64,7 @@ static void m_stop(struct seq_file *m, void *p)
>  
>  static unsigned int module_total_size(struct module *mod)
>  {
> -	int size = 0;
> +	unsigned int size = 0;

While there's no behavioral difference, using unsigned int seems like
good hygiene. With the commit message corrected:

Reviewed-by: Sami Tolvanen <samitolvanen@google.com>

Sami

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v2] module: procfs: fix signed integer overflow in module_total_size()
  2026-06-05 20:52 ` Sami Tolvanen
@ 2026-06-07  4:18   ` Naveen Kumar Chaudhary
  2026-07-09  8:45     ` Petr Pavlu
  0 siblings, 1 reply; 6+ messages in thread
From: Naveen Kumar Chaudhary @ 2026-06-07  4:18 UTC (permalink / raw)
  To: samitolvanen; +Cc: mcgrof, petr.pavlu, da.gomez, atomlin, linux-modules

module_total_size() returns unsigned int but uses a signed int
accumulator. While the result is numerically correct, the type
mismatch is misleading.

Change the accumulator to unsigned int to match the return type.

Signed-off-by: Naveen Kumar Chaudhary <naveen.osdev@gmail.com>
---
Changes in v2:
    - Modify the commit message

Thanks Sami for the catch. I have corrected the commit message.

Regards,
Naveen

 kernel/module/procfs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/module/procfs.c b/kernel/module/procfs.c
index 0a4841e88adb..90712aa9dd13 100644
--- a/kernel/module/procfs.c
+++ b/kernel/module/procfs.c
@@ -64,7 +64,7 @@ static void m_stop(struct seq_file *m, void *p)
 
 static unsigned int module_total_size(struct module *mod)
 {
-	int size = 0;
+	unsigned int size = 0;
 
 	for_each_mod_mem_type(type)
 		size += mod->mem[type].size;
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH v2] module: procfs: fix signed integer overflow in module_total_size()
  2026-06-07  4:18   ` [PATCH v2] " Naveen Kumar Chaudhary
@ 2026-07-09  8:45     ` Petr Pavlu
  2026-07-09 15:25       ` Sami Tolvanen
  0 siblings, 1 reply; 6+ messages in thread
From: Petr Pavlu @ 2026-07-09  8:45 UTC (permalink / raw)
  To: Naveen Kumar Chaudhary
  Cc: samitolvanen, mcgrof, da.gomez, atomlin, linux-modules

On 6/7/26 6:18 AM, Naveen Kumar Chaudhary wrote:
> module_total_size() returns unsigned int but uses a signed int
> accumulator. While the result is numerically correct, the type
> mismatch is misleading.
> 
> Change the accumulator to unsigned int to match the return type.
> 
> Signed-off-by: Naveen Kumar Chaudhary <naveen.osdev@gmail.com>

Queued on modules-next for v7.3-rc1.

-- 
Thanks,
Petr

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2] module: procfs: fix signed integer overflow in module_total_size()
  2026-07-09  8:45     ` Petr Pavlu
@ 2026-07-09 15:25       ` Sami Tolvanen
  2026-07-10  7:36         ` Petr Pavlu
  0 siblings, 1 reply; 6+ messages in thread
From: Sami Tolvanen @ 2026-07-09 15:25 UTC (permalink / raw)
  To: Petr Pavlu
  Cc: Naveen Kumar Chaudhary, mcgrof, da.gomez, atomlin, linux-modules

On Thu, Jul 9, 2026 at 1:45 AM Petr Pavlu <petr.pavlu@suse.com> wrote:
>
> On 6/7/26 6:18 AM, Naveen Kumar Chaudhary wrote:
> > module_total_size() returns unsigned int but uses a signed int
> > accumulator. While the result is numerically correct, the type
> > mismatch is misleading.
> >
> > Change the accumulator to unsigned int to match the return type.
> >
> > Signed-off-by: Naveen Kumar Chaudhary <naveen.osdev@gmail.com>
>
> Queued on modules-next for v7.3-rc1.

Note that the commit title still claims to fix a signed integer
overflow, which isn't accurate. Otherwise LGTM.

Sami

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2] module: procfs: fix signed integer overflow in module_total_size()
  2026-07-09 15:25       ` Sami Tolvanen
@ 2026-07-10  7:36         ` Petr Pavlu
  0 siblings, 0 replies; 6+ messages in thread
From: Petr Pavlu @ 2026-07-10  7:36 UTC (permalink / raw)
  To: Sami Tolvanen
  Cc: Naveen Kumar Chaudhary, mcgrof, da.gomez, atomlin, linux-modules

On 7/9/26 5:25 PM, Sami Tolvanen wrote:
> On Thu, Jul 9, 2026 at 1:45 AM Petr Pavlu <petr.pavlu@suse.com> wrote:
>>
>> On 6/7/26 6:18 AM, Naveen Kumar Chaudhary wrote:
>>> module_total_size() returns unsigned int but uses a signed int
>>> accumulator. While the result is numerically correct, the type
>>> mismatch is misleading.
>>>
>>> Change the accumulator to unsigned int to match the return type.
>>>
>>> Signed-off-by: Naveen Kumar Chaudhary <naveen.osdev@gmail.com>
>>
>> Queued on modules-next for v7.3-rc1.
> 
> Note that the commit title still claims to fix a signed integer
> overflow, which isn't accurate. Otherwise LGTM.

Thanks for noticing this. I tweaked the title to:

module: procfs: use matching type for accumulator in module_total_size()

-- Petr

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2026-07-10  7:36 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-03 16:24 [PATCH] module: procfs: fix signed integer overflow in module_total_size() Naveen Kumar Chaudhary
2026-06-05 20:52 ` Sami Tolvanen
2026-06-07  4:18   ` [PATCH v2] " Naveen Kumar Chaudhary
2026-07-09  8:45     ` Petr Pavlu
2026-07-09 15:25       ` Sami Tolvanen
2026-07-10  7:36         ` Petr Pavlu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox