Commit bd5f500
committed
KVM: SEV: Read save fields from GHCB exactly once
Wrap all reads of GHCB save fields with READ_ONCE() via a KVM-specific
GHCB get() utility to help guard against TOCTOU bugs. Using READ_ONCE()
doesn't completely prevent such bugs, e.g. doesn't prevent KVM from
redoing get() after checking the initial value, but at least addresses
all potential TOCTOU issues in the current KVM code base.
To prevent unintentional use of the generic helpers, take only @SVM for
the kvm_ghcb_get_xxx() helpers and retrieve the ghcb instead of explicitly
passing it in.
Opportunistically reduce the indentation of the macro-defined helpers and
clean up the alignment.
Fixes: 4e15a0d ("KVM: SEV: snapshot the GHCB before accessing it")
Reviewed-by: Tom Lendacky <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Sean Christopherson <[email protected]>1 parent e0ff302 commit bd5f500
2 files changed
+26
-21
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3299 | 3299 | | |
3300 | 3300 | | |
3301 | 3301 | | |
3302 | | - | |
3303 | | - | |
3304 | | - | |
3305 | | - | |
3306 | | - | |
| 3302 | + | |
| 3303 | + | |
| 3304 | + | |
| 3305 | + | |
| 3306 | + | |
3307 | 3307 | | |
3308 | | - | |
| 3308 | + | |
3309 | 3309 | | |
3310 | 3310 | | |
3311 | | - | |
| 3311 | + | |
3312 | 3312 | | |
3313 | 3313 | | |
3314 | 3314 | | |
3315 | 3315 | | |
3316 | | - | |
| 3316 | + | |
3317 | 3317 | | |
3318 | 3318 | | |
3319 | | - | |
3320 | | - | |
3321 | | - | |
| 3319 | + | |
| 3320 | + | |
| 3321 | + | |
3322 | 3322 | | |
3323 | 3323 | | |
3324 | 3324 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
913 | 913 | | |
914 | 914 | | |
915 | 915 | | |
916 | | - | |
917 | | - | |
918 | | - | |
919 | | - | |
920 | | - | |
921 | | - | |
922 | | - | |
923 | | - | |
924 | | - | |
925 | | - | |
| 916 | + | |
| 917 | + | |
| 918 | + | |
| 919 | + | |
| 920 | + | |
| 921 | + | |
| 922 | + | |
| 923 | + | |
| 924 | + | |
| 925 | + | |
| 926 | + | |
| 927 | + | |
| 928 | + | |
| 929 | + | |
| 930 | + | |
926 | 931 | | |
927 | 932 | | |
928 | 933 | | |
| |||
0 commit comments