kernel/module/strict_rwx.c

Source file repositories/reference/linux-study-clean/kernel/module/strict_rwx.c

File Facts

System
Linux kernel
Corpus path
kernel/module/strict_rwx.c
Extension
.c
Size
3622 bytes
Lines
152
Domain
Core OS
Bucket
Scheduler, Processes, Timers, Sync, And Syscalls
Inferred role
Core OS: implementation source
Status
source 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

if ((sechdrs[i].sh_flags & shf_wx) == shf_wx) {
			pr_err("%s: section %s (index %d) has invalid WRITE|EXEC flags\n",
			       mod->name, secstrings + sechdrs[i].sh_name, i);
			return -ENOEXEC;
		}
	}

	return 0;
}

static const char *const ro_after_init[] = {
	/*
	 * Section .data..ro_after_init holds data explicitly annotated by
	 * __ro_after_init.
	 */
	".data..ro_after_init",

	/*
	 * Section __jump_table holds data structures that are never modified,
	 * with the exception of entries that refer to code in the __init
	 * section, which are marked as such at module load time.
	 */
	"__jump_table",

#ifdef CONFIG_HAVE_STATIC_CALL_INLINE
	/*
	 * Section .static_call_sites holds data structures that need to be
	 * sorted and processed at module load time but are never modified
	 * afterwards.
	 */
	".static_call_sites",
#endif
};

void module_mark_ro_after_init(const Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
			       const char *secstrings)
{
	int i, j;

	for (i = 1; i < hdr->e_shnum; i++) {
		Elf_Shdr *shdr = &sechdrs[i];

		for (j = 0; j < ARRAY_SIZE(ro_after_init); j++) {
			if (strcmp(secstrings + shdr->sh_name,
				   ro_after_init[j]) == 0) {
				shdr->sh_flags |= SHF_RO_AFTER_INIT;
				break;
			}
		}
	}
}

Annotation

Implementation Notes