Commit Graph

59 Commits

Author SHA1 Message Date
martin
90b40fe3e2 kobj_machdep() needs a chance to moify the loaded code, so move the code
to protect it read-only a bit later.
2016-08-02 12:23:08 +00:00
maxv
607912eebd Don't fail if a module does not have a data or rodata section. Small
modules don't have data.
2016-08-01 15:41:05 +00:00
maxv
ece8cd54ab Split the data+bss+rodata segment in two data+bss and rodata segments. The
latter is made read-only.
2016-07-20 13:36:19 +00:00
maxv
d2c6c6c84f Change the protection of the kernel modules segments once we are done
relocating them. The text is allocated as RWX, and then mprotected to RW.

There is a bug that prevents us from doing RW->RX on amd64 and perhaps
sparc64. On x86, the pmap waits for the page to fault before granting it
the X permission. But in the trap handler, such a page is considered as
belonging to kernel_map, while it actually belongs to module_map. The
kernel then finds out the page is not present in kernel_map, and panics.
In all cases, module_map is non pageable, so even if the trap were handled
properly, it still wouldn't work.

Therefore, there is a small window in which the segment is RWX. But that's
fine enough, for now.
2016-07-20 13:11:58 +00:00
maxv
6c1bb9a544 When loading a module from VFS and from the bootloader, the kernel packs
up the module segments into one big RWX chunk. Split this chunk into two
different text and data+bss+rodata chunks. The latter is made non-
executable. This also provides some kind of ASLR, since the chunks are
not necessarily contiguous.
2016-07-09 07:25:00 +00:00
maxv
e169fdcc18 Force the kernel to dynamically reallocate the preloaded modules. 2016-07-08 08:55:48 +00:00
msaitoh
8bc54e5be6 KNF. Remove extra spaces. No functional change. 2016-07-07 06:55:38 +00:00
pgoyette
b847d6b87c Compare names of duplicate symbols properly, so we correctly return
an error status.

Fixes PR kern/45125 with patch supplied by Akinobu  Mita
2016-05-31 03:57:04 +00:00
pooka
d8e04c9094 to garnish, dust with _KERNEL_OPT 2015-08-24 22:50:32 +00:00
maxv
7d6c4f355e Keep setting 'error' as appropriate (even if this place is broken enough
to crash in many other ways...)
2014-07-16 13:26:33 +00:00
maxv
310a1a5a66 - limit the number of sections with ELF_MAXSHNUM
- fix the (symstrindex > hdr->e_shnum) check: it should be >=, otherwise there's an
   off-by-one
 - fix the (symstrindex < 0) check: the value is unsigned, so it can't be <0. However,
   we should ensure that symstrindex!=0 (done with SHN_UNDEF)
 - set 'error' as appropriate
 - ensure that e_shstrndx < hdr->e_shnum, to prevent out-of-bound reads

Fixes several crashes that could occur when loading a kernel module.

Quick glance from martin@
2014-07-09 05:50:51 +00:00
maxv
8d909506c6 Remove this (symtabindex == -1) check; it is already handled by (nsym != 1).
Put a KASSERT instead.
2014-07-06 15:35:32 +00:00
maxv
3021bdd8e1 Use a macro instead of always putting __func__ and __LINE__. 2014-07-06 15:22:31 +00:00
matt
a95f2fdeea Ignore REL/RELA if they aren't against a PROGBIT section.
(this causes EXIDX sections to be ignored for ARM).
2013-08-09 05:10:14 +00:00
pooka
79f4679e52 size_t needs to printed with %zu 2012-12-30 20:52:20 +00:00
christos
ec97828f5a Always provide a meaningful short name for the kobj in the error message,
as well as the function name and the linenumber, without extra line feeds.
2011-08-13 21:04:05 +00:00
joerg
3eb244d801 Retire varargs.h support. Move machine/stdarg.h logic into MI
sys/stdarg.h and expect compiler to provide proper builtins, defaulting
to the GCC interface. lint still has a special fallback.
Reduce abuse of _BSD_VA_LIST_ by defining __va_list by default and
derive va_list as required by standards.
2011-07-17 20:54:30 +00:00
matt
a20c25e484 Deal with ELFnn_MACHDEP_ID_CASES a bit better. 2011-01-18 08:15:51 +00:00
pooka
da792af712 Add an optional hook for adjusting module string table after load.
Currently to be used for rump "SAOS" namespace trick.
2010-04-26 22:58:53 +00:00
pooka
bbc50ef41d Due to the schizophrenic nature of kobj (mem + vfs source),
split the module in twain to subj_kobj.c (master + mem) and
subr_kobj_vfs.c (vfs).
2009-11-27 17:54:11 +00:00
dyoung
61fa5bb9be Make kobj_stat() return ENOSYS instead of panicking ("not modular")
on non-MODULAR kernels.  Make a few kobj_stat() callers check for
a non-zero return code and deal gracefully.
2009-06-17 21:04:25 +00:00
jnemeth
d73b80a12b Move all namei flags handling into kobj_load_file().
When I originally wrote this, I was going for maximum flexibility.
However, after a private discussion with dholland@, I see how this
will cause problems with the future world order of namei whenever
that might be.  At the moment, I don't need the extra flexibility,
but if something comes up this may have to be revisited.
2009-05-26 08:34:22 +00:00
jnemeth
a15ece476a Phase 0.5 of my options MODULAR enhancements. As suggested by ad@,
these commits move all path handling into module_do_load() from
kobj_load_file().  This way the final path used to load a module
is available for loading <module>.plist, which will store parameters
for a module.  The end goal of this project is good support for
MODULAR device drivers.
2009-05-25 22:33:00 +00:00
ad
193d553767 Split out kobj structures so crash/ddb can get at them. 2009-05-24 15:00:24 +00:00
ad
cb95ab6e35 Fix a crash observed when trying to load a corrupted ELF image. 2009-05-23 15:13:57 +00:00
apb
0cc72e51ac Use "defopt MODULAR" in sys/conf/files, and #include "opt_modular.h"
in all kernel sources that use the MODULAR option.
Proposed in tech-kern on 18 Jan 2009.
2009-02-13 22:41:00 +00:00
pooka
e99d5fab49 Sprinkle comments explaining purpose of kobj_machdep(), per email from ad.
no functional change
2009-01-08 01:03:24 +00:00
pooka
2577e51e90 revert previous, disabled aliasing in offending build
(XXX: two evil casts in the original)
2009-01-01 22:17:55 +00:00
pooka
44a89fbb01 Squelch type-punning warnings with void * casts. We are allowed
to do this because the pointers do not have aliases.
2009-01-01 21:35:22 +00:00
ad
38cbe1484b Another fix to previous. 2008-11-16 16:23:58 +00:00
ad
e2a270368e Correction to previous. 2008-11-16 14:55:42 +00:00
ad
d89eff7233 Do not look up any given symbol more than once. Does away with the vast
majority of symbol table lookups.
2008-11-16 11:26:28 +00:00
ad
6b88fdc0eb Use NOCHROOT when doing the lookup against the standard module path.
Prevents abuse of chroots to load tainted kernel modules.
2008-11-14 22:00:23 +00:00
ad
307004b54f Don't try appending ".o" to the module path. 2008-11-12 14:22:17 +00:00
ad
0efea177e3 Remove LKMs and switch to the module framework, pass 1.
Proposed on tech-kern@.
2008-11-12 12:35:50 +00:00
ad
19463db480 Correct an error message. 2008-10-20 20:07:35 +00:00
ad
ee66516bfd PR kern/38814 ksyms needs locking
- Make ksyms MT safe.
- Fix deadlock from an operation like "modload foo.lkm < /dev/ksyms".
- Fix uninitialized structure members.
- Reduce memory footprint for loaded modules.
- Export ksyms structures for kernel grovellers like savecore.
- Some KNF.
2008-10-20 10:24:18 +00:00
ad
1b31761afa kobj_read: plug a leak. 2008-10-06 10:46:58 +00:00
ad
61270d54f1 If autoloading a module, don't consider the current working directory. 2008-05-20 19:20:38 +00:00
martin
bd3d112a87 fix !MODULAR compiles 2008-05-20 16:18:51 +00:00
ad
7a3561a8dc PR kern/38694 module dependencies do not work as expected
Autoload modules from the correct path based on kernel version.
2008-05-20 14:11:55 +00:00
ad
d0bd9aa452 - Do local relocs before loading requisite modules, and all others only
after requisite modules have been loaded. For PR kern/38697.
- Simplify kobj interface slightly to make error handling easier.
2008-05-20 13:34:44 +00:00
jmcneill
3ea8229871 If we see a non-loadable BSS section in a pre-loaded module, make sure we
don't return success from kobj_load or nasty things will happen.
2008-05-19 17:33:42 +00:00
ad
517f9684fe Make it compile as part of librump. 2008-05-04 12:51:44 +00:00
ad
5982e60c2b Broken assertions. 2008-05-03 15:57:17 +00:00
ad
3f1b4f1759 Keep the program table and section strings around after loading the object,
since module_find_section() needs them.
2008-05-02 13:00:01 +00:00
ad
416e98a01e Another fix for pre-loaded modules. 2008-05-01 17:07:10 +00:00
ad
8ef40c772a Get the pre-loaded module code working. 2008-05-01 14:44:48 +00:00
martin
ce099b4099 Remove clause 3 and 4 from TNF licenses 2008-04-28 20:22:51 +00:00
ad
a9ca7a3734 Catch up with descriptor handling changes. See kern_descrip.c revision
1.173 for details.
2008-03-21 21:54:58 +00:00