kdbus-test: add seclabel: test whether SECLABEL is properly updated on every call...
authorKonrad Lipinski <konrad.l@samsung.com>
Mon, 28 Nov 2016 15:27:54 +0000 (16:27 +0100)
committerKonrad Lipinski <konrad.l@samsung.com>
Mon, 28 Nov 2016 15:27:54 +0000 (16:27 +0100)
tools/testing/selftests/kdbus/kdbus-test.c
tools/testing/selftests/kdbus/kdbus-test.h
tools/testing/selftests/kdbus/test-match.c

index 90dbd107cae1193cd19baea5cc2805014b5ad0bd..2a2e14e6f071d8c0beeefbfaae1d2d242058a5be 100644 (file)
@@ -202,6 +202,13 @@ static const struct kdbus_test tests[] = {
                .flags  = TEST_CREATE_BUS | TEST_CREATE_CONN,
                .timeout = 10,
        },
+       {
+               .name   = "seclabel",
+               .desc   = "dynamic seclabel change for messages and CONN_INFO",
+               .func   = kdbus_test_dynamic_seclabel,
+               .flags  = TEST_CREATE_BUS | TEST_CREATE_CONN,
+               .timeout = 10,
+       },
        {
                .name   = "message-free",
                .desc   = "freeing of memory",
index f2c955ac30045a94ab346badda3c8ec277d56160..9b2b281ca52c98e8433442663d2ffd3c50b40f76 100644 (file)
@@ -108,6 +108,7 @@ wur int kdbus_test_policy_priv(struct kdbus_test_env *env);
 wur int kdbus_test_sync_byebye(struct kdbus_test_env *env);
 wur int kdbus_test_sync_reply(struct kdbus_test_env *env);
 wur int kdbus_test_big_metadata(struct kdbus_test_env *env);
+wur int kdbus_test_dynamic_seclabel(struct kdbus_test_env *env);
 wur int kdbus_test_timeout(struct kdbus_test_env *env);
 wur int kdbus_test_writable_pool(struct kdbus_test_env *env);
 
index 6c35baf25d4273833342aa57d891caf7eefa2daa..323bb4278e3dc49a79385978cb081efe1a4463bb 100644 (file)
@@ -578,3 +578,45 @@ wur int kdbus_test_match_itemless(struct kdbus_test_env *env)
 
        return TEST_OK;
 }
+
+static wur int assert_label(char const *label, struct kdbus_item const *item)
+{
+       while (KDBUS_ITEM_SECLABEL != item->type)
+               item = KDBUS_ITEM_NEXT(item);
+       ASSERT_ZERO(strcmp(item->str, label));
+       return TEST_OK;
+}
+
+wur int kdbus_test_dynamic_seclabel(struct kdbus_test_env *env)
+{
+       char const *labels[] = {"System::Privileged", "UserTest"};
+       unsigned i;
+       for (i=TABSIZE(labels); --i;) {
+               char const *label = labels[i];
+               int fd = open("/proc/self/attr/current", O_RDWR);
+               ASSERT_RETURN(fd,>=,0);
+               int l = strlen(label);
+               ASSERT_NONZERO(l);
+               ASSERT_RETURN(l,==,write(fd, label, l));
+               ASSERT_ZERO(close(fd));
+
+               {
+                       struct kdbus_msg *msg;
+                       ASSERT_ZERO(kdbus_msg_send(env->conn, NULL, 1, 0, 0, 0, env->conn->id));
+                       ASSERT_ZERO(kdbus_msg_recv(env->conn, &msg, NULL));
+                       ASSERT_ZERO(assert_label(label, msg->items));
+                       kdbus_msg_free(msg);
+               }
+
+               {
+                       uint64_t offset = 0;
+                       ASSERT_ZERO(kdbus_conn_info(env->conn, env->conn->id, NULL, KDBUS_ATTACH_SECLABEL, &offset));
+                       struct kdbus_info *info = (struct kdbus_info *)(env->conn->buf + offset);
+                       ASSERT_RETURN(info->id,==,env->conn->id);
+                       ASSERT_ZERO(assert_label(label, info->items));
+                       ASSERT_ZERO(kdbus_free(env->conn, offset));
+               }
+       }
+
+       return TEST_OK;
+}