Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp2633301pxb; Sun, 15 Nov 2020 11:55:03 -0800 (PST) X-Google-Smtp-Source: ABdhPJzY4e8bbXcm8Y6+fsKZQ3jfncS3pLore/JhkooptnGjKTG5Xj/8Qfm2R8kACzD8nmcF6dcG X-Received: by 2002:a17:907:2805:: with SMTP id eb5mr11469932ejc.27.1605470103535; Sun, 15 Nov 2020 11:55:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605470103; cv=none; d=google.com; s=arc-20160816; b=SGksiq4JGMxoYa65msRjy2pzI3/ot5dr8KbH5eBg3/ZD7kSlbWA5Ak5L94pEIGw0qO NXqSbplX/7nrmSx1GmKWPwiwtMf83umj7ywZh2NET2ypoIcHX/AK8NYJAsgoTb+D4t1x 0W6MuijCiTnU/Bm2PiJGLWJLWttnUgKO3QTTTSxyjl0yzae0D3VqjukTMdvTCFZrj6rE tde84WW7nZ/NCDoFMCtm/r+sehhouIfupY/gLTXXROSdODi6CBmeRC/4/r+TcwD9WsfD BhfBzfXEchM8/0YSN/P1zg47014tWdiDFY6o/KsgXGp/1gwNmLQPDY2D2FryLCSaM59r XRyA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=6zNjOkpCVoYdq5SpvfJCUuoFxEeE/HXUKkYfS/pJSPQ=; b=m1gT0D6SqsVZvSqIeo0GsJZDIuhntcDELycoqn6o9gP3H302RdVVxAtdV1vZpw5W/i 2hb1uKxMFw2Q9AxpVIHZxkn4aNj6KTW0DtidBXZwtRmCnN2nBdKKuIsLocHD4UpdCDND Oh2yANAemqlbhJ0iZ2RJr/F5F4Te8IEHr16eY0jovNLnPNNeMXwj7/LPMOlZEiznvFL3 YYsIR2AVL/crHeY4PbgDv4Rzf51ZguHeHA0co7w/3SfiY+OMEdOYB8i+ey/j66lbq9BO 4zQSO4pneSr4PQciue77qA1NiJuUIbc71Pb/tKkwp4NjPjJuwoY6UpUOGrEk3a0a10QF Q+Dw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=YGqgAsRP; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f22si10792598edx.179.2020.11.15.11.54.23; Sun, 15 Nov 2020 11:55:03 -0800 (PST) Received-SPF: pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=YGqgAsRP; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727618AbgKOTpJ (ORCPT + 99 others); Sun, 15 Nov 2020 14:45:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41494 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727317AbgKOTpJ (ORCPT ); Sun, 15 Nov 2020 14:45:09 -0500 Received: from mail-ot1-x341.google.com (mail-ot1-x341.google.com [IPv6:2607:f8b0:4864:20::341]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0DE62C0613CF for ; Sun, 15 Nov 2020 11:45:09 -0800 (PST) Received: by mail-ot1-x341.google.com with SMTP id j14so13959177ots.1 for ; Sun, 15 Nov 2020 11:45:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=6zNjOkpCVoYdq5SpvfJCUuoFxEeE/HXUKkYfS/pJSPQ=; b=YGqgAsRPCcFEYGbkYFYFYF7c6IZTiUtw/7UtjsOW/6+vpk09z2RB5iBAvx2tDpeqPa x1axtuQ84E7Rco2Vg3VjKEvRBLHgd2h7kgIZwNvC2RC4tHeu3k5fizrI0IJLpuo+Bxui fR5kt64PckZC5KfiM7rDnIZFmXzDayvC4kRPWWYRkxWBOvcr9hoMPyQqxVl9yTkb5itJ V3cHUvlgbtSHHPGKhKjcXMGZ/jFAyJricyZAkGCS2EH7klMhEXQ4RImb+cxj0pejdAGc tO5imJcxIlNH4iw47ArLS/Z2NReC5lg45qAR7Yu6+WV5YWxBGzy/LbgfoHLMY5FsZ/FX EgtQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=6zNjOkpCVoYdq5SpvfJCUuoFxEeE/HXUKkYfS/pJSPQ=; b=kcoIKxDiZrmG/L7ytCCgRAIgy3KM9rtdsgvA/7jLm73DXQo4s409uha5jmMPkclrs9 woY7FCOVpvvf2mnk26ODUwmLevRM+ZXv6dxbiuPFXcXigzKS6xAxjqdxhY8ue1YYTVGe 8SySvFo84t42/Eq6Jls5mVjI0qyuha5Du3oAVuIZXNnWvHY/HQykMB+sa3iB53MOSmIq /1EzCDEE/vz5rZJ32GbqOwR/cLeDUhTArNINuClANP1Shivdz+RNP7Ho82RZwFVNayPJ PvCVfy+x5reiCMr2QMzoJ4gnZgjHPq5U5VTeaWGgdSjgvcGdry/EYUenRXmlVPzge6zn WSEg== X-Gm-Message-State: AOAM533WdVL864Prnt2u34AqFsOGOxkJBXfm3TO886iMYTmgfJEid4dm zm+nMYFEii7BAcULBkEiLYYWxyhoRVGdVHmYa/h4Hw== X-Received: by 2002:a9d:69:: with SMTP id 96mr4599418ota.233.1605469508232; Sun, 15 Nov 2020 11:45:08 -0800 (PST) MIME-Version: 1.0 References: <20201115185759.169279-1-98.arpi@gmail.com> <20201115185905.169349-1-98.arpi@gmail.com> In-Reply-To: <20201115185905.169349-1-98.arpi@gmail.com> From: Marco Elver Date: Sun, 15 Nov 2020 20:44:56 +0100 Message-ID: Subject: Re: [PATCH v8 2/2] fs: ext4: Modify inode-test.c to use KUnit parameterized testing feature To: Arpitha Raghunandan <98.arpi@gmail.com> Cc: Brendan Higgins , Shuah Khan , Iurii Zaikin , "Theodore Ts'o" , Andreas Dilger , Tim Bird , David Gow , "open list:KERNEL SELFTEST FRAMEWORK" , KUnit Development , LKML , linux-kernel-mentees@lists.linuxfoundation.org, linux-ext4@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org 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 > --- > 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