[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] Re: [PATCH v9 01/11] xen/memory: Fix mapping grant tables with XENMEM_acquire_resource
On 01/02/2021 23:26, Andrew Cooper wrote: > A guest's default number of grant frames is 64, and XENMEM_acquire_resource > will reject an attempt to map more than 32 frames. This limit is caused by > the size of mfn_list[] on the stack. > > Fix mapping of arbitrary size requests by looping over batches of 32 in > acquire_resource(), and using hypercall continuations when necessary. > > To start with, break _acquire_resource() out of acquire_resource() to cope > with type-specific dispatching, and update the return semantics to indicate > the number of mfns returned. Update gnttab_acquire_resource() and x86's > arch_acquire_resource() to match these new semantics. > > Have do_memory_op() pass start_extent into acquire_resource() so it can pick > up where it left off after a continuation, and loop over batches of 32 until > all the work is done, or a continuation needs to occur. > > compat_memory_op() is a bit more complicated, because it also has to marshal > frame_list in the XLAT buffer. Have it account for continuation information > itself and hide details from the upper layer, so it can marshal the buffer in > chunks if necessary. > > With these fixes in place, it is now possible to map the whole grant table for > a guest. > > Signed-off-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx> > Reviewed-by: Roger Pau Monné <roger.pau@xxxxxxxxxx> > --- > CC: George Dunlap <George.Dunlap@xxxxxxxxxxxxx> > CC: Ian Jackson <iwj@xxxxxxxxxxxxxx> > CC: Jan Beulich <JBeulich@xxxxxxxx> > CC: Stefano Stabellini <sstabellini@xxxxxxxxxx> > CC: Wei Liu <wl@xxxxxxx> > CC: Julien Grall <julien@xxxxxxx> > CC: Paul Durrant <paul@xxxxxxx> > CC: Michał Leszczyński <michal.leszczynski@xxxxxxx> > CC: Hubert Jasudowicz <hubert.jasudowicz@xxxxxxx> > CC: Tamas K Lengyel <tamas@xxxxxxxxxxxxx> > > v9: > * Crash domain rather than returning late with -ERANGE/-EFAULT. > > v8: > * nat => cmp change in the start_extent check. > * Rebase over 'frame' and ARM/IOREQ series. > > v3: > * Spelling fixes > --- > xen/common/compat/memory.c | 114 +++++++++++++++++++++++++++++++++-------- > xen/common/grant_table.c | 3 ++ > xen/common/memory.c | 124 > +++++++++++++++++++++++++++++++++------------ > 3 files changed, 187 insertions(+), 54 deletions(-) Attempt at release-ack paperwork. This is a bugfix for an issue which doesn't manifest by in-tree default callers, but does manifest when using the xenforeignmemory_map_resource() interface in the expected manner. The hypercall is made of a metadata structure, and an array of frames. The bug is that Xen only tolerates a maximum of 32 frames, and the bugfix is to accept an arbitrary number of frames. What can go wrong (other than the theoretical base case of everything, seeing as we're talking about C in system context)? The bugfix is basically "do { chunk_of_32(); } while ( !done );", so we're adding in an extra loop into the hypervisor. We could fail to terminate the loop (possible livelock in the hypervisor), or we could incorrectly marshal the buffer (guest kernel might receive junk instead of the mapping they expected). The majority of the complexity actually comes from the fact there are two nested loops, one in the compat layer doing 32=>64 (and back) marshalling, and one in the main layer, looping over chunks of 32 frames. Therefore, the same risks apply at both layers. I am certain the code is not bug free. The compat layer here is practically impossible to follow, and has (self inflicted) patterns where we have to crash the guest rather than raise a clean failure, due to an inability to unwind the fact that the upper layer decided to issue a continuation. There is also one bit where I literally had to give up, and put this logic in: > + /* > + * Well... Somethings gone wrong with the two levels of chunking. > + * My condolences to whomever next has to debug this mess. > + */ > + ASSERT_UNREACHABLE(); > + domain_crash(current->domain); > + split = 0; > break; Mitigations to these risks are thus: * Explicit use of failsafe coding patterns, will break out of the loops and pass -EINVAL back to the caller, or crashing the domain when we can't figure out how to pass an error back safely. * This codepath codepath gets used multiple times on every single VM boot, so will get ample testing from the in-tree caller point of view, as soon as OSSTest starts running. * The IPT series (which discovered this mess to start with) shows that, in addition to the in-tree paths working, the >32 frame mappings appear to work correctly. * An in-tree unit test exercising this codepath in a way which demonstrates this bug. Further work planned for this test. * Some incredibly invasive Xen+XTF testing to prove the correctness of the marshalling. Not suitable for committing, but available for inspection/query. In particular, this covers aspects of the logic with won't get any practical testing elsewhere. Overall, if there are bugs, they're very likely to be spotted by OSSTest in short order. ~Andrew
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |