tools/testing/selftests/lsm/lsm_set_self_attr_test.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/lsm/lsm_set_self_attr_test.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/lsm/lsm_set_self_attr_test.c- Extension
.c- Size
- 1658 bytes
- Lines
- 74
- Domain
- Support Tooling And Documentation
- Bucket
- tools
- Inferred role
- Support Tooling And Documentation: implementation source
- Status
- source implementation candidate
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/lsm.hstring.hstdio.hunistd.hsys/types.hkselftest_harness.hcommon.h
Detected Declarations
- No top-level syscall, struct, function, initcall, or export declaration detected by the generator.
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
/*
* Linux Security Module infrastructure tests
* Tests for the lsm_set_self_attr system call
*
* Copyright © 2022 Casey Schaufler <casey@schaufler-ca.com>
*/
#define _GNU_SOURCE
#include <linux/lsm.h>
#include <string.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include "kselftest_harness.h"
#include "common.h"
TEST(ctx_null_lsm_set_self_attr)
{
ASSERT_EQ(-1, lsm_set_self_attr(LSM_ATTR_CURRENT, NULL,
sizeof(struct lsm_ctx), 0));
}
TEST(size_too_small_lsm_set_self_attr)
{
const long page_size = sysconf(_SC_PAGESIZE);
struct lsm_ctx *ctx = calloc(page_size, 1);
__u32 size = page_size;
ASSERT_NE(NULL, ctx);
if (attr_lsm_count()) {
ASSERT_LE(1, lsm_get_self_attr(LSM_ATTR_CURRENT, ctx, &size,
0));
}
ASSERT_EQ(-1, lsm_set_self_attr(LSM_ATTR_CURRENT, ctx, 1, 0));
free(ctx);
}
TEST(flags_zero_lsm_set_self_attr)
{
const long page_size = sysconf(_SC_PAGESIZE);
struct lsm_ctx *ctx = calloc(page_size, 1);
__u32 size = page_size;
ASSERT_NE(NULL, ctx);
if (attr_lsm_count()) {
ASSERT_LE(1, lsm_get_self_attr(LSM_ATTR_CURRENT, ctx, &size,
0));
}
ASSERT_EQ(-1, lsm_set_self_attr(LSM_ATTR_CURRENT, ctx, size, 1));
free(ctx);
}
TEST(flags_overset_lsm_set_self_attr)
{
const long page_size = sysconf(_SC_PAGESIZE);
struct lsm_ctx *ctx = calloc(page_size, 1);
__u32 size = page_size;
ASSERT_NE(NULL, ctx);
if (attr_lsm_count()) {
ASSERT_LE(1, lsm_get_self_attr(LSM_ATTR_CURRENT, ctx, &size,
0));
}
ASSERT_EQ(-1, lsm_set_self_attr(LSM_ATTR_CURRENT | LSM_ATTR_PREV, ctx,
size, 0));
free(ctx);
}
TEST_HARNESS_MAIN
Annotation
- Immediate include surface: `linux/lsm.h`, `string.h`, `stdio.h`, `unistd.h`, `sys/types.h`, `kselftest_harness.h`, `common.h`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.