* [PATCH] kexec: Initialize ELF lowest address to ULONG_MAX
@ 2024-12-10 9:13 Sourabh Jain
2024-12-12 2:55 ` Baoquan he
0 siblings, 1 reply; 6+ messages in thread
From: Sourabh Jain @ 2024-12-10 9:13 UTC (permalink / raw)
To: ebiederm
Cc: Sourabh Jain, Baoquan he, Hari Bathini, Madhavan Srinivasan,
Michael Ellerman, kexec, linuxppc-dev, linux-kernel
kexec_elf_load() loads an ELF executable and sets the address of the
lowest PT_LOAD section to the address held by the lowest_load_addr
function argument.
To determine the lowest PT_LOAD address, a local variable lowest_addr
(type unsigned long) is initialized to UINT_MAX. After loading each
PT_LOAD, its address is compared to lowest_addr. If a loaded PT_LOAD
address is lower, lowest_addr is updated. However, setting lowest_addr
to UINT_MAX won't work when the kernel image is loaded above 4G, as the
returned lowest PT_LOAD address would be invalid. This is resolved by
initializing lowest_addr to ULONG_MAX instead.
This issue was discovered while implementing crashkernel high/low
reservation on the PowerPC architecture.
Fixes: a0458284f062 ("powerpc: Add support code for kexec_file_load()")
Cc: Baoquan he <bhe@redhat.com>
Cc: Hari Bathini <hbathini@linux.ibm.com>
CC: Madhavan Srinivasan <maddy@linux.ibm.com>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: kexec@lists.infradead.org
Cc: linuxppc-dev@lists.ozlabs.org
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Sourabh Jain <sourabhjain@linux.ibm.com>
---
kernel/kexec_elf.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/kernel/kexec_elf.c b/kernel/kexec_elf.c
index d3689632e8b9..3a5c25b2adc9 100644
--- a/kernel/kexec_elf.c
+++ b/kernel/kexec_elf.c
@@ -390,7 +390,7 @@ int kexec_elf_load(struct kimage *image, struct elfhdr *ehdr,
struct kexec_buf *kbuf,
unsigned long *lowest_load_addr)
{
- unsigned long lowest_addr = UINT_MAX;
+ unsigned long lowest_addr = ULONG_MAX;
int ret;
size_t i;
--
2.47.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] kexec: Initialize ELF lowest address to ULONG_MAX
2024-12-10 9:13 [PATCH] kexec: Initialize ELF lowest address to ULONG_MAX Sourabh Jain
@ 2024-12-12 2:55 ` Baoquan he
2024-12-12 2:58 ` Sourabh Jain
2025-01-09 4:12 ` Sourabh Jain
0 siblings, 2 replies; 6+ messages in thread
From: Baoquan he @ 2024-12-12 2:55 UTC (permalink / raw)
To: Sourabh Jain
Cc: ebiederm, Hari Bathini, akpm, Madhavan Srinivasan,
Michael Ellerman, kexec, linuxppc-dev, linux-kernel
On 12/10/24 at 02:43pm, Sourabh Jain wrote:
> kexec_elf_load() loads an ELF executable and sets the address of the
> lowest PT_LOAD section to the address held by the lowest_load_addr
> function argument.
>
> To determine the lowest PT_LOAD address, a local variable lowest_addr
> (type unsigned long) is initialized to UINT_MAX. After loading each
> PT_LOAD, its address is compared to lowest_addr. If a loaded PT_LOAD
> address is lower, lowest_addr is updated. However, setting lowest_addr
> to UINT_MAX won't work when the kernel image is loaded above 4G, as the
> returned lowest PT_LOAD address would be invalid. This is resolved by
> initializing lowest_addr to ULONG_MAX instead.
>
> This issue was discovered while implementing crashkernel high/low
> reservation on the PowerPC architecture.
>
> Fixes: a0458284f062 ("powerpc: Add support code for kexec_file_load()")
> Cc: Baoquan he <bhe@redhat.com>
> Cc: Hari Bathini <hbathini@linux.ibm.com>
> CC: Madhavan Srinivasan <maddy@linux.ibm.com>
> Cc: Michael Ellerman <mpe@ellerman.id.au>
> Cc: kexec@lists.infradead.org
> Cc: linuxppc-dev@lists.ozlabs.org
> Cc: linux-kernel@vger.kernel.org
> Signed-off-by: Sourabh Jain <sourabhjain@linux.ibm.com>
> ---
> kernel/kexec_elf.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/kernel/kexec_elf.c b/kernel/kexec_elf.c
> index d3689632e8b9..3a5c25b2adc9 100644
> --- a/kernel/kexec_elf.c
> +++ b/kernel/kexec_elf.c
> @@ -390,7 +390,7 @@ int kexec_elf_load(struct kimage *image, struct elfhdr *ehdr,
> struct kexec_buf *kbuf,
> unsigned long *lowest_load_addr)
> {
> - unsigned long lowest_addr = UINT_MAX;
> + unsigned long lowest_addr = ULONG_MAX;
Great catch.
Acked-by: Baoquan He <bhe@redhat.com>
> int ret;
> size_t i;
>
> --
> 2.47.1
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] kexec: Initialize ELF lowest address to ULONG_MAX
2024-12-12 2:55 ` Baoquan he
@ 2024-12-12 2:58 ` Sourabh Jain
2025-01-09 4:12 ` Sourabh Jain
1 sibling, 0 replies; 6+ messages in thread
From: Sourabh Jain @ 2024-12-12 2:58 UTC (permalink / raw)
To: Baoquan he
Cc: ebiederm, Hari Bathini, akpm, Madhavan Srinivasan,
Michael Ellerman, kexec, linuxppc-dev, linux-kernel
On 12/12/24 08:25, Baoquan he wrote:
> On 12/10/24 at 02:43pm, Sourabh Jain wrote:
>> kexec_elf_load() loads an ELF executable and sets the address of the
>> lowest PT_LOAD section to the address held by the lowest_load_addr
>> function argument.
>>
>> To determine the lowest PT_LOAD address, a local variable lowest_addr
>> (type unsigned long) is initialized to UINT_MAX. After loading each
>> PT_LOAD, its address is compared to lowest_addr. If a loaded PT_LOAD
>> address is lower, lowest_addr is updated. However, setting lowest_addr
>> to UINT_MAX won't work when the kernel image is loaded above 4G, as the
>> returned lowest PT_LOAD address would be invalid. This is resolved by
>> initializing lowest_addr to ULONG_MAX instead.
>>
>> This issue was discovered while implementing crashkernel high/low
>> reservation on the PowerPC architecture.
>>
>> Fixes: a0458284f062 ("powerpc: Add support code for kexec_file_load()")
>> Cc: Baoquan he <bhe@redhat.com>
>> Cc: Hari Bathini <hbathini@linux.ibm.com>
>> CC: Madhavan Srinivasan <maddy@linux.ibm.com>
>> Cc: Michael Ellerman <mpe@ellerman.id.au>
>> Cc: kexec@lists.infradead.org
>> Cc: linuxppc-dev@lists.ozlabs.org
>> Cc: linux-kernel@vger.kernel.org
>> Signed-off-by: Sourabh Jain <sourabhjain@linux.ibm.com>
>> ---
>> kernel/kexec_elf.c | 2 +-
>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/kernel/kexec_elf.c b/kernel/kexec_elf.c
>> index d3689632e8b9..3a5c25b2adc9 100644
>> --- a/kernel/kexec_elf.c
>> +++ b/kernel/kexec_elf.c
>> @@ -390,7 +390,7 @@ int kexec_elf_load(struct kimage *image, struct elfhdr *ehdr,
>> struct kexec_buf *kbuf,
>> unsigned long *lowest_load_addr)
>> {
>> - unsigned long lowest_addr = UINT_MAX;
>> + unsigned long lowest_addr = ULONG_MAX;
> Great catch.
>
> Acked-by: Baoquan He <bhe@redhat.com>
Thanks for the Ack Baoquan.
- Sourabh Jain
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] kexec: Initialize ELF lowest address to ULONG_MAX
2024-12-12 2:55 ` Baoquan he
2024-12-12 2:58 ` Sourabh Jain
@ 2025-01-09 4:12 ` Sourabh Jain
2025-01-09 5:28 ` Andrew Morton
1 sibling, 1 reply; 6+ messages in thread
From: Sourabh Jain @ 2025-01-09 4:12 UTC (permalink / raw)
To: Baoquan he, ebiederm
Cc: Hari Bathini, akpm, Madhavan Srinivasan, Michael Ellerman, kexec,
linuxppc-dev, linux-kernel
Hello Baoquan and Eric,
On 12/12/24 08:25, Baoquan he wrote:
> On 12/10/24 at 02:43pm, Sourabh Jain wrote:
>> kexec_elf_load() loads an ELF executable and sets the address of the
>> lowest PT_LOAD section to the address held by the lowest_load_addr
>> function argument.
>>
>> To determine the lowest PT_LOAD address, a local variable lowest_addr
>> (type unsigned long) is initialized to UINT_MAX. After loading each
>> PT_LOAD, its address is compared to lowest_addr. If a loaded PT_LOAD
>> address is lower, lowest_addr is updated. However, setting lowest_addr
>> to UINT_MAX won't work when the kernel image is loaded above 4G, as the
>> returned lowest PT_LOAD address would be invalid. This is resolved by
>> initializing lowest_addr to ULONG_MAX instead.
>>
>> This issue was discovered while implementing crashkernel high/low
>> reservation on the PowerPC architecture.
>>
>> Fixes: a0458284f062 ("powerpc: Add support code for kexec_file_load()")
>> Cc: Baoquan he <bhe@redhat.com>
>> Cc: Hari Bathini <hbathini@linux.ibm.com>
>> CC: Madhavan Srinivasan <maddy@linux.ibm.com>
>> Cc: Michael Ellerman <mpe@ellerman.id.au>
>> Cc: kexec@lists.infradead.org
>> Cc: linuxppc-dev@lists.ozlabs.org
>> Cc: linux-kernel@vger.kernel.org
>> Signed-off-by: Sourabh Jain <sourabhjain@linux.ibm.com>
>> ---
>> kernel/kexec_elf.c | 2 +-
>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/kernel/kexec_elf.c b/kernel/kexec_elf.c
>> index d3689632e8b9..3a5c25b2adc9 100644
>> --- a/kernel/kexec_elf.c
>> +++ b/kernel/kexec_elf.c
>> @@ -390,7 +390,7 @@ int kexec_elf_load(struct kimage *image, struct elfhdr *ehdr,
>> struct kexec_buf *kbuf,
>> unsigned long *lowest_load_addr)
>> {
>> - unsigned long lowest_addr = UINT_MAX;
>> + unsigned long lowest_addr = ULONG_MAX;
> Great catch.
>
> Acked-by: Baoquan He <bhe@redhat.com>
Thank you for the Ack! The upcoming two patch series, which aim to
enable generic crashkernel reservation, depends on this fix. One of them
is already posted for upstream review:
https://lore.kernel.org/all/20250108101458.406806-1-sourabhjain@linux.ibm.com/
I was wondering if you could guide us on how to get this fix pushed to
the mainline tree.
Thanks,
Sourabh Jain
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] kexec: Initialize ELF lowest address to ULONG_MAX
2025-01-09 4:12 ` Sourabh Jain
@ 2025-01-09 5:28 ` Andrew Morton
2025-01-09 5:32 ` Sourabh Jain
0 siblings, 1 reply; 6+ messages in thread
From: Andrew Morton @ 2025-01-09 5:28 UTC (permalink / raw)
To: Sourabh Jain
Cc: Baoquan he, ebiederm, Hari Bathini, Madhavan Srinivasan,
Michael Ellerman, kexec, linuxppc-dev, linux-kernel
On Thu, 9 Jan 2025 09:42:14 +0530 Sourabh Jain <sourabhjain@linux.ibm.com> wrote:
> Hello Baoquan and Eric,
>
>
> On 12/12/24 08:25, Baoquan he wrote:
> > On 12/10/24 at 02:43pm, Sourabh Jain wrote:
> >> kexec_elf_load() loads an ELF executable and sets the address of the
> >> lowest PT_LOAD section to the address held by the lowest_load_addr
> >> function argument.
> >>
> >> To determine the lowest PT_LOAD address, a local variable lowest_addr
> >> (type unsigned long) is initialized to UINT_MAX. After loading each
> >> PT_LOAD, its address is compared to lowest_addr. If a loaded PT_LOAD
> >> address is lower, lowest_addr is updated. However, setting lowest_addr
> >> to UINT_MAX won't work when the kernel image is loaded above 4G, as the
> >> returned lowest PT_LOAD address would be invalid. This is resolved by
> >> initializing lowest_addr to ULONG_MAX instead.
> >>
> >> This issue was discovered while implementing crashkernel high/low
> >> reservation on the PowerPC architecture.
> >>
> >> Fixes: a0458284f062 ("powerpc: Add support code for kexec_file_load()")
> >> Cc: Baoquan he <bhe@redhat.com>
> >> Cc: Hari Bathini <hbathini@linux.ibm.com>
> >> CC: Madhavan Srinivasan <maddy@linux.ibm.com>
> >> Cc: Michael Ellerman <mpe@ellerman.id.au>
> >> Cc: kexec@lists.infradead.org
> >> Cc: linuxppc-dev@lists.ozlabs.org
> >> Cc: linux-kernel@vger.kernel.org
> >> Signed-off-by: Sourabh Jain <sourabhjain@linux.ibm.com>
> >> ---
> >> kernel/kexec_elf.c | 2 +-
> >> 1 file changed, 1 insertion(+), 1 deletion(-)
> >>
> >> diff --git a/kernel/kexec_elf.c b/kernel/kexec_elf.c
> >> index d3689632e8b9..3a5c25b2adc9 100644
> >> --- a/kernel/kexec_elf.c
> >> +++ b/kernel/kexec_elf.c
> >> @@ -390,7 +390,7 @@ int kexec_elf_load(struct kimage *image, struct elfhdr *ehdr,
> >> struct kexec_buf *kbuf,
> >> unsigned long *lowest_load_addr)
> >> {
> >> - unsigned long lowest_addr = UINT_MAX;
> >> + unsigned long lowest_addr = ULONG_MAX;
> > Great catch.
> >
> > Acked-by: Baoquan He <bhe@redhat.com>
> Thank you for the Ack! The upcoming two patch series, which aim to
> enable generic crashkernel reservation, depends on this fix. One of them
> is already posted for upstream review:
> https://lore.kernel.org/all/20250108101458.406806-1-sourabhjain@linux.ibm.com/
> I was wondering if you could guide us on how to get this fix pushed to
> the mainline tree.
Please include this patch (with Baoquan's ack) in whichever tree
contains the powerpc patches which depend upon it.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] kexec: Initialize ELF lowest address to ULONG_MAX
2025-01-09 5:28 ` Andrew Morton
@ 2025-01-09 5:32 ` Sourabh Jain
0 siblings, 0 replies; 6+ messages in thread
From: Sourabh Jain @ 2025-01-09 5:32 UTC (permalink / raw)
To: Andrew Morton
Cc: Baoquan he, ebiederm, Hari Bathini, Madhavan Srinivasan,
Michael Ellerman, kexec, linuxppc-dev, linux-kernel
Hello Andrew,
On 09/01/25 10:58, Andrew Morton wrote:
> On Thu, 9 Jan 2025 09:42:14 +0530 Sourabh Jain <sourabhjain@linux.ibm.com> wrote:
>
>> Hello Baoquan and Eric,
>>
>>
>> On 12/12/24 08:25, Baoquan he wrote:
>>> On 12/10/24 at 02:43pm, Sourabh Jain wrote:
>>>> kexec_elf_load() loads an ELF executable and sets the address of the
>>>> lowest PT_LOAD section to the address held by the lowest_load_addr
>>>> function argument.
>>>>
>>>> To determine the lowest PT_LOAD address, a local variable lowest_addr
>>>> (type unsigned long) is initialized to UINT_MAX. After loading each
>>>> PT_LOAD, its address is compared to lowest_addr. If a loaded PT_LOAD
>>>> address is lower, lowest_addr is updated. However, setting lowest_addr
>>>> to UINT_MAX won't work when the kernel image is loaded above 4G, as the
>>>> returned lowest PT_LOAD address would be invalid. This is resolved by
>>>> initializing lowest_addr to ULONG_MAX instead.
>>>>
>>>> This issue was discovered while implementing crashkernel high/low
>>>> reservation on the PowerPC architecture.
>>>>
>>>> Fixes: a0458284f062 ("powerpc: Add support code for kexec_file_load()")
>>>> Cc: Baoquan he <bhe@redhat.com>
>>>> Cc: Hari Bathini <hbathini@linux.ibm.com>
>>>> CC: Madhavan Srinivasan <maddy@linux.ibm.com>
>>>> Cc: Michael Ellerman <mpe@ellerman.id.au>
>>>> Cc: kexec@lists.infradead.org
>>>> Cc: linuxppc-dev@lists.ozlabs.org
>>>> Cc: linux-kernel@vger.kernel.org
>>>> Signed-off-by: Sourabh Jain <sourabhjain@linux.ibm.com>
>>>> ---
>>>> kernel/kexec_elf.c | 2 +-
>>>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>>>
>>>> diff --git a/kernel/kexec_elf.c b/kernel/kexec_elf.c
>>>> index d3689632e8b9..3a5c25b2adc9 100644
>>>> --- a/kernel/kexec_elf.c
>>>> +++ b/kernel/kexec_elf.c
>>>> @@ -390,7 +390,7 @@ int kexec_elf_load(struct kimage *image, struct elfhdr *ehdr,
>>>> struct kexec_buf *kbuf,
>>>> unsigned long *lowest_load_addr)
>>>> {
>>>> - unsigned long lowest_addr = UINT_MAX;
>>>> + unsigned long lowest_addr = ULONG_MAX;
>>> Great catch.
>>>
>>> Acked-by: Baoquan He <bhe@redhat.com>
>> Thank you for the Ack! The upcoming two patch series, which aim to
>> enable generic crashkernel reservation, depends on this fix. One of them
>> is already posted for upstream review:
>> https://lore.kernel.org/all/20250108101458.406806-1-sourabhjain@linux.ibm.com/
>> I was wondering if you could guide us on how to get this fix pushed to
>> the mainline tree.
> Please include this patch (with Baoquan's ack) in whichever tree
> contains the powerpc patches which depend upon it.
Sure, I will include this patch in the respective patch series.
Thanks,
Sourabh Jain
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2025-01-09 5:32 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-12-10 9:13 [PATCH] kexec: Initialize ELF lowest address to ULONG_MAX Sourabh Jain
2024-12-12 2:55 ` Baoquan he
2024-12-12 2:58 ` Sourabh Jain
2025-01-09 4:12 ` Sourabh Jain
2025-01-09 5:28 ` Andrew Morton
2025-01-09 5:32 ` Sourabh Jain
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).