* linux-6.19-rc4/kernel/kexec_core.c:425: Possible loss of data ?
@ 2026-01-07 14:32 David Binderman
2026-01-08 3:12 ` bhe
0 siblings, 1 reply; 3+ messages in thread
From: David Binderman @ 2026-01-07 14:32 UTC (permalink / raw)
To: akpm, bhe, kexec, LKML
Hello there,
Static analyser cppcheck says:
linux-6.19-rc4/kernel/kexec_core.c:425:7: style: int result is assigned to long variable. If the variable is long to avoid loss of information, then you have loss of information. [truncLongCastAssignment]
Source code is
size = (1 << order) << PAGE_SHIFT;
I have no idea how large order gets, but if it gets over about
30 or so, then IMHO there will be a loss of bits.
Perhaps some sanity check on the value of order would
be a good idea ? Either that or
size = (1UL << order) << PAGE_SHIFT;
might be better code.
Regards
David Binderman
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: linux-6.19-rc4/kernel/kexec_core.c:425: Possible loss of data ?
2026-01-07 14:32 linux-6.19-rc4/kernel/kexec_core.c:425: Possible loss of data ? David Binderman
@ 2026-01-08 3:12 ` bhe
2026-01-08 8:42 ` David Binderman
0 siblings, 1 reply; 3+ messages in thread
From: bhe @ 2026-01-08 3:12 UTC (permalink / raw)
To: David Binderman; +Cc: akpm, kexec, LKML
On 01/07/26 at 02:32pm, David Binderman wrote:
> Hello there,
>
> Static analyser cppcheck says:
>
> linux-6.19-rc4/kernel/kexec_core.c:425:7: style: int result is assigned to long variable. If the variable is long to avoid loss of information, then you have loss of information. [truncLongCastAssignment]
>
> Source code is
>
> size = (1 << order) << PAGE_SHIFT;
>
> I have no idea how large order gets, but if it gets over about
> 30 or so, then IMHO there will be a loss of bits.
We may not need to worry about it. In all places where
kimage_alloc_control_pages is called, the order is 0 or
get_order(KEXEC_CONTROL_PAGE_SIZE) on mips which is 2.
arch/mips/include/asm/kexec.h:#define KEXEC_CONTROL_PAGE_SIZE (4096 + 3*4096)
[~]$ git grep kimage_alloc_control_pages
arch/arm64/kernel/machine_kexec.c: struct page *page = kimage_alloc_control_pages(kimage, 0);
arch/x86/kernel/machine_kexec_64.c: page = kimage_alloc_control_pages(image, 0);
include/linux/kexec.h:extern struct page *kimage_alloc_control_pages(struct kimage *image,
kernel/crash_core.c: vmcoreinfo_page = kimage_alloc_control_pages(image, 0);
kernel/kexec.c: image->control_code_page = kimage_alloc_control_pages(image,
kernel/kexec.c: image->swap_page = kimage_alloc_control_pages(image, 0);
kernel/kexec_core.c:struct page *kimage_alloc_control_pages(struct kimage *image,
kernel/kexec_file.c: image->control_code_page = kimage_alloc_control_pages(image,
kernel/kexec_file.c: image->swap_page = kimage_alloc_control_pages(image, 0);
>
> Perhaps some sanity check on the value of order would
> be a good idea ? Either that or
>
> size = (1UL << order) << PAGE_SHIFT;
>
> might be better code.
That is fine if people is worried, a patch is welcome.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: linux-6.19-rc4/kernel/kexec_core.c:425: Possible loss of data ?
2026-01-08 3:12 ` bhe
@ 2026-01-08 8:42 ` David Binderman
0 siblings, 0 replies; 3+ messages in thread
From: David Binderman @ 2026-01-08 8:42 UTC (permalink / raw)
To: bhe; +Cc: akpm, kexec, LKML
Hello there,
>We may not need to worry about it. In all places where
>kimage_alloc_control_pages is called, the order is 0 or
>get_order(KEXEC_CONTROL_PAGE_SIZE) on mips which is 2.
Thanks for the update.
>That is fine if people is worried, a patch is welcome.
Since my kernel patch success rate is 0.0 % (approx) I will avoid doing this.
Might be worth an assert that the value is in range [0..30].
Regards
David Binderman
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-01-08 8:42 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-01-07 14:32 linux-6.19-rc4/kernel/kexec_core.c:425: Possible loss of data ? David Binderman
2026-01-08 3:12 ` bhe
2026-01-08 8:42 ` David Binderman
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®