From patchwork Mon Nov 5 00:25:35 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: 150128 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp1991944ljp; Sun, 4 Nov 2018 16:25:47 -0800 (PST) X-Google-Smtp-Source: AJdET5fovsjCqnH0xOP5BhcYIZQ1oyLxehDqcucKsizzm4MVb0qMEWnE9MJJ8Q8KxNaACcoS6iTS X-Received: by 2002:a17:906:f04:: with SMTP id z4-v6mr7929584eji.106.1541377547108; Sun, 04 Nov 2018 16:25:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541377547; cv=none; d=google.com; s=arc-20160816; b=nAenkUiGnt4yeiv29y2fotwNcXluiKPJ0KtoFOi2BnQ7n+smx/vPmrdTh3HFClpQRj BdchrlEFS1JWPA2ma9JE7FowcutNOcQs9rhQYQm1N+EkG0kWA9oUGjCZ67mLPUD3XzGn toH9FL4iCLgfcJeP17IfsTBPjz8HSe2uswuCt5TiVhYalOIohpcuFufUAnyVpAEF4MXA FyXzK1fG0/qNZPMZE/pkPa4dx2ku2RIYJ+qBl4Rw1GbFjghDvO6HO6FaYhAn2tNwTc2/ wEpE/1vQqUSgHN7WJEu/D3XTOui1xticUh8haQxgJa3KqGL4bzAcV/Aj3MwvnuRPl8+B QSzg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence:subject :cc:mime-version:references:in-reply-to:message-id:date:to:from :dkim-signature:delivered-to; bh=MwJZAMqEedGCgoGHnqsxOT3lspCW7RAytwOf6z2uY98=; b=diymAal6f8G25dWj+Zq6Y0JtoiABP4Fu7J7nA8cg1s1zKC9PzwgsheANKlythFlzmV kV8WpvrBbq9OO79Io1Gaf8SeSrlbZmojc6xIrpa29Eurj9wKRVztYZztW2P1kTQWgOOt 6ozQKJ7wxlA/sYD1ekCmGwmFn0m59nzp5DnBZkTJeGqLZ44C1+NaJybac5otb+YlPkY/ ihkgjdNsZqzFkIv92mijo9k6ZCAd0ymz+IlXHFhtrWNi6zbxsIrk6yk+9rElibcXgdTO 2IxS1K3tpPFfpAwdlsZWpYBR9wm1tutPEx5qQ0ftvB2f974Vd6BcjuCZx8tqkqR5C+T/ 1k0w== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=eCx9tuRi; spf=pass (google.com: domain of ltp-bounces+patch=linaro.org@lists.linux.it designates 213.254.12.146 as permitted sender) smtp.mailfrom="ltp-bounces+patch=linaro.org@lists.linux.it"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from picard.linux.it (picard.linux.it. [213.254.12.146]) by mx.google.com with ESMTPS id r4-v6si8354955edy.231.2018.11.04.16.25.46 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 04 Nov 2018 16:25:47 -0800 (PST) Received-SPF: pass (google.com: domain of ltp-bounces+patch=linaro.org@lists.linux.it designates 213.254.12.146 as permitted sender) client-ip=213.254.12.146; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=eCx9tuRi; spf=pass (google.com: domain of ltp-bounces+patch=linaro.org@lists.linux.it designates 213.254.12.146 as permitted sender) smtp.mailfrom="ltp-bounces+patch=linaro.org@lists.linux.it"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id B20BC3E7845 for ; Mon, 5 Nov 2018 01:25:46 +0100 (CET) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-4.smtp.seeweb.it (in-4.smtp.seeweb.it [IPv6:2001:4b78:1:20::4]) by picard.linux.it (Postfix) with ESMTP id 0DB953E63A8 for ; Mon, 5 Nov 2018 01:25:42 +0100 (CET) Received: from mail-qk1-x741.google.com (mail-qk1-x741.google.com [IPv6:2607:f8b0:4864:20::741]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by in-4.smtp.seeweb.it (Postfix) with ESMTPS id 9093510005EE for ; Mon, 5 Nov 2018 01:25:41 +0100 (CET) Received: by mail-qk1-x741.google.com with SMTP id n12so11969923qkh.11 for ; Sun, 04 Nov 2018 16:25:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=kVBDFGXm2usm4msNjMVlMY3OwCo9PVIe4hRm2GGPWxE=; b=eCx9tuRitz81VFT5M/KMgYVRVEsad0WPU4mAAIV1YWoPnr1GFc06ImGAGlwK0hgU0w +t5VgO/xbawmlu9y5Zr8nDjoNhxZgW4hcdZEIAvO7eoUdpyu+kOlHmlaexlCt9xoUi/t km6ma5E7czSz2XnbEM/rMrTKXc3bF7FkWO+7c= 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=kVBDFGXm2usm4msNjMVlMY3OwCo9PVIe4hRm2GGPWxE=; b=Ar03xCSqjn3PwVTAxwQRCx70BesSYhaGrGDz1uD5jQcVpbpUtWCgmIA+AyHxz+5QbK LvZr2EFKQlXd44nhhF1X8MTHhkTXWCjJemwUV+JLLJsh4GMYFRLLfjfEImeJ+1/FrUXi geDz4j+UFLzxiuMbzw3SnrkqMWUlvyTBPfAYp7+klmI0skzfY8rMFMTwpZX45JfdJCi6 omB6PFYngH85Ppifyv4fIiSaI1WtUTlgYkFSwirD7m6UTuBnJCck3zJvSsGd12fA10J8 AoqwH7f2NZaagHU4ET1RiAh9+jrkQwVRSS9bNCG3o2TUWSrdH7+hjbCgvXCdXFFgdwjF +fZg== X-Gm-Message-State: AGRZ1gJranFj2qStxLNCU74QSqORI+HWE22GtuXFctcmDl2xZH2l+XUj kWi9Y6WizeKhrD8NW73AyOwBdKhP0a00Zkf0 X-Received: by 2002:a0c:e58b:: with SMTP id t11mr19219218qvm.76.1541377540006; Sun, 04 Nov 2018 16:25:40 -0800 (PST) Received: from workstation.celeiro.br ([138.204.25.17]) by smtp.gmail.com with ESMTPSA id p31sm20658279qkh.86.2018.11.04.16.25.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 04 Nov 2018 16:25:39 -0800 (PST) From: Rafael David Tinoco To: ltp@lists.linux.it Date: Sun, 4 Nov 2018 22:25:35 -0200 Message-Id: <20181105002536.29715-1-rafael.tinoco@linaro.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: References: MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.99.2 at in-4.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-4.smtp.seeweb.it Cc: rafael.tinoco@linaro.org Subject: [LTP] [PATCH v2 1/2] syscalls/fremovexattr: Add fremovexattr() tests 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: , Errors-To: ltp-bounces+patch=linaro.org@lists.linux.it Sender: "ltp" Fixes: #276 Following the same logic and tests used to test removexattr() syscall, this commit implements tests for fremovexattr(). It only differs from removexattr() on the given arguments: using a file descriptor instead of the filename. Kernel has different entry points for both, with slightly different execution paths, mainly related to dealing with the passed file descriptor. Signed-off-by: Rafael David Tinoco --- runtest/syscalls | 3 + .../kernel/syscalls/fremovexattr/.gitignore | 2 + .../kernel/syscalls/fremovexattr/Makefile | 8 ++ .../syscalls/fremovexattr/fremovexattr01.c | 106 ++++++++++++++ .../syscalls/fremovexattr/fremovexattr02.c | 130 ++++++++++++++++++ 5 files changed, 249 insertions(+) create mode 100644 testcases/kernel/syscalls/fremovexattr/.gitignore create mode 100644 testcases/kernel/syscalls/fremovexattr/Makefile create mode 100644 testcases/kernel/syscalls/fremovexattr/fremovexattr01.c create mode 100644 testcases/kernel/syscalls/fremovexattr/fremovexattr02.c diff --git a/runtest/syscalls b/runtest/syscalls index 2ac9f7665..c48ada707 100644 --- a/runtest/syscalls +++ b/runtest/syscalls @@ -319,6 +319,9 @@ fork14 fork14 fpathconf01 fpathconf01 +fremovexattr01 fremovexattr01 +fremovexattr02 fremovexattr02 + fstat01 fstat01 fstat01_64 fstat01_64 fstat02 fstat02 diff --git a/testcases/kernel/syscalls/fremovexattr/.gitignore b/testcases/kernel/syscalls/fremovexattr/.gitignore new file mode 100644 index 000000000..455a9db2e --- /dev/null +++ b/testcases/kernel/syscalls/fremovexattr/.gitignore @@ -0,0 +1,2 @@ +fremovexattr01 +fremovexattr02 diff --git a/testcases/kernel/syscalls/fremovexattr/Makefile b/testcases/kernel/syscalls/fremovexattr/Makefile new file mode 100644 index 000000000..f71e4fc25 --- /dev/null +++ b/testcases/kernel/syscalls/fremovexattr/Makefile @@ -0,0 +1,8 @@ +# Copyright (c) 2018 - Linaro Limited. All rights reserved. +# SPDX-License-Identifier: GPL-2.0-or-later + +top_srcdir ?= ../../../.. + +include $(top_srcdir)/include/mk/testcases.mk + +include $(top_srcdir)/include/mk/generic_leaf_target.mk \ No newline at end of file diff --git a/testcases/kernel/syscalls/fremovexattr/fremovexattr01.c b/testcases/kernel/syscalls/fremovexattr/fremovexattr01.c new file mode 100644 index 000000000..543016f01 --- /dev/null +++ b/testcases/kernel/syscalls/fremovexattr/fremovexattr01.c @@ -0,0 +1,106 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2018 Linaro Limited. All rights reserved. + * Author: Rafael David Tinoco + */ + +/* + * Test Name: fremovexattr01 + * + * Description: + * Like removexattr(2), fremovexattr(2) also removes an extended attribute, + * identified by a name, from a file but, instead of using a filename path, it + * uses a descriptor. This test verifies that a simple call to fremovexattr(2) + * removes, indeed, a previously set attribute key/value from a file. + */ + +#include "config.h" +#include +#include + +#ifdef HAVE_SYS_XATTR_H +# include +#endif + +#include "tst_test.h" + +#ifdef HAVE_SYS_XATTR_H + +#define ENOATTR ENODATA + +#define XATTR_TEST_KEY "user.testkey" +#define XATTR_TEST_VALUE "this is a test value" +#define XATTR_TEST_VALUE_SIZE 20 + +#define MNTPOINT "mntpoint" +#define FNAME MNTPOINT"/fremovexattr01testfile" + +static int fd = -1; +static char *got_value; + +static void verify_fremovexattr(void) +{ + SAFE_FSETXATTR(fd, XATTR_TEST_KEY, XATTR_TEST_VALUE, + XATTR_TEST_VALUE_SIZE, XATTR_CREATE); + + TEST(fremovexattr(fd, XATTR_TEST_KEY)); + + if (TST_RET != 0) { + tst_res(TFAIL | TTERRNO, "fremovexattr(2) failed"); + return; + } + + memset(got_value, 0, XATTR_TEST_VALUE_SIZE); + + TEST(fgetxattr(fd, XATTR_TEST_KEY, got_value, XATTR_TEST_VALUE_SIZE)); + + if (TST_RET >= 0) { + tst_res(TFAIL, "fremovexattr(2) did not remove attribute"); + return; + } + + if (TST_RET < 0 && TST_ERR != ENOATTR) { + tst_brk(TBROK, "fremovexattr(2) could not verify removal"); + return; + } + + tst_res(TPASS, "fremovexattr(2) removed attribute as expected"); +} + +static void cleanup(void) +{ + free(got_value); + + close(fd); +} + +static void setup(void) +{ + SAFE_TOUCH(FNAME, 0644, NULL); + + fd = SAFE_OPEN(FNAME, O_RDWR, NULL); + + TEST(fremovexattr(fd, XATTR_TEST_KEY)); + + if (TST_RET == -1 && TST_ERR == EOPNOTSUPP) { + tst_brk(TCONF, "fremovexattr(2) not supported"); + return; + } + + got_value = SAFE_MALLOC(XATTR_TEST_VALUE_SIZE); +} + +static struct tst_test test = { + .setup = setup, + .test_all = verify_fremovexattr, + .cleanup = cleanup, + .mntpoint = MNTPOINT, + .mount_device = 1, + .all_filesystems = 1, + .needs_tmpdir = 1, + .needs_root = 1, +}; + +#else /* HAVE_SYS_XATTR_H */ +TST_TEST_TCONF(" does not exist"); +#endif diff --git a/testcases/kernel/syscalls/fremovexattr/fremovexattr02.c b/testcases/kernel/syscalls/fremovexattr/fremovexattr02.c new file mode 100644 index 000000000..5585b6abe --- /dev/null +++ b/testcases/kernel/syscalls/fremovexattr/fremovexattr02.c @@ -0,0 +1,130 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2018 Linaro Limited. All rights reserved. + * Author: Rafael David Tinoco + */ + +/* + * Test Name: fremovexattr02 + * + * Test cases:: + * 1) fremovexattr(2) fails if the named attribute does not exist. + * 2) fremovexattr(2) fails if file descriptor is not valid. + * 3) fremovexattr(2) fails if named attribute has an invalid address. + * + * Expected Results: + * fremovexattr(2) should return -1 and set errno to ENODATA. + * fremovexattr(2) should return -1 and set errno to EBADF. + * fremovexattr(2) should return -1 and set errno to EFAULT. + */ + +#include "config.h" +#include +#include +#include +#include + +#ifdef HAVE_SYS_XATTR_H +# include +#endif + +#include "tst_test.h" + +#ifdef HAVE_SYS_XATTR_H + +#define XATTR_TEST_KEY "user.testkey" + +#define MNTPOINT "mntpoint" +#define FNAME MNTPOINT"/fremovexattr02testfile" + +static int fd = -1; + +struct test_case { + int fd; + char *key; + char *value; + char *gotvalue; + int size; + int exp_ret; + int exp_err; +}; + +struct test_case tc[] = { + { /* case 1: attribute does not exist */ + .key = XATTR_TEST_KEY, + .exp_ret = -1, + .exp_err = ENODATA, + }, + { /* case 2: file descriptor is invalid */ + .fd = -1, + .key = XATTR_TEST_KEY, + .exp_ret = -1, + .exp_err = EBADF, + }, + { /* case 3: bad name attribute */ + .exp_ret = -1, + .exp_err = EFAULT, + }, +}; + +static void verify_fremovexattr(unsigned int i) +{ + TEST(fremovexattr(tc[i].fd, tc[i].key)); + + if (TST_RET == -1 && TST_ERR == EOPNOTSUPP) + tst_brk(TCONF, "fremovexattr(2) not supported"); + + if (tc[i].exp_ret == TST_RET) { + + if (tc[i].exp_err) { + if (tc[i].exp_err == TST_ERR) { + tst_res(TPASS, "fremovexattr(2) passed"); + return; + } + } else { + tst_res(TPASS, "fremovexattr(2) passed"); + return; + } + } + + tst_res(TFAIL | TTERRNO, "fremovexattr(2) failed"); +} + +static void cleanup(void) +{ + if (fd > 0) + SAFE_CLOSE(fd); +} + +static void setup(void) +{ + size_t i = 0; + + SAFE_TOUCH(FNAME, 0644, NULL); + fd = SAFE_OPEN(FNAME, O_RDWR, NULL); + + for (i = 0; i < ARRAY_SIZE(tc); i++) { + + if (tc[i].fd != -1) + tc[i].fd = fd; + + if (!tc[i].key && tc[i].exp_err == EFAULT) + tc[i].key = tst_get_bad_addr(cleanup); + } +} + +static struct tst_test test = { + .setup = setup, + .test = verify_fremovexattr, + .cleanup = cleanup, + .tcnt = ARRAY_SIZE(tc), + .mntpoint = MNTPOINT, + .mount_device = 1, + .all_filesystems = 1, + .needs_tmpdir = 1, + .needs_root = 1, +}; + +#else /* HAVE_SYS_XATTR_H */ +TST_TEST_TCONF(" does not exist"); +#endif From patchwork Mon Nov 5 00:25:36 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: 150129 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp1992002ljp; Sun, 4 Nov 2018 16:25:51 -0800 (PST) X-Google-Smtp-Source: AJdET5dfNOS+wvupKWxuEiwK3Cf+joyESpF9enTm5ALt4A1MWfBAHKU2waYySWox2qyHy5VD/9L6 X-Received: by 2002:a50:b0e5:: with SMTP id j92-v6mr15970838edd.294.1541377551408; Sun, 04 Nov 2018 16:25:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541377551; cv=none; d=google.com; s=arc-20160816; b=AsEww1giCQcX+duer4ETwNPEJi0J86pajBsb2WMb5FnzzsGKzFHajJa9hnaVCwfOag xEl+pVvgwRz70KaHt2Y2RAnpSrUB+7sFoktjFhNxR5FLIJb3le9HfUUXF/b5+mK8eWTJ G62ylKGVgCK/FL9ziC1Rs0P1io3YkVl4i3yNnZU93QNuSp6j9GcPhF9/n0rPrJSuYnrk IRkBuuXy7gBCZemLOqqtIJxf2Fxgyap85vjJ8uv/XN4D1eOdfyVbrbsNKWG3Is0kPCdl CMM5HQwXpYFbyMr2CDtsxSrAbMOF0QN8s4kA4MXP+ILyPPFpISy1NtevxPLE3KvGDXFC 0nzA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence:subject :cc:mime-version:references:in-reply-to:message-id:date:to:from :dkim-signature:delivered-to; bh=Sx2yMA96U5Fn5OfAn7nfwZB5xmdrwOd93I63MuO5gEI=; b=Dllq1jVLWLZIE1PeLAIwHxd4dRIOF8t+dJsto6htiSgQjaJq2X3IrXJSmmvFQrECYj w1qGyR16qVvbxaMyw0o+m4ayc6oK+bWMe3e6XBtFReB9k1n+gDKjzuJ7o1usxCdnn1An f0dydtRN1ORLxGzhCuSeSPqH+7r/j7Rw7GjbRh0yrvTAvWV+l3KMfp+18UcEF50BMrPI omrgMtLTx5ExfLMPIcPzGuE7bfi8omRzP7r0h/uaZcU5zHOyL6cXPzoTg8yfcxJaRJ4j otJQjR2FkAzGepP4aASZPupNFwEeM995nuIMEnai0ol0qBFEkHPAuvdou2RDWqu2rR8m 6oMQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=PFC2T2tC; spf=pass (google.com: domain of ltp-bounces+patch=linaro.org@lists.linux.it designates 2001:1418:10:5::2 as permitted sender) smtp.mailfrom="ltp-bounces+patch=linaro.org@lists.linux.it"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from picard.linux.it (picard.linux.it. [2001:1418:10:5::2]) by mx.google.com with ESMTPS id v26-v6si3273495edb.95.2018.11.04.16.25.51 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 04 Nov 2018 16:25:51 -0800 (PST) Received-SPF: pass (google.com: domain of ltp-bounces+patch=linaro.org@lists.linux.it designates 2001:1418:10:5::2 as permitted sender) client-ip=2001:1418:10:5::2; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=PFC2T2tC; spf=pass (google.com: domain of ltp-bounces+patch=linaro.org@lists.linux.it designates 2001:1418:10:5::2 as permitted sender) smtp.mailfrom="ltp-bounces+patch=linaro.org@lists.linux.it"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 133363E78F9 for ; Mon, 5 Nov 2018 01:25:51 +0100 (CET) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-3.smtp.seeweb.it (in-3.smtp.seeweb.it [217.194.8.3]) by picard.linux.it (Postfix) with ESMTP id D0F083E63A8 for ; Mon, 5 Nov 2018 01:25:43 +0100 (CET) Received: from mail-qk1-x741.google.com (mail-qk1-x741.google.com [IPv6:2607:f8b0:4864:20::741]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by in-3.smtp.seeweb.it (Postfix) with ESMTPS id DBE691A00376 for ; Mon, 5 Nov 2018 01:25:42 +0100 (CET) Received: by mail-qk1-x741.google.com with SMTP id d19so12025304qkg.5 for ; Sun, 04 Nov 2018 16:25:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=OgAwMcMPzlxDnHzO/OFG1VVLe+f+skMZsoHuBLpF0qk=; b=PFC2T2tCwjHDuwwynhqRLq2TDx6o7ZqkAcXTw6yXJf28PiLktXh1cX20vfMkAiHYSW y//sa+FfMik/11msKbf7KcFsvnc4OJ5ZS6JagqlvaXlbxJGVMSdcchEr4U7k2benN+DY ldF32zkBDLSzLd0r+s8CPiDOwmt4deCItDGps= 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=OgAwMcMPzlxDnHzO/OFG1VVLe+f+skMZsoHuBLpF0qk=; b=TPvdYxPeiZRYFY6T+sknMp3zkg/gI73clpr52rFAlHx8uqK7J24VC9Lk8NLrlm4AdT b0n6ljCD/+mZbA7ICXRd+aIUQVLZmPQqu74Z+weqqiiEER03s9oKLNjovsh5fmwM2218 fVp32MmGWr3cGjG/Zy3C3/WVRjAAbqiIj17Tgl22/Dr7+5mWW3xLAelY3QlizHYMUoSd kdGagBpnGvBhvYWjTlNdKpMbHPcFmrWdoI4BjEbG7iyDvPWMwCro+RI6iVEnGI+O4VLF uEwfGP2h5JfQfMY9zVBKzVrw1XQFTRt4pWA7lx5S+x/u2YPP2jIO3I4yZWSaepsIJaOv Nq4A== X-Gm-Message-State: AGRZ1gKTStFh/dShG3OdAtuGXi/8R/JeEfH76wlQbcfuF7DUQ1lGBbsn RlaXJUyXreJOFB4bILbzNTUIUIfzxSTSV3W9 X-Received: by 2002:a0c:d933:: with SMTP id p48mr20044542qvj.15.1541377541480; Sun, 04 Nov 2018 16:25:41 -0800 (PST) Received: from workstation.celeiro.br ([138.204.25.17]) by smtp.gmail.com with ESMTPSA id p31sm20658279qkh.86.2018.11.04.16.25.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 04 Nov 2018 16:25:41 -0800 (PST) From: Rafael David Tinoco To: ltp@lists.linux.it Date: Sun, 4 Nov 2018 22:25:36 -0200 Message-Id: <20181105002536.29715-2-rafael.tinoco@linaro.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181105002536.29715-1-rafael.tinoco@linaro.org> References: <20181105002536.29715-1-rafael.tinoco@linaro.org> MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.99.2 at in-3.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-3.smtp.seeweb.it Cc: rafael.tinoco@linaro.org Subject: [LTP] [PATCH v2 2/2] syscalls/lremovexattr: Add lremovexattr() test 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: , Errors-To: ltp-bounces+patch=linaro.org@lists.linux.it Sender: "ltp" Fixes: #276 This commit implements a test for lremovexattr(). According to attr(5), extended attributes are interpreted differently among files, directories and symbolic links. User attributes are only allowed for regular files and directories, thus the need to test security.* attributes being removed from symbolic links. Signed-off-by: Rafael David Tinoco --- runtest/syscalls | 2 + .../kernel/syscalls/lremovexattr/.gitignore | 1 + .../kernel/syscalls/lremovexattr/Makefile | 8 + .../syscalls/lremovexattr/lremovexattr01.c | 140 ++++++++++++++++++ 4 files changed, 151 insertions(+) create mode 100644 testcases/kernel/syscalls/lremovexattr/.gitignore create mode 100644 testcases/kernel/syscalls/lremovexattr/Makefile create mode 100644 testcases/kernel/syscalls/lremovexattr/lremovexattr01.c diff --git a/runtest/syscalls b/runtest/syscalls index c48ada707..77a36b1f5 100644 --- a/runtest/syscalls +++ b/runtest/syscalls @@ -581,6 +581,8 @@ llseek01 llseek01 llseek02 llseek02 llseek03 llseek03 +lremovexattr01 lremovexattr01 + lseek01 lseek01 lseek02 lseek02 lseek07 lseek07 diff --git a/testcases/kernel/syscalls/lremovexattr/.gitignore b/testcases/kernel/syscalls/lremovexattr/.gitignore new file mode 100644 index 000000000..810f86214 --- /dev/null +++ b/testcases/kernel/syscalls/lremovexattr/.gitignore @@ -0,0 +1 @@ +lremovexattr01 diff --git a/testcases/kernel/syscalls/lremovexattr/Makefile b/testcases/kernel/syscalls/lremovexattr/Makefile new file mode 100644 index 000000000..f71e4fc25 --- /dev/null +++ b/testcases/kernel/syscalls/lremovexattr/Makefile @@ -0,0 +1,8 @@ +# Copyright (c) 2018 - Linaro Limited. All rights reserved. +# SPDX-License-Identifier: GPL-2.0-or-later + +top_srcdir ?= ../../../.. + +include $(top_srcdir)/include/mk/testcases.mk + +include $(top_srcdir)/include/mk/generic_leaf_target.mk \ No newline at end of file diff --git a/testcases/kernel/syscalls/lremovexattr/lremovexattr01.c b/testcases/kernel/syscalls/lremovexattr/lremovexattr01.c new file mode 100644 index 000000000..3084cd318 --- /dev/null +++ b/testcases/kernel/syscalls/lremovexattr/lremovexattr01.c @@ -0,0 +1,140 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2018 Linaro Limited. All rights reserved. + * Author: Rafael David Tinoco + */ + +/* + * Test Name: lremovexattr01 + * + * Description: + * lremovexattr(2) removes the extended attribute identified by a name and + * associated with a given path in the filesystem. Unlike removexattr(2), + * lremovexattr(2) removes the attribute from the symbolic link only, and not + * the file. This test verifies that a simple call to lremovexattr(2) removes, + * indeed, a previously set attribute key/value from a symbolic link, and the + * symbolic link _only_. + * + * Note: + * According to attr(5), extended attributes are interpreted differently from + * regular files, directories and symbolic links. User attributes are only + * allowed for regular files and directories, thus the need of using security.* + * attributes for this test. + */ + +#include "config.h" +#include +#include +#include +#include +#include + +#ifdef HAVE_SYS_XATTR_H +# include +#endif + +#include "tst_test.h" + +#ifdef HAVE_SYS_XATTR_H + +#define ENOATTR ENODATA + +#define XATTR_KEY "security.key1" +#define XATTR_VALUE "file and link" +#define XATTR_VALUE_SIZE 13 + +#define MNTPOINT "mntpoint" +#define FILENAME MNTPOINT"/lremovexattr01testfile" +#define SYMLINK MNTPOINT"/lremovexattr01symlink" + +static char *got_value; + +static void verify_lremovexattr(void) +{ + /* set attribute on both: file and symlink */ + + SAFE_SETXATTR(FILENAME, XATTR_KEY, XATTR_VALUE, XATTR_VALUE_SIZE, + XATTR_CREATE); + + SAFE_LSETXATTR(SYMLINK, XATTR_KEY, XATTR_VALUE, XATTR_VALUE_SIZE, + XATTR_CREATE); + + /* remove attribute from symlink only */ + + TEST(lremovexattr(SYMLINK, XATTR_KEY)); + + if (TST_RET != 0) { + tst_res(TFAIL | TTERRNO, "lremovexattr(2) failed"); + return; + } + + /* make sure attribute is gone from symlink */ + + memset(got_value, 0, XATTR_VALUE_SIZE); + + TEST(lgetxattr(SYMLINK, XATTR_KEY, got_value, XATTR_VALUE_SIZE)); + + if (TST_RET >= 0) { + tst_res(TFAIL, "lremovexattr(2) did not work"); + return; + } + + if (TST_RET < 0 && TST_ERR != ENOATTR) { + tst_brk(TBROK, "lgetxattr(2) failed unexpectedly"); + return; + } + + /* check if file is unchanged, like it should be */ + + memset(got_value, 0, XATTR_VALUE_SIZE); + + TEST(getxattr(FILENAME, XATTR_KEY, got_value, XATTR_VALUE_SIZE)); + + if (TST_RET <= 0) { + tst_res(TFAIL, "lremovexattr(2) deleted file attribute"); + return; + } + + if (strcmp(got_value, XATTR_VALUE)) { + tst_res(TFAIL, "lremovexattr(2) changed file attribute"); + return; + } + + /* cleanup file attribute for iteration */ + + SAFE_REMOVEXATTR(FILENAME, XATTR_KEY); + + tst_res(TPASS, "lremovexattr(2) removed attribute as expected"); +} + +static void cleanup(void) +{ + free(got_value); +} + +static void setup(void) +{ + SAFE_TOUCH(FILENAME, 0644, NULL); + + if (symlink(FILENAME, SYMLINK) < 0) { + tst_brk(TCONF, "symlink() not supported"); + return; + } + + got_value = SAFE_MALLOC(XATTR_VALUE_SIZE); +} + +static struct tst_test test = { + .setup = setup, + .test_all = verify_lremovexattr, + .cleanup = cleanup, + .mntpoint = MNTPOINT, + .mount_device = 1, + .all_filesystems = 1, + .needs_tmpdir = 1, + .needs_root = 1, +}; + +#else /* HAVE_SYS_XATTR_H */ +TST_TEST_TCONF(" does not exist"); +#endif