Linux Hardening
 help / color / mirror / Atom feed
* [PATCH] fortify: Ignore intermediate *.tmp files
@ 2025-11-12 11:47 WangYuli
  2025-11-12 22:36 ` Nathan Chancellor
  0 siblings, 1 reply; 3+ messages in thread
From: WangYuli @ 2025-11-12 11:47 UTC (permalink / raw)
  To: kees, nathan, nicolas
  Cc: linux-hardening, linux-kernel, linux-kbuild, WangYuli, WangYuli

From: WangYuli <wangyl5933@chinaunicom.cn>

The test_fortify.sh script generates logs of build-time warnings
for string and memory functions. To ensure the final log file is
updated atomically, the script first writes its output to a temporary
file with a .log.tmp extension. Upon successful completion, this
temporary file is renamed to the final .log file.

If the build process is interrupted before this rename operation,
these *.log.tmp intermediate files will be left in the directory,
creating a risk of them being accidentally added to the git repository.

To prevent this from happening, add *.tmp to the .gitignore file to
explicitly ignore these temporary files.

Signed-off-by: WangYuli <wangyl5933@chinaunicom.cn>
Signed-off-by: WangYuli <wangyuli@aosc.io>
---
 lib/test_fortify/.gitignore | 1 +
 1 file changed, 1 insertion(+)

diff --git a/lib/test_fortify/.gitignore b/lib/test_fortify/.gitignore
index c1ba37d14b50..8056bc75b442 100644
--- a/lib/test_fortify/.gitignore
+++ b/lib/test_fortify/.gitignore
@@ -1,2 +1,3 @@
 # SPDX-License-Identifier: GPL-2.0-only
 /*.log
+/*.tmp
-- 
2.51.0


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

* Re: [PATCH] fortify: Ignore intermediate *.tmp files
  2025-11-12 11:47 [PATCH] fortify: Ignore intermediate *.tmp files WangYuli
@ 2025-11-12 22:36 ` Nathan Chancellor
  2025-11-28 19:21   ` Nicolas Schier
  0 siblings, 1 reply; 3+ messages in thread
From: Nathan Chancellor @ 2025-11-12 22:36 UTC (permalink / raw)
  To: WangYuli
  Cc: kees, nicolas, linux-hardening, linux-kernel, linux-kbuild,
	WangYuli

On Wed, Nov 12, 2025 at 07:47:25PM +0800, WangYuli wrote:
> From: WangYuli <wangyl5933@chinaunicom.cn>
> 
> The test_fortify.sh script generates logs of build-time warnings
> for string and memory functions. To ensure the final log file is
> updated atomically, the script first writes its output to a temporary
> file with a .log.tmp extension. Upon successful completion, this
> temporary file is renamed to the final .log file.
> 
> If the build process is interrupted before this rename operation,
> these *.log.tmp intermediate files will be left in the directory,
> creating a risk of them being accidentally added to the git repository.

Shouldn't the cleanup trap in lib/test_fortify/test_fortify.sh be enough
to avoid leaving behind .log.tmp? Or does that only work for clean
exits? Would adding INT to the trap avoid the problem?

> To prevent this from happening, add *.tmp to the .gitignore file to
> explicitly ignore these temporary files.
> 
> Signed-off-by: WangYuli <wangyl5933@chinaunicom.cn>
> Signed-off-by: WangYuli <wangyuli@aosc.io>

Regardless, this seems fine in the meantime.

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

> ---
>  lib/test_fortify/.gitignore | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/lib/test_fortify/.gitignore b/lib/test_fortify/.gitignore
> index c1ba37d14b50..8056bc75b442 100644
> --- a/lib/test_fortify/.gitignore
> +++ b/lib/test_fortify/.gitignore
> @@ -1,2 +1,3 @@
>  # SPDX-License-Identifier: GPL-2.0-only
>  /*.log
> +/*.tmp
> -- 
> 2.51.0
> 

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

* Re: [PATCH] fortify: Ignore intermediate *.tmp files
  2025-11-12 22:36 ` Nathan Chancellor
@ 2025-11-28 19:21   ` Nicolas Schier
  0 siblings, 0 replies; 3+ messages in thread
From: Nicolas Schier @ 2025-11-28 19:21 UTC (permalink / raw)
  To: Nathan Chancellor
  Cc: WangYuli, kees, linux-hardening, linux-kernel, linux-kbuild,
	WangYuli

[-- Attachment #1: Type: text/plain, Size: 2093 bytes --]

On Wed, Nov 12, 2025 at 03:36:06PM -0700, Nathan Chancellor wrote:
> On Wed, Nov 12, 2025 at 07:47:25PM +0800, WangYuli wrote:
> > From: WangYuli <wangyl5933@chinaunicom.cn>
> > 
> > The test_fortify.sh script generates logs of build-time warnings
> > for string and memory functions. To ensure the final log file is
> > updated atomically, the script first writes its output to a temporary
> > file with a .log.tmp extension. Upon successful completion, this
> > temporary file is renamed to the final .log file.

Sounds good, but does not reflect the current implementation:

The output log file may be written in several steps, and the temporary
file is not renamed but simply used to read the buffered output.

> > 
> > If the build process is interrupted before this rename operation,
> > these *.log.tmp intermediate files will be left in the directory,
> > creating a risk of them being accidentally added to the git repository.

Instead of adding a directory specific ignore, I'd rather rename the
temporary file to match a global ignore pattern (e.g. '.*.tmp').

> 
> Shouldn't the cleanup trap in lib/test_fortify/test_fortify.sh be enough
> to avoid leaving behind .log.tmp? Or does that only work for clean
> exits? Would adding INT to the trap avoid the problem?

Correct, the current 'EXIT' trap is only executed if test_fortify.sh
exits with 'exit' or reaches its EOF.  We could add HUP, INT, QUIT, TERM
and PIPE as well, as it is done in scripts/Kbuild.include; this may be a
bit more than usually needed, but then we can expect the cleanup to
happen, too, if the script is killed by typical signals (or due to 'set
-e').

> 
> > To prevent this from happening, add *.tmp to the .gitignore file to
> > explicitly ignore these temporary files.
> > 
> > Signed-off-by: WangYuli <wangyl5933@chinaunicom.cn>
> > Signed-off-by: WangYuli <wangyuli@aosc.io>
> 
> Regardless, this seems fine in the meantime.
> 
> Reviewed-by: Nathan Chancellor <nathan@kernel.org>

I am going to send an alternative approach.


Kind regards,
Nicolas

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

end of thread, other threads:[~2025-11-28 19:21 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-12 11:47 [PATCH] fortify: Ignore intermediate *.tmp files WangYuli
2025-11-12 22:36 ` Nathan Chancellor
2025-11-28 19:21   ` Nicolas Schier

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox