Commit 4954f5b
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
7024f60 ("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: f980f9c ("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.org1 parent c25bbdb commit 4954f5b
1 file changed
Lines changed: 46 additions & 20 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
315 | 315 | | |
316 | 316 | | |
317 | 317 | | |
318 | | - | |
319 | | - | |
320 | | - | |
321 | | - | |
322 | | - | |
323 | | - | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
324 | 337 | | |
325 | 338 | | |
326 | 339 | | |
327 | | - | |
| 340 | + | |
328 | 341 | | |
329 | 342 | | |
330 | 343 | | |
331 | 344 | | |
332 | | - | |
| 345 | + | |
333 | 346 | | |
334 | 347 | | |
335 | 348 | | |
336 | 349 | | |
337 | | - | |
| 350 | + | |
338 | 351 | | |
339 | 352 | | |
340 | 353 | | |
341 | 354 | | |
342 | | - | |
| 355 | + | |
343 | 356 | | |
344 | 357 | | |
345 | 358 | | |
| |||
370 | 383 | | |
371 | 384 | | |
372 | 385 | | |
373 | | - | |
374 | | - | |
375 | | - | |
376 | | - | |
377 | | - | |
378 | | - | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
379 | 405 | | |
380 | 406 | | |
381 | | - | |
| 407 | + | |
382 | 408 | | |
383 | 409 | | |
384 | 410 | | |
385 | 411 | | |
386 | | - | |
| 412 | + | |
387 | 413 | | |
388 | 414 | | |
389 | 415 | | |
390 | 416 | | |
391 | | - | |
| 417 | + | |
392 | 418 | | |
393 | 419 | | |
394 | 420 | | |
395 | 421 | | |
396 | | - | |
| 422 | + | |
397 | 423 | | |
398 | 424 | | |
399 | 425 | | |
| |||
0 commit comments