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]
Date:   Tue, 16 Jun 2020 11:12:53 +0200
From:   Peter Zijlstra <peterz@...radead.org>
To:     Josh Poimboeuf <jpoimboe@...hat.com>
Cc:     linux-kernel@...r.kernel.org, x86@...nel.org, dvyukov@...gle.com,
        elver@...gle.com, andreyknvl@...gle.com, mark.rutland@....com,
        mhelsley@...are.com, rostedt@...dmis.org, jthierry@...hat.com,
        mbenes@...e.cz
Subject: Re: [RFC][PATCH 2/3] objtool: Provide elf_write_{insn,reloc}()

On Fri, Jun 12, 2020 at 04:30:36PM +0200, Peter Zijlstra wrote:
> +int elf_write_insn(struct elf *elf, struct section *sec,
> +		   unsigned long offset, unsigned int len,
> +		   const char *insn)
> +{
> +	Elf_Data *data = sec->data;
> +
> +	if (data->d_type != ELF_T_BYTE || data->d_off) {
> +		WARN("write to unexpected data for section: %s", sec->name);
> +		return -1;
> +	}
> +
> +	memcpy(data->d_buf + offset, insn, len);
> +	elf_flagdata(data, ELF_C_SET, ELF_F_DIRTY);
> +
> +	sec->changed = true;
> +	elf->changed = true;
> +
> +	return 0;
> +}
> +
> +int elf_write_reloc(struct elf *elf, struct reloc *reloc)
> +{
> +	struct section *sec = reloc->sec;
> +
> +	if (sec->sh.sh_type == SHT_REL) {
> +		reloc->rel.r_info = GELF_R_INFO(reloc->sym->idx, reloc->type);
> +		reloc->rel.r_offset = reloc->offset;
> +
> +		if (!gelf_update_rel(sec->data, reloc->idx, &reloc->rel)) {
> +			WARN_ELF("gelf_update_rel");
> +			return -1;
> +		}
> +	} else {
> +		reloc->rela.r_info = GELF_R_INFO(reloc->sym->idx, reloc->type);
> +		reloc->rela.r_addend = reloc->addend;
> +		reloc->rela.r_offset = reloc->offset;
> +
> +		if (!gelf_update_rela(sec->data, reloc->idx, &reloc->rela)) {
> +			WARN_ELF("gelf_update_rela");
> +			return -1;
> +		}
> +	}
> +
> +	sec->changed = true;
> +	elf->changed = true;
> +
> +	return 0;
> +}

Doing the change Matt asked for #1, I realized that sec->changed is only
required if we need to rewrite the section header, neither of these two
changes requires that, they already mark the elf data dirty so
elf_update() DTRT.

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ