Commit Graph

6 Commits

Author SHA1 Message Date
Vitaly Kuznetsov 6e825739ea x86/static-call: provide a way to do very early static-call updates
JIRA: https://issues.redhat.com/browse/RHEL-70669
CVE: CVE-2024-53241

commit 0ef8047b737d7480a5d4c46d956e97c190f13050
Author: Juergen Gross <jgross@suse.com>
Date:   Fri Nov 29 16:15:54 2024 +0100

    x86/static-call: provide a way to do very early static-call updates

    Add static_call_update_early() for updating static-call targets in
    very early boot.

    This will be needed for support of Xen guest type specific hypercall
    functions.

    This is part of XSA-466 / CVE-2024-53241.

    Reported-by: Andrew Cooper <andrew.cooper3@citrix.com>
    Signed-off-by: Juergen Gross <jgross@suse.com>
    Co-developed-by: Peter Zijlstra <peterz@infradead.org>
    Co-developed-by: Josh Poimboeuf <jpoimboe@redhat.com>

Conflicts:
	include/linux/compiler.h (skipping ed2f752e0e0a2, context)

Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
2025-02-18 17:58:05 +01:00
Rado Vrbovsky 867e888b15 Merge: static_call: Replace pointless WARN_ON() in static_call_module_notify()
MR: https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-9/-/merge_requests/5634

JIRA: https://issues.redhat.com/browse/RHEL-64532      
CVE: CVE-2024-49954      
      
Signed-off-by: David Arcari <darcari@redhat.com>

Approved-by: Rafael Aquini <raquini@redhat.com>
Approved-by: Steve Best <sbest@redhat.com>
Approved-by: Tony Camuso <tcamuso@redhat.com>
Approved-by: Jan Stancek <jstancek@redhat.com>
Approved-by: CKI KWF Bot <cki-ci-bot+kwf-gitlab-com@redhat.com>

Merged-by: Rado Vrbovsky <rvrbovsk@redhat.com>
2024-11-15 21:09:46 +00:00
David Arcari d5c54d6677 static_call: Replace pointless WARN_ON() in static_call_module_notify()
JIRA: https://issues.redhat.com/browse/RHEL-64532
CVE: CVE-2024-49954

commit fe513c2ef0a172a58f158e2e70465c4317f0a9a2
Author: Thomas Gleixner <tglx@linutronix.de>
Date:   Wed Sep 4 11:08:28 2024 +0200

    static_call: Replace pointless WARN_ON() in static_call_module_notify()

    static_call_module_notify() triggers a WARN_ON(), when memory allocation
    fails in __static_call_add_module().

    That's not really justified, because the failure case must be correctly
    handled by the well known call chain and the error code is passed
    through to the initiating userspace application.

    A memory allocation fail is not a fatal problem, but the WARN_ON() takes
    the machine out when panic_on_warn is set.

    Replace it with a pr_warn().

    Fixes: 9183c3f9ed ("static_call: Add inline static call infrastructure")
    Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
    Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
    Link: https://lkml.kernel.org/r/8734mf7pmb.ffs@tglx

Signed-off-by: David Arcari <darcari@redhat.com>
2024-10-30 13:40:35 -04:00
CKI Backport Bot 14490dee7f static_call: Handle module init failure correctly in static_call_del_module()
JIRA: https://issues.redhat.com/browse/RHEL-64157
CVE: CVE-2024-50002

commit 4b30051c4864234ec57290c3d142db7c88f10d8a
Author: Thomas Gleixner <tglx@linutronix.de>
Date:   Wed Sep 4 11:09:07 2024 +0200

    static_call: Handle module init failure correctly in static_call_del_module()

    Module insertion invokes static_call_add_module() to initialize the static
    calls in a module. static_call_add_module() invokes __static_call_init(),
    which allocates a struct static_call_mod to either encapsulate the built-in
    static call sites of the associated key into it so further modules can be
    added or to append the module to the module chain.

    If that allocation fails the function returns with an error code and the
    module core invokes static_call_del_module() to clean up eventually added
    static_call_mod entries.

    This works correctly, when all keys used by the module were converted over
    to a module chain before the failure. If not then static_call_del_module()
    causes a #GP as it blindly assumes that key::mods points to a valid struct
    static_call_mod.

    The problem is that key::mods is not a individual struct member of struct
    static_call_key, it's part of a union to save space:

            union {
                    /* bit 0: 0 = mods, 1 = sites */
                    unsigned long type;
                    struct static_call_mod *mods;
                    struct static_call_site *sites;
            };

    key::sites is a pointer to the list of built-in usage sites of the static
    call. The type of the pointer is differentiated by bit 0. A mods pointer
    has the bit clear, the sites pointer has the bit set.

    As static_call_del_module() blidly assumes that the pointer is a valid
    static_call_mod type, it fails to check for this failure case and
    dereferences the pointer to the list of built-in call sites, which is
    obviously bogus.

    Cure it by checking whether the key has a sites or a mods pointer.

    If it's a sites pointer then the key is not to be touched. As the sites are
    walked in the same order as in __static_call_init() the site walk can be
    terminated because all subsequent sites have not been touched by the init
    code due to the error exit.

    If it was converted before the allocation fail, then the inner loop which
    searches for a module match will find nothing.

    A fail in the second allocation in __static_call_init() is harmless and
    does not require special treatment. The first allocation succeeded and
    converted the key to a module chain. That first entry has mod::mod == NULL
    and mod::next == NULL, so the inner loop of static_call_del_module() will
    neither find a module match nor a module chain. The next site in the walk
    was either already converted, but can't match the module, or it will exit
    the outer loop because it has a static_call_site pointer and not a
    static_call_mod pointer.

    Fixes: 9183c3f9ed ("static_call: Add inline static call infrastructure")
    Closes: https://lore.kernel.org/all/20230915082126.4187913-1-ruanjinjie@huawei.com
    Reported-by: Jinjie Ruan <ruanjinjie@huawei.com>
    Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
    Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
    Tested-by: Jinjie Ruan <ruanjinjie@huawei.com>
    Link: https://lore.kernel.org/r/87zfon6b0s.ffs@tglx

Signed-off-by: CKI Backport Bot <cki-ci-bot+cki-gitlab-backport-bot@redhat.com>
2024-10-22 16:21:24 +00:00
Waiman Long 7dd9aa64c3 static_call: Add call depth tracking support
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2190342

commit 7825451fa4dc04660f1f53d236e4302161d0ebd1
Author: Peter Zijlstra <peterz@infradead.org>
Date:   Thu, 15 Sep 2022 13:11:31 +0200

    static_call: Add call depth tracking support

    When indirect calls are switched to direct calls then it has to be ensured
    that the call target is not the function, but the call thunk when call
    depth tracking is enabled. But static calls are available before call
    thunks have been set up.

    Ensure a second run through the static call patching code after call thunks
    have been created. When call thunks are not enabled this has no side
    effects.

    Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
    Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
    Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
    Link: https://lore.kernel.org/r/20220915111148.306100465@infradead.org

Signed-off-by: Waiman Long <longman@redhat.com>
2023-06-30 20:31:53 -04:00
Waiman Long d676ce57d5 static_call: Don't make __static_call_return0 static
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2190342

commit 8fd4ddda2f49a66bf5dd3d0c01966c4b1971308b
Author: Christophe Leroy <christophe.leroy@csgroup.eu>
Date:   Mon, 14 Mar 2022 12:49:36 +0100

    static_call: Don't make __static_call_return0 static

    System.map shows that vmlinux contains several instances of
    __static_call_return0():

            c0004fc0 t __static_call_return0
            c0011518 t __static_call_return0
            c00d8160 t __static_call_return0

    arch_static_call_transform() uses the middle one to check whether we are
    setting a call to __static_call_return0 or not:

            c0011520 <arch_static_call_transform>:
            c0011520:       3d 20 c0 01     lis     r9,-16383       <== r9 =  0xc001 << 16
            c0011524:       39 29 15 18     addi    r9,r9,5400      <== r9 += 0x1518
            c0011528:       7c 05 48 00     cmpw    r5,r9           <== r9 has value 0xc0011518 here

    So if static_call_update() is called with one of the other instances of
    __static_call_return0(), arch_static_call_transform() won't recognise it.

    In order to work properly, global single instance of __static_call_return0() is required.

    Fixes: 3f2a8fc4b1 ("static_call/x86: Add __static_call_return0()")
    Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>
    Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
    Acked-by: Josh Poimboeuf <jpoimboe@redhat.com>
    Link: https://lkml.kernel.org/r/30821468a0e7d28251954b578e5051dc09300d04.1647258493.git.christophe.leroy@csgroup.eu

Signed-off-by: Waiman Long <longman@redhat.com>
2023-06-30 19:59:53 -04:00