Re: [Patch v3 Part2 1/9] x86/microcode: Taint kernel only if microcode loading was successful
From: Ashok Raj
Date: Tue Jan 31 2023 - 10:34:35 EST
On Tue, Jan 31, 2023 at 08:17:25PM +0800, Li, Aubrey wrote:
> On 2023/1/31 5:39, Ashok Raj wrote:
> > Currently when late loading is aborted due to check_online_cpu(), kernel
> > still ends up tainting the kernel.
> >
> > Taint only when microcode loading was successful.
> >
[snip]
> > diff --git a/arch/x86/kernel/cpu/microcode/core.c b/arch/x86/kernel/cpu/microcode/core.c
> > index 61d57d9b93ee..1c6831b8b244 100644
> > --- a/arch/x86/kernel/cpu/microcode/core.c
> > +++ b/arch/x86/kernel/cpu/microcode/core.c
> > @@ -472,7 +472,8 @@ static ssize_t reload_store(struct device *dev,
> > enum ucode_state tmp_ret = UCODE_OK;
> > int bsp = boot_cpu_data.cpu_index;
> > unsigned long val;
> > - ssize_t ret = 0;
> > + int load_ret = -1;
> > + ssize_t ret;
> > ret = kstrtoul(buf, 0, &val);
> > if (ret)
> > @@ -488,20 +489,26 @@ static ssize_t reload_store(struct device *dev,
> > goto put;
> > tmp_ret = microcode_ops->request_microcode_fw(bsp, µcode_pdev->dev);
> > - if (tmp_ret != UCODE_NEW)
> > + if (tmp_ret != UCODE_NEW) {
> > + ret = size;
> > goto put;
> > + }
> > mutex_lock(µcode_mutex);
> > - ret = microcode_reload_late();
> > + load_ret = microcode_reload_late();
> > mutex_unlock(µcode_mutex);
> > put:
> > cpus_read_unlock();
> > - if (ret == 0)
> > + /*
> > + * Taint only when loading was successful
> > + */
> > + if (load_ret == 0) {
> > ret = size;
>
> What about if loading was not successful(load_ret != 0)?
> ret has no chance to be returned as size here and we'll run into the endless
> update?
Good catch, we'll need to make that some meaningful return code to stop the
endless wait.