public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: David Laight <David.Laight@ACULAB.COM>
To: 'Andy Shevchenko' <andriy.shevchenko@linux.intel.com>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Cc: Kees Cook <keescook@chromium.org>
Subject: RE: [PATCH v1 1/1] seq_file: Replace strncpy()+nul by strscpy()
Date: Tue, 18 Jul 2023 09:42:13 +0000	[thread overview]
Message-ID: <4aef09112d0c4a59a1a3fa393af59f37@AcuMS.aculab.com> (raw)
In-Reply-To: <20230717093332.54236-1-andriy.shevchenko@linux.intel.com>

From: Andy Shevchenko
> Sent: 17 July 2023 10:34
...
>  #define seq_show_option_n(m, name, value, length) {	\
>  	char val_buf[length + 1];			\
> -	strncpy(val_buf, value, length);		\
> -	val_buf[length] = '\0';				\
> +	strscpy(val_buf, value, sizeof(val_buf));	\
>  	seq_show_option(m, name, val_buf);		\
>  }

Why the extra double-copy with (potentially) a VLA?

seq_show_option() calls seq_escape_str(),
seq_escape_str calls seq_escape_mem(...  strlen(src) ...).

Implement seq_show_option() as seq_show_option_n(... strlen(value))
and use seq_escape_mem() for the value.

	David

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

      parent reply	other threads:[~2023-07-18  9:42 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-17  9:33 [PATCH v1 1/1] seq_file: Replace strncpy()+nul by strscpy() Andy Shevchenko
2023-07-17 15:43 ` Kees Cook
2023-07-17 16:05   ` Andy Shevchenko
2023-07-17 22:58     ` Kees Cook
2023-07-17 23:09 ` Kees Cook
2023-07-19  5:00   ` Kees Cook
2023-07-19  5:26     ` Andy Shevchenko
2023-07-18  9:42 ` David Laight [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=4aef09112d0c4a59a1a3fa393af59f37@AcuMS.aculab.com \
    --to=david.laight@aculab.com \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=keescook@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    /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