From patchwork Thu Nov 8 18:33:19 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: 150567 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp1176490ljp; Thu, 8 Nov 2018 10:33:30 -0800 (PST) X-Google-Smtp-Source: AJdET5e9EdgvL/MndbrLi04mks7VRRExmtcvmWZ9ouXQY/3POu/DIfSR28Ko2H/vmZ1MyW9BdfXn X-Received: by 2002:a1c:568b:: with SMTP id k133-v6mr2281458wmb.4.1541702010791; Thu, 08 Nov 2018 10:33:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541702010; cv=none; d=google.com; s=arc-20160816; b=esJMmTlYP0EeWnOe8OUffWrcTWn28ZE5pBNOEJuitGx99ipBBkBDCwax3QsO2Te/WA hE7HldkCiSnCQwshc+cVHbnsH9z7mxNpt8HhW3W4WBIQtQICWnlnhtiPE9EUYZeHuIPc softy6fqZKEDX8LL8N7mRYXeVR8RcbF2gjZnEzSURlCRxybMG+1s3+snbtUwT1Ma1GhW q7Uwb5Rnj0ufbgCALEYjZGyYMAsRjenqbJfC4L6ZUCuusxI3LBMHpCyDRqtN0rZDFwac u/XccmXJjcPpQKFJIZOQWOpoflcLfzdGcTCBNOoRGQ+g94G8xb5kbY9i5rRqhwa6AWUx FdbQ== 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=t7KbuAHKn6rlQrhpFZOnnrdgQsS+5sLcf+JRKyhEuSw=; b=AJkH+RBEvY6FyijXHBdIi4pjgkh7ga736Q+moOXZAM4U8WXakJJBfkf1H9FU3pkY2t Feiu5bmHeQsy4B35Mu4OPCFoMm5ncVpveTbBtAe5MOcllXOtuQrdrbBCocDAhITbYtm/ elvPxD6dMIZ1PC6KfKTs2oUj0+os6SwM5Ccp7fmWzoyGqJVAeLDFGWRbV3q5vX1Zdpn8 xXf0QYgx8zqcVg0H82kYJ1iYWT0KFcTObw1fpaF3SN+mjOLKm5DACwJKwa766soleqnZ WyNSAO8ul8DH0Juq5db93cK8BJFiWc9RcbcKIfx1gKE6y6k915uAh4I56KfQdPJr1yxa 4ciw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=OYhhEwwd; 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 f5-v6si4219663wrh.140.2018.11.08.10.33.30 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 08 Nov 2018 10:33:30 -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=OYhhEwwd; 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 4A8153E7588 for ; Thu, 8 Nov 2018 19:33:30 +0100 (CET) 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 [IPv6:2001:4b78:1:20::6]) by picard.linux.it (Postfix) with ESMTP id 45D303E60C1 for ; Thu, 8 Nov 2018 19:33:27 +0100 (CET) Received: from mail-qk1-x743.google.com (mail-qk1-x743.google.com [IPv6:2607:f8b0:4864:20::743]) (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 15B3E14002BE for ; Thu, 8 Nov 2018 19:33:26 +0100 (CET) Received: by mail-qk1-x743.google.com with SMTP id d19so28249382qkg.5 for ; Thu, 08 Nov 2018 10:33:25 -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=XBeYKpXml6Mw0iynE1LmirLaBch/nurgu6X89LovykQ=; b=OYhhEwwdgpboWUwHFION21vQBZBMZepUIjTsWSaCeykwy8gftzmLueYZ5kEwb7/Nhy PemlqVPMCDtUKYqHxFzw2C1aLZNduSLVuXQJ6RlccMUpS4bXJw6S1funZTV4HnD2kYkq 5u8PeZNWcqWeT4T4W2A62LNVjXfgLuawmo/gA= 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=XBeYKpXml6Mw0iynE1LmirLaBch/nurgu6X89LovykQ=; b=Mr6SXZuy3gj6XQG2A13MIRgvEYSZuqAStChnLgpzCHDASaciCZW0S1/GM2Hl8iEJ04 GW9E3DjCTTUCz/BWNTKBt2pCehRZia6pCbqERzmLUWrbH/LwjA+GfxPAMAzvFsgausHX bmwxUWgvVXFsNqtxjFUzs36iWnXgYjsLkyyLy/08Bi/RVjeQQJqDxubIeSF9OTG+bras ul1hQnXJGbvNfTGAv2UQKRtOsN+snHfNvDPKmvZLqfizXZqalweHO/65XpEG0IAr3DDK k+Q4iducKhGM8V0nogximo5XNJBUsWpjWuF2AvYmK/GQrDNmJnmrm5UzkxPHVpZ9ZA7U 5NVw== X-Gm-Message-State: AGRZ1gKTolCTX+5p6mZ1OY+SerO2IK6V9Itj9RGpdhSKCyEuEz9liygH wx2i6Zv2G+xuJD3ou9XeNM7vqaOZRvmmEWCB X-Received: by 2002:a0c:ace4:: with SMTP id n33mr5638740qvc.79.1541702004392; Thu, 08 Nov 2018 10:33:24 -0800 (PST) Received: from workstation.celeiro.br ([168.194.163.12]) by smtp.gmail.com with ESMTPSA id t128-v6sm2366453qkh.80.2018.11.08.10.33.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 08 Nov 2018 10:33:23 -0800 (PST) From: Rafael David Tinoco To: ltp@lists.linux.it Date: Thu, 8 Nov 2018 16:33:19 -0200 Message-Id: <20181108183320.11262-1-rafael.tinoco@linaro.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181107153855.GA8153@rei> References: <20181107153855.GA8153@rei> MIME-Version: 1.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: rafael.tinoco@linaro.org Subject: [LTP] [PATCH v3 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 | 99 ++++++++++++++ .../syscalls/fremovexattr/fremovexattr02.c | 126 ++++++++++++++++++ 5 files changed, 238 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 95bb47b96..24110b623 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..96b92fb24 --- /dev/null +++ b/testcases/kernel/syscalls/fremovexattr/fremovexattr01.c @@ -0,0 +1,99 @@ +// 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[XATTR_TEST_VALUE_SIZE]; + +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) +{ + if (fd > 0) + SAFE_CLOSE(fd); +} + +static void setup(void) +{ + fd = SAFE_OPEN(FNAME, O_RDWR | O_CREAT, 0644); + + TEST(fremovexattr(fd, XATTR_TEST_KEY)); + + if (TST_RET == -1 && TST_ERR == EOPNOTSUPP) + tst_brk(TCONF, "fremovexattr(2) not supported"); +} + +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..8eb1e9a99 --- /dev/null +++ b/testcases/kernel/syscalls/fremovexattr/fremovexattr02.c @@ -0,0 +1,126 @@ +// 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; + 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; + + fd = SAFE_OPEN(FNAME, O_RDWR | O_CREAT, 0644); + + 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 Thu Nov 8 18:33:20 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: 150568 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp1176542ljp; Thu, 8 Nov 2018 10:33:35 -0800 (PST) X-Google-Smtp-Source: AJdET5f0PE7Wl+pnOZr22IQ5LwQn0xVn7OctY+dOwznRFC0pi6jC3Zmlz9yHz2Shz8w/mk4GsTgu X-Received: by 2002:a50:8b61:: with SMTP id l88-v6mr4879323edl.52.1541702015508; Thu, 08 Nov 2018 10:33:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541702015; cv=none; d=google.com; s=arc-20160816; b=SOmOj5gkUmRu1gNntrzjzYoISYxhMjQGXzy26t9nllXbtFxK4ohihhfKGdvq+lrv5K qVEmpTpnwkeM67ij4lB9Gl+d3xNr8WoWIQ9WgfpEk/Q0ysRoGx41xSCDB0Wpzp3YFj1G yqkrNCaJnT4jI+a4l+Iaj/BtCQauajS07MFqVHoLpbvtVrwJ6wgbtwGq5VftwXW3i6Hs aykv3FW9MGrp8LqLe839+T5uSYqg+pMleiZzJ4eDOX72cVGsBikIB/s7Q+bfx+YRtNCC ilmB90T4NsmZCgbQq4ZFnY6BrnVmvdkkBoP8thJwV0jfv8jSgAD6q1derDxcjjxE6839 3Yrg== 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=Rtyg1owuhIYtV9JduXFSlGgkTpdrdBKjup5Y57LQfHY=; b=nQbsMlTowmqMPtEt4Z0FxSeyKpLIm/W6h2pQfVhwbMu3QBLaebPpKubmcFEc1IP+pN eUnT/8u5HUE97rEk+r4YDMx7mRjzVH2rKcsXiltH9SLSh6L0T0EdPC3BlpItWsP8TLow MjuPW8l5ZMKzjcwqmag0kM6sBiCK8VgyGBLmQVvNcS6Rv9I+uZ6zaMslpJMR9yejhHAX /AWlOQlT3tvwC8bxuRkmhkQjLfdkQKbTlxLtE2eqG1NyQZnHSKY2Z2WfodOG1PIC7zyc P7Xq7YnR5BWSFmbAUUe6Do6ZBrzCmGjikAuc0C5bC1LYD6jMd3dguk4oHvTMyuagydjf F9Yw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=baPo2smH; 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 y16-v6si2835967edm.418.2018.11.08.10.33.35 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 08 Nov 2018 10:33:35 -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=baPo2smH; 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 2062C3E769B for ; Thu, 8 Nov 2018 19:33:35 +0100 (CET) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-5.smtp.seeweb.it (in-5.smtp.seeweb.it [IPv6:2001:4b78:1:20::5]) by picard.linux.it (Postfix) with ESMTP id D9DCC3E6CBC for ; Thu, 8 Nov 2018 19:33:28 +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-5.smtp.seeweb.it (Postfix) with ESMTPS id D85B3600748 for ; Thu, 8 Nov 2018 19:33:27 +0100 (CET) Received: by mail-qk1-x741.google.com with SMTP id n12so28186040qkh.11 for ; Thu, 08 Nov 2018 10:33:27 -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=ZAqIu5I3ZCyHXi8HqDEQhN/A0NJX37j/IXD3i41d+qo=; b=baPo2smHZefkRs/gcxb7Pfv93+bzp7tgHu/H9xDaSFyhlm2B7c8o/nmpJezlNDtQFW 2q21dpFsfHVv+teIK9ETTKPIiq19ehO+KK9oDrzN7OMxMm7rxAn+AJCGiCgocJHIcVzu /BnxGXqIFOAqix8a3JOGYC5NemHRrESsEGzW4= 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=ZAqIu5I3ZCyHXi8HqDEQhN/A0NJX37j/IXD3i41d+qo=; b=UzqiRMyf8KNByEzse2G7LjQqSUxrMmilyPOArAxODpDPN3oP/fmmIwuNtMiwsGjBJw 7wOc8lo38s0aGUJ2kGgZjNRCm2yarwWBIxQgWENbB/suuL6fSPHBU6MStw3ZPgoCanbG rgO3PV5+rqs9BKwUzKXJKeFMwkQj+Opy1hmoqYs+v2bR2J//hPIj5s9x3HjpflSBR/oB S5JEuFQJtJNks4JlKOgop/UR8oyUreJ83NsdvfFOxY5cRCn6qlwzwRmcuIVr5fk28gY3 +rzWIGw7rrHkVRhsskMzD9FXDuIQ9NAsVwQ1SdlRCPpzk9y5MrqFZFpeo7MPTjj+cQJl q2lw== X-Gm-Message-State: AGRZ1gInAXYELgBbYolGCEZ3BlesxX4quErwSUxY96WayRHvwmLi9wXV IXXymO/+Vqmpd0ncHrEDIBzzB2CnmReF5s4T X-Received: by 2002:a0c:8c8a:: with SMTP id p10mr5668531qvb.218.1541702006372; Thu, 08 Nov 2018 10:33:26 -0800 (PST) Received: from workstation.celeiro.br ([168.194.163.12]) by smtp.gmail.com with ESMTPSA id t128-v6sm2366453qkh.80.2018.11.08.10.33.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 08 Nov 2018 10:33:25 -0800 (PST) From: Rafael David Tinoco To: ltp@lists.linux.it Date: Thu, 8 Nov 2018 16:33:20 -0200 Message-Id: <20181108183320.11262-2-rafael.tinoco@linaro.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181108183320.11262-1-rafael.tinoco@linaro.org> References: <20181107153855.GA8153@rei> <20181108183320.11262-1-rafael.tinoco@linaro.org> MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.99.2 at in-5.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-5.smtp.seeweb.it Cc: rafael.tinoco@linaro.org Subject: [LTP] [PATCH v3 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 | 132 ++++++++++++++++++ 4 files changed, 143 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 24110b623..26c142bf8 100644 --- a/runtest/syscalls +++ b/runtest/syscalls @@ -582,6 +582,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..2cf46ebdf --- /dev/null +++ b/testcases/kernel/syscalls/lremovexattr/lremovexattr01.c @@ -0,0 +1,132 @@ +// 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[XATTR_VALUE_SIZE]; + +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 setup(void) +{ + SAFE_TOUCH(FILENAME, 0644, NULL); + + if (symlink(FILENAME, SYMLINK) < 0) { + tst_brk(TCONF, "symlink() not supported"); + return; + } +} + +static struct tst_test test = { + .setup = setup, + .test_all = verify_lremovexattr, + .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