All of lore.kernel.org
 help / color / mirror / Atom feed
From: Al Viro <viro@ZenIV.linux.org.uk>
To: Fabian Frederick <fabf@skynet.be>
Cc: Linus Torvalds <torvalds@linux-foundation.org>,
	linux-kernel@vger.kernel.org
Subject: Re: revert "fs/befs/linuxvfs.c: replace strncpy by strlcpy"
Date: Tue, 28 Apr 2015 17:05:23 +0100	[thread overview]
Message-ID: <20150428160523.GJ889@ZenIV.linux.org.uk> (raw)
In-Reply-To: <1363736428.511175.1430199310500.open-xchange@webmail.nmp.proximus.be>

On Tue, Apr 28, 2015 at 07:35:10AM +0200, Fabian Frederick wrote:

> > Al, very unhappy about the prospect of looking through ~2000 calls of
> > strlcpy()
> > we have in the tree...
> 
> Sorry Al, I thought it was more secure.

It's not just you, unfortunately, and dumping all that annoyance on you
as a proxy for everyone who does that kind of thing had been unfair.
My apologies...

> I guess the 2 following patches should be reversed as well :
> 
> 6cb103b6f45a
> "fs/befs/btree.c: replace strncpy by strlcpy + coding style fixing"
> 
> 69201bb11327
> "fs/ocfs2/super.c: use OCFS2_MAX_VOL_LABEL_LEN and strlcpy"

AFAICS, they should.

Unfortunately, we _can't_ make strlcpy() never look past src + size - 1 -
not without changing its semantics.  Its callers expect it to return
the length of source; one of the intended uses is
	wanted = strlcpy(dst, src, dst_size);
	if (wanted >= dst_size) {
		p = realloc(dst, wanted + 1);
		if (!p) {
			// too bad
		} else {
			dst = p;
			memcpy(dst, src, wanted + 1);
		}
	}
and that really wants the accurate length.  Now, the absolute majority of
strlcpy() users in the kernel completely ignore the return value, i.e. go for
silent truncation.  About 1% do not.

Out of those, some are correctly implemented "fail if truncated" uses.
The rest...  Some are weirdly open-coded snprintf() (series of strlcpy and
strlcat) and some are _very_ dubious.  Either they really never get
truncated, or we have a problem.  For example, this
kernel/module.c:2349:			s += strlcpy(s, &mod->strtab[src[i].st_name],
smells really bad.  We are truncating a bunch of strings dowsn to KSYM_NAME_LEN
there and storing them in a buffer, with spacing that matches _untruncated_
strings.

drivers/s390/scsi/zfcp_fc.c:825:	len = strlcpy(rspn_req->rspn.fr_name, fc_host_symbolic_name(shost),
also looks fishy - what happens there is
        len = strlcpy(rspn_req->rspn.fr_name, fc_host_symbolic_name(shost),
                      FC_SYMBOLIC_NAME_SIZE);
        rspn_req->rspn.fr_name_len = len;

drivers/usb/gadget/function/f_midi.c:976:	result = strlcpy(page, opts->id, PAGE_SIZE);
drivers/usb/gadget/function/f_printer.c:1172:	result = strlcpy(page, opts->pnp_string + 2, PNP_STRING_LEN - 2);
drivers/usb/gadget/function/f_printer.c:1184:	result = strlcpy(opts->pnp_string + 2, page, PNP_STRING_LEN - 2);

are also strange...

  reply	other threads:[~2015-04-28 16:05 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-28  3:48 revert "fs/befs/linuxvfs.c: replace strncpy by strlcpy" Al Viro
2015-04-28  5:35 ` Fabian Frederick
2015-04-28 16:05   ` Al Viro [this message]
2015-04-28 16:42     ` Fabian Frederick
2015-04-28 17:39       ` Al Viro
2015-04-28 20:16         ` Fabian Frederick
2015-04-28 16:42     ` Linus Torvalds
2015-04-28 19:48       ` Chris Metcalf
2015-04-28 20:51         ` Linus Torvalds
2015-04-28 21:38           ` Chris Metcalf
2015-04-28 21:48             ` Linus Torvalds
2015-04-29  0:35               ` Al Viro
2015-04-29  8:24                 ` Geert Uytterhoeven
2015-04-30 16:01               ` [PATCH 0/3] add new strscpy() API for string copy Chris Metcalf
2015-04-30 16:01                 ` Chris Metcalf
2015-04-30 16:01                 ` [PATCH 1/3] Make asm/word-at-a-time.h available on all architectures Chris Metcalf
2015-04-30 16:01                   ` Chris Metcalf
2015-04-30 16:01                 ` [PATCH 2/3] string: provide strscpy() and strscpy_truncate() Chris Metcalf
2015-04-30 16:01                   ` Chris Metcalf
2015-05-06 15:01                   ` Dan Carpenter
2015-05-06 15:21                     ` Chris Metcalf
2015-05-06 15:21                       ` Chris Metcalf
2015-05-06 15:59                       ` Dan Carpenter
2015-05-06 16:45                         ` Geert Uytterhoeven
2015-05-07  9:00                           ` Dan Carpenter
2015-05-07 15:10                             ` Chris Metcalf
2015-04-30 16:01                 ` [PATCH 3/3] tile: use global strscpy() rather than private copy Chris Metcalf
2015-04-30 16:01                   ` Chris Metcalf
2015-05-11 15:37                 ` [PATCH 0/3] add new strscpy() API for string copy Chris Metcalf
2015-05-11 15:37                   ` Chris Metcalf
2015-05-14 23:10                 ` Michael Ellerman
2015-05-15 15:15                   ` Chris Metcalf
2015-05-15 15:15                     ` Chris Metcalf
2015-05-18  1:13                     ` Michael Ellerman
2015-05-26 19:33                       ` Chris Metcalf
2015-05-26 19:33                         ` Chris Metcalf
  -- strict thread matches above, loose matches on Subject: below --
2015-06-30 18:01 [GIT PULL] strscpy string copy function Chris Metcalf
2015-07-01 16:11 ` Linus Torvalds
2015-07-08 20:20   ` [PATCH v2 0/3] add new strscpy() API for string copy Chris Metcalf
2015-07-08 20:20     ` Chris Metcalf
2015-07-08 20:20     ` [PATCH v2 1/3] Make asm/word-at-a-time.h available on all architectures Chris Metcalf
2015-07-08 20:20       ` Chris Metcalf
2015-07-08 20:20     ` [PATCH v2 2/3] string: provide strscpy() Chris Metcalf
2015-07-08 20:20       ` Chris Metcalf
2015-07-08 20:54       ` Geert Uytterhoeven
2015-07-08 20:20     ` [PATCH v2 3/3] tile: use global strscpy() rather than private copy Chris Metcalf
2015-07-08 20:20       ` Chris Metcalf

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=20150428160523.GJ889@ZenIV.linux.org.uk \
    --to=viro@zeniv.linux.org.uk \
    --cc=fabf@skynet.be \
    --cc=linux-kernel@vger.kernel.org \
    --cc=torvalds@linux-foundation.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.