x86/sme: Fix memory encryption setting if enabled by default and not overridden
authorArd Biesheuvel <ardb@kernel.org>
Fri, 26 Jan 2024 16:39:19 +0000 (17:39 +0100)
committerBorislav Petkov (AMD) <bp@alien8.de>
Mon, 29 Jan 2024 16:08:33 +0000 (17:08 +0100)
commite814b59e6c2b11f5a3d007b2e61f7d550c354c3a
tree2f1988eed16b947f53c5e30353e5de112bb828cb
parent4cab62c058f5a150d9960c112362e5c76d204d9d
x86/sme: Fix memory encryption setting if enabled by default and not overridden

Commit

  cbebd68f59f0 ("x86/mm: Fix use of uninitialized buffer in sme_enable()")

'fixed' an issue in sme_enable() detected by static analysis, and broke
the common case in the process.

cmdline_find_option() will return < 0 on an error, or when the command
line argument does not appear at all. In this particular case, the
latter is not an error condition, and so the early exit is wrong.

Instead, without mem_encrypt= on the command line, the compile time
default should be honoured, which could be to enable memory encryption,
and this is currently broken.

Fix it by setting sme_me_mask to a preliminary value based on the
compile time default, and only omitting the command line argument test
when cmdline_find_option() returns an error.

  [ bp: Drop active_by_default while at it. ]

Fixes: cbebd68f59f0 ("x86/mm: Fix use of uninitialized buffer in sme_enable()")
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Reviewed-by: Tom Lendacky <thomas.lendacky@amd.com>
Link: https://lore.kernel.org/r/20240126163918.2908990-2-ardb+git@google.com
arch/x86/mm/mem_encrypt_identity.c