From: Nikolay Borisov <nik.borisov@suse.com>
To: Borislav Petkov <bp@alien8.de>
Cc: x86@kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2/3] x86/microcode/AMD: Make __verify_patch_size() return bool
Date: Thu, 14 Nov 2024 16:13:33 +0200 [thread overview]
Message-ID: <3fd8368f-fb21-452c-b9da-5382fcf4f657@suse.com> (raw)
In-Reply-To: <20241114140154.GFZzYC0ifEztvQ49-P@fat_crate.local>
On 14.11.24 г. 16:01 ч., Borislav Petkov wrote:
> 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;
Isn't sh_psize < max_size valid here?
>
> ret:
> /* Working with the whole buffer so < is ok. */
> return sh_psize <= buf_size;
> }
>
next prev parent reply other threads:[~2024-11-14 14:13 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-18 15:51 [PATCH 0/3] Minor cleanups in AMD microcode loader Nikolay Borisov
2024-10-18 15:51 ` [PATCH 1/3] x86/microcode/AMD: Return bool from find_blobs_in_containers() Nikolay Borisov
2024-11-14 10:16 ` Borislav Petkov
2025-01-01 12:14 ` [tip: x86/microcode] " tip-bot2 for Nikolay Borisov
2024-10-18 15:51 ` [PATCH 2/3] x86/microcode/AMD: Make __verify_patch_size() return bool Nikolay Borisov
2024-11-14 12:58 ` Borislav Petkov
2024-11-14 13:19 ` Nikolay Borisov
2024-11-14 14:01 ` Borislav Petkov
2024-11-14 14:13 ` Nikolay Borisov [this message]
2024-11-14 14:26 ` Borislav Petkov
2024-11-14 14:40 ` Nikolay Borisov
2024-11-14 15:47 ` Borislav Petkov
2024-11-15 16:43 ` Borislav Petkov
2025-01-01 12:14 ` [tip: x86/microcode] " tip-bot2 for Nikolay Borisov
2024-10-18 15:51 ` [PATCH 3/3] x86/microcode/AMD: Remove bogus comment from parse_container() Nikolay Borisov
2025-01-01 12:14 ` [tip: x86/microcode] " tip-bot2 for Nikolay Borisov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=3fd8368f-fb21-452c-b9da-5382fcf4f657@suse.com \
--to=nik.borisov@suse.com \
--cc=bp@alien8.de \
--cc=linux-kernel@vger.kernel.org \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®