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 for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20180302060424.GC15422@dhcp-128-65.nay.redhat.com>
Date:   Fri, 2 Mar 2018 14:04:24 +0800
From:   Dave Young <dyoung@...hat.com>
To:     AKASHI Takahiro <takahiro.akashi@...aro.org>, vgoyal@...hat.com,
        bhe@...hat.com, mpe@...erman.id.au, bauerman@...ux.vnet.ibm.com,
        prudo@...ux.vnet.ibm.com, kexec@...ts.infradead.org,
        linux-arm-kernel@...ts.infradead.org, linux-kernel@...r.kernel.org,
        linux-s390@...r.kernel.org
Subject: Re: [PATCH 6/7] x86: kexec_file: clean up prepare_elf64_headers()

On 03/02/18 at 02:58pm, AKASHI Takahiro wrote:
> On Fri, Mar 02, 2018 at 01:39:45PM +0800, Dave Young wrote:
> > On 02/27/18 at 01:48pm, AKASHI Takahiro wrote:
> > > removing bufp variable in prepare_elf64_headers() makes the code simpler
> > > and more understandable.
> > > 
> > > Signed-off-by: AKASHI Takahiro <takahiro.akashi@...aro.org>
> > > Cc: Dave Young <dyoung@...hat.com>
> > > Cc: Vivek Goyal <vgoyal@...hat.com>
> > > Cc: Baoquan He <bhe@...hat.com>
> > > ---
> > >  arch/x86/kernel/crash.c | 18 +++++++-----------
> > >  1 file changed, 7 insertions(+), 11 deletions(-)
> > > 
> > > diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
> > > index bfc37ad20d4a..a842fd847684 100644
> > > --- a/arch/x86/kernel/crash.c
> > > +++ b/arch/x86/kernel/crash.c
> > > @@ -334,7 +334,7 @@ static int prepare_elf64_headers(struct crash_mem *cmem, int kernel_map,
> > >  	Elf64_Ehdr *ehdr;
> > >  	Elf64_Phdr *phdr;
> > >  	unsigned long nr_cpus = num_possible_cpus(), nr_phdr, elf_sz;
> > > -	unsigned char *buf, *bufp;
> > > +	unsigned char *buf;
> > >  	unsigned int cpu, i;
> > >  	unsigned long long notes_addr;
> > >  	unsigned long mstart, mend;
> > > @@ -359,9 +359,8 @@ static int prepare_elf64_headers(struct crash_mem *cmem, int kernel_map,
> > >  	if (!buf)
> > >  		return -ENOMEM;
> > >  
> > > -	bufp = buf;
> > > -	ehdr = (Elf64_Ehdr *)bufp;
> > > -	bufp += sizeof(Elf64_Ehdr);
> > > +	ehdr = (Elf64_Ehdr *)buf;
> > > +	phdr = (Elf64_Phdr *)(ehdr + 1);
> > 
> > phdr should start with ehdr + sizeof(Elf64_Ehdr);
> 
> Well, it's a matter of rhetoric :)
> The values from both expressions are the same.
> Or do you mean my expression is confusing?

Oops, I interpret it as (Elf64_Phdr *)ehdr + 1;

Please ignore this comment then.

> 
> -Takahiro AKASHI
> 
> 
> > >  	memcpy(ehdr->e_ident, ELFMAG, SELFMAG);
> > >  	ehdr->e_ident[EI_CLASS] = ELFCLASS64;
> > >  	ehdr->e_ident[EI_DATA] = ELFDATA2LSB;
> > > @@ -377,33 +376,30 @@ static int prepare_elf64_headers(struct crash_mem *cmem, int kernel_map,
> > >  
> > >  	/* Prepare one phdr of type PT_NOTE for each present cpu */
> > >  	for_each_present_cpu(cpu) {
> > > -		phdr = (Elf64_Phdr *)bufp;
> > > -		bufp += sizeof(Elf64_Phdr);
> > >  		phdr->p_type = PT_NOTE;
> > >  		notes_addr = per_cpu_ptr_to_phys(per_cpu_ptr(crash_notes, cpu));
> > >  		phdr->p_offset = phdr->p_paddr = notes_addr;
> > >  		phdr->p_filesz = phdr->p_memsz = sizeof(note_buf_t);
> > >  		(ehdr->e_phnum)++;
> > > +		phdr++;
> > >  	}
> > >  
> > >  	/* Prepare one PT_NOTE header for vmcoreinfo */
> > > -	phdr = (Elf64_Phdr *)bufp;
> > > -	bufp += sizeof(Elf64_Phdr);
> > >  	phdr->p_type = PT_NOTE;
> > >  	phdr->p_offset = phdr->p_paddr = paddr_vmcoreinfo_note();
> > >  	phdr->p_filesz = phdr->p_memsz = VMCOREINFO_NOTE_SIZE;
> > >  	(ehdr->e_phnum)++;
> > > +	phdr++;
> > >  
> > >  	/* Prepare PT_LOAD type program header for kernel text region */
> > >  	if (kernel_map) {
> > > -		phdr = (Elf64_Phdr *)bufp;
> > > -		bufp += sizeof(Elf64_Phdr);
> > >  		phdr->p_type = PT_LOAD;
> > >  		phdr->p_flags = PF_R|PF_W|PF_X;
> > >  		phdr->p_vaddr = (Elf64_Addr)_text;
> > >  		phdr->p_filesz = phdr->p_memsz = _end - _text;
> > >  		phdr->p_offset = phdr->p_paddr = __pa_symbol(_text);
> > > -		(ehdr->e_phnum)++;
> > > +		ehdr->e_phnum++;
> > > +		phdr++;
> > >  	}
> > >  
> > >  	/* Go through all the ranges in cmem->ranges[] and prepare phdr */
> > > -- 
> > > 2.16.2
> > > 
> > 
> > Thanks
> > Dave

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ