@@ -581,6 +581,8 @@ llseek01 llseek01
llseek02 llseek02
llseek03 llseek03
+lremovexattr01 lremovexattr01
+
lseek01 lseek01
lseek02 lseek02
lseek07 lseek07
new file mode 100644
@@ -0,0 +1 @@
+lremovexattr01
new file mode 100644
@@ -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
new file mode 100644
@@ -0,0 +1,140 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2018 Linaro Limited. All rights reserved.
+ * Author: Rafael David Tinoco <rafael.tinoco@linaro.org>
+ */
+
+/*
+ * 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 <errno.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <fcntl.h>
+
+#ifdef HAVE_SYS_XATTR_H
+# include <sys/xattr.h>
+#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("<sys/xattr.h> does not exist");
+#endif
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 <rafael.tinoco@linaro.org> --- 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