From: Rasmus Villemoes <linux@rasmusvillemoes.dk>
To: Kees Cook <keescook@chromium.org>
Cc: Andrew Morton <akpm@linux-foundation.org>,
Tejun Heo <tj@kernel.org>,
Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 4/4] test_printf: test printf family at runtime
Date: Tue, 29 Sep 2015 09:10:57 +0200 [thread overview]
Message-ID: <871tdhsnsu.fsf@rasmusvillemoes.dk> (raw)
In-Reply-To: <CAGXu5jK+kDMv0co-1Fu6+owR7j_JfWxJv_9ThEG05-Hx3swMQg@mail.gmail.com> (Kees Cook's message of "Mon, 28 Sep 2015 15:38:25 -0700")
On Tue, Sep 29 2015, Kees Cook <keescook@chromium.org> wrote:
>> +static void __init
>> +test_string(void)
>> +{
>> + test("", "%s%.0s", "", "123");
>> + test("ABCD|abc|123", "%s|%.3s|%.*s", "ABCD", "abcdef", 3, "123456");
>> + test("1 | 2|3 | 4|5 ", "%-3s|%3s|%-*s|%*s|%*s", "1", "2", 3, "3", 3, "4", -3, "5");
>> + /*
>> + * POSIX and C99 say that a missing precision should be
>> + * treated as a precision of 0. However, the kernel's printf
>> + * implementation treats this case as if the . wasn't
>> + * present. Let's add a test case documenting the current
>> + * behaviour; should anyone ever feel the need to follow the
>> + * standards more closely, this can be revisited.
>> + */
>> + test("a||", "%.s|%.0s|%.*s", "a", "b", 0, "c");
>> + test("a | | ", "%-3.s|%-3.0s|%-3.*s", "a", "b", 0, "c");
>> +}
>
> Could you add a test for your 2/4 patch (bstr_printf size > INT_MAX
> change) as well?
I suppose you'd also want checks for the somewhat more important
vsnprintf size check and unknown specifiers? I guess I could, but do we
really want to intentionally trigger WARN_ON_ONCEs? Say some distro
chooses to load this module at boot time, then we'd both spam the kernel
log with "false positives", and we'd have effectively disabled the
WARN_ON_ONCEs for the actual kernel code.
Maybe we can hide such things behind some module parameter, so that the
user explicitly has to ask for them. Also, we can't really probe the
"success" if these sanity checks from within the module (can we?) - the
user would have to check dmesg manually anyway.
>> +
>> +static void __init
>> +dentry(void)
>> +{
>> +}
>> +
>> +static void __init
>> +struct_va_format(void)
>> +{
>> +}
>> +
>> +static void __init
>> +struct_clk(void)
>> +{
>> +}
>
> For the empty functions, maybe just add a pr_info("TODO: struct_clk")
> or something?
I think that would be unnecessarily spammy. It should be obvious from
the code that it is just waiting for someone to fill in the blanks.
>> +static int __init
>> +test_printf_init(void)
>> +{
>> + test_buffer = kmalloc(BUF_SIZE, GFP_KERNEL);
>> + if (!test_buffer)
>> + return -ENOMEM;
>> +
>> + test_basic();
>> + test_number();
>> + test_string();
>> + test_pointer();
>> +
>> + kfree(test_buffer);
>> +
>> + if (failed_tests == 0)
>> + pr_info("all %u tests passed\n", total_tests);
>> + else
>> + pr_warn("failed %u out of %u tests\n", failed_tests, total_tests);
>> +
>> + return 0;
>> +}
>
> I actually have different feedback on leaving the module loaded: I
> think it should succeed to load when the tests pass and fail when they
> don't. This makes it a one-step test to check things ("what is
> modprobe's return code?"), instead of needed to parse dmesg.
Hm, I guess that makes sense. But, assuming we go with the module param
suggested above, would it be possible to (unload and) load with a
different set of parameters?
> I love tests! Thank you. :) One suggestion would be to wire it up to
> the tools/testing/selftests tree; it should be trivial once you change
> the test_printf_init return code.
I'll look into that. Not sure I have too much time to work on this this
side of the merge window, and since these all seem to be things that can
be incrementally added, I'd prefer seeing something go into 4.4 instead
of waiting till it's "perfect". So unless I hear otherwise, I'll post a
v2 with the minor things addressed and ask Andrew to take that through
-mm.
Thanks,
Rasmus
next prev parent reply other threads:[~2015-09-29 7:11 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-09-25 17:41 [PATCH 0/4] printf stuff Rasmus Villemoes
2015-09-25 17:41 ` [PATCH 1/4] lib/vsprintf.c: handle invalid format specifiers more robustly Rasmus Villemoes
2015-09-28 8:08 ` Andy Shevchenko
2015-09-28 20:12 ` Rasmus Villemoes
2015-09-28 22:30 ` Kees Cook
2015-09-25 17:41 ` [PATCH 2/4] lib/vsprintf.c: also improve sanity check in bstr_printf() Rasmus Villemoes
2015-09-28 22:31 ` Kees Cook
2015-09-25 17:41 ` [PATCH 3/4] lib/vsprintf.c: Remove SPECIAL handling in pointer() Rasmus Villemoes
2015-09-28 8:55 ` Andy Shevchenko
2015-09-25 17:41 ` [PATCH 4/4] test_printf: test printf family at runtime Rasmus Villemoes
2015-09-28 9:12 ` Andy Shevchenko
2015-09-28 20:55 ` Rasmus Villemoes
2015-09-30 6:38 ` Andy Shevchenko
2015-09-30 8:56 ` Rasmus Villemoes
2015-09-28 22:38 ` Kees Cook
2015-09-29 7:10 ` Rasmus Villemoes [this message]
2015-09-29 17:32 ` Kees Cook
2015-09-30 9:05 ` Rasmus Villemoes
2015-09-30 15:30 ` [PATCH v2 0/4] printf stuff Rasmus Villemoes
2015-09-30 15:30 ` [PATCH v2 1/4] lib/vsprintf.c: handle invalid format specifiers more robustly Rasmus Villemoes
2015-09-30 15:30 ` [PATCH v2 2/4] lib/vsprintf.c: also improve sanity check in bstr_printf() Rasmus Villemoes
2015-09-30 15:30 ` [PATCH v2 3/4] lib/vsprintf.c: Remove SPECIAL handling in pointer() Rasmus Villemoes
2015-09-30 15:40 ` Andy Shevchenko
2015-09-30 15:30 ` [PATCH v2 4/4] test_printf: test printf family at runtime Rasmus Villemoes
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=871tdhsnsu.fsf@rasmusvillemoes.dk \
--to=linux@rasmusvillemoes.dk \
--cc=akpm@linux-foundation.org \
--cc=andriy.shevchenko@linux.intel.com \
--cc=keescook@chromium.org \
--cc=linux-kernel@vger.kernel.org \
--cc=tj@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.