03 Oct, 2019

1 commit

  • The new __must_check annotation on __copy_from_user() successfully
    identified some code that has lacked the check since at least
    linux-2.1.73:

    arch/x86/math-emu/reg_ld_str.c:88:2: error: ignoring return value of \
    function declared with 'warn_unused_result' attribute [-Werror,-Wunused-result]
            __copy_from_user(sti_ptr, s, 10);
            ^~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~
    arch/x86/math-emu/reg_ld_str.c:1129:2: error: ignoring return value of \
    function declared with 'warn_unused_result' attribute [-Werror,-Wunused-result]
            __copy_from_user(register_base + offset, s, other);
            ^~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    arch/x86/math-emu/reg_ld_str.c:1131:3: error: ignoring return value of \
    function declared with 'warn_unused_result' attribute [-Werror,-Wunused-result]
                    __copy_from_user(register_base, s + other, offset);
                    ^~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    In addition, the get_user()/put_user() helpers do not enforce a return
    value check, but actually still require one. These have been missing for
    even longer.

    Change the internal wrappers around get_user()/put_user() to force
    a signal and add a corresponding wrapper around __copy_from_user()
    to check all such cases.

    [ bp: Break long lines. ]

    Fixes: 257e458057e5 ("Import 2.1.73")
    Fixes: 9dd819a15162 ("uaccess: add missing __must_check attributes")
    Signed-off-by: Arnd Bergmann
    Signed-off-by: Borislav Petkov
    Reviewed-by: Kees Cook
    Cc: "H. Peter Anvin"
    Cc: Bill Metzenthen
    Cc: Ingo Molnar
    Cc: Thomas Gleixner
    Cc: x86-ml
    Link: https://lkml.kernel.org/r/20191001142344.1274185-1-arnd@arndb.de

    Arnd Bergmann
     

04 Jan, 2019

1 commit

  • Nobody has actually used the type (VERIFY_READ vs VERIFY_WRITE) argument
    of the user address range verification function since we got rid of the
    old racy i386-only code to walk page tables by hand.

    It existed because the original 80386 would not honor the write protect
    bit when in kernel mode, so you had to do COW by hand before doing any
    user access. But we haven't supported that in a long time, and these
    days the 'type' argument is a purely historical artifact.

    A discussion about extending 'user_access_begin()' to do the range
    checking resulted this patch, because there is no way we're going to
    move the old VERIFY_xyz interface to that model. And it's best done at
    the end of the merge window when I've done most of my merges, so let's
    just get this done once and for all.

    This patch was mostly done with a sed-script, with manual fix-ups for
    the cases that weren't of the trivial 'access_ok(VERIFY_xyz' form.

    There were a couple of notable cases:

    - csky still had the old "verify_area()" name as an alias.

    - the iter_iov code had magical hardcoded knowledge of the actual
    values of VERIFY_{READ,WRITE} (not that they mattered, since nothing
    really used it)

    - microblaze used the type argument for a debug printout

    but other than those oddities this should be a total no-op patch.

    I tried to fix up all architectures, did fairly extensive grepping for
    access_ok() uses, and the changes are trivial, but I may have missed
    something. Any missed conversion should be trivially fixable, though.

    Signed-off-by: Linus Torvalds

    Linus Torvalds
     

02 Nov, 2017

1 commit

  • Many source files in the tree are missing licensing information, which
    makes it harder for compliance tools to determine the correct license.

    By default all files without license information are under the default
    license of the kernel, which is GPL version 2.

    Update the files which contain no license information with the 'GPL-2.0'
    SPDX license identifier. The SPDX identifier is a legally binding
    shorthand, which can be used instead of the full boiler plate text.

    This patch is based on work done by Thomas Gleixner and Kate Stewart and
    Philippe Ombredanne.

    How this work was done:

    Patches were generated and checked against linux-4.14-rc6 for a subset of
    the use cases:
    - file had no licensing information it it.
    - file was a */uapi/* one with no licensing information in it,
    - file was a */uapi/* one with existing licensing information,

    Further patches will be generated in subsequent months to fix up cases
    where non-standard license headers were used, and references to license
    had to be inferred by heuristics based on keywords.

    The analysis to determine which SPDX License Identifier to be applied to
    a file was done in a spreadsheet of side by side results from of the
    output of two independent scanners (ScanCode & Windriver) producing SPDX
    tag:value files created by Philippe Ombredanne. Philippe prepared the
    base worksheet, and did an initial spot review of a few 1000 files.

    The 4.13 kernel was the starting point of the analysis with 60,537 files
    assessed. Kate Stewart did a file by file comparison of the scanner
    results in the spreadsheet to determine which SPDX license identifier(s)
    to be applied to the file. She confirmed any determination that was not
    immediately clear with lawyers working with the Linux Foundation.

    Criteria used to select files for SPDX license identifier tagging was:
    - Files considered eligible had to be source code files.
    - Make and config files were included as candidates if they contained >5
    lines of source
    - File already had some variant of a license header in it (even if
    Reviewed-by: Philippe Ombredanne
    Reviewed-by: Thomas Gleixner
    Signed-off-by: Greg Kroah-Hartman

    Greg Kroah-Hartman
     

29 Aug, 2017

2 commits

  • The GDT entry related code uses two ways to access entries via
    union fields:

    - bitfields

    - macros which initialize the two 16-bit parts of the entry
    by magic shift and mask operations.

    Clean it up and only use the bitfields to initialize and access entries.

    ( The old access patterns were partly done due to GCC optimizing bitfield
    accesses in a horrible way - that's mostly fixed these days and clarity
    of code in such low level accessors is very important. )

    Signed-off-by: Thomas Gleixner
    Cc: Andy Lutomirski
    Cc: Borislav Petkov
    Cc: Brian Gerst
    Cc: Denys Vlasenko
    Cc: H. Peter Anvin
    Cc: Josh Poimboeuf
    Cc: Linus Torvalds
    Cc: Peter Zijlstra
    Cc: Steven Rostedt
    Link: http://lkml.kernel.org/r/20170828064958.197673367@linutronix.de
    Signed-off-by: Ingo Molnar

    Thomas Gleixner
     
  • desc_struct is a union of u32 fields and bitfields. The access to the u32
    fields is done with magic macros.

    Convert it to use the bitfields and replace the macro magic with parseable
    inline functions.

    Signed-off-by: Thomas Gleixner
    Cc: Andy Lutomirski
    Cc: Borislav Petkov
    Cc: Brian Gerst
    Cc: Denys Vlasenko
    Cc: H. Peter Anvin
    Cc: Josh Poimboeuf
    Cc: Linus Torvalds
    Cc: Peter Zijlstra
    Cc: Steven Rostedt
    Link: http://lkml.kernel.org/r/20170828064958.042406718@linutronix.de
    Signed-off-by: Ingo Molnar

    Thomas Gleixner
     

08 Jun, 2017

1 commit

  • ... because this is exactly what it is: the number of entries in the
    LDT. Calling it "size" is simply confusing and it is actually begging
    to be called "nr_entries" or somesuch, especially if you see constructs
    like:

    alloc_size = size * LDT_ENTRY_SIZE;

    since LDT_ENTRY_SIZE is the size of a single entry.

    There should be no functionality change resulting from this patch, as
    the before/after output from tools/testing/selftests/x86/ldt_gdt.c
    shows.

    Signed-off-by: Borislav Petkov
    Acked-by: Andy Lutomirski
    Cc: Linus Torvalds
    Cc: Peter Zijlstra
    Cc: Thomas Gleixner
    Link: http://lkml.kernel.org/r/20170606173116.13977-1-bp@alien8.de
    [ Renamed 'n_entries' to 'nr_entries' ]
    Signed-off-by: Ingo Molnar

    Borislav Petkov
     

08 Aug, 2015

1 commit

  • Commit 37868fe113ff ("x86/ldt: Make modify_ldt synchronous")
    introduced a new struct ldt_struct anchored at mm->context.ldt.

    Adapt the x86 fpu emulation code to use that new structure.

    Signed-off-by: Juergen Gross
    Reviewed-by: Andy Lutomirski
    Cc: # On top of: 37868fe113ff: x86/ldt: Make modify_ldt synchronous
    Cc: Linus Torvalds
    Cc: Peter Zijlstra
    Cc: Thomas Gleixner
    Cc: billm@melbpc.org.au
    Link: http://lkml.kernel.org/r/1438883674-1240-1-git-send-email-jgross@suse.com
    Signed-off-by: Ingo Molnar

    Juergen Gross
     

19 May, 2015

1 commit

  • So 6 years ago we made the FPU fpstate dynamically allocated:

    aa283f49276e ("x86, fpu: lazy allocation of FPU area - v5")
    61c4628b5386 ("x86, fpu: split FPU state from task struct - v5")

    In hindsight this was a mistake:

    - it complicated context allocation failure handling, such as:

    /* kthread execs. TODO: cleanup this horror. */
    if (WARN_ON(fpstate_alloc_init(fpu)))
    force_sig(SIGKILL, tsk);

    - it caused us to enable irqs in fpu__restore():

    local_irq_enable();
    /*
    * does a slab alloc which can sleep
    */
    if (fpstate_alloc_init(fpu)) {
    /*
    * ran out of memory!
    */
    do_group_exit(SIGKILL);
    return;
    }
    local_irq_disable();

    - it (slightly) slowed down task creation/destruction by adding
    slab allocation/free pattens.

    - it made access to context contents (slightly) slower by adding
    one more pointer dereference.

    The motivation for the dynamic allocation was two-fold:

    - reduce memory consumption by non-FPU tasks

    - allocate and handle only the necessary amount of context for
    various XSAVE processors that have varying hardware frame
    sizes.

    These days, with glibc using SSE memcpy by default and GCC optimizing
    for SSE/AVX by default, the scope of FPU using apps on an x86 system is
    much larger than it was 6 years ago.

    For example on a freshly installed Fedora 21 desktop system, with a
    recent kernel, all non-kthread tasks have used the FPU shortly after
    bootup.

    Also, even modern embedded x86 CPUs try to support the latest vector
    instruction set - so they'll too often use the larger xstate frame
    sizes.

    So remove the dynamic allocation complication by embedding the FPU
    fpstate in task_struct again. This should make the FPU a lot more
    accessible to all sorts of atomic contexts.

    We could still optimize for the xstate frame size in the future,
    by moving the state structure to the last element of task_struct,
    and allocating only a part of that.

    This change is kept minimal by still keeping the ctx_alloc()/free()
    routines (that now do nothing substantial) - we'll remove them in
    the following patches.

    Reviewed-by: Borislav Petkov
    Cc: Andy Lutomirski
    Cc: Dave Hansen
    Cc: Fenghua Yu
    Cc: H. Peter Anvin
    Cc: Linus Torvalds
    Cc: Oleg Nesterov
    Cc: Peter Zijlstra
    Cc: Thomas Gleixner
    Signed-off-by: Ingo Molnar

    Ingo Molnar
     

11 May, 2010

1 commit


10 Feb, 2009

1 commit

  • do_device_not_available() is the handler for #NM and it declares that
    it takes a unsigned long and calls math_emu(), which takes a long
    argument and surprisingly expects the stack frame starting at the zero
    argument would match struct math_emu_info, which isn't true regardless
    of configuration in the current code.

    This patch makes do_device_not_available() take struct pt_regs like
    other exception handlers and initialize struct math_emu_info with
    pointer to it and pass pointer to the math_emu_info to math_emulate()
    like normal C functions do. This way, unless gcc makes a copy of
    struct pt_regs in do_device_not_available(), the register frame is
    correctly accessed regardless of kernel configuration or compiler
    used.

    This doesn't fix all math_emu problems but it at least gets it
    somewhat working.

    Signed-off-by: Tejun Heo
    Signed-off-by: Ingo Molnar

    Tejun Heo
     

09 Feb, 2009

1 commit

  • Impact: cleanup

    * Come on, struct info? s/struct info/struct math_emu_info/

    * Use struct pt_regs and kernel_vm86_regs instead of defining its own
    register frame structure.

    Signed-off-by: Tejun Heo
    Signed-off-by: Ingo Molnar

    Tejun Heo
     

20 Apr, 2008

1 commit

  • Split the FPU save area from the task struct. This allows easy migration
    of FPU context, and it's generally cleaner. It also allows the following
    two optimizations:

    1) only allocate when the application actually uses FPU, so in the first
    lazy FPU trap. This could save memory for non-fpu using apps. Next patch
    does this lazy allocation.

    2) allocate the right size for the actual cpu rather than 512 bytes always.
    Patches enabling xsave/xrstor support (coming shortly) will take advantage
    of this.

    Signed-off-by: Suresh Siddha
    Signed-off-by: Arjan van de Ven
    Signed-off-by: Ingo Molnar
    Signed-off-by: Thomas Gleixner

    Suresh Siddha
     

11 Oct, 2007

1 commit