Commit 191ecf3b 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 e504fc51
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -730,6 +730,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
		struct elfhdr interp_elf_ex;
	} *loc;
	struct arch_elf_state arch_state = INIT_ARCH_ELF_STATE;
	const int snapshot_randomize_va_space = READ_ONCE(randomize_va_space);
	loff_t pos;

	loc = kmalloc(sizeof(*loc), GFP_KERNEL);
@@ -897,7 +898,6 @@ static int load_elf_binary(struct linux_binprm *bprm)
	if (elf_read_implies_exec(loc->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;