• Luis Chamberlain's avatar
    module: add sanity check for ELF module section · 46752820
    Luis Chamberlain authored
    The ELF ".gnu.linkonce.this_module" section is special, it is what we
    use to construct the struct module __this_module, which THIS_MODULE
    points to. When userspace loads a module we always deal first with a
    copy of the userspace buffer, and twiddle with the userspace copy's
    version of the struct module. Eventually we allocate memory to do a
    memcpy() of that struct module, under the assumption that the module
    size is right. But we have no validity checks against the size or
    the requirements for the section.
    
    Add some validity checks for the special module section early and while
    at it, cache the module section index early, so we don't have to do that
    later.
    
    While at it, just move over the assigment of the info->mod to make the
    code clearer. The validity checker also adds an explicit size check to
    ensure the module section size matches the kernel's run time size for
    sizeof(struct module). This should prevent sloppy loads of modules
    which are built today *without* actually increasing the size of
    the struct module. A developer today can for example expand the size
    of struct module, rebuild a directoroy 'make fs/xfs/' for example and
    then try to insmode the driver there. That module would in effect have
    an incorrect size. This new size check would put a stop gap against such
    mistakes.
    
    This also makes the entire goal of ".gnu.linkonce.this_module" pretty
    clear. Before this patch verification of the goal / intent required some
    Indian Jones whips, torches and cleaning up big old spider webs.
    Signed-off-by: default avatarLuis Chamberlain <mcgrof@kernel.org>
    46752820
main.c 80 KB