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: <aBD165pVhOIl3_by@kernel.org>
Date: Tue, 29 Apr 2025 18:53:15 +0300
From: Mike Rapoport <rppt@...nel.org>
To: Dave Hansen <dave.hansen@...el.com>
Cc: Changyuan Lyu <changyuanl@...gle.com>, linux-kernel@...r.kernel.org,
	akpm@...ux-foundation.org, anthony.yznaga@...cle.com, arnd@...db.de,
	ashish.kalra@....com, benh@...nel.crashing.org, bp@...en8.de,
	catalin.marinas@....com, corbet@....net,
	dave.hansen@...ux.intel.com, devicetree@...r.kernel.org,
	dwmw2@...radead.org, ebiederm@...ssion.com, graf@...zon.com,
	hpa@...or.com, jgowans@...zon.com, kexec@...ts.infradead.org,
	krzk@...nel.org, linux-arm-kernel@...ts.infradead.org,
	linux-doc@...r.kernel.org, linux-mm@...ck.org, luto@...nel.org,
	mark.rutland@....com, mingo@...hat.com, pasha.tatashin@...een.com,
	pbonzini@...hat.com, peterz@...radead.org, ptyadav@...zon.de,
	robh@...nel.org, rostedt@...dmis.org, saravanak@...gle.com,
	skinsburskii@...ux.microsoft.com, tglx@...utronix.de,
	thomas.lendacky@....com, will@...nel.org, x86@...nel.org
Subject: Re: [PATCH v6 11/14] x86: add KHO support

On Mon, Apr 28, 2025 at 03:05:55PM -0700, Dave Hansen wrote:
> On 4/10/25 22:37, Changyuan Lyu wrote:
> > From: Alexander Graf <graf@...zon.com>
> > 
> > +#ifdef CONFIG_KEXEC_HANDOVER
> > +static bool process_kho_entries(unsigned long minimum, unsigned long image_size)
> > +{
> > +	struct kho_scratch *kho_scratch;
> > +	struct setup_data *ptr;
> > +	int i, nr_areas = 0;
> 
> Do these really need actual #ifdefs or will a nice IS_ENABLED() check
> work instead?
> 
> > +	ptr = (struct setup_data *)(unsigned long)boot_params_ptr->hdr.setup_data;
> 
> What's with the double cast?

The double cast is required for this to be compiled on 32 bits (just like
in mem_avoid_overlap). The setup_data is all u64 and to cast it to a
pointer on 32 bit it has to go via unsigned long.

If we keep actual #ifdef we can drop the double cast because KHO depends on
CONFIG_KEXEC_FILE which is only enabled for 64 bits.
 
> > diff --git a/arch/x86/kernel/kexec-bzimage64.c b/arch/x86/kernel/kexec-bzimage64.c
> > index 68530fad05f74..518635cc0876c 100644
> > --- a/arch/x86/kernel/kexec-bzimage64.c
> > +++ b/arch/x86/kernel/kexec-bzimage64.c
> > @@ -233,6 +233,31 @@ setup_ima_state(const struct kimage *image, struct boot_params *params,
> >  #endif /* CONFIG_IMA_KEXEC */
> >  }
> >  
> > +static void setup_kho(const struct kimage *image, struct boot_params *params,
> > +		      unsigned long params_load_addr,
> > +		      unsigned int setup_data_offset)
> > +{
> > +#ifdef CONFIG_KEXEC_HANDOVER
> 
> Can this #ifdef be replaced with IS_ENABLED()?

The KHO structures in kexec image are under #ifdef, so it won't compile
with IS_ENABLED().

> > @@ -312,6 +337,13 @@ setup_boot_parameters(struct kimage *image, struct boot_params *params,
> >  				     sizeof(struct ima_setup_data);
> >  	}
> >  
> > +	if (IS_ENABLED(CONFIG_KEXEC_HANDOVER)) {
> > +		/* Setup space to store preservation metadata */
> > +		setup_kho(image, params, params_load_addr, setup_data_offset);
> > +		setup_data_offset += sizeof(struct setup_data) +
> > +				     sizeof(struct kho_data);
> > +	}
> 
> This is a bit weird that it needs this IS_ENABLED() check and the
> earlier #ifdef. But I guess  it's following the IMA_KEXEC code's pattern
> at least.

And with other #ifdefs as well :)

if (IS_ENABLED()) can be dropped here, but having it makes things more
explicit IMHO.
 
> > diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
> > index 766176c4f5ee8..496dae89cf95d 100644
> > --- a/arch/x86/kernel/setup.c
> > +++ b/arch/x86/kernel/setup.c
> > @@ -451,6 +451,28 @@ int __init ima_get_kexec_buffer(void **addr, size_t *size)
> >  }
> >  #endif
> >  
> > +static void __init add_kho(u64 phys_addr, u32 data_len)
> > +{
> > +#ifdef CONFIG_KEXEC_HANDOVER
> > +	struct kho_data *kho;
> > +	u64 addr = phys_addr + sizeof(struct setup_data);
> > +	u64 size = data_len - sizeof(struct setup_data);
> > +
> > +	kho = early_memremap(addr, size);
> > +	if (!kho) {
> > +		pr_warn("setup: failed to memremap kho data (0x%llx, 0x%llx)\n",
> > +			addr, size);
> > +		return;
> > +	}
> > +
> > +	kho_populate(kho->fdt_addr, kho->fdt_size, kho->scratch_addr, kho->scratch_size);
> > +
> > +	early_memunmap(kho, size);
> > +#else
> > +	pr_warn("Passed KHO data, but CONFIG_KEXEC_HANDOVER not set. Ignoring.\n");
> > +#endif
> > +}
> 
> Please axe the #ifdef in the .c file if at all possible, just like the
> others.

This one follows IMA, but it's easy to make it IS_ENABLED(). It's really up
to x86 folks preference.

-- 
Sincerely yours,
Mike.

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ