[PATCH 5.19 145/365] kbuild: dummy-tools: avoid tmpdir leak in dummy gcc

Greg Kroah-Hartman posted 365 patches 3 years, 3 months ago
[PATCH 5.19 145/365] kbuild: dummy-tools: avoid tmpdir leak in dummy gcc
Posted by Greg Kroah-Hartman 3 years, 3 months ago
From: Ondrej Mosnacek <omosnace@redhat.com>

commit aac289653fa5adf9e9985e4912c1d24a3e8cbab2 upstream.

When passed -print-file-name=plugin, the dummy gcc script creates a
temporary directory that is never cleaned up. To avoid cluttering
$TMPDIR, instead use a static directory included in the source tree.

Fixes: 76426e238834 ("kbuild: add dummy toolchains to enable all cc-option etc. in Kconfig")
Signed-off-by: Ondrej Mosnacek <omosnace@redhat.com>
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
 .../dummy-tools/dummy-plugin-dir/include/plugin-version.h | 0
 scripts/dummy-tools/gcc |    8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
 create mode 100644 scripts/dummy-tools/dummy-plugin-dir/include/plugin-version.h

--- a/scripts/dummy-tools/gcc
+++ b/scripts/dummy-tools/gcc
@@ -96,12 +96,8 @@ fi
 
 # To set GCC_PLUGINS
 if arg_contain -print-file-name=plugin "$@"; then
-	plugin_dir=$(mktemp -d)
-
-	mkdir -p $plugin_dir/include
-	touch $plugin_dir/include/plugin-version.h
-
-	echo $plugin_dir
+	# Use $0 to find the in-tree dummy directory
+	echo "$(dirname "$(readlink -f "$0")")/dummy-plugin-dir"
 	exit 0
 fi
Re: [PATCH 5.19 145/365] kbuild: dummy-tools: avoid tmpdir leak in dummy gcc
Posted by Jiri Slaby 3 years, 3 months ago
On 23. 08. 22, 10:00, Greg Kroah-Hartman wrote:
> From: Ondrej Mosnacek <omosnace@redhat.com>
> 
> commit aac289653fa5adf9e9985e4912c1d24a3e8cbab2 upstream.
> 
> When passed -print-file-name=plugin, the dummy gcc script creates a
> temporary directory that is never cleaned up. To avoid cluttering
> $TMPDIR, instead use a static directory included in the source tree.

This breaks our (SUSE) use of dummy tools (GCC_PLUGINS became =n). I 
will investigate whether this is stable-only and the root cause later.

> Fixes: 76426e238834 ("kbuild: add dummy toolchains to enable all cc-option etc. in Kconfig")
> Signed-off-by: Ondrej Mosnacek <omosnace@redhat.com>
> Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> ---
>   .../dummy-tools/dummy-plugin-dir/include/plugin-version.h | 0
>   scripts/dummy-tools/gcc |    8 ++------
>   1 file changed, 2 insertions(+), 6 deletions(-)
>   create mode 100644 scripts/dummy-tools/dummy-plugin-dir/include/plugin-version.h
> 
> --- a/scripts/dummy-tools/gcc
> +++ b/scripts/dummy-tools/gcc
> @@ -96,12 +96,8 @@ fi
>   
>   # To set GCC_PLUGINS
>   if arg_contain -print-file-name=plugin "$@"; then
> -	plugin_dir=$(mktemp -d)
> -
> -	mkdir -p $plugin_dir/include
> -	touch $plugin_dir/include/plugin-version.h
> -
> -	echo $plugin_dir
> +	# Use $0 to find the in-tree dummy directory
> +	echo "$(dirname "$(readlink -f "$0")")/dummy-plugin-dir"
>   	exit 0
>   fi
>   
> 
> 

-- 
js
suse labs
Re: [PATCH 5.19 145/365] kbuild: dummy-tools: avoid tmpdir leak in dummy gcc
Posted by Ondrej Mosnacek 3 years, 3 months ago
On Sat, Aug 27, 2022 at 9:51 AM Jiri Slaby <jirislaby@kernel.org> wrote:
> On 23. 08. 22, 10:00, Greg Kroah-Hartman wrote:
> > From: Ondrej Mosnacek <omosnace@redhat.com>
> >
> > commit aac289653fa5adf9e9985e4912c1d24a3e8cbab2 upstream.
> >
> > When passed -print-file-name=plugin, the dummy gcc script creates a
> > temporary directory that is never cleaned up. To avoid cluttering
> > $TMPDIR, instead use a static directory included in the source tree.
>
> This breaks our (SUSE) use of dummy tools (GCC_PLUGINS became =n). I
> will investigate whether this is stable-only and the root cause later.

It looks like both the Greg's generated patch and the final stable
commit (d7e676b7dc6a) are missing the addition of the empty
plugin-version.h file. It appears in the patch's diffstat, but not in
the actual diff. The mainline commit does include the empty file
correctly, so it's likely a bug in the stable cherry pick automation.

> > Fixes: 76426e238834 ("kbuild: add dummy toolchains to enable all cc-option etc. in Kconfig")
> > Signed-off-by: Ondrej Mosnacek <omosnace@redhat.com>
> > Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
> > Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> > ---
> >   .../dummy-tools/dummy-plugin-dir/include/plugin-version.h | 0
> >   scripts/dummy-tools/gcc |    8 ++------
> >   1 file changed, 2 insertions(+), 6 deletions(-)
> >   create mode 100644 scripts/dummy-tools/dummy-plugin-dir/include/plugin-version.h
> >
> > --- a/scripts/dummy-tools/gcc
> > +++ b/scripts/dummy-tools/gcc
> > @@ -96,12 +96,8 @@ fi
> >
> >   # To set GCC_PLUGINS
> >   if arg_contain -print-file-name=plugin "$@"; then
> > -     plugin_dir=$(mktemp -d)
> > -
> > -     mkdir -p $plugin_dir/include
> > -     touch $plugin_dir/include/plugin-version.h
> > -
> > -     echo $plugin_dir
> > +     # Use $0 to find the in-tree dummy directory
> > +     echo "$(dirname "$(readlink -f "$0")")/dummy-plugin-dir"
> >       exit 0
> >   fi
> >
> >
> >
>
> --
> js
> suse labs
>

-- 
Ondrej Mosnacek
Senior Software Engineer, Linux Security - SELinux kernel
Red Hat, Inc.
Re: [PATCH 5.19 145/365] kbuild: dummy-tools: avoid tmpdir leak in dummy gcc
Posted by Jiri Slaby 3 years, 3 months ago
On 27. 08. 22, 10:34, Ondrej Mosnacek wrote:
> On Sat, Aug 27, 2022 at 9:51 AM Jiri Slaby <jirislaby@kernel.org> wrote:
>> On 23. 08. 22, 10:00, Greg Kroah-Hartman wrote:
>>> From: Ondrej Mosnacek <omosnace@redhat.com>
>>>
>>> commit aac289653fa5adf9e9985e4912c1d24a3e8cbab2 upstream.
>>>
>>> When passed -print-file-name=plugin, the dummy gcc script creates a
>>> temporary directory that is never cleaned up. To avoid cluttering
>>> $TMPDIR, instead use a static directory included in the source tree.
>>
>> This breaks our (SUSE) use of dummy tools (GCC_PLUGINS became =n). I
>> will investigate whether this is stable-only and the root cause later.
> 
> It looks like both the Greg's generated patch and the final stable
> commit (d7e676b7dc6a) are missing the addition of the empty
> plugin-version.h file. It appears in the patch's diffstat, but not in
> the actual diff. The mainline commit does include the empty file
> correctly, so it's likely a bug in the stable cherry pick automation.

Right, this fixed the issue for me:
--- 
a/patches.kernel.org/5.19.4-144-kbuild-dummy-tools-avoid-tmpdir-leak-in-dummy-.patch
+++ 
b/patches.kernel.org/5.19.4-144-kbuild-dummy-tools-avoid-tmpdir-leak-in-dummy-.patch
@@ -20,6 +20,8 @@ Signed-off-by: Jiri Slaby <jslaby@suse.cz>
   scripts/dummy-tools/gcc | 8 ++------
   1 file changed, 2 insertions(+), 6 deletions(-)

+diff --git 
a/scripts/dummy-tools/dummy-plugin-dir/include/plugin-version.h 
b/scripts/dummy-tools/dummy-plugin-dir/include/plugin-version.h
+new file mode 100644
  diff --git a/scripts/dummy-tools/gcc b/scripts/dummy-tools/gcc
  index b2483149bbe5..7db825843435 100755
  --- a/scripts/dummy-tools/gcc

>>> Fixes: 76426e238834 ("kbuild: add dummy toolchains to enable all cc-option etc. in Kconfig")
>>> Signed-off-by: Ondrej Mosnacek <omosnace@redhat.com>
>>> Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
>>> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
>>> ---
>>>    .../dummy-tools/dummy-plugin-dir/include/plugin-version.h | 0
>>>    scripts/dummy-tools/gcc |    8 ++------
>>>    1 file changed, 2 insertions(+), 6 deletions(-)
>>>    create mode 100644 scripts/dummy-tools/dummy-plugin-dir/include/plugin-version.h
>>>
>>> --- a/scripts/dummy-tools/gcc
>>> +++ b/scripts/dummy-tools/gcc
>>> @@ -96,12 +96,8 @@ fi
>>>
>>>    # To set GCC_PLUGINS
>>>    if arg_contain -print-file-name=plugin "$@"; then
>>> -     plugin_dir=$(mktemp -d)
>>> -
>>> -     mkdir -p $plugin_dir/include
>>> -     touch $plugin_dir/include/plugin-version.h
>>> -
>>> -     echo $plugin_dir
>>> +     # Use $0 to find the in-tree dummy directory
>>> +     echo "$(dirname "$(readlink -f "$0")")/dummy-plugin-dir"
>>>        exit 0
>>>    fi

thanks,
-- 
js
suse labs
Re: [PATCH 5.19 145/365] kbuild: dummy-tools: avoid tmpdir leak in dummy gcc
Posted by Greg Kroah-Hartman 3 years, 3 months ago
On Mon, Aug 29, 2022 at 09:12:39AM +0200, Jiri Slaby wrote:
> On 27. 08. 22, 10:34, Ondrej Mosnacek wrote:
> > On Sat, Aug 27, 2022 at 9:51 AM Jiri Slaby <jirislaby@kernel.org> wrote:
> > > On 23. 08. 22, 10:00, Greg Kroah-Hartman wrote:
> > > > From: Ondrej Mosnacek <omosnace@redhat.com>
> > > > 
> > > > commit aac289653fa5adf9e9985e4912c1d24a3e8cbab2 upstream.
> > > > 
> > > > When passed -print-file-name=plugin, the dummy gcc script creates a
> > > > temporary directory that is never cleaned up. To avoid cluttering
> > > > $TMPDIR, instead use a static directory included in the source tree.
> > > 
> > > This breaks our (SUSE) use of dummy tools (GCC_PLUGINS became =n). I
> > > will investigate whether this is stable-only and the root cause later.
> > 
> > It looks like both the Greg's generated patch and the final stable
> > commit (d7e676b7dc6a) are missing the addition of the empty
> > plugin-version.h file. It appears in the patch's diffstat, but not in
> > the actual diff. The mainline commit does include the empty file
> > correctly, so it's likely a bug in the stable cherry pick automation.
> 
> Right, this fixed the issue for me:
> --- a/patches.kernel.org/5.19.4-144-kbuild-dummy-tools-avoid-tmpdir-leak-in-dummy-.patch
> +++ b/patches.kernel.org/5.19.4-144-kbuild-dummy-tools-avoid-tmpdir-leak-in-dummy-.patch
> @@ -20,6 +20,8 @@ Signed-off-by: Jiri Slaby <jslaby@suse.cz>
>   scripts/dummy-tools/gcc | 8 ++------
>   1 file changed, 2 insertions(+), 6 deletions(-)
> 
> +diff --git a/scripts/dummy-tools/dummy-plugin-dir/include/plugin-version.h
> b/scripts/dummy-tools/dummy-plugin-dir/include/plugin-version.h
> +new file mode 100644
>  diff --git a/scripts/dummy-tools/gcc b/scripts/dummy-tools/gcc
>  index b2483149bbe5..7db825843435 100755
>  --- a/scripts/dummy-tools/gcc

Ick, looks like a bad interaction between git and quilt, and then back
to git.  I'll manually fix this up and push out a new stable release
with it.

thanks for reporting this!

greg k-h
Re: [PATCH 5.19 145/365] kbuild: dummy-tools: avoid tmpdir leak in dummy gcc
Posted by Greg Kroah-Hartman 3 years, 3 months ago
On Mon, Aug 29, 2022 at 10:05:13AM +0200, Greg Kroah-Hartman wrote:
> On Mon, Aug 29, 2022 at 09:12:39AM +0200, Jiri Slaby wrote:
> > On 27. 08. 22, 10:34, Ondrej Mosnacek wrote:
> > > On Sat, Aug 27, 2022 at 9:51 AM Jiri Slaby <jirislaby@kernel.org> wrote:
> > > > On 23. 08. 22, 10:00, Greg Kroah-Hartman wrote:
> > > > > From: Ondrej Mosnacek <omosnace@redhat.com>
> > > > > 
> > > > > commit aac289653fa5adf9e9985e4912c1d24a3e8cbab2 upstream.
> > > > > 
> > > > > When passed -print-file-name=plugin, the dummy gcc script creates a
> > > > > temporary directory that is never cleaned up. To avoid cluttering
> > > > > $TMPDIR, instead use a static directory included in the source tree.
> > > > 
> > > > This breaks our (SUSE) use of dummy tools (GCC_PLUGINS became =n). I
> > > > will investigate whether this is stable-only and the root cause later.
> > > 
> > > It looks like both the Greg's generated patch and the final stable
> > > commit (d7e676b7dc6a) are missing the addition of the empty
> > > plugin-version.h file. It appears in the patch's diffstat, but not in
> > > the actual diff. The mainline commit does include the empty file
> > > correctly, so it's likely a bug in the stable cherry pick automation.
> > 
> > Right, this fixed the issue for me:
> > --- a/patches.kernel.org/5.19.4-144-kbuild-dummy-tools-avoid-tmpdir-leak-in-dummy-.patch
> > +++ b/patches.kernel.org/5.19.4-144-kbuild-dummy-tools-avoid-tmpdir-leak-in-dummy-.patch
> > @@ -20,6 +20,8 @@ Signed-off-by: Jiri Slaby <jslaby@suse.cz>
> >   scripts/dummy-tools/gcc | 8 ++------
> >   1 file changed, 2 insertions(+), 6 deletions(-)
> > 
> > +diff --git a/scripts/dummy-tools/dummy-plugin-dir/include/plugin-version.h
> > b/scripts/dummy-tools/dummy-plugin-dir/include/plugin-version.h
> > +new file mode 100644
> >  diff --git a/scripts/dummy-tools/gcc b/scripts/dummy-tools/gcc
> >  index b2483149bbe5..7db825843435 100755
> >  --- a/scripts/dummy-tools/gcc
> 
> Ick, looks like a bad interaction between git and quilt, and then back
> to git.  I'll manually fix this up and push out a new stable release
> with it.

Odd, 5.15.y worked just fine, but 5.10.y and 5.19.y did not.

I've done a new 5.10 and 5.19 release with this fixed up.  If there are
still any issues here, please let me know.

thanks,

greg k-h