All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ryan Anderson <ryan@autoweb.net>
To: kernel-janitors@vger.kernel.org
Subject: Re: [KJ] critical bug in strncpy()
Date: Mon, 28 Mar 2005 15:03:35 +0000	[thread overview]
Message-ID: <20050328150335.GO11081@ryan2> (raw)
In-Reply-To: <200503281155.16199.vicente.feito@gmail.com>

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

On Mon, Mar 28, 2005 at 04:34:16PM +0200, walter harms wrote:
> hi all,
> The kernel version of strcpy() is buggy. it copies ALWAYS n bytes.
> since i have NO idea if this is exploidable somehow, i would still
> recomend to REMOVE the code. See example below if you do not believe me.
> Also below you find a sniplet from libString/Strncpy.c.

The kernel version prevents information leakage by overwriting the rest
of the buffer with 0 after finishing the actual copy.

I'm fairly certain the behavior was intendend.

> i did not provide a patch since this is NOT my code. (btw: changed the 
> name from Strncopy to strncpy). C&P this in to the kernel/lib/string.c.
> 
> 
> re,
> 	walter
> 
> 
> /* in case this is needed */
> Signed-off-by: walter harms <wharms@bfs.de>
> 
> 
> 
> /* linux kernel */
> char * K_strncpy(char * dest,const char *src,size_t count)
> {
>         char *tmp = dest;
> 
>         while (count) {
>                 if ((*tmp = *src) != 0) src++;    <-MISSING  case == 0 
> 
>                 tmp++;
>                 count--;
>         }
>         printf("count=%d\n",count);
>         return dest;
> }
> 
> int main()
> {
> char *src="15" ;
> char dst[]="123";
> 
> K_strncpy(dst,src,500);
> 
> }
> 
> 
> i looked a bit around and found these nice version.
> 
> 
> /*
>  * libString, Copyright (C) 1999 Patrick Alken
>  * This library comes with absolutely NO WARRANTY
>  *
>  * Should you choose to use and/or modify this source code, please
>  * do so under the terms of the GNU General Public License under which
>  * this library is distributed.
>  *
>  * $Id: Strncpy.c,v 1.1.1.1 2000/10/02 12:02:27 decho Exp $
>  */
> 
> #include <sys/types.h>
> 
> /*
> Strncpy()
>  Optimized version of strncpy().
> 
> Inputs: dest   - destination string
>         source - source string
>         bytes  - number of bytes to copy
> 
> NOTE: A terminating \0 character is only copied to 'dest' if
>       'source' is terminated by one, provided the limit 'bytes'
>       has not yet been reached.
> 
> Return: destination string
> */
> 
> char *
> strncpy(char *dest, const char *source, const size_t bytes)
> 
> {
>   register char *end = dest + bytes;
>   register char *s = dest;
> 
>   while ((s < end) && (*s++ = *source++))
>     ;
> 
>   return (dest);
> } /* Strncpy() */
> 
> 

> _______________________________________________
> Kernel-janitors mailing list
> Kernel-janitors@lists.osdl.org
> http://lists.osdl.org/mailman/listinfo/kernel-janitors


-- 

Ryan Anderson
AutoWeb Communications, Inc.
email: ryan@autoweb.net



[-- Attachment #2: Type: text/plain, Size: 167 bytes --]

_______________________________________________
Kernel-janitors mailing list
Kernel-janitors@lists.osdl.org
http://lists.osdl.org/mailman/listinfo/kernel-janitors

  parent reply	other threads:[~2005-03-28 15:03 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-03-28 11:55 [KJ] critical bug in strncpy() Vicente Feito
2005-03-28 14:34 ` walter harms
2005-03-28 15:03 ` Ryan Anderson [this message]
2005-03-28 15:31 ` walter harms
2005-03-28 18:18 ` Ryan Anderson
2005-03-28 19:19 ` walter harms
2005-03-28 21:26 ` Matthew Wilcox

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=20050328150335.GO11081@ryan2 \
    --to=ryan@autoweb.net \
    --cc=kernel-janitors@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.