mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: David Laight <David.Laight@ACULAB.COM>
To: 'Rob Landley' <rob@landley.net>,
	kernel test robot <oliver.sang@intel.com>
Cc: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	0day robot <lkp@intel.com>, "lkp@lists.01.org" <lkp@lists.01.org>
Subject: RE: ac0e958a00: Kernel_panic-not_syncing:stack-protector:Kernel_stack_is_corrupted_in:run_init_process
Date: Thu, 12 Nov 2020 13:49:27 +0000	[thread overview]
Message-ID: <2bd72a2f0af948d29eb201e3072e514e@AcuMS.aculab.com> (raw)
In-Reply-To: <87765a0e-3a49-d437-4010-4848b8ece199@landley.net>

From: Rob Landley
> Sent: 12 November 2020 12:46
> 
> On 11/12/20 1:11 AM, kernel test robot wrote:
> >
> > Greeting,
> >
> > FYI, we noticed the following commit (built with gcc-9):
> 
> Blah, switched from strlcpy to sprintf due to the lack of spaces and didn't
> adjust the size.
> 
> (And yes, the compiler's lifetime analysis should free the stack space before
> the tail call, and I'd assume exec restarts the stack anyway.)
> 
> Second-attempt-by: Rob Landley <rob@landley.net>
> ---
> 
>  init/main.c |   15 ++++++++-------
>  1 file changed, 8 insertions(+), 7 deletions(-)
> 
> diff --git a/init/main.c b/init/main.c
> index 130376ec10ba..e92320816ef8 100644
> --- a/init/main.c
> +++ b/init/main.c
> @@ -1328,15 +1328,16 @@ static void __init do_pre_smp_initcalls(void)
>  static int run_init_process(const char *init_filename)
>  {
>  	const char *const *p;
> +	char buf[512], *s = buf;
> 
>  	argv_init[0] = init_filename;
> -	pr_info("Run %s as init process\n", init_filename);
> -	pr_debug("  with arguments:\n");
> -	for (p = argv_init; *p; p++)
> -		pr_debug("    %s\n", *p);
> -	pr_debug("  with environment:\n");
> -	for (p = envp_init; *p; p++)
> -		pr_debug("    %s\n", *p);
> +
> +	for (p = (void *)envp_init; *p; p++)
> +		s += sprintf(s, "%.*s ", (int)(sizeof(buf)-(s-buf)-2), *p);
> +	for (p = (void *)argv_init; *p; p++)
> +		s += sprintf(s, "%.*s ", (int)(sizeof(buf)-(s-buf)-2), *p);
> +	pr_info("Run init: %s\n", buf);
> +

Why not use scnprintf() as:
	len += scnprintf(buf + len, 256 - len, " %s", *p);

or even:
	s = buf + sizeof buf;
	len = sizeof buf;
	...
		len -= scnprintf(s - len, len, " %s", *p);

and remove the " " before the %s in the final pr_info().

	David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)


  reply	other threads:[~2020-11-12 13:49 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-11 15:47 [PATCH] Collate "run init" message to one line with prefixed var assignments Rob Landley
2020-11-12  7:11 ` ac0e958a00: Kernel_panic-not_syncing:stack-protector:Kernel_stack_is_corrupted_in:run_init_process kernel test robot
2020-11-12 12:46   ` Rob Landley
2020-11-12 13:49     ` David Laight [this message]
2020-11-12 16:02       ` Rob Landley

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=2bd72a2f0af948d29eb201e3072e514e@AcuMS.aculab.com \
    --to=david.laight@aculab.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lkp@intel.com \
    --cc=lkp@lists.01.org \
    --cc=oliver.sang@intel.com \
    --cc=rob@landley.net \
    /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

Powered by JetHome