From f0b82c4b17cd4e72b76b778d3a23b1e7304ce088 Mon Sep 17 00:00:00 2001 From: Idan Horowitz Date: Mon, 3 Jan 2022 20:41:59 +0200 Subject: [PATCH] Kernel: Replace incorrect loop condition in write_raw_gdt_entry Contradictory to the comment above it, this while loop was actually clearing the selectors above or equal to the edited one (instead of the selectors that were skipped when the gdt was extended), this wasn't really an issue so far, as all calls to this function did extend the GDT, which meant this condition was always false, but future calls to this function that will try to edit an existing entry would fail. --- Kernel/Arch/x86/common/Processor.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Kernel/Arch/x86/common/Processor.cpp b/Kernel/Arch/x86/common/Processor.cpp index 5dd342b3d1..6627970352 100644 --- a/Kernel/Arch/x86/common/Processor.cpp +++ b/Kernel/Arch/x86/common/Processor.cpp @@ -461,10 +461,9 @@ void Processor::write_raw_gdt_entry(u16 selector, u32 low, u32 high) m_gdt[i].high = high; // clear selectors we may have skipped - while (i < prev_gdt_length) { - m_gdt[i].low = 0; - m_gdt[i].high = 0; - i++; + for (auto j = prev_gdt_length; j < i; ++j) { + m_gdt[j].low = 0; + m_gdt[j].high = 0; } }