From: Konstantin Khlebnikov <khlebnikov@yandex-team.ru>
To: linux-kernel@vger.kernel.org
Cc: Tejun Heo <tj@kernel.org>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Andrew Morton <akpm@linux-foundation.org>,
Linus Torvalds <torvalds@linux-foundation.org>,
Alexey Dobriyan <adobriyan@gmail.com>
Subject: [PATCH v1 0/6] Make sscanf safer
Date: Sun, 10 Mar 2019 19:56:29 +0300 [thread overview]
Message-ID: <155223448227.4075.6846910559654700796.stgit@buzz> (raw)
Standard sscanf isn't well designed for input validation:
* no way to detect interger overflow
* unmached tail text is ignored
* no mandatory buffer overflow checks
All these problems were found in the wild in cgroup interfaces:
https://patchwork.kernel.org/patch/10831387/
https://lore.kernel.org/patchwork/patch/1046130/
This patchset has patches for first two issues.
Unbounded "%s" is out of scope for now.
Second patch handles integer overlow as parse error:
sscanf exits without touching related argument.
Third patch adds convenient way for checking that
whole text was matched and nothing left.
Fourth adds missing standard features for %[...],
this might be useful for input validation.
Fifth adds __must_check and will generate some new warnings.
The last is a simple test module for chechking some basic and
new corner-cases added by this patchset.
Code haven't chaneged much:
$ ./scripts/bloat-o-meter lib/vsprintf.o.old lib/vsprintf.o.new
add/remove: 0/0 grow/shrink: 1/0 up/down: 60/0 (60)
Function old new delta
vsscanf 2270 2330 +60
Total: Before=16904, After=16964, chg +0.35%
Unbounded "%s" could be fixed only by making field width mandatory.
There are only few users and in most cases sscanf could be eliminated.
---
Konstantin Khlebnikov (6):
lib: scanf: document features of scanf format string
lib: scanf: handle integer overflows in vsscanf
lib: scanf: add vsscanf feature for matching end of text
lib: scanf: handle character ranges in %[...]
lib: scanf: mark sscanf and vsscanf as __must_check
lib: scanf: add test module
include/linux/kernel.h | 10 ++
lib/Kconfig.debug | 3 +
lib/Makefile | 1
lib/test_scanf.c | 252 ++++++++++++++++++++++++++++++++++++++++++++++++
lib/vsprintf.c | 153 +++++++++++++++++++++--------
5 files changed, 376 insertions(+), 43 deletions(-)
create mode 100644 lib/test_scanf.c
--
Signature
next reply other threads:[~2019-03-10 16:56 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-03-10 16:56 Konstantin Khlebnikov [this message]
2019-03-10 16:56 ` [PATCH v1 1/6] lib: scanf: document features of scanf format string Konstantin Khlebnikov
2019-03-10 16:56 ` [PATCH v1 2/6] lib: scanf: handle integer overflows in vsscanf Konstantin Khlebnikov
2019-03-10 21:06 ` Rasmus Villemoes
2019-03-10 21:52 ` Linus Torvalds
2019-03-11 7:22 ` Konstantin Khlebnikov
2019-03-10 16:56 ` [PATCH v1 3/6] lib: scanf: add vsscanf feature for matching end of text Konstantin Khlebnikov
2019-03-10 16:56 ` [PATCH v1 4/6] lib: scanf: handle character ranges in %[...] Konstantin Khlebnikov
2019-03-10 16:56 ` [PATCH v1 5/6] lib: scanf: mark sscanf and vsscanf as __must_check Konstantin Khlebnikov
2019-03-10 16:56 ` [PATCH v1 6/6] lib: scanf: add test module Konstantin Khlebnikov
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=155223448227.4075.6846910559654700796.stgit@buzz \
--to=khlebnikov@yandex-team.ru \
--cc=adobriyan@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=tj@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 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®