Commit Graph

654 Commits

Author SHA1 Message Date
maxv 556958a38c Make sure we're loading a relocatable binary, to give the user a chance to
correct the kernel name if he mistakenly typed pkboot on a static kernel,
without having to reboot the machine (currently the prekern sees it's a
static kernel and panics).
2017-12-21 14:28:39 +00:00
maxv 26e9e80df3 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.
2017-11-15 18:02:36 +00:00
maxv 85357f1eab 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.
2017-11-13 21:32:21 +00:00
maxv 2c3f7fd267 Revert my last revision, that is to say, don't group sections into
segments anymore. Initially I did this because I wanted to compress the
sections by reducing the padding between them; but we'll handle that
differently.
2017-11-13 20:21:10 +00:00
maxv e1daa555fd Group the sections into segments, and align to KERNALIGN only between
segments. Prerequisite for other changes. Unfortunately the code is not
very compact, but whatever.
2017-10-18 16:29:56 +00:00
maxv f184c30907 Introduce two functions, and dedup code. 2017-10-13 10:39:26 +00:00
maxv 1b305151b2 Constify offset, it must not change. 2017-10-13 10:04:27 +00:00
maxv b0f8eacf51 Improve comments. 2017-10-08 13:51:31 +00:00
maxv a8d8f69c27 Add a new option in libsa, to load dynamic binaries. A separate function
is used, and it does not break in any way the generic static loader. Then,
add a new "pkboot" command in the x86 bootloader, which boots a
GENERIC_KASLR kernel via the prekern. (See thread on tech-kern@.)
2017-10-07 10:26:38 +00:00
christos 39acc162ef try a different style of __used. 2017-10-05 02:59:21 +00:00
christos df46e7377d mark first as used for platforms that define PROGRESS to nothing (mvme68k) 2017-10-04 22:00:40 +00:00
maxv 16a900cef9 Clean up and split loadfile, reduces a patch I have. 2017-09-25 20:39:21 +00:00
uwe 34951e704c Swap arguments to strncmp() so that the thing we are testing, the
section name, comes first; and so that the length of the string
constant is right next to that constant.
2017-04-18 07:44:20 +00:00
uwe 084859f23d Move deallocation of shstrsz inside the block where it is allocated. 2017-04-18 06:39:54 +00:00
uwe 49bc163dcc Section at index 0 is SHN_UNDEF. When searching for symbol sections
skip it and start with index 1.
2017-04-17 18:06:30 +00:00
uwe 936554cd90 Don't hide first = 1 assignment inside for(), that just obscures the
loop.  Same object code is generated.
2017-04-17 17:44:48 +00:00
nonaka 15c3e657d9 update marks[MARK_DATA] with COUNT_DATA. 2017-02-23 12:13:59 +00:00
nonaka 3f166eb124 fix CTF section symbol size was not counted with COUNT_KERNEL. 2017-02-23 12:13:05 +00:00
maxv 88aac29387 Explain how all that mess works, without actually fixing it yet. 2017-01-06 09:14:36 +00:00
maxv d5c86237f5 Fix a wrong flag and KNF. 2016-12-03 09:20:55 +00:00
dholland 9367ee5723 Check bounds on input. From Michael Plass. 2016-09-05 21:11:11 +00:00
martin f4a9b09e6c Initialize the marker for the data segment, in case the caller passes not
fully initialized markers to loadfile().
Pointed out by Mark Cave-Ayland.
2016-08-31 16:22:37 +00:00
dholland 030c3497b1 Remove gets() from here too. 2016-08-27 18:59:18 +00:00
dholland e3acc29ae1 PR 51200 gets in libsa considered harmful: remove gets() from libsa. 2016-08-27 06:31:42 +00:00
christos 4c2fb15304 delete now unused function . 2016-08-21 08:27:57 +00:00
rjs f0f10739bd Another header change. 2016-08-04 21:39:20 +00:00
nonaka 4c81930262 Sync with sys/ufs/ext2fs/ext2fs_bswap.c. 2016-08-04 06:58:41 +00:00
nonaka d20f5b128f pass EXT2_DINODE_SIZE(fs) as isize to e2fs_iload().
should fix build failure.
2016-08-04 03:16:00 +00:00
rjs bbe119dec3 Adjust for change to kernel ext2fs headers. 2016-08-03 09:11:18 +00:00
isaki 82b5f6482c Fix typo. 2016-06-25 04:53:32 +00:00
dholland bf8938557c PR 51200 gets in libsa considered harmful: use kgets 2016-06-11 06:58:42 +00:00
dholland 979b72c6a6 gets_s -> kgets.
The exact name isn't that important; but it is important not to use
"gets_s" and thereby allow anyone to falsely get the impression we're
implementing Annex K. We aren't.

ok core.
2016-06-11 06:20:11 +00:00
christos aab1a996f7 dedup 2016-06-05 15:05:49 +00:00
maxv 6896e29d1e Remove the ALLOC_FIRST_FIT and ALLOC_TRACE options. This is a rather simple
allocator, and it does not need to be that complicated.
2016-06-05 13:44:48 +00:00
maxv f5998d880a Use gets_s instead of gets. The x86 bootloader prompt is easy to
overflow.
2016-06-05 13:33:03 +00:00
mrg 65f5251eae remove a bunch of "@echo done" from the tail of rules. these messages
were vaguely useful back when we didn't run make -j, but now you end
up with a single line "done" every so often, with no idea what it is
for.  very few other targets claim they're done so just remove these.
2016-03-22 08:25:22 +00:00
christos 95614a30c2 PR/50952: David Binderman: Clarify expression 2016-03-11 18:38:25 +00:00
tsutsui 89a198b4f5 Add an option (LIBSA_CREAD_NOCRC) to disable gunzip CRC32 calculation.
No obvious sideeffect on booting i386 GENERIC kernels (without the option).
Closes PR/50638 (Extreme slowness on loading gzipped kernels on old CPUs).
2016-01-17 04:35:42 +00:00
uebayasi ea72de740f Order library object build. 2015-09-07 03:44:19 +00:00
uebayasi 9068ec741b Sprinkle more done messages. 2015-09-07 03:20:18 +00:00
uebayasi dd204a345e In kernel lib build, print message when things not only start bug also end. 2015-09-06 15:34:55 +00:00
dholland ec175d5025 Add new accessors for the d_type and d_namlen fields of struct lfs_direct.
Napalm the old byteswap access logic for these.
2015-09-01 06:16:58 +00:00
dholland eb2560adae The ifile's inode number is constant. (it is always 1)
Therefore, storing the value in the superblock and reading it out
again is silly and offers the opportunity for it to become corrupted.
So, don't do that (most of the code already didn't) and use the
existing constant instead. Initialize new 32-bit superblocks with
the value for the sake of old userland programs, but don't keep the
value in the 64-bit superblock at all.

(approved by Margo Seltzer)
2015-09-01 06:12:04 +00:00
dholland b1828e0ba3 Hack up dinode usage to be 64 vs. 32 as needed. Part 1.
(This part changes the native lfs code; the ufs-derived code already
has 64 vs. 32 logic, but as aspects of it are unsafe, and don't
entirely interoperate cleanly with the lfs 64/32 stuff, pass 2 will be
rehashing that.)
2015-08-12 18:28:00 +00:00
dholland 32577c4f1c Add IFILE32 and IFILE64 structures for the on-disk ifile entries.
Add and use accessors. There are also a bunch of places that cast and
I hope I've found them all...
2015-08-12 18:25:51 +00:00
dholland 9e5184b86b Add a (draft) 64-bit superblock. Make things build again.
Add pieces of support for using both superblock types where
convenient, and specifically to the superblock accessors, but don't
actually enable it anywhere.

First substantive step on PR 50000.
2015-08-02 18:18:09 +00:00
dholland 62d11b422e Move struct salfs back inside libsa now that lfs_accessors.h is separate. 2015-07-28 05:13:14 +00:00
dholland 34f0d74c9e Add a new lfs header file: lfs_accessors.h.
This contains all the accessor functions and macros out of lfs.h.
Add an include of lfs_accessors.h after all uses of lfs.h... except
for code that wants to define its own struct lfs-alike that the
accessors are supposed to play along with. For these, set STRUCT_LFS
and include lfs_accessors.h after the necessary structure has been
defined, so that lfs_accessors.h can emit functions in terms of it.
2015-07-28 05:09:34 +00:00
isaki b0705370de white space -> tab. 2015-07-25 07:06:11 +00:00
dholland f59b8f4b3a Switch to accessor functions for elements of the LFS on-disk
superblock. This will allow switching between 32/64 bit forms on the
fly; it will also allow handling LFS_EI reasonably tidily. (That
currently doesn't work on the superblock.)

It also gets rid of cpp abuse in the form of fake structure member
macros.

Also, instead of doing sleep/wakeup on &lfs_avail and &lfs_nextseg
inside the on-disk superblock, add extra elements to the in-memory
struct lfs for this. (XXX: these should be changed to condvars, but
not right now)

XXX: this migrates a structure needed by the lfs code in libsa (struct
salfs) into lfs.h, where it doesn't belong, but for the time being
this is necessary in order to allow the accessors (and the various
lfs macros and other goop that relies on them) to compile.
2015-07-24 06:56:41 +00:00