Skip to content

Commit d3e021a

Browse files
ChangSeokBaeKAGA-KOKO
authored andcommitted
x86/fpu: Fix the init_fpstate size check with the actual size
The init_fpstate buffer is statically allocated. Thus, the sanity test was established to check whether the pre-allocated buffer is enough for the calculated size or not. The currently measured size is not strictly relevant. Fix to validate the calculated init_fpstate size with the pre-allocated area. Also, replace the sanity check function with open code for clarity. The abstraction itself and the function naming do not tend to represent simply what it does. Fixes: 2ae996e ("x86/fpu: Calculate the default sizes independently") Signed-off-by: Chang S. Bae <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent c32d7ca commit d3e021a

File tree

1 file changed

+6
-18
lines changed

1 file changed

+6
-18
lines changed

arch/x86/kernel/fpu/xstate.c

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -678,20 +678,6 @@ static unsigned int __init get_xsave_size_user(void)
678678
return ebx;
679679
}
680680

681-
/*
682-
* Will the runtime-enumerated 'xstate_size' fit in the init
683-
* task's statically-allocated buffer?
684-
*/
685-
static bool __init is_supported_xstate_size(unsigned int test_xstate_size)
686-
{
687-
if (test_xstate_size <= sizeof(init_fpstate.regs))
688-
return true;
689-
690-
pr_warn("x86/fpu: xstate buffer too small (%zu < %d), disabling xsave\n",
691-
sizeof(init_fpstate.regs), test_xstate_size);
692-
return false;
693-
}
694-
695681
static int __init init_xstate_size(void)
696682
{
697683
/* Recompute the context size for enabled features: */
@@ -717,10 +703,6 @@ static int __init init_xstate_size(void)
717703
kernel_default_size =
718704
xstate_calculate_size(fpu_kernel_cfg.default_features, compacted);
719705

720-
/* Ensure we have the space to store all default enabled features. */
721-
if (!is_supported_xstate_size(kernel_default_size))
722-
return -EINVAL;
723-
724706
if (!paranoid_xstate_size_valid(kernel_size))
725707
return -EINVAL;
726708

@@ -879,6 +861,12 @@ void __init fpu__init_system_xstate(unsigned int legacy_size)
879861
init_fpstate.size = fpu_kernel_cfg.max_size;
880862
init_fpstate.xfeatures = fpu_kernel_cfg.max_features;
881863

864+
if (init_fpstate.size > sizeof(init_fpstate.regs)) {
865+
pr_warn("x86/fpu: init_fpstate buffer too small (%zu < %d), disabling XSAVE\n",
866+
sizeof(init_fpstate.regs), init_fpstate.size);
867+
goto out_disable;
868+
}
869+
882870
setup_init_fpu_buf();
883871

884872
/*

0 commit comments

Comments
 (0)