1 // SPDX-License-Identifier: GPL-2.0
3 * Linux Security Module infrastructure tests
4 * Tests for the lsm_set_self_attr system call
6 * Copyright © 2022 Casey Schaufler <casey@schaufler-ca.com>
10 #include <linux/lsm.h>
14 #include <sys/types.h>
15 #include "../kselftest_harness.h"
18 TEST(ctx_null_lsm_set_self_attr
)
20 ASSERT_EQ(-1, lsm_set_self_attr(LSM_ATTR_CURRENT
, NULL
,
21 sizeof(struct lsm_ctx
), 0));
24 TEST(size_too_small_lsm_set_self_attr
)
26 const long page_size
= sysconf(_SC_PAGESIZE
);
27 struct lsm_ctx
*ctx
= calloc(page_size
, 1);
28 __u32 size
= page_size
;
31 if (attr_lsm_count()) {
32 ASSERT_LE(1, lsm_get_self_attr(LSM_ATTR_CURRENT
, ctx
, &size
,
35 ASSERT_EQ(-1, lsm_set_self_attr(LSM_ATTR_CURRENT
, ctx
, 1, 0));
40 TEST(flags_zero_lsm_set_self_attr
)
42 const long page_size
= sysconf(_SC_PAGESIZE
);
43 struct lsm_ctx
*ctx
= calloc(page_size
, 1);
44 __u32 size
= page_size
;
47 if (attr_lsm_count()) {
48 ASSERT_LE(1, lsm_get_self_attr(LSM_ATTR_CURRENT
, ctx
, &size
,
51 ASSERT_EQ(-1, lsm_set_self_attr(LSM_ATTR_CURRENT
, ctx
, size
, 1));
56 TEST(flags_overset_lsm_set_self_attr
)
58 const long page_size
= sysconf(_SC_PAGESIZE
);
59 char *ctx
= calloc(page_size
, 1);
60 __u32 size
= page_size
;
61 struct lsm_ctx
*tctx
= (struct lsm_ctx
*)ctx
;
64 if (attr_lsm_count()) {
65 ASSERT_LE(1, lsm_get_self_attr(LSM_ATTR_CURRENT
, tctx
, &size
,
68 ASSERT_EQ(-1, lsm_set_self_attr(LSM_ATTR_CURRENT
| LSM_ATTR_PREV
, tctx
,