public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Guorui Yu <GuoRui.Yu@linux.alibaba.com>
To: kirill.shutemov@linux.intel.com
Cc: ak@linux.intel.com, bp@alien8.de, dan.j.williams@intel.com,
	dave.hansen@intel.com, david@redhat.com,
	elena.reshetova@intel.com, hpa@zytor.com,
	linux-kernel@vger.kernel.org, luto@kernel.org, mingo@redhat.com,
	peterz@infradead.org, sathyanarayanan.kuppuswamy@linux.intel.com,
	seanjc@google.com, stable@vger.kernel.org, tglx@linutronix.de,
	thomas.lendacky@amd.com, x86@kernel.org
Subject: Re: [PATCH 2/2] x86/tdx: Do not allow #VE due to EPT violation on the private memory
Date: Mon, 31 Oct 2022 12:07:45 +0800	[thread overview]
Message-ID: <b5d04a6c-79b4-bbdc-b613-6958d9f75d53@linux.alibaba.com> (raw)
In-Reply-To: <20221028141220.29217-3-kirill.shutemov@linux.intel.com>

The core of this vulnerability is not directly related to the 
ATTR_SEPT_VE_DISABLE, but the MMIO processing logic in #VE.

We have encountered similar problems on SEV-ES, here are their fixes on 
Kernel [1] and OVMF[2].

Instead of enforcing the ATTR_SEPT_VE_DISABLE in TDX guest kernel, I 
think the fix should also include necessary check on the MMIO path of 
the #VE routine.

static int handle_mmio(struct pt_regs *regs, struct ve_info *ve)
{
	unsigned long *reg, val, vaddr;
	char buffer[MAX_INSN_SIZE];
	struct insn insn = {};
	enum mmio_type mmio;
	int size, extend_size;
	u8 extend_val = 0;

	// Some addtional security check about ve->gpa should be introduced here.

	/* Only in-kernel MMIO is supported */
	if (WARN_ON_ONCE(user_mode(regs)))
		return -EFAULT;

	// ...
}

If we don't fix the problem at the point where we found, but rely on 
complicated composite logic and long comments in the kernel, I'm 
confident we'll fall back into the same pit in the near future :).


[1] 
https://github.com/torvalds/linux/blob/1a2dcbdde82e3a5f1db9b2f4c48aa1aeba534fb2/arch/x86/kernel/sev.c#L503
[2] OVMF: 
https://github.com/tianocore/edk2/blob/db2c22633f3c761975d8f469a0e195d8b79e1287/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c#L670

  parent reply	other threads:[~2022-10-31  4:07 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-28 14:12 [PATCH 0/2] x86/tdx: Enforce no #VE on private memory accesses Kirill A. Shutemov
2022-10-28 14:12 ` [PATCH 1/2] x86/tdx: Extract GET_INFO call from get_cc_mask() Kirill A. Shutemov
2022-10-28 15:43   ` Dave Hansen
2022-10-28 23:27   ` Dave Hansen
2022-10-28 23:59     ` Kirill A. Shutemov
2022-10-31  4:12       ` Kirill A. Shutemov
2022-10-31 16:42         ` Dave Hansen
2022-10-31 19:19           ` Kirill A. Shutemov
2022-10-31 19:27         ` Andi Kleen
2022-10-31 19:44           ` Dave Hansen
2022-10-31 22:10             ` Kirill A. Shutemov
2022-10-28 14:12 ` [PATCH 2/2] x86/tdx: Do not allow #VE due to EPT violation on the private memory Kirill A. Shutemov
2022-10-28 15:41   ` Dave Hansen
2022-10-31  4:07   ` Guorui Yu [this message]
2022-10-31  4:33     ` Kirill A. Shutemov
2022-10-31 14:22     ` Dave Hansen
2022-11-04 22:36       ` Erdem Aktas
2022-11-04 22:50         ` Dave Hansen
2022-11-07 22:53           ` Erdem Aktas
2022-11-07 23:30             ` Dave Hansen
2022-11-07  5:10       ` Guorui Yu
2022-11-07 13:31         ` Dave Hansen
2022-11-07 13:43           ` Guorui Yu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=b5d04a6c-79b4-bbdc-b613-6958d9f75d53@linux.alibaba.com \
    --to=guorui.yu@linux.alibaba.com \
    --cc=ak@linux.intel.com \
    --cc=bp@alien8.de \
    --cc=dan.j.williams@intel.com \
    --cc=dave.hansen@intel.com \
    --cc=david@redhat.com \
    --cc=elena.reshetova@intel.com \
    --cc=hpa@zytor.com \
    --cc=kirill.shutemov@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luto@kernel.org \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=sathyanarayanan.kuppuswamy@linux.intel.com \
    --cc=seanjc@google.com \
    --cc=stable@vger.kernel.org \
    --cc=tglx@linutronix.de \
    --cc=thomas.lendacky@amd.com \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox