tools/testing/selftests/tty/tty_tiocsti_test.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/tty/tty_tiocsti_test.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/tty/tty_tiocsti_test.c- Extension
.c- Size
- 17548 bytes
- Lines
- 651
- 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.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
stdio.hstdlib.hunistd.hfcntl.hsys/ioctl.herrno.hstdbool.hstring.hsys/socket.hsys/wait.hpwd.htermios.hgrp.hsys/capability.hsys/prctl.hpty.hutmp.h../kselftest_harness.h
Detected Declarations
enum test_typefunction capablefunction Variantsfunction send_fd_via_socketfunction recv_fd_via_socketfunction has_cap_sys_adminfunction drop_all_privsfunction get_legacy_tiocsti_settingfunction set_legacy_tiocsti_settingfunction test_tiocsti_injectionfunction run_basic_tiocsti_testfunction run_fdpass_tiocsti_testfunction EXPECT_EQfunction ASSERT_FALSE
Annotated Snippet
if (current_value != self->original_legacy_tiocsti_setting) {
TH_LOG("Backup: Restoring legacy_tiocsti from %d to %d",
current_value,
self->original_legacy_tiocsti_setting);
set_legacy_tiocsti_setting(
_metadata,
self->original_legacy_tiocsti_setting);
}
}
if (self->has_pty) {
if (self->pty_master_fd >= 0)
close(self->pty_master_fd);
if (self->pty_slave_fd >= 0)
close(self->pty_slave_fd);
}
}
TEST_F(tiocsti, test)
{
int status;
pid_t child_pid;
if (variant->test_type == TEST_PTY_TIOCSTI_BASIC) {
/* ===== BASIC TIOCSTI TEST ===== */
child_pid = fork();
ASSERT_GE(child_pid, 0);
/* Perform the actual test in the child process */
if (child_pid == 0)
run_basic_tiocsti_test(_metadata, self, variant);
} else {
/* ===== FD PASSING SECURITY TEST ===== */
int sockpair[2];
ASSERT_EQ(socketpair(AF_UNIX, SOCK_STREAM, 0, sockpair), 0);
child_pid = fork();
ASSERT_GE(child_pid, 0);
if (child_pid == 0) {
/* Child process - create PTY and send FD */
close(sockpair[0]);
run_fdpass_tiocsti_test(_metadata, variant,
sockpair[1]);
}
/* Parent process - receive FD and test TIOCSTI */
close(sockpair[1]);
int received_fd = recv_fd_via_socket(sockpair[0]);
ASSERT_GE(received_fd, 0);
bool parent_has_cap = self->initial_cap_sys_admin;
TH_LOG("=== TIOCSTI FD Passing Test Context ===");
TH_LOG("legacy_tiocsti: %d, Parent CAP_SYS_ADMIN: %s, Child: %s",
variant->legacy_tiocsti, parent_has_cap ? "yes" : "no",
variant->requires_cap ? "kept" : "dropped");
/* SECURITY TEST: Try TIOCSTI with FD opened by child */
int result = test_tiocsti_injection(_metadata, received_fd);
/* Log security concern if demonstrated */
if (result == 0 && !variant->requires_cap) {
TH_LOG("*** SECURITY CONCERN DEMONSTRATED ***");
TH_LOG("Privileged parent can use TIOCSTI on FD from unprivileged child");
TH_LOG("This shows current process credentials are used, not opener credentials");
}
EXPECT_EQ(result, variant->expected_success)
{
TH_LOG("FD passing: expected error %d, got %d",
variant->expected_success, result);
}
/* Signal child completion */
char sync_byte = 'D';
ssize_t bytes_written = write(sockpair[0], &sync_byte, 1);
ASSERT_EQ(bytes_written, 1);
close(received_fd);
close(sockpair[0]);
}
/* Common child process cleanup for both test types */
ASSERT_EQ(waitpid(child_pid, &status, 0), child_pid);
Annotation
- Immediate include surface: `stdio.h`, `stdlib.h`, `unistd.h`, `fcntl.h`, `sys/ioctl.h`, `errno.h`, `stdbool.h`, `string.h`.
- Detected declarations: `enum test_type`, `function capable`, `function Variants`, `function send_fd_via_socket`, `function recv_fd_via_socket`, `function has_cap_sys_admin`, `function drop_all_privs`, `function get_legacy_tiocsti_setting`, `function set_legacy_tiocsti_setting`, `function test_tiocsti_injection`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
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.