]> git.baikalelectronics.ru Git - kernel.git/commit
x86/sev-es: Use __put_user()/__get_user() for data accesses
authorJoerg Roedel <jroedel@suse.de>
Wed, 19 May 2021 13:52:46 +0000 (15:52 +0200)
committerBorislav Petkov <bp@suse.de>
Wed, 19 May 2021 16:45:37 +0000 (18:45 +0200)
commit67e27a0081c25f94ed109182afecea7189c8977a
treef4b3d278c3c604ef8590b0f4aa915ab76629fc06
parenteae0d0cd282b2ed34e4c82a1380e2e217084a693
x86/sev-es: Use __put_user()/__get_user() for data accesses

The put_user() and get_user() functions do checks on the address which is
passed to them. They check whether the address is actually a user-space
address and whether its fine to access it. They also call might_fault()
to indicate that they could fault and possibly sleep.

All of these checks are neither wanted nor needed in the #VC exception
handler, which can be invoked from almost any context and also for MMIO
instructions from kernel space on kernel memory. All the #VC handler
wants to know is whether a fault happened when the access was tried.

This is provided by __put_user()/__get_user(), which just do the access
no matter what. Also add comments explaining why __get_user() and
__put_user() are the best choice here and why it is safe to use them
in this context. Also explain why copy_to/from_user can't be used.

In addition, also revert commit

  43b74c7c7640 ("x86/sev-es: Handle string port IO to kernel memory properly")

because using __get_user()/__put_user() fixes the same problem while
the above commit introduced several problems:

  1) It uses access_ok() which is only allowed in task context.

  2) It uses memcpy() which has no fault handling at all and is
     thus unsafe to use here.

  [ bp: Fix up commit ID of the reverted commit above. ]

Fixes: 9439a3a1ab8b ("x86/sev-es: Compile early handler code into kernel image")
Signed-off-by: Joerg Roedel <jroedel@suse.de>
Signed-off-by: Borislav Petkov <bp@suse.de>
Cc: stable@vger.kernel.org # v5.10+
Link: https://lkml.kernel.org/r/20210519135251.30093-4-joro@8bytes.org
arch/x86/kernel/sev.c