public inbox for llvm@lists.linux.dev
 help / color / mirror / Atom feed
From: Kees Cook <keescook@chromium.org>
To: Justin Stitt <justinstitt@google.com>
Cc: Nathan Chancellor <nathan@kernel.org>,
	Nick Desaulniers <ndesaulniers@google.com>,
	Tom Rix <trix@redhat.com>,
	linux-kernel@vger.kernel.org, llvm@lists.linux.dev
Subject: Re: [PATCH RFC] init: fix -Wmissing-variable-declarations warning
Date: Thu, 31 Aug 2023 14:19:28 -0700	[thread overview]
Message-ID: <202308311411.B2B57B7441@keescook> (raw)
In-Reply-To: <20230829-missingvardecl-init-main-c-v1-1-ddf0f1a71215@google.com>

On Tue, Aug 29, 2023 at 11:38:31PM +0000, Justin Stitt wrote:
> Hi all,
> 
> I was looking to get some help on solving this -Wmissing-variable-declarations
> warning as there is some hope to turn it on for W=1 soon [1].
> 
> When building x86/defconfig with Clang-18 I encounter the following warning:
> | init/main.c:189:13: warning: no previous extern declaration for non-static variable 'envp_init' [-Wmissing-variable-declarations]
> |   189 | const char *envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
> |       |             ^
> | init/main.c:189:7: note: declare 'static' if the variable is not intended to be used outside of this translation unit
> |   189 | const char *envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
> |       |       ^
> 
> It seems like the obvious solution is to just add the `static` keyword
> and be done with it. I suspect, however, that it is not so simple for
> the following reasons:
> 
> Firstly, `envp_init` is surrounded by two other variables that have been
> explicitly marked as `static` which leads me to believe that this one
> was intentionally _not_ marked as static for some reason:
> | static const char *argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
> | static const char *envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
> | static const char *panic_later, *panic_param;

I went looking to see the history here and it goes beyond git history.  :)

> 
> Secondly, there exists this `extern` declaration for `envp_init`:
> | init/do_mounts_initrd.c
> | 90:     extern char *envp_init[];

This is the only user of call_usermodehelper_setup() that doesn't make
its own envp. And there's a deprecation warning in that function too:

9acc17baf1fd6   (Christoph Hellwig      2020-07-08 18:18:54 +0200 93)     pr_warn("using deprecated initrd support, will be removed in 2021.\n");

> Any help here would be appreciated!

I recommend making it static and giving handle_initrd() its own copy:

diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
index 425f4bcf4b77..154bd0de85a6 100644
--- a/init/do_mounts_initrd.c
+++ b/init/do_mounts_initrd.c
@@ -87,7 +87,7 @@ static void __init handle_initrd(char *root_device_name)
 {
 	struct subprocess_info *info;
 	static char *argv[] = { "linuxrc", NULL, };
-	extern char *envp_init[];
+	static char *envp[] = { "HOME=/", "TERM=linux", NULL, };
 	int error;
 
 	pr_warn("using deprecated initrd support, will be removed in 2021.\n");
@@ -100,7 +100,7 @@ static void __init handle_initrd(char *root_device_name)
 	init_mkdir("/old", 0700);
 	init_chdir("/old");
 
-	info = call_usermodehelper_setup("/linuxrc", argv, envp_init,
+	info = call_usermodehelper_setup("/linuxrc", argv, envp,
 					 GFP_KERNEL, init_linuxrc, NULL, NULL);
 	if (!info)
 		return;

-- 
Kees Cook

      reply	other threads:[~2023-08-31 21:19 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-29 23:38 [PATCH RFC] init: fix -Wmissing-variable-declarations warning Justin Stitt
2023-08-31 21:19 ` Kees Cook [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=202308311411.B2B57B7441@keescook \
    --to=keescook@chromium.org \
    --cc=justinstitt@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=llvm@lists.linux.dev \
    --cc=nathan@kernel.org \
    --cc=ndesaulniers@google.com \
    --cc=trix@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox