lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAKwvOdkzNaJhM9PGBY_Ae+B34F2H_4aGjD+kBEC_5ZcQUuDm2g@mail.gmail.com>
Date:   Tue, 24 May 2022 13:42:06 -0700
From:   Nick Desaulniers <ndesaulniers@...gle.com>
To:     Masahiro Yamada <masahiroy@...nel.org>
Cc:     linux-kbuild@...r.kernel.org, linux-kernel@...r.kernel.org,
        Michal Marek <michal.lkml@...kovi.net>
Subject: Re: [PATCH 1/5] modpost: fix undefined behavior of is_arm_mapping_symbol()

On Mon, May 23, 2022 at 9:48 AM Masahiro Yamada <masahiroy@...nel.org> wrote:
>
> The return value of is_arm_mapping_symbol() is unpredictable when
> "$" is passed in.
>
> strchr(3) says:
>   The strchr() and strrchr() functions return a pointer to the matched
>   character or NULL if the character is not found. The terminating null
>   byte is considered part of the string, so that if c is specified as
>   '\0', these functions return a pointer to the terminator.
>
> When str[1] is '\0', strchr("axtd", str[1]) is not NULL, and str[2] is
> referenced (i.e. buffer overrun).
>
> Test code
> ---------
>
>   char str1[] = "abc";
>   char str2[] = "ab";
>
>   strcpy(str1, "$");
>   strcpy(str2, "$");
>
>   printf("test1: %d\n", is_arm_mapping_symbol(str1));
>   printf("test2: %d\n", is_arm_mapping_symbol(str2));
>
> Result
> ------
>
>   test1: 0
>   test2: 1
>
> Signed-off-by: Masahiro Yamada <masahiroy@...nel.org>

I guess this is shorter than a call to strlen then conditional call to strchr.
Reviewed-by: Nick Desaulniers <ndesaulniers@...gle.com>

> ---
>
>  scripts/mod/modpost.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
> index 6f5c605ab0fb..845bc438ca49 100644
> --- a/scripts/mod/modpost.c
> +++ b/scripts/mod/modpost.c
> @@ -1179,7 +1179,8 @@ static int secref_whitelist(const struct sectioncheck *mismatch,
>
>  static inline int is_arm_mapping_symbol(const char *str)
>  {
> -       return str[0] == '$' && strchr("axtd", str[1])
> +       return str[0] == '$' &&
> +              (str[1] == 'a' || str[1] == 'd' || str[1] == 't' || str[1] == 'x')
>                && (str[2] == '\0' || str[2] == '.');
>  }
>
> --
> 2.32.0
>


-- 
Thanks,
~Nick Desaulniers

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ