Commit a6e353d5 authored by Gu Bowen's avatar Gu Bowen
Browse files

ELF: Fix mixed declarations and code of "snapshot_randomize_va_space"

hulk inclusion
category: bugfix
bugzilla: https://gitee.com/src-openeuler/kernel/issues/IAU9NT


CVE: CVE-2024-46826

--------------------------------

Due to the use of the compilation instruction -Wdeclaration-after-statment,
declaring snapshot_randomize_va_space here will generate a compilation
warning, so move it up.

Fixes: 2a97388a807b ("ELF: fix kernel.randomize_va_space double read")

Signed-off-by: default avatarGu Bowen <gubowen5@huawei.com>
parent 88180076
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -839,6 +839,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
	struct arch_elf_state arch_state = INIT_ARCH_ELF_STATE;
	struct mm_struct *mm;
	struct pt_regs *regs;
	const int snapshot_randomize_va_space = READ_ONCE(randomize_va_space);

	retval = -ENOEXEC;
	/* First of all, some simple consistency checks */
@@ -1005,7 +1006,6 @@ static int load_elf_binary(struct linux_binprm *bprm)
	if (elf_read_implies_exec(*elf_ex, executable_stack))
		current->personality |= READ_IMPLIES_EXEC;

	const int snapshot_randomize_va_space = READ_ONCE(randomize_va_space);
	if (!(current->personality & ADDR_NO_RANDOMIZE) && snapshot_randomize_va_space)
		current->flags |= PF_RANDOMIZE;