0067-x86-fpu-Parse-clearcpuid-as-early-XSAVE-argument.patch 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. From df469cffe07c84906be43e89d33f2a8a5312e60f Mon Sep 17 00:00:00 2001
  2. From: Andi Kleen <[email protected]>
  3. Date: Fri, 13 Oct 2017 14:56:43 -0700
  4. Subject: [PATCH 067/242] x86/fpu: Parse clearcpuid= as early XSAVE argument
  5. MIME-Version: 1.0
  6. Content-Type: text/plain; charset=UTF-8
  7. Content-Transfer-Encoding: 8bit
  8. CVE-2017-5754
  9. With a followon patch we want to make clearcpuid affect the XSAVE
  10. configuration. But xsave is currently initialized before arguments
  11. are parsed. Move the clearcpuid= parsing into the special
  12. early xsave argument parsing code.
  13. Since clearcpuid= contains a = we need to keep the old __setup
  14. around as a dummy, otherwise it would end up as a environment
  15. variable in init's environment.
  16. Signed-off-by: Andi Kleen <[email protected]>
  17. Reviewed-by: Thomas Gleixner <[email protected]>
  18. Cc: Linus Torvalds <[email protected]>
  19. Cc: Peter Zijlstra <[email protected]>
  20. Link: http://lkml.kernel.org/r/[email protected]
  21. Signed-off-by: Ingo Molnar <[email protected]>
  22. (cherry picked from commit 0c2a3913d6f50503f7c59d83a6219e39508cc898)
  23. Signed-off-by: Andy Whitcroft <[email protected]>
  24. Signed-off-by: Kleber Sacilotto de Souza <[email protected]>
  25. (cherry picked from commit 27deb452eb0d27c406f3817ab057201aa8767abe)
  26. Signed-off-by: Fabian Grünbichler <[email protected]>
  27. ---
  28. arch/x86/kernel/cpu/common.c | 16 +++++++---------
  29. arch/x86/kernel/fpu/init.c | 11 +++++++++++
  30. 2 files changed, 18 insertions(+), 9 deletions(-)
  31. diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
  32. index 4be7b209a3d6..ef7b1ba56363 100644
  33. --- a/arch/x86/kernel/cpu/common.c
  34. +++ b/arch/x86/kernel/cpu/common.c
  35. @@ -1293,18 +1293,16 @@ void print_cpu_info(struct cpuinfo_x86 *c)
  36. pr_cont(")\n");
  37. }
  38. -static __init int setup_disablecpuid(char *arg)
  39. +/*
  40. + * clearcpuid= was already parsed in fpu__init_parse_early_param.
  41. + * But we need to keep a dummy __setup around otherwise it would
  42. + * show up as an environment variable for init.
  43. + */
  44. +static __init int setup_clearcpuid(char *arg)
  45. {
  46. - int bit;
  47. -
  48. - if (get_option(&arg, &bit) && bit >= 0 && bit < NCAPINTS * 32)
  49. - setup_clear_cpu_cap(bit);
  50. - else
  51. - return 0;
  52. -
  53. return 1;
  54. }
  55. -__setup("clearcpuid=", setup_disablecpuid);
  56. +__setup("clearcpuid=", setup_clearcpuid);
  57. #ifdef CONFIG_X86_64
  58. struct desc_ptr idt_descr __ro_after_init = {
  59. diff --git a/arch/x86/kernel/fpu/init.c b/arch/x86/kernel/fpu/init.c
  60. index d5d44c452624..07f0ab877f49 100644
  61. --- a/arch/x86/kernel/fpu/init.c
  62. +++ b/arch/x86/kernel/fpu/init.c
  63. @@ -249,6 +249,10 @@ static void __init fpu__init_system_ctx_switch(void)
  64. */
  65. static void __init fpu__init_parse_early_param(void)
  66. {
  67. + char arg[32];
  68. + char *argptr = arg;
  69. + int bit;
  70. +
  71. if (cmdline_find_option_bool(boot_command_line, "no387"))
  72. setup_clear_cpu_cap(X86_FEATURE_FPU);
  73. @@ -266,6 +270,13 @@ static void __init fpu__init_parse_early_param(void)
  74. if (cmdline_find_option_bool(boot_command_line, "noxsaves"))
  75. setup_clear_cpu_cap(X86_FEATURE_XSAVES);
  76. +
  77. + if (cmdline_find_option(boot_command_line, "clearcpuid", arg,
  78. + sizeof(arg)) &&
  79. + get_option(&argptr, &bit) &&
  80. + bit >= 0 &&
  81. + bit < NCAPINTS * 32)
  82. + setup_clear_cpu_cap(bit);
  83. }
  84. /*
  85. --
  86. 2.14.2