From: Marco Elver <elver@google.com>
To: Arpitha Raghunandan <98.arpi@gmail.com>
Cc: Brendan Higgins <brendanhiggins@google.com>,
Shuah Khan <skhan@linuxfoundation.org>,
Iurii Zaikin <yzaikin@google.com>,
"Theodore Ts'o" <tytso@mit.edu>,
Andreas Dilger <adilger.kernel@dilger.ca>,
Tim Bird <Tim.Bird@sony.com>, David Gow <davidgow@google.com>,
"open list:KERNEL SELFTEST FRAMEWORK"
<linux-kselftest@vger.kernel.org>,
KUnit Development <kunit-dev@googlegroups.com>,
LKML <linux-kernel@vger.kernel.org>,
linux-kernel-mentees@lists.linuxfoundation.org,
linux-ext4@vger.kernel.org
Subject: Re: [PATCH v8 2/2] fs: ext4: Modify inode-test.c to use KUnit parameterized testing feature
Date: Sun, 15 Nov 2020 20:44:56 +0100 [thread overview]
Message-ID: <CANpmjNPKfPeiXUUPwz1aU6iKwOXpSZNV5ZJq22NkZZWEhE9r1w@mail.gmail.com> (raw)
In-Reply-To: <20201115185905.169349-1-98.arpi@gmail.com>
On Sun, 15 Nov 2020 at 19:59, Arpitha Raghunandan <98.arpi@gmail.com> wrote:
>
> Modify fs/ext4/inode-test.c to use the parameterized testing
> feature of KUnit.
>
> Signed-off-by: Arpitha Raghunandan <98.arpi@gmail.com>
> Signed-off-by: Marco Elver <elver@google.com>
> ---
> Changes v7->v8:
> - Replace strcpy() with strncpy() in timestamp_expectation_to_desc()
> Changes v6->v7:
> - Introduce timestamp_expectation_to_desc() to convert param to
> description.
> Changes v5->v6:
> - No change to this patch of the patch series
> Changes v4->v5:
> - No change to this patch of the patch series
> Changes v3->v4:
> - Modification based on latest implementation of KUnit parameterized testing
> Changes v2->v3:
> - Marked hardcoded test data const
> - Modification based on latest implementation of KUnit parameterized testing
> Changes v1->v2:
> - Modification based on latest implementation of KUnit parameterized testing
>
> fs/ext4/inode-test.c | 323 ++++++++++++++++++++++---------------------
> 1 file changed, 167 insertions(+), 156 deletions(-)
>
> diff --git a/fs/ext4/inode-test.c b/fs/ext4/inode-test.c
> index d62d802c9c12..2c0c00c45c6b 100644
> --- a/fs/ext4/inode-test.c
> +++ b/fs/ext4/inode-test.c
> @@ -80,6 +80,148 @@ struct timestamp_expectation {
> bool lower_bound;
> };
>
> +static const struct timestamp_expectation test_data[] = {
> + {
> + .test_case_name = LOWER_BOUND_NEG_NO_EXTRA_BITS_CASE,
> + .msb_set = true,
> + .lower_bound = true,
> + .extra_bits = 0,
> + .expected = {.tv_sec = -0x80000000LL, .tv_nsec = 0L},
> + },
> +
> + {
> + .test_case_name = UPPER_BOUND_NEG_NO_EXTRA_BITS_CASE,
> + .msb_set = true,
> + .lower_bound = false,
> + .extra_bits = 0,
> + .expected = {.tv_sec = -1LL, .tv_nsec = 0L},
> + },
> +
> + {
> + .test_case_name = LOWER_BOUND_NONNEG_NO_EXTRA_BITS_CASE,
> + .msb_set = false,
> + .lower_bound = true,
> + .extra_bits = 0,
> + .expected = {0LL, 0L},
> + },
> +
> + {
> + .test_case_name = UPPER_BOUND_NONNEG_NO_EXTRA_BITS_CASE,
> + .msb_set = false,
> + .lower_bound = false,
> + .extra_bits = 0,
> + .expected = {.tv_sec = 0x7fffffffLL, .tv_nsec = 0L},
> + },
> +
> + {
> + .test_case_name = LOWER_BOUND_NEG_LO_1_CASE,
> + .msb_set = true,
> + .lower_bound = true,
> + .extra_bits = 1,
> + .expected = {.tv_sec = 0x80000000LL, .tv_nsec = 0L},
> + },
> +
> + {
> + .test_case_name = UPPER_BOUND_NEG_LO_1_CASE,
> + .msb_set = true,
> + .lower_bound = false,
> + .extra_bits = 1,
> + .expected = {.tv_sec = 0xffffffffLL, .tv_nsec = 0L},
> + },
> +
> + {
> + .test_case_name = LOWER_BOUND_NONNEG_LO_1_CASE,
> + .msb_set = false,
> + .lower_bound = true,
> + .extra_bits = 1,
> + .expected = {.tv_sec = 0x100000000LL, .tv_nsec = 0L},
> + },
> +
> + {
> + .test_case_name = UPPER_BOUND_NONNEG_LO_1_CASE,
> + .msb_set = false,
> + .lower_bound = false,
> + .extra_bits = 1,
> + .expected = {.tv_sec = 0x17fffffffLL, .tv_nsec = 0L},
> + },
> +
> + {
> + .test_case_name = LOWER_BOUND_NEG_HI_1_CASE,
> + .msb_set = true,
> + .lower_bound = true,
> + .extra_bits = 2,
> + .expected = {.tv_sec = 0x180000000LL, .tv_nsec = 0L},
> + },
> +
> + {
> + .test_case_name = UPPER_BOUND_NEG_HI_1_CASE,
> + .msb_set = true,
> + .lower_bound = false,
> + .extra_bits = 2,
> + .expected = {.tv_sec = 0x1ffffffffLL, .tv_nsec = 0L},
> + },
> +
> + {
> + .test_case_name = LOWER_BOUND_NONNEG_HI_1_CASE,
> + .msb_set = false,
> + .lower_bound = true,
> + .extra_bits = 2,
> + .expected = {.tv_sec = 0x200000000LL, .tv_nsec = 0L},
> + },
> +
> + {
> + .test_case_name = UPPER_BOUND_NONNEG_HI_1_CASE,
> + .msb_set = false,
> + .lower_bound = false,
> + .extra_bits = 2,
> + .expected = {.tv_sec = 0x27fffffffLL, .tv_nsec = 0L},
> + },
> +
> + {
> + .test_case_name = UPPER_BOUND_NONNEG_HI_1_NS_1_CASE,
> + .msb_set = false,
> + .lower_bound = false,
> + .extra_bits = 6,
> + .expected = {.tv_sec = 0x27fffffffLL, .tv_nsec = 1L},
> + },
> +
> + {
> + .test_case_name = LOWER_BOUND_NONNEG_HI_1_NS_MAX_CASE,
> + .msb_set = false,
> + .lower_bound = true,
> + .extra_bits = 0xFFFFFFFF,
> + .expected = {.tv_sec = 0x300000000LL,
> + .tv_nsec = MAX_NANOSECONDS},
> + },
> +
> + {
> + .test_case_name = LOWER_BOUND_NONNEG_EXTRA_BITS_1_CASE,
> + .msb_set = false,
> + .lower_bound = true,
> + .extra_bits = 3,
> + .expected = {.tv_sec = 0x300000000LL, .tv_nsec = 0L},
> + },
> +
> + {
> + .test_case_name = UPPER_BOUND_NONNEG_EXTRA_BITS_1_CASE,
> + .msb_set = false,
> + .lower_bound = false,
> + .extra_bits = 3,
> + .expected = {.tv_sec = 0x37fffffffLL, .tv_nsec = 0L},
> + }
> +};
> +
> +static void timestamp_expectation_to_desc(const struct timestamp_expectation *t,
> + char *desc)
> +{
> + int desc_length = strlen(t->test_case_name);
> +
> + strncpy(desc, t->test_case_name, desc_length);
> + desc[desc_length] = '\0';
> +}
This unfortunately won't prevent out-of-bounds accesses if the
description is longer than KUNIT_PARAM_DESC_SIZE.
With strncpy() we want to avoid copying more bytes than the
destination buffer can hold. This can be done by simply a
strncpy(desc, t->test_case_name, KUNIT_PARAM_DESC_SIZE). But,
strncpy() is unsafe in certain cases, too, so the kernel introduced
strscpy() -- see the note about strncpy() in
Documentation/process/deprecated.rst. Also have a look at the
documentation about str{n,l,s}cpy() in lib/string.c.
So, finally, what we want here is just 1 line:
strscpy(desc, t->test_case_name, KUNIT_PARAM_DESC_SIZE);
Patch 1/2 looks fine though, so hopefully v9 will be final. :-)
Thanks,
-- Marco
next prev parent reply other threads:[~2020-11-15 19:45 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-15 18:57 [PATCH v8 1/2] kunit: Support for Parameterized Testing Arpitha Raghunandan
2020-11-15 18:59 ` [PATCH v8 2/2] fs: ext4: Modify inode-test.c to use KUnit parameterized testing feature Arpitha Raghunandan
2020-11-15 19:44 ` Marco Elver [this message]
2020-11-16 4:54 ` Arpitha Raghunandan
2020-11-30 22:24 ` [PATCH v8 1/2] kunit: Support for Parameterized Testing Brendan Higgins
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=CANpmjNPKfPeiXUUPwz1aU6iKwOXpSZNV5ZJq22NkZZWEhE9r1w@mail.gmail.com \
--to=elver@google.com \
--cc=98.arpi@gmail.com \
--cc=Tim.Bird@sony.com \
--cc=adilger.kernel@dilger.ca \
--cc=brendanhiggins@google.com \
--cc=davidgow@google.com \
--cc=kunit-dev@googlegroups.com \
--cc=linux-ext4@vger.kernel.org \
--cc=linux-kernel-mentees@lists.linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=skhan@linuxfoundation.org \
--cc=tytso@mit.edu \
--cc=yzaikin@google.com \
/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).