diff mbox

kconfig: loop boundary condition fix

Message ID 20180623204904.11378-1-alexpl@fedoraproject.org (mailing list archive)
State New, archived
Headers show

Commit Message

Alexander Ploumistos June 23, 2018, 8:49 p.m. UTC
From: Jerry James <loganjerry@gmail.com>

If buf[-1] just happens to hold the byte 0x0A, then nread can wrap around
to (size_t)-1, leading to invalid memory accesses.

This has caused segmentation faults when trying to build the latest
kernel snapshots for i686 in Fedora:
https://bugzilla.redhat.com/show_bug.cgi?id=1592374

Signed-off-by: Jerry James <loganjerry@gmail.com>
[alexpl@fedoraproject.org: reformatted patch for submission]
Signed-off-by: Alexander Ploumistos <alexpl@fedoraproject.org>
---
 scripts/kconfig/preprocess.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Masahiro Yamada June 24, 2018, 9:03 a.m. UTC | #1
2018-06-24 5:49 GMT+09:00 Alexander Ploumistos <alexpl@fedoraproject.org>:
> From: Jerry James <loganjerry@gmail.com>
>
> If buf[-1] just happens to hold the byte 0x0A, then nread can wrap around
> to (size_t)-1, leading to invalid memory accesses.
>
> This has caused segmentation faults when trying to build the latest
> kernel snapshots for i686 in Fedora:
> https://bugzilla.redhat.com/show_bug.cgi?id=1592374
>
> Signed-off-by: Jerry James <loganjerry@gmail.com>
> [alexpl@fedoraproject.org: reformatted patch for submission]
> Signed-off-by: Alexander Ploumistos <alexpl@fedoraproject.org>
> ---

Applied to linux-kbuild/fixes.  Thanks!


>  scripts/kconfig/preprocess.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/scripts/kconfig/preprocess.c b/scripts/kconfig/preprocess.c
> index 65da87fce907..5ca2df790d3c 100644
> --- a/scripts/kconfig/preprocess.c
> +++ b/scripts/kconfig/preprocess.c
> @@ -156,7 +156,7 @@ static char *do_shell(int argc, char *argv[])
>                 nread--;
>
>         /* remove trailing new lines */
> -       while (buf[nread - 1] == '\n')
> +       while (nread > 0 && buf[nread - 1] == '\n')
>                 nread--;
>
>         buf[nread] = 0;
> --
> 2.17.1
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kbuild" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/scripts/kconfig/preprocess.c b/scripts/kconfig/preprocess.c
index 65da87fce907..5ca2df790d3c 100644
--- a/scripts/kconfig/preprocess.c
+++ b/scripts/kconfig/preprocess.c
@@ -156,7 +156,7 @@  static char *do_shell(int argc, char *argv[])
 		nread--;
 
 	/* remove trailing new lines */
-	while (buf[nread - 1] == '\n')
+	while (nread > 0 && buf[nread - 1] == '\n')
 		nread--;
 
 	buf[nread] = 0;