From: Al Viro <viro@ZenIV.linux.org.uk>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Chris Metcalf <cmetcalf@ezchip.com>,
Fabian Frederick <fabf@skynet.be>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
Randy Dunlap <rdunlap@infradead.org>,
Rickard Strandqvist <rickard_strandqvist@spectrumdigital.se>
Subject: Re: revert "fs/befs/linuxvfs.c: replace strncpy by strlcpy"
Date: Wed, 29 Apr 2015 01:35:14 +0100 [thread overview]
Message-ID: <20150429003514.GL889@ZenIV.linux.org.uk> (raw)
In-Reply-To: <CA+55aFwbRZe5gVsTyHvjKqE5eA3zQ_58_UQW7KACCt7V7FpZbQ@mail.gmail.com>
On Tue, Apr 28, 2015 at 02:48:45PM -0700, Linus Torvalds wrote:
> I suspect you could take that lib/strncpy_from_user.c and massage it
> reasonably trivially to be a good function.
>
> That said, I can't think of a single strncpy (or strlcpy) in kernel
> space that is actually worth even optimizing for. They just don't tend
> to be in the critical path. So correctness is likely *much* more
> important than worrying about performance.
Indeed. As it is, I suspect that strlcpy() use should be uniformly
discouraged; if nothing else, snprintf() gives the same semantics,
is less likely to cause confusion regardling the expected return
value and none of those paths are performance-critical.
strncpy() has another use, though, and it can't be replaced by strlcpy() -
see the commits that had started this thread. IMO they (and anything
else of the same nature) really need to be reverted; using strlcpy() on
something that isn't guaranteed to be NUL-terminated is a serious bug.
And catching all such places is going to be quite a work - there are too
many strlcpy() callers out there.
Frankly, looking through call sites in fs...
* two callers in fs/9p - strlcpy() + sscanf(), both should've been
plain sscanf() (and the second should've been "HARDLINKCOUNT%u" instead
of "%13s %u" + comparison of string with "HARDLINKCOUNT" - sscanf() is
quite capable of matching explicit string literals)
* affs one: match_strdup + strlcpy + kfree. Should just use match_strlcpy
instead (BTW, despite the name, it does *not* use strclpy() internally).
* afs: might be correct.
* two in befs: both broken.
* binfmt_misc: fishy; load_misc_binary() finds an object under rwlock, copies
one of its fields (->interpreter), drops rwlock and proceeds to do various
blocking operations (including open_exec()). Using another field of the
same object (->interp_flags) all along. If it gets freed and reused, well...
let's hope we won't fuck up too badly. IMO we'd be better off if we added
a refcount to that sucker and used it to control the freeing.
* btrfs: undefined behaviour - potentially overlapping source and destination.
* another btrfs one:
char b[BDEVNAME_SIZE];
strlcpy(s->s_id, bdevname(bdev, b), sizeof(s->s_id));
complete garbage; might as well do bdevname(bdev, s->s_id) and be done with
that.
... and so on; this stuff is misused more often than not.
next prev parent reply other threads:[~2015-04-29 0:35 UTC|newest]
Thread overview: 35+ 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
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 [this message]
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 ` [PATCH 1/3] Make asm/word-at-a-time.h available on all architectures Chris Metcalf
2015-04-30 16:01 ` [PATCH 2/3] string: provide strscpy() and strscpy_truncate() Chris Metcalf
2015-05-06 15:01 ` Dan Carpenter
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-05-11 15:37 ` [PATCH 0/3] add new strscpy() API for string copy Chris Metcalf
2015-05-14 23:10 ` Michael Ellerman
2015-05-15 15:15 ` Chris Metcalf
2015-05-18 1:13 ` Michael Ellerman
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 ` [PATCH v2 1/3] Make asm/word-at-a-time.h available on all architectures Chris Metcalf
2015-07-08 20:20 ` [PATCH v2 2/3] string: provide strscpy() 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
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=20150429003514.GL889@ZenIV.linux.org.uk \
--to=viro@zeniv.linux.org.uk \
--cc=cmetcalf@ezchip.com \
--cc=fabf@skynet.be \
--cc=linux-kernel@vger.kernel.org \
--cc=rdunlap@infradead.org \
--cc=rickard_strandqvist@spectrumdigital.se \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).