[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <DM8PR11MB575097797C8CA3779F11C303E7BF2@DM8PR11MB5750.namprd11.prod.outlook.com>
Date: Tue, 6 Aug 2024 11:41:57 +0000
From: "Reshetova, Elena" <elena.reshetova@...el.com>
To: Alexey Gladkov <legion@...nel.org>, "kirill.shutemov@...ux.intel.com"
<kirill.shutemov@...ux.intel.com>
CC: "Edgecombe, Rick P" <rick.p.edgecombe@...el.com>,
"linux-coco@...ts.linux.dev" <linux-coco@...ts.linux.dev>,
"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
"ytcoode@...il.com" <ytcoode@...il.com>, "Huang, Kai" <kai.huang@...el.com>,
"Yao, Yuan" <yuan.yao@...el.com>, "dave.hansen@...ux.intel.com"
<dave.hansen@...ux.intel.com>, "John.Starks@...rosoft.com"
<John.Starks@...rosoft.com>, "akpm@...ux-foundation.org"
<akpm@...ux-foundation.org>, "mingo@...hat.com" <mingo@...hat.com>,
"tglx@...utronix.de" <tglx@...utronix.de>, "Cui, Dexuan"
<decui@...rosoft.com>, "oleg@...hat.com" <oleg@...hat.com>, "bhe@...hat.com"
<bhe@...hat.com>, "hpa@...or.com" <hpa@...or.com>, "bp@...en8.de"
<bp@...en8.de>, "geert@...ux-m68k.org" <geert@...ux-m68k.org>,
"cho@...rosoft.com" <cho@...rosoft.com>
Subject: RE: [PATCH v2 2/5] x86/tdx: Add validation of userspace MMIO
instructions
> On Tue, Aug 06, 2024 at 10:18:20AM +0300, kirill.shutemov@...ux.intel.com
> wrote:
> > On Mon, Aug 05, 2024 at 10:40:55PM +0000, Edgecombe, Rick P wrote:
> > > On Mon, 2024-08-05 at 15:29 +0200, Alexey Gladkov (Intel) wrote:
> > > > + vaddr = (unsigned long)insn_get_addr_ref(&insn, regs);
> > > > +
> > > > + if (user_mode(regs)) {
> > > > + if (mmap_read_lock_killable(current->mm))
> > > > + return -EINTR;
> > > > +
> > > > + ret = valid_vaddr(ve, mmio, size, vaddr);
> > > > + if (ret)
> > > > + goto unlock;
> > > > + }
> > > > +
> > >
> > > In the case of user MMIO, if the user instruction + MAX_INSN_SIZE
> straddles a
> > > page, then the "fetch" in the kernel could trigger a #VE. In this case the
> > > kernel would handle this second #VE as a !user_mode() MMIO I guess.
> > >
> > > Would something prevent the same munmap() checks needing to happen
> for that
> > > second kernel #VE? If not, I wonder if the munmap() protection logic
> should also
> > > trigger for any userspace range ve->gpa as well.
> >
> > That's an interesting scenario, but I think we are fine.
> >
> > The fetch is copy_from_user() which is "REP; MOVSB" on all TDX platforms.
> > Kernel rejects MOVS instruction emulation for !user_mode() with -EFAULT.
>
> But MOVS will be used only if X86_FEATURE_FSRM feature is present.
> Otherwise rep_movs_alternative will be used, which uses MOVB.
>
> I know that X86_FEATURE_FSRM appeared since Ice Lake, but still.
This is how the X86_FEATURE_FSRM cpuid bit is treated under TDX:
{
"MSB": "4",
"LSB": "4",
"Field Size": "1",
"Field Name": "Fast Short REP MOV",
"Configuration Details": "TD_PARAMS.CPUID_CONFIG",
"Bit or Field Virtualization Type": "Configured & Native",
"Virtualization Details": null
},
Which means VMM has the way to overwrite the native platform value
and set it to "0", so we must account for both cases.
Powered by blists - more mailing lists