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-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20241114140154.GFZzYC0ifEztvQ49-P@fat_crate.local>
Date: Thu, 14 Nov 2024 15:01:54 +0100
From: Borislav Petkov <bp@...en8.de>
To: Nikolay Borisov <nik.borisov@...e.com>
Cc: x86@...nel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH 2/3] x86/microcode/AMD: Make __verify_patch_size() return
 bool

On Thu, Nov 14, 2024 at 03:19:33PM +0200, Nikolay Borisov wrote:
> For the older families we have a hard upper bound so we want to ensure that
> the size in the header is strictly <= than buf_size, which in turn must be
> <= max_size .
> 
> 
> i.e Is it not valid to have sh_psize < buf_size rather than strictly equal ?

Let's look at all possible cases:

* sh_psize > min_t(sh_psize, buf_size) == buf_size -- means the buffer is
truncated so the patch is incomplete 

* sh_psize < min_t(sh_psize, buf_size) == buf_size -- this is actually ok
because we're working with the whole buffer and there can be other patches
following. Now I remember why I had ">" there.

* sh_psize > min_t(u32, buf_size, max_size) == buf_size -- truncated buffer

* sh_psize < min_t(u32, buf_size, max_size) == buf_size -- that's ok

* sh_psize > min_t(u32, buf_size, max_size) == max_size -- some mismatch, fail

* sh_psize < min_t(u32, buf_size, max_size) == max_size -- ditto.

So this needs more staring and I need to make it more readable.

Btw, one more spot:

diff --git a/arch/x86/kernel/cpu/microcode/amd.c b/arch/x86/kernel/cpu/microcode/amd.c
index 01ea25f31c0c..7554d83f00e6 100644
--- a/arch/x86/kernel/cpu/microcode/amd.c
+++ b/arch/x86/kernel/cpu/microcode/amd.c
@@ -303,7 +303,7 @@ static bool __verify_patch_size(u32 sh_psize, size_t buf_size)
 		break;
 	default:
 		WARN(1, "%s: WTF family: 0x%x\n", __func__, family);
-		return 0;
+		return false;
 	}
 
 	return sh_psize == min_t(u32, buf_size, max_size);

---

IOW, I'm thinking about something like this (pasting the whole function here):

static bool __verify_patch_size(u32 sh_psize, size_t buf_size)
{
        u8 family = x86_family(bsp_cpuid_1_eax);
        u32 max_size;

        if (family >= 0x15)
                goto ret;

#define F1XH_MPB_MAX_SIZE 2048
#define F14H_MPB_MAX_SIZE 1824

        switch (family) {
        case 0x10 ... 0x12:
                max_size = F1XH_MPB_MAX_SIZE;
                break;
        case 0x14:
                max_size = F14H_MPB_MAX_SIZE;
                break;
        default:
                WARN(1, "%s: WTF family: 0x%x\n", __func__, family);
                return false;
        }       

        if (sh_psize != max_size)
                return false;
                
ret:    
        /* Working with the whole buffer so < is ok. */
        return sh_psize <= buf_size;
}

-- 
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ