fs/exec.c

Source file repositories/reference/linux-study-clean/fs/exec.c

File Facts

System
Linux kernel
Corpus path
fs/exec.c
Extension
.c
Size
51011 bytes
Lines
2030
Domain
Core OS
Bucket
VFS And Filesystem Core
Inferred role
Core OS: syscall or user/kernel boundary
Status
core implementation candidate

Why This File Exists

Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.

Dependency Surface

Detected Declarations

Annotated Snippet

SYSCALL_DEFINE3(execve,
		const char __user *, filename,
		const char __user *const __user *, argv,
		const char __user *const __user *, envp)
{
	CLASS(filename, name)(filename);
	return do_execveat_common(AT_FDCWD, name,
				  native_arg(argv), native_arg(envp), 0);
}

SYSCALL_DEFINE5(execveat,
		int, fd, const char __user *, filename,
		const char __user *const __user *, argv,
		const char __user *const __user *, envp,
		int, flags)
{
	CLASS(filename_uflags, name)(filename, flags);
	return do_execveat_common(fd, name,
				  native_arg(argv), native_arg(envp), flags);
}

#ifdef CONFIG_COMPAT

static inline struct user_arg_ptr compat_arg(const compat_uptr_t __user *p)
{
	return (struct user_arg_ptr){.is_compat = true, .ptr.compat = p};
}

COMPAT_SYSCALL_DEFINE3(execve, const char __user *, filename,
	const compat_uptr_t __user *, argv,
	const compat_uptr_t __user *, envp)
{
	CLASS(filename, name)(filename);
	return do_execveat_common(AT_FDCWD, name,
				  compat_arg(argv), compat_arg(envp), 0);
}

COMPAT_SYSCALL_DEFINE5(execveat, int, fd,
		       const char __user *, filename,
		       const compat_uptr_t __user *, argv,
		       const compat_uptr_t __user *, envp,
		       int,  flags)
{
	CLASS(filename_uflags, name)(filename, flags);
	return do_execveat_common(fd, name,
				  compat_arg(argv), compat_arg(envp), flags);
}
#endif

#ifdef CONFIG_SYSCTL

static int proc_dointvec_minmax_coredump(const struct ctl_table *table, int write,
		void *buffer, size_t *lenp, loff_t *ppos)
{
	int error, old = READ_ONCE(suid_dumpable);

	error = proc_dointvec_minmax(table, write, buffer, lenp, ppos);

	if (!error && write && (old != READ_ONCE(suid_dumpable)))
		validate_coredump_safety();
	return error;
}

static const struct ctl_table fs_exec_sysctls[] = {
	{
		.procname	= "suid_dumpable",
		.data		= &suid_dumpable,
		.maxlen		= sizeof(int),
		.mode		= 0644,
		.proc_handler	= proc_dointvec_minmax_coredump,
		.extra1		= SYSCTL_ZERO,
		.extra2		= SYSCTL_TWO,
	},
};

static int __init init_fs_exec_sysctls(void)
{
	register_sysctl_init("fs", fs_exec_sysctls);
	return 0;
}

fs_initcall(init_fs_exec_sysctls);
#endif /* CONFIG_SYSCTL */

#ifdef CONFIG_EXEC_KUNIT_TEST
#include "tests/exec_kunit.c"
#endif

Annotation

Implementation Notes