mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Kees Cook <kees@kernel.org>
To: Azeem Shaikh <azeemshaikh38@gmail.com>,
	Chuck Lever <chuck.lever@oracle.com>,
	Jeff Layton <jlayton@kernel.org>,
	Kees Cook <keescook@chromium.org>
Cc: linux-hardening@vger.kernel.org, Neil Brown <neilb@suse.de>,
	Olga Kornievskaia <kolga@netapp.com>,
	Dai Ngo <Dai.Ngo@oracle.com>, Tom Talpey <tom@talpey.com>,
	linux-nfs@vger.kernel.org, linux-kernel@vger.kernel.org,
	Trond Myklebust <trond.myklebust@hammerspace.com>,
	Anna Schumaker <anna@kernel.org>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	netdev@vger.kernel.org
Subject: Re: [PATCH v2] SUNRPC: Remove strlcpy
Date: Tue, 13 Jun 2023 18:04:19 -0700	[thread overview]
Message-ID: <7E4A66A6-0B58-43AF-B9E0-62087F2EA11C@kernel.org> (raw)
In-Reply-To: <20230614001246.538643-1-azeemshaikh38@gmail.com>

On June 13, 2023 5:12:46 PM PDT, Azeem Shaikh <azeemshaikh38@gmail.com> wrote:
>strlcpy() reads the entire source buffer first.
>This read may exceed the destination size limit.
>This is both inefficient and can lead to linear read
>overflows if a source string is not NUL-terminated [1].
>In an effort to remove strlcpy() completely [2], replace
>strlcpy() here with sysfs_emit().
>
>Direct replacement is safe here since the getter in kernel_params_ops
>handles -errno return [3].
>
>[1] https://www.kernel.org/doc/html/latest/process/deprecated.html#strlcpy
>[2] https://github.com/KSPP/linux/issues/89
>[3] https://elixir.bootlin.com/linux/v6.4-rc6/source/include/linux/moduleparam.h#L52
>
>Signed-off-by: Azeem Shaikh <azeemshaikh38@gmail.com>
>---
> net/sunrpc/svc.c |    8 ++++----
> 1 file changed, 4 insertions(+), 4 deletions(-)
>
>diff --git a/net/sunrpc/svc.c b/net/sunrpc/svc.c
>index e6d4cec61e47..77326f163801 100644
>--- a/net/sunrpc/svc.c
>+++ b/net/sunrpc/svc.c
>@@ -109,13 +109,13 @@ param_get_pool_mode(char *buf, const struct kernel_param *kp)
> 	switch (*ip)
> 	{
> 	case SVC_POOL_AUTO:
>-		return strlcpy(buf, "auto\n", 20);
>+		return sysfs_emit(buf, "auto\n");
> 	case SVC_POOL_GLOBAL:
>-		return strlcpy(buf, "global\n", 20);
>+		return sysfs_emit(buf, "global\n");
> 	case SVC_POOL_PERCPU:
>-		return strlcpy(buf, "percpu\n", 20);
>+		return sysfs_emit(buf, "percpu\n");
> 	case SVC_POOL_PERNODE:
>-		return strlcpy(buf, "pernode\n", 20);
>+		return sysfs_emit(buf, "pernode\n");
> 	default:
> 		return sprintf(buf, "%d\n", *ip);

Please replace the sprintf too (and then the Subject could be "use sysfs_emit" or so).

-Kees



-- 
Kees Cook

  reply	other threads:[~2023-06-14  1:04 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-14  0:12 Azeem Shaikh
2023-06-14  1:04 ` Kees Cook [this message]
2023-06-14  1:10   ` Azeem Shaikh

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=7E4A66A6-0B58-43AF-B9E0-62087F2EA11C@kernel.org \
    --to=kees@kernel.org \
    --cc=Dai.Ngo@oracle.com \
    --cc=anna@kernel.org \
    --cc=azeemshaikh38@gmail.com \
    --cc=chuck.lever@oracle.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=jlayton@kernel.org \
    --cc=keescook@chromium.org \
    --cc=kolga@netapp.com \
    --cc=kuba@kernel.org \
    --cc=linux-hardening@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-nfs@vger.kernel.org \
    --cc=neilb@suse.de \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=tom@talpey.com \
    --cc=trond.myklebust@hammerspace.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

all inboxes | Powered by JetHome®