linux-hardening.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] fortify: Update compile-time tests for Clang 14
@ 2022-01-30 18:16 Kees Cook
  2022-01-30 19:55 ` Nathan Chancellor
  2022-01-31 19:09 ` Nick Desaulniers
  0 siblings, 2 replies; 5+ messages in thread
From: Kees Cook @ 2022-01-30 18:16 UTC (permalink / raw)
  To: Kees Cook
  Cc: Nathan Chancellor, Nick Desaulniers, linux-hardening, llvm, linux-kernel

Clang 14 introduces support for compiletime_assert(). Update the
compile-time warning regex to catch Clang's variant of the warning text
in preparation for Clang supporting CONFIG_FORTIFY_SOURCE.

Cc: Nathan Chancellor <nathan@kernel.org>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: linux-hardening@vger.kernel.org
Cc: llvm@lists.linux.dev
Signed-off-by: Kees Cook <keescook@chromium.org>
---
I'm splitting this patch out of the main Clang FORTIFY enabling patch.
---
 scripts/test_fortify.sh | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/scripts/test_fortify.sh b/scripts/test_fortify.sh
index a4da365508f0..c2688ab8281d 100644
--- a/scripts/test_fortify.sh
+++ b/scripts/test_fortify.sh
@@ -46,8 +46,12 @@ if "$@" -Werror -c "$IN" -o "$OUT".o 2> "$TMP" ; then
 		status="warning: unsafe ${FUNC}() usage lacked '$WANT' symbol in $IN"
 	fi
 else
-	# If the build failed, check for the warning in the stderr (gcc).
-	if ! grep -q -m1 "error: call to .\b${WANT}\b." "$TMP" ; then
+	# If the build failed, check for the warning in the stderr.
+	# GCC:
+	# ./include/linux/fortify-string.h:316:25: error: call to '__write_overflow_field' declared with attribute warning: detected write beyond size of field (1st parameter); maybe use struct_group()? [-Werror=attribute-warning]
+	# Clang 14:
+	# ./include/linux/fortify-string.h:316:4: error: call to __write_overflow_field declared with 'warning' attribute: detected write beyond size of field (1st parameter); maybe use struct_group()? [-Werror,-Wattribute-warning]
+	if ! grep -Eq -m1 "error: call to .?\b${WANT}\b.?" "$TMP" ; then
 		status="warning: unsafe ${FUNC}() usage lacked '$WANT' warning in $IN"
 	fi
 fi
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] fortify: Update compile-time tests for Clang 14
  2022-01-30 18:16 [PATCH] fortify: Update compile-time tests for Clang 14 Kees Cook
@ 2022-01-30 19:55 ` Nathan Chancellor
  2022-01-31 19:09 ` Nick Desaulniers
  1 sibling, 0 replies; 5+ messages in thread
From: Nathan Chancellor @ 2022-01-30 19:55 UTC (permalink / raw)
  To: Kees Cook; +Cc: Nick Desaulniers, linux-hardening, llvm, linux-kernel

On Sun, Jan 30, 2022 at 10:16:16AM -0800, Kees Cook wrote:
> Clang 14 introduces support for compiletime_assert(). Update the
> compile-time warning regex to catch Clang's variant of the warning text
> in preparation for Clang supporting CONFIG_FORTIFY_SOURCE.
> 
> Cc: Nathan Chancellor <nathan@kernel.org>
> Cc: Nick Desaulniers <ndesaulniers@google.com>
> Cc: linux-hardening@vger.kernel.org
> Cc: llvm@lists.linux.dev
> Signed-off-by: Kees Cook <keescook@chromium.org>

Reviewed-by: Nathan Chancellor <nathan@kernel.org>

> ---
> I'm splitting this patch out of the main Clang FORTIFY enabling patch.
> ---
>  scripts/test_fortify.sh | 8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
> 
> diff --git a/scripts/test_fortify.sh b/scripts/test_fortify.sh
> index a4da365508f0..c2688ab8281d 100644
> --- a/scripts/test_fortify.sh
> +++ b/scripts/test_fortify.sh
> @@ -46,8 +46,12 @@ if "$@" -Werror -c "$IN" -o "$OUT".o 2> "$TMP" ; then
>  		status="warning: unsafe ${FUNC}() usage lacked '$WANT' symbol in $IN"
>  	fi
>  else
> -	# If the build failed, check for the warning in the stderr (gcc).
> -	if ! grep -q -m1 "error: call to .\b${WANT}\b." "$TMP" ; then
> +	# If the build failed, check for the warning in the stderr.
> +	# GCC:
> +	# ./include/linux/fortify-string.h:316:25: error: call to '__write_overflow_field' declared with attribute warning: detected write beyond size of field (1st parameter); maybe use struct_group()? [-Werror=attribute-warning]
> +	# Clang 14:
> +	# ./include/linux/fortify-string.h:316:4: error: call to __write_overflow_field declared with 'warning' attribute: detected write beyond size of field (1st parameter); maybe use struct_group()? [-Werror,-Wattribute-warning]
> +	if ! grep -Eq -m1 "error: call to .?\b${WANT}\b.?" "$TMP" ; then
>  		status="warning: unsafe ${FUNC}() usage lacked '$WANT' warning in $IN"
>  	fi
>  fi
> -- 
> 2.30.2
> 

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] fortify: Update compile-time tests for Clang 14
  2022-01-30 18:16 [PATCH] fortify: Update compile-time tests for Clang 14 Kees Cook
  2022-01-30 19:55 ` Nathan Chancellor
@ 2022-01-31 19:09 ` Nick Desaulniers
  2022-01-31 21:09   ` Kees Cook
  1 sibling, 1 reply; 5+ messages in thread
From: Nick Desaulniers @ 2022-01-31 19:09 UTC (permalink / raw)
  To: Kees Cook; +Cc: Nathan Chancellor, linux-hardening, llvm, linux-kernel

On Sun, Jan 30, 2022 at 10:16 AM Kees Cook <keescook@chromium.org> wrote:
>
> Clang 14 introduces support for compiletime_assert(). Update the
> compile-time warning regex to catch Clang's variant of the warning text
> in preparation for Clang supporting CONFIG_FORTIFY_SOURCE.

https://twitter.com/ifosteve/status/1190348262500421634?lang=en
error messages can change over time. More thoughts below.

>
> Cc: Nathan Chancellor <nathan@kernel.org>
> Cc: Nick Desaulniers <ndesaulniers@google.com>
> Cc: linux-hardening@vger.kernel.org
> Cc: llvm@lists.linux.dev
> Signed-off-by: Kees Cook <keescook@chromium.org>
> ---
> I'm splitting this patch out of the main Clang FORTIFY enabling patch.
> ---
>  scripts/test_fortify.sh | 8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/scripts/test_fortify.sh b/scripts/test_fortify.sh
> index a4da365508f0..c2688ab8281d 100644
> --- a/scripts/test_fortify.sh
> +++ b/scripts/test_fortify.sh
> @@ -46,8 +46,12 @@ if "$@" -Werror -c "$IN" -o "$OUT".o 2> "$TMP" ; then
>                 status="warning: unsafe ${FUNC}() usage lacked '$WANT' symbol in $IN"
>         fi
>  else
> -       # If the build failed, check for the warning in the stderr (gcc).
> -       if ! grep -q -m1 "error: call to .\b${WANT}\b." "$TMP" ; then
> +       # If the build failed, check for the warning in the stderr.
> +       # GCC:
> +       # ./include/linux/fortify-string.h:316:25: error: call to '__write_overflow_field' declared with attribute warning: detected write beyond size of field (1st parameter); maybe use struct_group()? [-Werror=attribute-warning]
> +       # Clang 14:
> +       # ./include/linux/fortify-string.h:316:4: error: call to __write_overflow_field declared with 'warning' attribute: detected write beyond size of field (1st parameter); maybe use struct_group()? [-Werror,-Wattribute-warning]
> +       if ! grep -Eq -m1 "error: call to .?\b${WANT}\b.?" "$TMP" ; then

Doesn't this depend on -Werror being set? I guess it did so before
hand, too, but couldn't I unset CONFIG_WERROR then this check would
still fail (since instead of `error:` we'd have `warning:`)? If we
used __attribute__((error(""))) then this would always be an error.
Right now, it is only because -Werror is set promoting the warning
diagnostic to an error.

>                 status="warning: unsafe ${FUNC}() usage lacked '$WANT' warning in $IN"
>         fi
>  fi
> --
> 2.30.2
>


-- 
Thanks,
~Nick Desaulniers

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] fortify: Update compile-time tests for Clang 14
  2022-01-31 19:09 ` Nick Desaulniers
@ 2022-01-31 21:09   ` Kees Cook
  2022-01-31 21:34     ` Nick Desaulniers
  0 siblings, 1 reply; 5+ messages in thread
From: Kees Cook @ 2022-01-31 21:09 UTC (permalink / raw)
  To: Nick Desaulniers; +Cc: Nathan Chancellor, linux-hardening, llvm, linux-kernel

On Mon, Jan 31, 2022 at 11:09:27AM -0800, Nick Desaulniers wrote:
> On Sun, Jan 30, 2022 at 10:16 AM Kees Cook <keescook@chromium.org> wrote:
> >
> > Clang 14 introduces support for compiletime_assert(). Update the
> > compile-time warning regex to catch Clang's variant of the warning text
> > in preparation for Clang supporting CONFIG_FORTIFY_SOURCE.
> 
> https://twitter.com/ifosteve/status/1190348262500421634?lang=en
> error messages can change over time. More thoughts below.

Sure, but I don't want the compile-time checks to silently regress,
which requires looking specifically for the error.

> > Cc: Nathan Chancellor <nathan@kernel.org>
> > Cc: Nick Desaulniers <ndesaulniers@google.com>
> > Cc: linux-hardening@vger.kernel.org
> > Cc: llvm@lists.linux.dev
> > Signed-off-by: Kees Cook <keescook@chromium.org>
> > ---
> > I'm splitting this patch out of the main Clang FORTIFY enabling patch.
> > ---
> >  scripts/test_fortify.sh | 8 ++++++--
> >  1 file changed, 6 insertions(+), 2 deletions(-)
> >
> > diff --git a/scripts/test_fortify.sh b/scripts/test_fortify.sh
> > index a4da365508f0..c2688ab8281d 100644
> > --- a/scripts/test_fortify.sh
> > +++ b/scripts/test_fortify.sh
> > @@ -46,8 +46,12 @@ if "$@" -Werror -c "$IN" -o "$OUT".o 2> "$TMP" ; then
> >                 status="warning: unsafe ${FUNC}() usage lacked '$WANT' symbol in $IN"
> >         fi
> >  else
> > -       # If the build failed, check for the warning in the stderr (gcc).
> > -       if ! grep -q -m1 "error: call to .\b${WANT}\b." "$TMP" ; then
> > +       # If the build failed, check for the warning in the stderr.
> > +       # GCC:
> > +       # ./include/linux/fortify-string.h:316:25: error: call to '__write_overflow_field' declared with attribute warning: detected write beyond size of field (1st parameter); maybe use struct_group()? [-Werror=attribute-warning]
> > +       # Clang 14:
> > +       # ./include/linux/fortify-string.h:316:4: error: call to __write_overflow_field declared with 'warning' attribute: detected write beyond size of field (1st parameter); maybe use struct_group()? [-Werror,-Wattribute-warning]
> > +       if ! grep -Eq -m1 "error: call to .?\b${WANT}\b.?" "$TMP" ; then
> 
> Doesn't this depend on -Werror being set? I guess it did so before
> hand, too, but couldn't I unset CONFIG_WERROR then this check would
> still fail (since instead of `error:` we'd have `warning:`)? If we
> used __attribute__((error(""))) then this would always be an error.
> Right now, it is only because -Werror is set promoting the warning
> diagnostic to an error.

Right, see earlier up in the script. "-Werror" is explicitly set:

line 40: if "$@" -Werror -c "$IN" -o "$OUT".o 2> "$TMP" ; then

-- 
Kees Cook

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] fortify: Update compile-time tests for Clang 14
  2022-01-31 21:09   ` Kees Cook
@ 2022-01-31 21:34     ` Nick Desaulniers
  0 siblings, 0 replies; 5+ messages in thread
From: Nick Desaulniers @ 2022-01-31 21:34 UTC (permalink / raw)
  To: Kees Cook; +Cc: Nathan Chancellor, linux-hardening, llvm, linux-kernel

On Mon, Jan 31, 2022 at 1:09 PM Kees Cook <keescook@chromium.org> wrote:
>
> On Mon, Jan 31, 2022 at 11:09:27AM -0800, Nick Desaulniers wrote:
> > On Sun, Jan 30, 2022 at 10:16 AM Kees Cook <keescook@chromium.org> wrote:
> > >
> > > Clang 14 introduces support for compiletime_assert(). Update the
> > > compile-time warning regex to catch Clang's variant of the warning text
> > > in preparation for Clang supporting CONFIG_FORTIFY_SOURCE.
> >
> > https://twitter.com/ifosteve/status/1190348262500421634?lang=en
> > error messages can change over time. More thoughts below.
>
> Sure, but I don't want the compile-time checks to silently regress,
> which requires looking specifically for the error.
>
> > > Cc: Nathan Chancellor <nathan@kernel.org>
> > > Cc: Nick Desaulniers <ndesaulniers@google.com>
> > > Cc: linux-hardening@vger.kernel.org
> > > Cc: llvm@lists.linux.dev
> > > Signed-off-by: Kees Cook <keescook@chromium.org>
> > > ---
> > > I'm splitting this patch out of the main Clang FORTIFY enabling patch.
> > > ---
> > >  scripts/test_fortify.sh | 8 ++++++--
> > >  1 file changed, 6 insertions(+), 2 deletions(-)
> > >
> > > diff --git a/scripts/test_fortify.sh b/scripts/test_fortify.sh
> > > index a4da365508f0..c2688ab8281d 100644
> > > --- a/scripts/test_fortify.sh
> > > +++ b/scripts/test_fortify.sh
> > > @@ -46,8 +46,12 @@ if "$@" -Werror -c "$IN" -o "$OUT".o 2> "$TMP" ; then
> > >                 status="warning: unsafe ${FUNC}() usage lacked '$WANT' symbol in $IN"
> > >         fi
> > >  else
> > > -       # If the build failed, check for the warning in the stderr (gcc).
> > > -       if ! grep -q -m1 "error: call to .\b${WANT}\b." "$TMP" ; then
> > > +       # If the build failed, check for the warning in the stderr.
> > > +       # GCC:
> > > +       # ./include/linux/fortify-string.h:316:25: error: call to '__write_overflow_field' declared with attribute warning: detected write beyond size of field (1st parameter); maybe use struct_group()? [-Werror=attribute-warning]
> > > +       # Clang 14:
> > > +       # ./include/linux/fortify-string.h:316:4: error: call to __write_overflow_field declared with 'warning' attribute: detected write beyond size of field (1st parameter); maybe use struct_group()? [-Werror,-Wattribute-warning]
> > > +       if ! grep -Eq -m1 "error: call to .?\b${WANT}\b.?" "$TMP" ; then
> >
> > Doesn't this depend on -Werror being set? I guess it did so before
> > hand, too, but couldn't I unset CONFIG_WERROR then this check would
> > still fail (since instead of `error:` we'd have `warning:`)? If we
> > used __attribute__((error(""))) then this would always be an error.
> > Right now, it is only because -Werror is set promoting the warning
> > diagnostic to an error.
>
> Right, see earlier up in the script. "-Werror" is explicitly set:
>
> line 40: if "$@" -Werror -c "$IN" -o "$OUT".o 2> "$TMP" ; then

Yep, I missed that.
Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>

>
> --
> Kees Cook



-- 
Thanks,
~Nick Desaulniers

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-01-31 21:34 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-30 18:16 [PATCH] fortify: Update compile-time tests for Clang 14 Kees Cook
2022-01-30 19:55 ` Nathan Chancellor
2022-01-31 19:09 ` Nick Desaulniers
2022-01-31 21:09   ` Kees Cook
2022-01-31 21:34     ` Nick Desaulniers

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).