* [PATCH] x86/boot/compressed/64: Fix 'may be used uninitialized' issue
@ 2019-09-02 9:30 Zhenzhong Duan
2019-09-02 9:35 ` Borislav Petkov
0 siblings, 1 reply; 3+ messages in thread
From: Zhenzhong Duan @ 2019-09-02 9:30 UTC (permalink / raw)
To: linux-kernel
Cc: Zhenzhong Duan, Kirill A. Shutemov, Thomas Gleixner, Ingo Molnar,
Borislav Petkov, H. Peter Anvin, x86-ml
Builds kernel with "make bzImage EXTRA_CFLAGS=-Wall", gcc complains:
arch/x86/boot/compressed/pgtable_64.c: In function 'paging_prepare':
arch/x86/boot/compressed/pgtable_64.c:92:7: warning: 'new' may be used uninitialized in this function [-Wmaybe-uninitialized]
new = round_down(new, PAGE_SIZE);
In theory a random value of variable new may pass all the check and be
assigned to bios_start, fixing it by assigning it an initial value.
Fixes: 0a46fff2f910 ("x86/boot/compressed/64: Fix boot on machines with broken E820 table")
Signed-off-by: Zhenzhong Duan <zhenzhong.duan@oracle.com>
Cc: Kirill A. Shutemov <kirill@shutemov.name>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Borislav Petkov <bp@alien8.de>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: x86-ml <x86@kernel.org>
---
arch/x86/boot/compressed/pgtable_64.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/x86/boot/compressed/pgtable_64.c b/arch/x86/boot/compressed/pgtable_64.c
index 2faddeb..c886269 100644
--- a/arch/x86/boot/compressed/pgtable_64.c
+++ b/arch/x86/boot/compressed/pgtable_64.c
@@ -72,7 +72,7 @@ static unsigned long find_trampoline_placement(void)
/* Find the first usable memory region under bios_start. */
for (i = boot_params->e820_entries - 1; i >= 0; i--) {
- unsigned long new;
+ unsigned long new = bios_start;
entry = &boot_params->e820_table[i];
--
1.8.3.1
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] x86/boot/compressed/64: Fix 'may be used uninitialized' issue
2019-09-02 9:30 [PATCH] x86/boot/compressed/64: Fix 'may be used uninitialized' issue Zhenzhong Duan
@ 2019-09-02 9:35 ` Borislav Petkov
2019-09-02 9:40 ` Zhenzhong Duan
0 siblings, 1 reply; 3+ messages in thread
From: Borislav Petkov @ 2019-09-02 9:35 UTC (permalink / raw)
To: Zhenzhong Duan
Cc: linux-kernel, Kirill A. Shutemov, Thomas Gleixner, Ingo Molnar,
H. Peter Anvin, x86-ml
On Mon, Sep 02, 2019 at 05:30:24PM +0800, Zhenzhong Duan wrote:
> Builds kernel with "make bzImage EXTRA_CFLAGS=-Wall", gcc complains:
>
> arch/x86/boot/compressed/pgtable_64.c: In function 'paging_prepare':
> arch/x86/boot/compressed/pgtable_64.c:92:7: warning: 'new' may be used uninitialized in this function [-Wmaybe-uninitialized]
> new = round_down(new, PAGE_SIZE);
>
> In theory a random value of variable new may pass all the check and be
> assigned to bios_start, fixing it by assigning it an initial value.
>
> Fixes: 0a46fff2f910 ("x86/boot/compressed/64: Fix boot on machines with broken E820 table")
> Signed-off-by: Zhenzhong Duan <zhenzhong.duan@oracle.com>
> Cc: Kirill A. Shutemov <kirill@shutemov.name>
> Cc: Thomas Gleixner <tglx@linutronix.de>
> Cc: Ingo Molnar <mingo@redhat.com>
> Cc: Borislav Petkov <bp@alien8.de>
> Cc: "H. Peter Anvin" <hpa@zytor.com>
> Cc: x86-ml <x86@kernel.org>
> ---
> arch/x86/boot/compressed/pgtable_64.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/arch/x86/boot/compressed/pgtable_64.c b/arch/x86/boot/compressed/pgtable_64.c
> index 2faddeb..c886269 100644
> --- a/arch/x86/boot/compressed/pgtable_64.c
> +++ b/arch/x86/boot/compressed/pgtable_64.c
> @@ -72,7 +72,7 @@ static unsigned long find_trampoline_placement(void)
>
> /* Find the first usable memory region under bios_start. */
> for (i = boot_params->e820_entries - 1; i >= 0; i--) {
> - unsigned long new;
> + unsigned long new = bios_start;
>
> entry = &boot_params->e820_table[i];
>
> --
https://git.kernel.org/tip/c96e8483cb2da6695c8b8d0896fe7ae272a07b54
In the future, use tip/master when preparing fixes because it has the
latest state of the x86 tree and you won't have to duplicate effort,
like in this case.
Thx.
--
Regards/Gruss,
Boris.
Good mailing practices for 400: avoid top-posting and trim the reply.
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] x86/boot/compressed/64: Fix 'may be used uninitialized' issue
2019-09-02 9:35 ` Borislav Petkov
@ 2019-09-02 9:40 ` Zhenzhong Duan
0 siblings, 0 replies; 3+ messages in thread
From: Zhenzhong Duan @ 2019-09-02 9:40 UTC (permalink / raw)
To: Borislav Petkov
Cc: linux-kernel, Kirill A. Shutemov, Thomas Gleixner, Ingo Molnar,
H. Peter Anvin, x86-ml
On 2019/9/2 17:35, Borislav Petkov wrote:
> On Mon, Sep 02, 2019 at 05:30:24PM +0800, Zhenzhong Duan wrote:
>> Builds kernel with "make bzImage EXTRA_CFLAGS=-Wall", gcc complains:
>>
>> arch/x86/boot/compressed/pgtable_64.c: In function 'paging_prepare':
>> arch/x86/boot/compressed/pgtable_64.c:92:7: warning: 'new' may be used uninitialized in this function [-Wmaybe-uninitialized]
>> new = round_down(new, PAGE_SIZE);
>>
>> In theory a random value of variable new may pass all the check and be
>> assigned to bios_start, fixing it by assigning it an initial value.
>>
>> Fixes: 0a46fff2f910 ("x86/boot/compressed/64: Fix boot on machines with broken E820 table")
>> Signed-off-by: Zhenzhong Duan<zhenzhong.duan@oracle.com>
>> Cc: Kirill A. Shutemov<kirill@shutemov.name>
>> Cc: Thomas Gleixner<tglx@linutronix.de>
>> Cc: Ingo Molnar<mingo@redhat.com>
>> Cc: Borislav Petkov<bp@alien8.de>
>> Cc: "H. Peter Anvin"<hpa@zytor.com>
>> Cc: x86-ml<x86@kernel.org>
>> ---
>> arch/x86/boot/compressed/pgtable_64.c | 2 +-
>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/arch/x86/boot/compressed/pgtable_64.c b/arch/x86/boot/compressed/pgtable_64.c
>> index 2faddeb..c886269 100644
>> --- a/arch/x86/boot/compressed/pgtable_64.c
>> +++ b/arch/x86/boot/compressed/pgtable_64.c
>> @@ -72,7 +72,7 @@ static unsigned long find_trampoline_placement(void)
>>
>> /* Find the first usable memory region under bios_start. */
>> for (i = boot_params->e820_entries - 1; i >= 0; i--) {
>> - unsigned long new;
>> + unsigned long new = bios_start;
>>
>> entry = &boot_params->e820_table[i];
>>
>> --
> https://git.kernel.org/tip/c96e8483cb2da6695c8b8d0896fe7ae272a07b54
>
> In the future, use tip/master when preparing fixes because it has the
> latest state of the x86 tree and you won't have to duplicate effort,
> like in this case.
Ok, I see. Thanks for your suggestion.
Zhenzhong
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2019-09-02 9:41 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-02 9:30 [PATCH] x86/boot/compressed/64: Fix 'may be used uninitialized' issue Zhenzhong Duan
2019-09-02 9:35 ` Borislav Petkov
2019-09-02 9:40 ` Zhenzhong Duan
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®