mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Mark D Rustad <mrustad@gmail.com>
To: Rickard Strandqvist <rickard_strandqvist@spectrumdigital.se>
Cc: Neil Horman <nhorman@tuxdriver.com>,
	Herbert Xu <herbert@gondor.apana.org.au>,
	"David S. Miller" <davem@davemloft.net>,
	linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] crypto: rng.c:  Cleaning up missing null-terminate in conjunction with strncpy
Date: Sat, 26 Jul 2014 19:35:22 -0700	[thread overview]
Message-ID: <B1C69CE0-CA18-4853-B4EB-15B0D0F107E7@gmail.com> (raw)
In-Reply-To: <1406384308-2269-1-git-send-email-rickard_strandqvist@spectrumdigital.se>

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

Rickard,

On Jul 26, 2014, at 7:18 AM, Rickard Strandqvist <rickard_strandqvist@spectrumdigital.se> wrote:

> Replacing strncpy with strlcpy to avoid strings that lacks null terminate.
> 
> Signed-off-by: Rickard Strandqvist <rickard_strandqvist@spectrumdigital.se>
> ---
> crypto/rng.c |    2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/crypto/rng.c b/crypto/rng.c
> index e0a25c2..c3d4fb3 100644
> --- a/crypto/rng.c
> +++ b/crypto/rng.c
> @@ -65,7 +65,7 @@ static int crypto_rng_report(struct sk_buff *skb, struct crypto_alg *alg)
> {
> 	struct crypto_report_rng rrng;
> 
> -	strncpy(rrng.type, "rng", sizeof(rrng.type));
> +	strlcpy(rrng.type, "rng", sizeof(rrng.type));
> 
> 	rrng.seedsize = alg->cra_rng.seedsize;

Not to pick on this patch in particular, but you need to be careful about changing strncpy to strlcpy. Although strlcpy ensures termination, it does not prevent information leakage - strncpy ensures that the entire destination buffer is written. When leakage is a concern, it is better to use strncpy and then to store a zero in the last location of the buffer to ensure termination.

These "simple" transformations can be risky - and many of these do not represent any sort of problem when the source is smaller than the destination. I hope information leakage is being considered.

-- 
Mark Rustad, MRustad@gmail.com


[-- Attachment #2: Message signed with OpenPGP using GPGMail --]
[-- Type: application/pgp-signature, Size: 841 bytes --]

  reply	other threads:[~2014-07-27  2:35 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-26 14:18 Rickard Strandqvist
2014-07-27  2:35 ` Mark D Rustad [this message]
2014-07-27 12:14   ` Rickard Strandqvist

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=B1C69CE0-CA18-4853-B4EB-15B0D0F107E7@gmail.com \
    --to=mrustad@gmail.com \
    --cc=davem@davemloft.net \
    --cc=herbert@gondor.apana.org.au \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nhorman@tuxdriver.com \
    --cc=rickard_strandqvist@spectrumdigital.se \
    /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®