[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <aV8grrXoMlkJZ0fY@MiWiFi-R3L-srv>
Date: Thu, 8 Jan 2026 11:12:46 +0800
From: "bhe@...hat.com" <bhe@...hat.com>
To: David Binderman <dcb314@...mail.com>
Cc: "akpm@...ux-foundation.org" <akpm@...ux-foundation.org>,
"kexec@...ts.infradead.org" <kexec@...ts.infradead.org>,
LKML <linux-kernel@...r.kernel.org>
Subject: Re: linux-6.19-rc4/kernel/kexec_core.c:425: Possible loss of data ?
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.
Powered by blists - more mailing lists