lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20210105113414.3277-1-bp@alien8.de>
Date:   Tue,  5 Jan 2021 12:34:14 +0100
From:   Borislav Petkov <bp@...en8.de>
To:     X86 ML <x86@...nel.org>
Cc:     Yazen Ghannam <Yazen.Ghannam@....com>,
        LKML <linux-kernel@...r.kernel.org>,
        Rafael Kitover <rkitover@...il.com>,
        Johnathan Smithinovic <johnathan.smithinovic@....at>
Subject: [RFC PATCH] x86/cpu: Do not check c->initialized in topology_phys_to_logical_die()

From: Borislav Petkov <bp@...e.de>

During boot, identify_secondary_cpu() calls at some point
validate_apic_and_package_id() which calls topology_update_die_map() to
update/verify the physical to logical DIE map of the CPUs on the system.

There's a call down that path to topology_phys_to_logical_die() which
maps a physical die to a logical one. The check in there looks at
cpuinfo_x86.initialized first before comparing die_ids and proc_ids.

And this is where the problem lies: both ->cpu_die_id and ->phys_proc_id
have been initialized as part of the identify_secondary_cpu() dance -
just the cpuinfo_x86.initialized thing hasn't been set yet (it gets set
as the last thing in smp_store_cpu_info()).

So what that means is that initialized fields are being compared but the
initialized flag says they're not, leading to:

  smpboot: topology_phys_to_logical_die: init: 1, cpu 7, cur_cpu: 8, cpu_die_id: 0, die_id: 2, phys_proc_id: 0, proc_id: 0, logical_die_id: 0
  smpboot: topology_phys_to_logical_die: init: 0, cpu 8, cur_cpu: 8, cpu_die_id: 2, die_id: 2, phys_proc_id: 0, proc_id: 0, logical_die_id: 0
  ...
  smpboot: topology_phys_to_logical_die: init: 0, cpu 127, cur_cpu: 8, cpu_die_id: 0, die_id: 2, phys_proc_id: 0, proc_id: 0, logical_die_id: 0
  smpboot: CPU 8 Converting physical 2 to logical die 1

On CPU8 and all the way up to all possible_cpus, boot_cpu_data is not
initialized yet even though

  cpu_die_id == die_id
&&
  phys_proc_id == proc_id

for that CPU 8.

As a result, topology_update_die_map() increments logical_die which gets
written into cpuinfo_x86.logical_die_id of that CPU.

Later, in the RAPL code, that logical_die_id is outside of the range of
maximum dies present on the system:

  int maxdie = topology_max_packages() * topology_max_die_per_package();

which leads to indexing into the rapl_pmus->pmus[] array out of bounds.
Boom.

Thus, drop the c->initialized check because the values it should protect
against checking, have been actually already initialized. (Yes, our boot
order is fragile. :-\).

Reported-by: Rafael Kitover <rkitover@...il.com>
Reported-by: Johnathan Smithinovic <johnathan.smithinovic@....at>
Signed-off-by: Borislav Petkov <bp@...e.de>
Link: https://bugzilla.kernel.org/show_bug.cgi?id=210939
---
 arch/x86/kernel/smpboot.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
index 8ca66af96a54..56d2ac8c54ab 100644
--- a/arch/x86/kernel/smpboot.c
+++ b/arch/x86/kernel/smpboot.c
@@ -319,7 +319,7 @@ int topology_phys_to_logical_die(unsigned int die_id, unsigned int cur_cpu)
 	for_each_possible_cpu(cpu) {
 		struct cpuinfo_x86 *c = &cpu_data(cpu);
 
-		if (c->initialized && c->cpu_die_id == die_id &&
+		if (c->cpu_die_id == die_id &&
 		    c->phys_proc_id == proc_id)
 			return c->logical_die_id;
 	}
-- 
2.29.2

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ