mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Baoquan He <bhe@redhat.com>
To: Daniil Dulov <d.dulov@aladdin.ru>
Cc: Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
	x86@kernel.org, "H. Peter Anvin" <hpa@zytor.com>,
	Kees Cook <keescook@chromium.org>,
	linux-kernel@vger.kernel.org, lvc-project@linuxtesting.org
Subject: Re: [PATCH] x86/kaslr: Fix potential dereference of NULL pointer.
Date: Tue, 18 Apr 2023 15:43:33 +0800	[thread overview]
Message-ID: <ZD5KJWk+QFIKF8/s@bhe.users.ipa.redhat.com> (raw)
In-Reply-To: <20230418065308.452462-1-d.dulov@aladdin.ru>

On 04/17/23 at 11:53pm, Daniil Dulov wrote:
> Pointer val can have NULL value. Then its value is assigned to the pointer p.
> p is dereferenced by calling strcmp().
> 
> Found by Linux Verification Center (linuxtesting.org) with SVACE.

It's true for strcmp from lib/string.c, while may not be so true for
strcmp in arch/x86/boot/string.c which I copy at below for reference.
Here, boot/compressed/kaslr.c is using the strcmp in
arch/x86/boot/string.c. So leaving it as is or fixing it, either looks
good to me, I even prefer the former.

int strcmp(const char *str1, const char *str2)
{
        const unsigned char *s1 = (const unsigned char *)str1;
        const unsigned char *s2 = (const unsigned char *)str2;
        int delta = 0;

        while (*s1 || *s2) {
                delta = *s1 - *s2;
                if (delta)
                        return delta;
                s1++;
                s2++;
        }
        return 0;
}

> 
> Fixes: 4cdba14f84c9 ("x86/KASLR: Handle the memory limit specified by the 'memmap=' and 'mem=' boot options")
> Signed-off-by: Daniil Dulov <d.dulov@aladdin.ru>
> ---
>  arch/x86/boot/compressed/kaslr.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/arch/x86/boot/compressed/kaslr.c b/arch/x86/boot/compressed/kaslr.c
> index b92fffbe761f..51b3925d4d2d 100644
> --- a/arch/x86/boot/compressed/kaslr.c
> +++ b/arch/x86/boot/compressed/kaslr.c
> @@ -291,7 +291,7 @@ static void handle_mem_options(void)
>  		} else if (!strcmp(param, "mem")) {
>  			char *p = val;
>  
> -			if (!strcmp(p, "nopentium"))
> +			if (!p || !strcmp(p, "nopentium"))
>  				continue;
>  			mem_size = memparse(p, &p);
>  			if (mem_size == 0)
> -- 
> 2.25.1
> 


      reply	other threads:[~2023-04-18  7:44 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-18  6:53 Daniil Dulov
2023-04-18  7:43 ` Baoquan He [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZD5KJWk+QFIKF8/s@bhe.users.ipa.redhat.com \
    --to=bhe@redhat.com \
    --cc=bp@alien8.de \
    --cc=d.dulov@aladdin.ru \
    --cc=hpa@zytor.com \
    --cc=keescook@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lvc-project@linuxtesting.org \
    --cc=mingo@redhat.com \
    --cc=tglx@linutronix.de \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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®