From patchwork Thu Aug 9 01:22:12 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rafael David Tinoco X-Patchwork-Id: 955294 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=lists.linux.it (client-ip=2001:1418:10:5::2; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="OZxDUXLY"; dkim-atps=neutral Received: from picard.linux.it (picard.linux.it [IPv6:2001:1418:10:5::2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41m9Tr3kGLz9s1c for ; Thu, 9 Aug 2018 11:22:24 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id C73663E7463 for ; Thu, 9 Aug 2018 03:22:20 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-6.smtp.seeweb.it (in-6.smtp.seeweb.it [217.194.8.6]) by picard.linux.it (Postfix) with ESMTP id A50D03E772B for ; Thu, 9 Aug 2018 03:22:18 +0200 (CEST) Received: from mail-qk0-x241.google.com (mail-qk0-x241.google.com [IPv6:2607:f8b0:400d:c09::241]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by in-6.smtp.seeweb.it (Postfix) with ESMTPS id C8C5414004F4 for ; Thu, 9 Aug 2018 03:22:17 +0200 (CEST) Received: by mail-qk0-x241.google.com with SMTP id c192-v6so2939383qkg.12 for ; Wed, 08 Aug 2018 18:22:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=jo4FizPXEWV0iWI4PFRw8H6B1Mf7cWaeEd23GFbF0SQ=; b=OZxDUXLYFp2vOA8yhNWbN59bZ9ZPh1gFxm2U9q7E7KE0/c4KUxr5I/jJV1EavhPlwy qFFegPW2+mn5L4SIYsrpVMy1m+YF+iB0NxMjrjkRLcXYjWnWP9En/ulmT57TPzSFjlBV Yycletzx+vVzykPygxES8PMObnsrX/aRUlq+Y= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=jo4FizPXEWV0iWI4PFRw8H6B1Mf7cWaeEd23GFbF0SQ=; b=SI20yrt2iIdX5rPpJDzuB6t9St7kYvBbcy5qmU0tQeqSFGYIL5d/pSdnE6LIKekMZS V4TFEirbYi6WmQ9kown0LBGOQpSEMJRsbICV2jIWH8XS8or2AMhEpcyWuj2FsMIfK6Pr H21r/FuAEoY15Okz5wZb4aBj9uyFEDDU1GpcsgPgaovYiHsDtmalpngsZy+TxXKWUV2D w8NECL2qPkgsIBO/4u6KpTDjzDYwB9VU4o9opzULzTflA97nKR6vZ7KezS4WHyZ+Jciy 3wQV6lW6pgIOnDg72hATQ+HcFGM8hd0YsxZ5TheHam0NWsX54baVeSdCu2qgym83Zs4r zeGA== X-Gm-Message-State: AOUpUlEfttV6wIq6PGGleI0Xo4RG3EmXtuFoPJtkOQzMDQ3eKgQc4/Bi 2tN1iycqpL1TdIvrkkgkgYdqhuZKcgA= X-Google-Smtp-Source: AA+uWPyDR62m0atZw1RMTTEw3XGwztnPGboSFcoTIDxdez8z2qjtAW9fdLuorw/8E6SIYcgFL+5uVg== X-Received: by 2002:a37:d60f:: with SMTP id t15-v6mr70144qki.316.1533777736335; Wed, 08 Aug 2018 18:22:16 -0700 (PDT) Received: from mobile.celeiro.br ([138.204.25.2]) by smtp.gmail.com with ESMTPSA id o18-v6sm2697020qtm.84.2018.08.08.18.22.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 08 Aug 2018 18:22:15 -0700 (PDT) From: Rafael David Tinoco To: ltp@lists.linux.it Date: Wed, 8 Aug 2018 22:22:12 -0300 Message-Id: <20180809012212.1884-1-rafael.tinoco@linaro.org> X-Mailer: git-send-email 2.18.0 X-Virus-Scanned: clamav-milter 0.99.2 at in-6.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=0.1 required=7.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,SPF_PASS autolearn=disabled version=3.4.0 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-6.smtp.seeweb.it Cc: chrubis@suze.cz, rafael.tinoco@linaro.org Subject: [LTP] [PATCH] syscalls/setxattr: fix iterations and missing coverage X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.18 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" During issue #274 resolution, the following was observed: setxattr(2) tests are not considering iterations on files that are not re-created in between subsequent iterations. This leads to false results due to existing attributes not cleaned in between the calls. setxattr(2) tests were not considering 2 cases, now added: - new attr with a key with length 0 - new attr with a key that is NULL This commit makes setxattr(2) tests to behave like newly created fsetxattr(2) tests. Signed-off-by: Rafael David Tinoco --- .../kernel/syscalls/setxattr/setxattr01.c | 61 ++++++++++++++++--- .../kernel/syscalls/setxattr/setxattr02.c | 45 +++++++++++--- 2 files changed, 89 insertions(+), 17 deletions(-) diff --git a/testcases/kernel/syscalls/setxattr/setxattr01.c b/testcases/kernel/syscalls/setxattr/setxattr01.c index b9797df2c..c1ac84846 100644 --- a/testcases/kernel/syscalls/setxattr/setxattr01.c +++ b/testcases/kernel/syscalls/setxattr/setxattr01.c @@ -41,6 +41,10 @@ * setxattr(2) should return -1 and set errno to EEXIST * 7. Replace attr value with XATTR_REPLACE flag being set, * setxattr(2) should succeed + * 8. Create new attr whose key length is zero, + * setxattr(2) should return -1 and set errno to ERANGE + * 9. Create new attr whose key is NULL, + * setxattr(2) should return -1 and set errno to EFAULT */ #include "config.h" @@ -79,10 +83,11 @@ struct test_case { size_t size; int flags; int exp_err; + int keyneeded; }; struct test_case tc[] = { { /* case 00, invalid flags */ - .key = long_key, + .key = XATTR_TEST_KEY, .value = &xattr_value, .size = XATTR_TEST_VALUE_SIZE, .flags = ~0, @@ -122,6 +127,7 @@ struct test_case tc[] = { .size = XATTR_TEST_VALUE_SIZE, .flags = XATTR_CREATE, .exp_err = EEXIST, + .keyneeded = 1, }, { /* case 06, replace existing attribute */ .key = XATTR_TEST_KEY, @@ -129,43 +135,77 @@ struct test_case tc[] = { .size = XATTR_TEST_VALUE_SIZE, .flags = XATTR_REPLACE, .exp_err = 0, + .keyneeded = 1, + }, + { /* case 07, zero length key */ + .key = "", + .value = &xattr_value, + .size = XATTR_TEST_VALUE_SIZE, + .flags = XATTR_CREATE, + .exp_err = ERANGE, + }, + { /* case 08, NULL key */ + .value = &xattr_value, + .size = XATTR_TEST_VALUE_SIZE, + .flags = XATTR_CREATE, + .exp_err = EFAULT, }, }; static void verify_setxattr(unsigned int i) { + /* some tests might require existing keys for each iteration */ + if (tc[i].keyneeded) { + SAFE_SETXATTR(FNAME, tc[i].key, tc[i].value, tc[i].size, + XATTR_CREATE); + } + TEST(setxattr(FNAME, tc[i].key, *tc[i].value, tc[i].size, tc[i].flags)); if (TST_RET == -1 && TST_ERR == EOPNOTSUPP) - tst_brk(TCONF, "setxattr() not supported"); + tst_brk(TCONF, "setxattr(2) not supported"); + + /* success */ if (!tc[i].exp_err) { if (TST_RET) { tst_res(TFAIL | TTERRNO, - "setxattr() failed with %li", TST_RET); + "setxattr(2) failed with %li", TST_RET); return; } - tst_res(TPASS, "setxattr() passed"); + /* this is needed for subsequent iterations */ + SAFE_REMOVEXATTR(FNAME, tc[i].key); + + tst_res(TPASS, "setxattr(2) passed"); + return; } if (TST_RET == 0) { - tst_res(TFAIL, "setxattr() passed unexpectedly"); + tst_res(TFAIL, "setxattr(2) passed unexpectedly"); return; } - if (TST_ERR != tc[i].exp_err) { - tst_res(TFAIL | TTERRNO, "setxattr() should fail with %s", + /* error */ + + if (tc[i].exp_err != TST_ERR) { + tst_res(TFAIL | TTERRNO, "setxattr(2) should fail with %s", tst_strerrno(tc[i].exp_err)); return; } - tst_res(TPASS | TTERRNO, "setxattr() failed"); + /* key might have been added AND test might have failed, remove it */ + if (tc[i].keyneeded) + SAFE_REMOVEXATTR(FNAME, tc[i].key); + + tst_res(TPASS | TTERRNO, "setxattr(2) failed"); } static void setup(void) { + size_t i = 0; + snprintf(long_key, 6, "%s", "user."); memset(long_key + 5, 'k', XATTR_NAME_LEN - 5); long_key[XATTR_NAME_LEN - 1] = '\0'; @@ -175,6 +215,11 @@ static void setup(void) long_value[XATTR_SIZE_MAX + 1] = '\0'; SAFE_TOUCH(FNAME, 0644, NULL); + + for (i = 0; i < ARRAY_SIZE(tc); i++) { + if (!tc[i].key) + tc[i].key = tst_get_bad_addr(NULL); + } } static struct tst_test test = { diff --git a/testcases/kernel/syscalls/setxattr/setxattr02.c b/testcases/kernel/syscalls/setxattr/setxattr02.c index aa80c1e5e..b947990b6 100644 --- a/testcases/kernel/syscalls/setxattr/setxattr02.c +++ b/testcases/kernel/syscalls/setxattr/setxattr02.c @@ -64,6 +64,7 @@ #define XATTR_TEST_VALUE "this is a test value" #define XATTR_TEST_VALUE_SIZE 20 +#define OFFSET 10 #define FILENAME "setxattr02testfile" #define DIRNAME "setxattr02testdir" #define SYMLINK "setxattr02symlink" @@ -79,6 +80,7 @@ struct test_case { size_t size; int flags; int exp_err; + int needskeyset; }; static struct test_case tc[] = { { /* case 00, set attr to reg */ @@ -104,6 +106,7 @@ static struct test_case tc[] = { .size = XATTR_TEST_VALUE_SIZE, .flags = XATTR_CREATE, .exp_err = EEXIST, + .needskeyset = 1, }, { /* case 03, set attr to fifo */ .fname = FIFO, @@ -141,34 +144,58 @@ static struct test_case tc[] = { static void verify_setxattr(unsigned int i) { - TEST(setxattr(tc[i].fname, tc[i].key, tc[i].value, tc[i].size, tc[i].flags)); + /* some tests might require existing keys for each iteration */ + if (tc[i].needskeyset) { + SAFE_SETXATTR(tc[i].fname, tc[i].key, tc[i].value, tc[i].size, + XATTR_CREATE); + } + + TEST(setxattr(tc[i].fname, tc[i].key, tc[i].value, tc[i].size, + tc[i].flags)); if (TST_RET == -1 && TST_ERR == EOPNOTSUPP) - tst_brk(TCONF, "setxattr() not supported"); + tst_brk(TCONF, "setxattr(2) not supported"); + + /* success */ if (!tc[i].exp_err) { if (TST_RET) { tst_res(TFAIL | TTERRNO, - "setxattr() failed with %li", TST_RET); + "setxattr(2) on %s failed with %li", + tc[i].fname + OFFSET, TST_RET); return; } - tst_res(TPASS, "setxattr() passed"); + /* this is needed for subsequent iterations */ + SAFE_REMOVEXATTR(tc[i].fname, tc[i].key); + + tst_res(TPASS, "setxattr(2) on %s passed", + tc[i].fname + OFFSET); return; } if (TST_RET == 0) { - tst_res(TFAIL, "setxattr() passed unexpectedly"); + tst_res(TFAIL, "setxattr(2) on %s passed unexpectedly", + tc[i].fname + OFFSET); return; } - if (TST_ERR != tc[i].exp_err) { - tst_res(TFAIL | TTERRNO, "setxattr() should fail with %s", - tst_strerrno(tc[i].exp_err)); + /* fail */ + + if (tc[i].exp_err != TST_ERR) { + tst_res(TFAIL | TTERRNO, + "setxattr(2) on %s should have failed with %s", + tc[i].fname + OFFSET, + tst_strerrno(tc[i].exp_err)); return; } - tst_res(TPASS | TTERRNO, "setxattr() failed"); + /* key might have been added AND test might have failed, remove it */ + if (tc[i].needskeyset) + SAFE_REMOVEXATTR(tc[i].fname, tc[i].key); + + tst_res(TPASS | TTERRNO, "setxattr(2) on %s failed", + tc[i].fname + OFFSET); } static void setup(void)