The NetBSD Project

CVS log for src/sys/arch/amd64/stand/prekern/elf.c

[BACK] Up to [cvs.NetBSD.org] / src / sys / arch / amd64 / stand / prekern

Request diff between arbitrary revisions


Default branch: MAIN


Revision 1.21.6.1 / (download) - annotate - [select for diffs], Thu May 13 00:47:22 2021 UTC (2 years ago) by thorpej
Branch: thorpej-i2c-spi-conf
Changes since 1.21: +6 -6 lines
Diff to previous 1.21 (colored) next main 1.22 (colored)

Sync with HEAD.

Revision 1.22 / (download) - annotate - [select for diffs], Tue May 4 21:09:16 2021 UTC (2 years ago) by khorben
Branch: MAIN
CVS Tags: thorpej-i2c-spi-conf2-base, thorpej-i2c-spi-conf2, thorpej-i2c-spi-conf-base, thorpej-futex2-base, thorpej-futex2, thorpej-cfargs2-base, thorpej-cfargs2, netbsd-10-base, netbsd-10, cjep_sun2x-base1, cjep_sun2x-base, cjep_sun2x, cjep_staticlib_x-base1, cjep_staticlib_x-base, cjep_staticlib_x, bouyer-sunxi-drm-base, bouyer-sunxi-drm, HEAD
Changes since 1.21: +6 -6 lines
Diff to previous 1.21 (colored)

prekern: add support for warning messages

As submitted on port-amd64@ (part 1/3)

Tested on NetBSD/amd64.

Revision 1.21 / (download) - annotate - [select for diffs], Thu May 7 17:58:26 2020 UTC (3 years ago) by maxv
Branch: MAIN
CVS Tags: thorpej-futex-base, thorpej-futex, thorpej-cfargs-base, thorpej-cfargs
Branch point for: thorpej-i2c-spi-conf
Changes since 1.20: +44 -31 lines
Diff to previous 1.20 (colored)

Clarify.

Revision 1.20 / (download) - annotate - [select for diffs], Thu May 7 16:49:59 2020 UTC (3 years ago) by maxv
Branch: MAIN
Changes since 1.19: +48 -15 lines
Diff to previous 1.19 (colored)

If we encounter relocations from a section that the bootloader dropped,
AND if the section is a note, then skip the relocations.

Considering a note that the bootloader dropped, there are two possible
sides for the relocations: (1) the relocations from the note towards the
rest of the binary, and (2) the relocations from the rest of the binary
towards the note.

We skip (1), which is correct, because the notes do not play any role at
run time. If we encounter (2) however then there is a bug in the kernel,
so add a sanity check against that.

This fixes KASLR since the latest Xen changes (which introduced .note.Xen).

Revision 1.19 / (download) - annotate - [select for diffs], Tue May 5 19:26:47 2020 UTC (3 years ago) by maxv
Branch: MAIN
Changes since 1.18: +25 -10 lines
Diff to previous 1.18 (colored)

Gather the section filtering in a single function, and add a sanity check
when relocating, to make sure the section we're accessing is mappable.

Currently this check fails, because of the Xen section, which has RELAs but
is an unmappable unallocated note.

Also improve the prekern ASSERTs while here.

Revision 1.17.6.1 / (download) - annotate - [select for diffs], Mon Jun 10 22:05:47 2019 UTC (3 years, 11 months ago) by christos
Branch: phil-wifi
Changes since 1.17: +2 -1 lines
Diff to previous 1.17 (colored) next main 1.18 (colored)

Sync with HEAD

Revision 1.17.4.1 / (download) - annotate - [select for diffs], Fri Jan 18 08:50:13 2019 UTC (4 years, 4 months ago) by pgoyette
Branch: pgoyette-compat
CVS Tags: pgoyette-compat-merge-20190127
Changes since 1.17: +2 -1 lines
Diff to previous 1.17 (colored) next main 1.18 (colored)

Synch with HEAD

Revision 1.18 / (download) - annotate - [select for diffs], Sat Jan 5 22:11:07 2019 UTC (4 years, 4 months ago) by maxv
Branch: MAIN
CVS Tags: phil-wifi-20200421, phil-wifi-20200411, phil-wifi-20200406, phil-wifi-20191119, phil-wifi-20190609, pgoyette-compat-20190127, pgoyette-compat-20190118, netbsd-9-base, netbsd-9-3-RELEASE, netbsd-9-2-RELEASE, netbsd-9-1-RELEASE, netbsd-9-0-RELEASE, netbsd-9-0-RC2, netbsd-9-0-RC1, netbsd-9, isaki-audio2-base, isaki-audio2, is-mlppp-base, is-mlppp, bouyer-xenpvh-base2, bouyer-xenpvh-base1, bouyer-xenpvh-base, bouyer-xenpvh, ad-namecache-base3, ad-namecache-base2, ad-namecache-base1, ad-namecache-base, ad-namecache
Changes since 1.17: +2 -1 lines
Diff to previous 1.17 (colored)

Apply amd64/kobj_machdep.c::rev1.7 to the prekern too, to fix the
relocation with updated binutils.

Revision 1.17.2.2 / (download) - annotate - [select for diffs], Sun Dec 3 11:35:48 2017 UTC (5 years, 5 months ago) by jdolecek
Branch: tls-maxphys
Changes since 1.17.2.1: +471 -0 lines
Diff to previous 1.17.2.1 (colored) to branchpoint 1.17 (colored) next main 1.18 (colored)

update from HEAD

Revision 1.17.2.1, Tue Nov 21 07:56:05 2017 UTC (5 years, 6 months ago) by jdolecek
Branch: tls-maxphys
Changes since 1.17: +0 -471 lines
FILE REMOVED

file elf.c was added on branch tls-maxphys on 2017-12-03 11:35:48 +0000

Revision 1.17 / (download) - annotate - [select for diffs], Tue Nov 21 07:56:05 2017 UTC (5 years, 6 months ago) by maxv
Branch: MAIN
CVS Tags: tls-maxphys-base-20171202, phil-wifi-base, pgoyette-compat-base, pgoyette-compat-1226, pgoyette-compat-1126, pgoyette-compat-1020, pgoyette-compat-0930, pgoyette-compat-0906, pgoyette-compat-0728, pgoyette-compat-0625, pgoyette-compat-0521, pgoyette-compat-0502, pgoyette-compat-0422, pgoyette-compat-0415, pgoyette-compat-0407, pgoyette-compat-0330, pgoyette-compat-0322, pgoyette-compat-0315
Branch point for: tls-maxphys, phil-wifi, pgoyette-compat
Changes since 1.16: +13 -4 lines
Diff to previous 1.16 (colored)

Clean up and add some ASSERTs.

Revision 1.16 / (download) - annotate - [select for diffs], Fri Nov 17 07:07:52 2017 UTC (5 years, 6 months ago) by maxv
Branch: MAIN
Changes since 1.15: +2 -1 lines
Diff to previous 1.15 (colored)

style

Revision 1.15 / (download) - annotate - [select for diffs], Wed Nov 15 20:45:16 2017 UTC (5 years, 6 months ago) by maxv
Branch: MAIN
Changes since 1.14: +1 -6 lines
Diff to previous 1.14 (colored)

Small cleanup.

Revision 1.14 / (download) - annotate - [select for diffs], Wed Nov 15 18:02:36 2017 UTC (5 years, 6 months ago) by maxv
Branch: MAIN
Changes since 1.13: +3 -2 lines
Diff to previous 1.13 (colored)

Support large pages on KASLR kernels, in a way that does not reduce
randomness, but on the contrary that increases it.

The size of the kernel sub-blocks is changed to be 1MB. This produces a
kernel with sections that are always < 2MB in size, that can fit a large
page.

Each section is put in a 2MB physical chunk. In this chunk, there is a
padding of approximately 1MB. The prekern uses a random offset aligned to
sh_addralign, to shift the section in physical memory.

For example, physical memory layout created by the bootloader for .text.4
and .rodata.0:
 +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+
 |+---------------+                  |+---------------+                  |
 ||    .text.4    |       PAD        ||   .rodata.0   |       PAD        |
 |+---------------+                  |+---------------+                  |
 +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+
 PA                                  PA+2MB                         PA+4MB

Then, physical memory layout, after having been shifted by the prekern:
 +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+
 | P +---------------+               |          +---------------+        |
 | A |    .text.4    |      PAD      |   PAD    |   .rodata.0   |   PAD  |
 | D +---------------+               |          +---------------+        |
 +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+
 PA                                  PA+2MB                         PA+4MB

The kernel maps these 2MB physical chunks with 2MB large pages. Therefore,
randomness is enforced at both the virtual and physical levels, and the
resulting entropy is higher than that of our current implementaion until
now.

The padding around the section is filled by the prekern. Not to consume
too much memory, the sections that are smaller than PAGE_SIZE are mapped
with normal pages - because there is no point in optimizing them. In these
normal pages, the same shift is applied.

This change has two additional advantages: (a) the cache attacks based on
the TLB are mostly mitigated, because even if you are able to determine
that a given page-aligned range is mapped as executable you don't know
where exactly within that range the section actually begins, and (b) given
that we are slightly randomizing the physical layout we are making some
rare physical attacks more difficult to conduct.

NOTE: after this change you need to update GENERIC_KASLR / prekern /
bootloader.

Revision 1.13 / (download) - annotate - [select for diffs], Tue Nov 14 07:06:34 2017 UTC (5 years, 6 months ago) by maxv
Branch: MAIN
Changes since 1.12: +6 -7 lines
Diff to previous 1.12 (colored)

Add -Wstrict-prototypes, and fix each warning.

Revision 1.12 / (download) - annotate - [select for diffs], Mon Nov 13 21:33:42 2017 UTC (5 years, 6 months ago) by maxv
Branch: MAIN
Changes since 1.11: +2 -1 lines
Diff to previous 1.11 (colored)

One more ASSERT, won't hurt.

Revision 1.11 / (download) - annotate - [select for diffs], Mon Nov 13 21:32:21 2017 UTC (5 years, 6 months ago) by maxv
Branch: MAIN
Changes since 1.10: +4 -1 lines
Diff to previous 1.10 (colored)

Don't process ELF sections that don't have the ALLOC flag set.

NOTE: you need to update both the prekern and the bootloader after this
change.

Revision 1.10 / (download) - annotate - [select for diffs], Mon Nov 13 21:14:04 2017 UTC (5 years, 6 months ago) by maxv
Branch: MAIN
Changes since 1.9: +21 -164 lines
Diff to previous 1.9 (colored)

Change the mapping logic: don't group sections of the same type into
segments, and rather map each section independently at a random VA.

In particular, .data and .bss are not merged anymore and reside at
different addresses.

Revision 1.9 / (download) - annotate - [select for diffs], Thu Nov 9 15:56:56 2017 UTC (5 years, 6 months ago) by maxv
Branch: MAIN
Changes since 1.8: +1 -24 lines
Diff to previous 1.8 (colored)

Define utility functions as inlines in prekern.h.

Revision 1.8 / (download) - annotate - [select for diffs], Thu Nov 9 15:24:39 2017 UTC (5 years, 6 months ago) by maxv
Branch: MAIN
Changes since 1.7: +3 -3 lines
Diff to previous 1.7 (colored)

Fill in the page padding. Only .text is pre-filled by the ld script, but
this will change in the future.

Revision 1.7 / (download) - annotate - [select for diffs], Sun Nov 5 16:26:15 2017 UTC (5 years, 6 months ago) by maxv
Branch: MAIN
Changes since 1.6: +7 -37 lines
Diff to previous 1.6 (colored)

Mprotect the segments in mm.c using bootspace, and remove the now unused
fields of elfinfo.

Revision 1.6 / (download) - annotate - [select for diffs], Wed Nov 1 17:00:17 2017 UTC (5 years, 6 months ago) by maxv
Branch: MAIN
Changes since 1.5: +5 -1 lines
Diff to previous 1.5 (colored)

Handle absolute symbols. Since my linux_sigcode.S::rev1.4 there are two
Elf_Rela that point to the NULL symbol - which the prekern thought was an
external reference.

In the ELF spec, STN_UNDEF means the value of the symbol is zero.

Revision 1.5 / (download) - annotate - [select for diffs], Sun Oct 29 11:38:43 2017 UTC (5 years, 6 months ago) by maxv
Branch: MAIN
Changes since 1.4: +7 -7 lines
Diff to previous 1.4 (colored)

Fix a few error messages, and be a little more verbose.

Revision 1.4 / (download) - annotate - [select for diffs], Sun Oct 29 11:28:30 2017 UTC (5 years, 6 months ago) by maxv
Branch: MAIN
Changes since 1.3: +205 -99 lines
Diff to previous 1.3 (colored)

Randomize the kernel segments independently. That is to say, put text,
rodata and data at different addresses (and in a random order).

To achieve that, the mapping order in the prekern is changed. Until now,
we were creating the kernel map the following way:
	-> choose a random VA
	-> map [kernpa_start; kernpa_end[ at this VA
	-> parse the ELF structures from there
	-> determine where exactly the kernel segments are located
	-> relocate etc
Now, we are doing:
	-> create a read-only view of [kernpa_start; kernpa_end[
	-> from this view, compute the size of the "head" region
	-> choose a random VA in the HEAD window, and map the head there
	-> for each region in (text, rodata, data, boot)
		-> compute the size of the region from the RO view
		-> choose a random VA in the KASLR window
		-> map the region there
	-> relocate etc

Each time we map a region, we initialize its bootspace fields right away.

The "head" region must be put before the other regions in memory, because
the kernel uses (headva + sh_offset) to get the addresses of the symbols,
and the offset is unsigned.

Given that the head does not have an mcmodel constraint, its location is
randomized in a window located below the KASLR window.

The rest of the regions being in the same window, we need to detect
collisions.

Note that the module map is embedded in the "boot" region, and that
therefore its location is randomized too.

Revision 1.3 / (download) - annotate - [select for diffs], Sun Oct 29 10:07:08 2017 UTC (5 years, 6 months ago) by maxv
Branch: MAIN
Changes since 1.2: +44 -17 lines
Diff to previous 1.2 (colored)

Add three functions and start using them; will be more useful soon.

Revision 1.2 / (download) - annotate - [select for diffs], Wed Oct 11 16:21:06 2017 UTC (5 years, 7 months ago) by maxv
Branch: MAIN
Changes since 1.1: +3 -2 lines
Diff to previous 1.1 (colored)

Make sure we're relocating a relocatable kernel.

Revision 1.1 / (download) - annotate - [select for diffs], Tue Oct 10 09:29:14 2017 UTC (5 years, 7 months ago) by maxv
Branch: MAIN

Add the amd64 prekern. It is a kernel relocator used for Kernel ASLR (see
tech-kern@). It works, but is not yet linked to the build system, because
I can't build a distribution right now.

This form allows you to request diff's between any two revisions of a file. You may select a symbolic revision name using the selection box or you may type in a numeric name using the type-in text box.




CVSweb <webmaster@jp.NetBSD.org>