16 Jan, 2012

1 commit

  • Recent changes to kernel/module.c caused the following compile
    error:

    kernel/module.c: In function ‘show_taint’:
    kernel/module.c:1024:2: error: implicit declaration of function ‘module_flags_taint’ [-Werror=implicit-function-declaration]
    cc1: some warnings being treated as errors

    Correct this error by moving the definition of module_flags_taint
    outside of the #ifdef CONFIG_MODULE_UNLOAD section.

    Signed-off-by: Kevin Winchester
    Signed-off-by: Linus Torvalds

    Kevin Winchester
     

13 Jan, 2012

5 commits

  • Recent tools do not want to use /proc to retrieve module information. A few
    values are currently missing from sysfs to replace the information available
    in /proc/modules.

    This adds /sys/module/*/{coresize,initsize,taint} attributes.

    TAINT_PROPRIETARY_MODULE (P) and TAINT_OOT_MODULE (O) flags are both always
    shown now, and do no longer exclude each other, also in /proc/modules.

    Replace the open-coded sysfs attribute initializers with the __ATTR() macro.

    Add the new attributes to Documentation/ABI.

    Cc: Lucas De Marchi
    Signed-off-by: Kay Sievers
    Signed-off-by: Rusty Russell

    Kay Sievers
     
  • Use more flexible pr_debug. This allows:

    echo "module module +p" > /dbg/dynamic_debug/control

    to turn on debug messages when needed.

    Signed-off-by: Jim Cromie
    Signed-off-by: Rusty Russell

    Jim Cromie
     
  • module_ref contains two "unsigned int" fields.

    Thats now too small, since some machines can open more than 2^32 files.

    Check commit 518de9b39e8 (fs: allow for more than 2^31 files) for
    reference.

    We can add an aligned(2 * sizeof(unsigned long)) attribute to force
    alloc_percpu() allocating module_ref areas in single cache lines.

    Signed-off-by: Eric Dumazet
    CC: Rusty Russell
    CC: Tejun Heo
    CC: Robin Holt
    CC: David Miller
    Signed-off-by: Rusty Russell

    Eric Dumazet
     
  • Looking at /proc/kallsyms, one starts to ponder whether all of the extra
    strtab-related complexity in module.c is worth the memory savings.

    Instead of making the add_kallsyms() loop even more complex, I tried the
    other route of deleting the strmap logic and naively copying each string
    into core_strtab with no consideration for consolidating duplicates.

    Performance on an "already exists" insmod of nvidia.ko (runs
    add_kallsyms() but does not actually initialize the module):

    Original scheme: 1.230s
    With naive copying: 0.058s

    Extra space used: 35k (of a 408k module).

    Signed-off-by: Kevin Cernekee
    Signed-off-by: Rusty Russell
    LKML-Reference:

    Kevin Cernekee
     
  • Signed-off-by: Kevin Cernekee
    Signed-off-by: Rusty Russell

    Kevin Cernekee
     

07 Nov, 2011

3 commits

  • * 'modsplit-Oct31_2011' of git://git.kernel.org/pub/scm/linux/kernel/git/paulg/linux: (230 commits)
    Revert "tracing: Include module.h in define_trace.h"
    irq: don't put module.h into irq.h for tracking irqgen modules.
    bluetooth: macroize two small inlines to avoid module.h
    ip_vs.h: fix implicit use of module_get/module_put from module.h
    nf_conntrack.h: fix up fallout from implicit moduleparam.h presence
    include: replace linux/module.h with "struct module" wherever possible
    include: convert various register fcns to macros to avoid include chaining
    crypto.h: remove unused crypto_tfm_alg_modname() inline
    uwb.h: fix implicit use of asm/page.h for PAGE_SIZE
    pm_runtime.h: explicitly requires notifier.h
    linux/dmaengine.h: fix implicit use of bitmap.h and asm/page.h
    miscdevice.h: fix up implicit use of lists and types
    stop_machine.h: fix implicit use of smp.h for smp_processor_id
    of: fix implicit use of errno.h in include/linux/of.h
    of_platform.h: delete needless include
    acpi: remove module.h include from platform/aclinux.h
    miscdevice.h: delete unnecessary inclusion of module.h
    device_cgroup.h: delete needless include
    net: sch_generic remove redundant use of
    net: inet_timewait_sock doesnt need
    ...

    Fix up trivial conflicts (other header files, and removal of the ab3550 mfd driver) in
    - drivers/media/dvb/frontends/dibx000_common.c
    - drivers/media/video/{mt9m111.c,ov6650.c}
    - drivers/mfd/ab3550-core.c
    - include/linux/dmaengine.h

    Linus Torvalds
     
  • Use of the GPL or a compatible licence doesn't necessarily make the code
    any good. We already consider staging modules to be suspect, and this
    should also be true for out-of-tree modules which may receive very
    little review.

    Signed-off-by: Ben Hutchings
    Reviewed-by: Dave Jones
    Acked-by: Greg Kroah-Hartman
    Signed-off-by: Rusty Russell (patched oops-tracing.txt)

    Ben Hutchings
     
  • Dynamic debugging is currently disabled for tainted modules, except
    for TAINT_CRAP. This prevents use of dynamic debugging for
    out-of-tree modules once the next patch is applied.

    This condition was apparently intended to avoid a crash if a force-
    loaded module has an incompatible definition of dynamic debug
    structures. However, a administrator that forces us to load a module
    is claiming that it *is* compatible even though it fails our version
    checks. If they are mistaken, there are any number of ways the module
    could crash the system.

    As a side-effect, proprietary and other tainted modules can now use
    dynamic_debug.

    Signed-off-by: Ben Hutchings
    Acked-by: Mathieu Desnoyers
    Signed-off-by: Rusty Russell

    Ben Hutchings
     

31 Oct, 2011

1 commit

  • The changed files were only including linux/module.h for the
    EXPORT_SYMBOL infrastructure, and nothing else. Revector them
    onto the isolated export header for faster compile times.

    Nothing to see here but a whole lot of instances of:

    -#include
    +#include

    This commit is only changing the kernel dir; next targets
    will probably be mm, fs, the arch dirs, etc.

    Signed-off-by: Paul Gortmaker

    Paul Gortmaker
     

11 Aug, 2011

1 commit

  • Copy the information needed from struct module into a local module list
    held within tracepoint.c from within the module coming/going notifier.

    This vastly simplifies locking of tracepoint registration /
    unregistration, because we don't have to take the module mutex to
    register and unregister tracepoints anymore. Steven Rostedt ran into
    dependency problems related to modules mutex vs kprobes mutex vs ftrace
    mutex vs tracepoint mutex that seems to be hard to fix without removing
    this dependency between tracepoint and module mutex. (note: it should be
    investigated whether kprobes could benefit of being dissociated from the
    modules mutex too.)

    This also fixes module handling of tracepoint list iterators, because it
    was expecting the list to be sorted by pointer address. Given we have
    control on our own list now, it's OK to sort this list which has
    tracepoints as its only purpose. The reason why this sorting is required
    is to handle the fact that seq files (and any read() operation from
    user-space) cannot hold the tracepoint mutex across multiple calls, so
    list entries may vanish between calls. With sorting, the tracepoint
    iterator becomes usable even if the list don't contain the exact item
    pointed to by the iterator anymore.

    Signed-off-by: Mathieu Desnoyers
    Acked-by: Jason Baron
    CC: Ingo Molnar
    CC: Lai Jiangshan
    CC: Peter Zijlstra
    CC: Thomas Gleixner
    CC: Masami Hiramatsu
    Link: http://lkml.kernel.org/r/20110810191839.GC8525@Krystal
    Signed-off-by: Steven Rostedt

    Mathieu Desnoyers
     

24 Jul, 2011

3 commits

  • Userspace wants to manage module parameters with udev rules.
    This currently only works for loaded modules, but not for
    built-in ones.

    To allow access to the built-in modules we need to
    re-trigger all module load events that happened before any
    userspace was running. We already do the same thing for all
    devices, subsystems(buses) and drivers.

    This adds the currently missing /sys/module//uevent files
    to all module entries.

    Signed-off-by: Kay Sievers
    Signed-off-by: Rusty Russell (split & trivial fix)

    Kay Sievers
     
  • This simplifies the next patch, where we have an attribute on a
    builtin module (ie. module == NULL).

    Signed-off-by: Kay Sievers
    Signed-off-by: Rusty Russell (split into 2)

    Kay Sievers
     
  • The module loader code allows architectures to hook into the code by
    providing a small number of entry points that each arch must implement.
    This patch provides __weakly linked generic implementations of these
    entry points for architectures that don't need to do anything special.

    Signed-off-by: Jonas Bonn
    Signed-off-by: Rusty Russell

    Jonas Bonn
     

24 May, 2011

1 commit

  • * 'staging-next' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/staging-2.6: (970 commits)
    staging: usbip: replace usbip_u{dbg,err,info} and printk with dev_ and pr_
    staging:iio: Trivial kconfig reorganization and uniformity improvements.
    staging:iio:documenation partial update.
    staging:iio: use pollfunc allocation helpers in remaining drivers.
    staging:iio:max1363 misc cleanups and use of for_each_bit_set to simplify event code spitting out.
    staging:iio: implement an iio_info structure to take some of the constant elements out of iio_dev.
    staging:iio:meter:ade7758: Use private data space from iio_allocate_device
    staging:iio:accel:lis3l02dq make write_reg_8 take value not a pointer to value.
    staging:iio: ring core cleanups + check if read_last available in lis3l02dq
    staging:iio:core cleanup: squash tiny wrappers and use dev_set_name to handle creation of event interface name.
    staging:iio: poll func allocation clean up.
    staging:iio:ad7780 trivial unused header cleanup.
    staging:iio:adc: AD7780: Use private data space from iio_allocate_device + trivial fixes
    staging:iio:adc:AD7780: Convert to new channel registration method
    staging:iio:adc: AD7606: Drop dev_data in favour of iio_priv()
    staging:iio:adc: AD7606: Consitently use indio_dev
    staging:iio: Rip out helper for software rings.
    staging:iio:adc:AD7298: Use private data space from iio_allocate_device
    staging:iio: rationalization of different buffer implementation hooks.
    staging:iio:imu:adis16400 avoid allocating rx, tx, and state separately from iio_dev.
    ...

    Fix up trivial conflicts in
    - drivers/staging/intel_sst/intelmid.c: patches applied in both branches
    - drivers/staging/rt2860/common/cmm_data_{pci,usb}.c: removed vs spelling
    - drivers/staging/usbip/vhci_sysfs.c: trivial header file inclusion

    Linus Torvalds
     

19 May, 2011

7 commits

  • The function is_exported() with its helper function lookup_symbol() are used to
    verify if a provided symbol is effectively exported by the kernel or by the
    modules. Now that both have their symbols sorted we can replace a linear search
    with a binary search which provide a considerably speed-up.

    This work was supported by a hardware donation from the CE Linux Forum.

    Signed-off-by: Alessio Igor Bogani
    Acked-by: Greg Kroah-Hartman
    Signed-off-by: Rusty Russell

    Alessio Igor Bogani
     
  • Takes advantage of the order and locates symbols using binary search.

    This work was supported by a hardware donation from the CE Linux Forum.

    Signed-off-by: Alessio Igor Bogani
    Signed-off-by: Rusty Russell
    Tested-by: Dirk Behme

    Alessio Igor Bogani
     
  • Instead of having a callback function for each symbol in the kernel,
    have a callback for each array of symbols.

    This eases the logic when we move to sorted symbols and binary search.

    Signed-off-by: Rusty Russell
    Signed-off-by: Alessio Igor Bogani

    Rusty Russell
     
  • Split the unprotect function into a function per section to make
    the code more readable and add the missing static declaration.

    Signed-off-by: Jan Glauber
    Signed-off-by: Rusty Russell

    Jan Glauber
     
  • While debugging I stumbled over two problems in the code that protects module
    pages.

    First issue is that disabling the protection before freeing init or unload of
    a module is not symmetric with the enablement. For instance, if pages are set
    to RO the page range from module_core to module_core + core_ro_size is
    protected. If a module is unloaded the page range from module_core to
    module_core + core_size is set back to RW.
    So pages that were not set to RO are also changed to RW.
    This is not critical but IMHO it should be symmetric.

    Second issue is that while set_memory_rw & set_memory_ro are used for
    RO/RW changes only set_memory_nx is involved for NX/X. One would await that
    the inverse function is called when the NX protection should be removed,
    which is not the case here, unless I'm missing something.

    Signed-off-by: Jan Glauber
    Signed-off-by: Rusty Russell

    Jan Glauber
     
  • Reset mod->init_ro_size to zero after the init part of a module is unloaded.
    Otherwise we need to check if module->init is NULL in the unprotect functions
    in the next patch.

    Signed-off-by: Jan Glauber
    Signed-off-by: Rusty Russell

    Jan Glauber
     
  • Fix function prototype to be ANSI-C compliant, consistent with other
    function prototypes, addressing a sparse warning.

    Signed-off-by: Daniel J Blueman
    Signed-off-by: Rusty Russell

    Daniel J Blueman
     

26 Apr, 2011

1 commit

  • Driver modules from the staging directory are marked 'tainted'
    by module.c. Subsequently, tainted modules are denied dynamic
    debugging. This is unwanted behavior, since staging modules should
    be able to use the dynamic debugging mechanism.

    Please merge this also into the staging-linus branch.

    Signed-off-by: Roland Vossen
    Acked-by: Jason Baron
    Signed-off-by: Greg Kroah-Hartman

    Roland Vossen
     

31 Mar, 2011

1 commit


23 Mar, 2011

1 commit

  • In an effort to reduce kernel address leaks that might be used to help
    target kernel privilege escalation exploits, this patch uses %pK when
    displaying addresses in /proc/kallsyms, /proc/modules, and
    /sys/module/*/sections/*.

    Note that this changes %x to %p, so some legitimately 0 values in
    /proc/kallsyms would have changed from 00000000 to "(null)". To avoid
    this, "(null)" is not used when using the "K" format. Anything that was
    already successfully parsing "(null)" in addition to full hex digits
    should have no problem with this change. (Thanks to Joe Perches for the
    suggestion.) Due to the %x to %p, "void *" casts are needed since these
    addresses are already "unsigned long" everywhere internally, due to their
    starting life as ELF section offsets.

    Signed-off-by: Kees Cook
    Cc: Eugene Teo
    Cc: Dan Rosenberg
    Cc: Rusty Russell
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Kees Cook
     

03 Feb, 2011

1 commit

  • Make the tracepoints more robust, making them solid enough to handle compiler
    changes by not relying on anything based on compiler-specific behavior with
    respect to structure alignment. Implement an approach proposed by David Miller:
    use an array of const pointers to refer to the individual structures, and export
    this pointer array through the linker script rather than the structures per se.
    It will consume 32 extra bytes per tracepoint (24 for structure padding and 8
    for the pointers), but are less likely to break due to compiler changes.

    History:

    commit 7e066fb8 tracepoints: add DECLARE_TRACE() and DEFINE_TRACE()
    added the aligned(32) type and variable attribute to the tracepoint structures
    to deal with gcc happily aligning statically defined structures on 32-byte
    multiples.

    One attempt was to use a 8-byte alignment for tracepoint structures by applying
    both the variable and type attribute to tracepoint structures definitions and
    declarations. It worked fine with gcc 4.5.1, but broke with gcc 4.4.4 and 4.4.5.

    The reason is that the "aligned" attribute only specify the _minimum_ alignment
    for a structure, leaving both the compiler and the linker free to align on
    larger multiples. Because tracepoint.c expects the structures to be placed as an
    array within each section, up-alignment cause NULL-pointer exceptions due to the
    extra unexpected padding.

    (this patch applies on top of -tip)

    Signed-off-by: Mathieu Desnoyers
    Acked-by: David S. Miller
    LKML-Reference:
    CC: Frederic Weisbecker
    CC: Ingo Molnar
    CC: Thomas Gleixner
    CC: Andrew Morton
    CC: Peter Zijlstra
    CC: Rusty Russell
    Signed-off-by: Steven Rostedt

    Mathieu Desnoyers
     

23 Dec, 2010

2 commits

  • The commit:

    84e1c6bb38eb318e456558b610396d9f1afaabf0
    x86: Add RO/NX protection for loadable kernel modules

    Broke the function tracer with this output:

    ------------[ cut here ]------------
    WARNING: at kernel/trace/ftrace.c:1014 ftrace_bug+0x114/0x171()
    Hardware name: Precision WorkStation 470
    Modules linked in: i2c_core(+)
    Pid: 86, comm: modprobe Not tainted 2.6.37-rc2+ #68
    Call Trace:
    [] warn_slowpath_common+0x85/0x9d
    [] ? __process_new_adapter+0x7/0x34 [i2c_core]
    [] ? __process_new_adapter+0x7/0x34 [i2c_core]
    [] warn_slowpath_null+0x1a/0x1c
    [] ftrace_bug+0x114/0x171
    [] ? __process_new_adapter+0x7/0x34 [i2c_core]
    [] ftrace_process_locs+0x1ae/0x274
    [] ? __process_new_adapter+0x7/0x34 [i2c_core]
    [] ftrace_module_notify+0x39/0x44
    [] notifier_call_chain+0x37/0x63
    [] __blocking_notifier_call_chain+0x46/0x5b
    [] blocking_notifier_call_chain+0x14/0x16
    [] sys_init_module+0x73/0x1f3
    [] system_call_fastpath+0x16/0x1b
    ---[ end trace 2aff4f4ca53ec746 ]---
    ftrace faulted on writing []
    __process_new_adapter+0x7/0x34 [i2c_core]

    The cause was that the module text was set to read only before ftrace
    could convert the calls to mcount to nops. Thus, the conversions failed
    due to not being able to write to the text locations.

    The simple fix is to move setting the module to read only after the
    module notifiers are called (where ftrace sets the module mcounts to nops).

    Reported-by: Peter Zijlstra
    Acked-by: Rusty Russell
    Signed-off-by: Steven Rostedt

    Steven Rostedt
     
  • Ingo Molnar
     

18 Nov, 2010

1 commit

  • This patch is a logical extension of the protection provided by
    CONFIG_DEBUG_RODATA to LKMs. The protection is provided by
    splitting module_core and module_init into three logical parts
    each and setting appropriate page access permissions for each
    individual section:

    1. Code: RO+X
    2. RO data: RO+NX
    3. RW data: RW+NX

    In order to achieve proper protection, layout_sections() have
    been modified to align each of the three parts mentioned above
    onto page boundary. Next, the corresponding page access
    permissions are set right before successful exit from
    load_module(). Further, free_module() and sys_init_module have
    been modified to set module_core and module_init as RW+NX right
    before calling module_free().

    By default, the original section layout and access flags are
    preserved. When compiled with CONFIG_DEBUG_SET_MODULE_RONX=y,
    the patch will page-align each group of sections to ensure that
    each page contains only one type of content and will enforce
    RO/NX for each group of pages.

    -v1: Initial proof-of-concept patch.
    -v2: The patch have been re-written to reduce the number of #ifdefs
    and to make it architecture-agnostic. Code formatting has also
    been corrected.
    -v3: Opportunistic RO/NX protection is now unconditional. Section
    page-alignment is enabled when CONFIG_DEBUG_RODATA=y.
    -v4: Removed most macros and improved coding style.
    -v5: Changed page-alignment and RO/NX section size calculation
    -v6: Fixed comments. Restricted RO/NX enforcement to x86 only
    -v7: Introduced CONFIG_DEBUG_SET_MODULE_RONX, added
    calls to set_all_modules_text_rw() and set_all_modules_text_ro()
    in ftrace
    -v8: updated for compatibility with linux 2.6.33-rc5
    -v9: coding style fixes
    -v10: more coding style fixes
    -v11: minor adjustments for -tip
    -v12: minor adjustments for v2.6.35-rc2-tip
    -v13: minor adjustments for v2.6.37-rc1-tip

    Signed-off-by: Siarhei Liakh
    Signed-off-by: Xuxian Jiang
    Acked-by: Arjan van de Ven
    Reviewed-by: James Morris
    Signed-off-by: H. Peter Anvin
    Cc: Andi Kleen
    Cc: Rusty Russell
    Cc: Stephen Rothwell
    Cc: Dave Jones
    Cc: Kees Cook
    Cc: Linus Torvalds
    LKML-Reference:
    [ minor cleanliness edits, -v14: build failure fix ]
    Signed-off-by: Ingo Molnar

    matthieu castet
     

11 Nov, 2010

1 commit

  • On use of trace_printk() there's a macro that determines if the format
    is static or a variable. If it is static, it defaults to __trace_bprintk()
    otherwise it uses __trace_printk().

    A while ago, Lai Jiangshan added __trace_bprintk(). In that patch, we
    discussed a way to allow modules to use it. The difference between
    __trace_bprintk() and __trace_printk() is that for faster processing,
    just the format and args are stored in the trace instead of running
    it through a sprintf function. In order to do this, the format used
    by the __trace_bprintk() had to be persistent.

    See commit 1ba28e02a18cbdbea123836f6c98efb09cbf59ec

    The problem comes with trace_bprintk() where the module is unloaded.
    The pointer left in the buffer is still pointing to the format.

    To solve this issue, the formats in the module were copied into kernel
    core. If the same format was used, they would use the same copy (to prevent
    memory leak). This all worked well until we tried to merge everything.

    At the time this was written, Lai Jiangshan, Frederic Weisbecker,
    Ingo Molnar and myself were all touching the same code. When this was
    merged, we lost the part of it that was in module.c. This kept out the
    copying of the formats and unloading the module could cause bad pointers
    left in the ring buffer.

    This patch adds back (with updates required for current kernel) the
    module code that sets up the necessary pointers.

    Cc: Lai Jiangshan
    Cc: Rusty Russell
    Signed-off-by: Steven Rostedt

    Steven Rostedt
     

27 Oct, 2010

1 commit

  • Building with CONFIG_KALLSYMS=n gives following warning:

    /mnt/src/linux-git/kernel/module.c: In function ‘post_relocation’:
    /mnt/src/linux-git/kernel/module.c:2534:2: warning: passing argument 2 of ‘add_kallsyms’ discards qualifiers from pointer target type
    /mnt/src/linux-git/kernel/module.c:2038:13: note: expected ‘struct load_info *’ but argument is of type ‘const struct load_info *’

    Signed-off-by: Michał Mirosław
    Signed-off-by: Rusty Russell

    Michał Mirosław
     

08 Oct, 2010

1 commit


06 Oct, 2010

1 commit

  • With all the recent module loading cleanups, we've minimized the code
    that sits under module_mutex, fixing various deadlocks and making it
    possible to do most of the module loading in parallel.

    However, that whole conversion totally missed the rather obscure code
    that adds a new module to the list for BUG() handling. That code was
    doubly obscure because (a) the code itself lives in lib/bugs.c (for
    dubious reasons) and (b) it gets called from the architecture-specific
    "module_finalize()" rather than from generic code.

    Calling it from arch-specific code makes no sense what-so-ever to begin
    with, and is now actively wrong since that code isn't protected by the
    module loading lock any more.

    So this commit moves the "module_bug_{finalize,cleanup}()" calls away
    from the arch-specific code, and into the generic code - and in the
    process protects it with the module_mutex so that the list operations
    are now safe.

    Future fixups:
    - move the module list handling code into kernel/module.c where it
    belongs.
    - get rid of 'module_bug_list' and just use the regular list of modules
    (called 'modules' - imagine that) that we already create and maintain
    for other reasons.

    Reported-and-tested-by: Thomas Gleixner
    Cc: Rusty Russell
    Cc: Adrian Bunk
    Cc: Andrew Morton
    Cc: stable@kernel.org
    Signed-off-by: Linus Torvalds

    Linus Torvalds
     

23 Sep, 2010

1 commit

  • base patch to implement 'jump labeling'. Based on a new 'asm goto' inline
    assembly gcc mechanism, we can now branch to labels from an 'asm goto'
    statment. This allows us to create a 'no-op' fastpath, which can subsequently
    be patched with a jump to the slowpath code. This is useful for code which
    might be rarely used, but which we'd like to be able to call, if needed.
    Tracepoints are the current usecase that these are being implemented for.

    Acked-by: David S. Miller
    Signed-off-by: Jason Baron
    LKML-Reference:

    [ cleaned up some formating ]

    Signed-off-by: Steven Rostedt

    Jason Baron
     

05 Aug, 2010

6 commits