Skip to contentSkip to conversation

Revokable Grants Design (draft B)

DISCUSSION David Vrabel 2 participants 4 messages Jan 25, 2016 – Jan 28, 2016

lore
Share & tools
lore
#0 lore raw

% Revokable Grants
% David Vrabel <<[email protected]>>
% Draft B

http://xenbits.xen.org/people/dvrabel/revokable-grants-B.pdf

Introduction
============

Revision History
----------------

--------------------------------------------------------------------

Version  Date         Changes
-------  -----------  ----------------------------------------------
Draft A  24 Dec 2015  Initial draft.

Draft B 25 Jan 2015 Resolved some FIXMES: Don't allow GNTMAP_map_ref
on revokable grants; allow up-to two mappings for each grant reference.

New sub-sections on domain death and gntalloc driver notification mechanisms.

Clarify that the revoke hypercall is only needed if the grant is in-use.
--------------------------------------------------------------------

Purpose
-------

Using grant references to share memory between mutually untrusting VMs is not possible because the grantee can keep grants mapped indefinitely. This limits the use of inter-domain communication mechanisms (such as libvchan) to between mutually trusting VMs.

This design proposes a mechanism where the VM granting access may specify that the grant is _revokable_. Access via such a grant may be revoked at any time, even if the grant is mapped by the other domain.

High Level Design
=================

A revokable grant is indicated by an additional flag in the grant table entry. A domain may only map such a grant using a new sub-op (GNTABOP_map_revokable) and must supply a local GFN.

When the granting domain wishes to revoke a grant it:

1. Removes access from the grant, but does not make the grant available for other uses. The prevents any new grant map or copies from starting.

2. Makes a GNTTABOP_revoke hypercall if the grant is in use (e.g., mapped). The hypervisor atomically switches any mappings of the grant to the local GFN supplied when it was mapped. The hypervisor will also wait for any in-progress grant copies to complete.

3. Frees the grant references, making it available for other uses.

Grant mappers will need to handle grants being revoked, e.g., by copying the data from the shared page before checking the copied data is valid.

Low Level Design
================

Grant Table Entry
-----------------

A new GTF_revokable flag is added. A grant reference with this bit set may only be mapped with GNTTABOP_map_revokable or copied with GNTTABOP_grant_copy (subject to the usual permission checks).

Attempts to use GNTTABOP_map_grant_ref with such a reference must fail with -EACCESS. Without a replacement page, revoking such a mapping would require clearing the mapping which would allow the granter to trigger faults in the mapper.

Hypercall ABI
-------------

Two new grant table sub-ops are added:

* GNTTABOP_map_revokable
* GNTTABOP_revoke

### GNTTABOP_map_revokable

    struct gnttab_map_revokable {
        struct gnttab_map_grant_ref map;
        xen_pfn_t lgfn;
    };

--------------------------------------------------------------------

Field         Purpose
-----         ------------------------------------------------------
`map`         Parameters as per the `GNTTAB_map_grant_ref` sub-op.

lgfn A local GFN owned by the mapping domain that will be used if
the grant is revoked.
--------------------------------------------------------------------

The hypervisor will validate lgfn as owned by the mapping domain and take an additional reference. It will then map the grant reference as normal. The lgfn page will be recorded in the new map track entry.

A revokable grant may only be mapped twice. This limit is to prevent thousands of mappings causing performance problems for GNTTABOP_revoke. Two mappings are required for a PV guest to map a grant reference into both the kernel and userspace virtual address space.

### GNTTABOP_revoke

    struct gnttab_revoke {
        grant_ref_t ref;
    };

--------------------------------------------------------------------

Field         Purpose
-----         ------------------------------------------------------
`ref`         The grant reference whose access is being revoked.

--------------------------------------------------------------------

The caller must first remove access from the grant reference to prevent any new grant maps or copies from starting.

For each mapping of this grant the hypervisor will atomically update the mapping to the local GFN in the map track entry. Both host and device (IOMMU) mappings will be updated. This ensures that the mapper will always see a valid mapping and will not receive unexpected page faults.

Quoted 3 lines

FIXME: will probably need a way to efficiently walk the set of map track entries for a given grant ref. Scanning the whole map track table may be too slow.

Also, by taking the appropriate grant table lock, any grant copies will be known to be complete.

Domain Death
------------

When a domain dies, all in-use revokable grants shall be revoked. This shall be done after other domains are no longer able to use grants from the dying domain (this is so the hypervisor does not need to clear the GTF_permit_access flag to block a grant's use).

Notification
------------

libxenctrl provides mechanisms to notify mappers that the granting process has exited. These are implemented by IOCTL_GNTALLOC_SET_UNMAP_NOTIFY in Linux's gntalloc driver. The two mechanisms are:

* UNMAP_NOTIFY_CLEAR_BYTE -- clear a byte in the shared page.
* UNMAP_NOTIFY_SEND_EVENT -- send an event channel event.

UNMAP_NOTIFY_CLEAR_BYTE is not compatible with revokable grants. When the granting process dies the grant will be revoked and the mapper will see its local page, thus the cleared byte will not be visible.

UNMAP_NOTIFY_SEND_EVENT would be compatible but is unreliable because:

* Events are delivered asynchronously so the revoked mapping may be visible before the event is received.

* It only worked if the granting process dies. An event was not raised if the domain died.

The gntalloc driver shall return an EINVAL error if either option is requested for a revokable grant.

#1 lore raw
Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 25.01.16 at 18:20, <[email protected]> wrote:

High Level Design
=================

A revokable grant is indicated by an additional flag in the grant table entry. A domain may only map such a grant using a new sub-op (GNTABOP_map_revokable) and must supply a local GFN.

When the granting domain wishes to revoke a grant it:

Quoted 8 lines

1. Removes access from the grant, but does not make the grant available for other uses. The prevents any new grant map or copies from starting.

2. Makes a GNTTABOP_revoke hypercall if the grant is in use (e.g., mapped). The hypervisor atomically switches any mappings of the grant to the local GFN supplied when it was mapped. The hypervisor will also wait for any in-progress grant copies to complete.

What about transfers? Presumably no-one uses them these days, but they're part of the interface and hence need to be considered. (But I guess accounting for them here is as simple as naming them alongside copies. Or wait, "Low Level Design" seems to suggest you simply disallow transfers for them.)

Quoted 6 lines

Low Level Design
================

Grant Table Entry
-----------------

Quoted 8 lines

A new GTF_revokable flag is added. A grant reference with this bit set may only be mapped with GNTTABOP_map_revokable or copied with GNTTABOP_grant_copy (subject to the usual permission checks).

Attempts to use GNTTABOP_map_grant_ref with such a reference must fail with -EACCESS. Without a replacement page, revoking such a mapping would require clearing the mapping which would allow the granter to trigger faults in the mapper.

What about the inverse (GNTTABOP_map_revokable on non- revokable grant)? Failure, or some kind of indication to the caller that the GFN is not going to be used?

Quoted 6 lines

### GNTTABOP_revoke

    struct gnttab_revoke {
        grant_ref_t ref;
    };
Quoted 8 lines

--------------------------------------------------------------------

Field         Purpose
-----         ------------------------------------------------------
`ref`         The grant reference whose access is being revoked.

--------------------------------------------------------------------

The caller must first remove access from the grant reference to prevent any new grant maps or copies from starting.

Is the hypervisor expected to check this, and fail if it's not the case?

Nice work, I don't think there's much in the way of moving on to the implementation.

Jan

#2 lore raw
Quoted 19 lines · Jan Beulich
Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 25.01.16 at 18:20, <[email protected]> wrote:

High Level Design
=================

A revokable grant is indicated by an additional flag in the grant table entry. A domain may only map such a grant using a new sub-op (GNTABOP_map_revokable) and must supply a local GFN.

When the granting domain wishes to revoke a grant it:

Quoted 8 lines

1. Removes access from the grant, but does not make the grant available for other uses. The prevents any new grant map or copies from starting.

2. Makes a GNTTABOP_revoke hypercall if the grant is in use (e.g., mapped). The hypervisor atomically switches any mappings of the grant to the local GFN supplied when it was mapped. The hypervisor will also wait for any in-progress grant copies to complete.

Quoted 5 lines

What about transfers? Presumably no-one uses them these days, but they're part of the interface and hence need to be considered. (But I guess accounting for them here is as simple as naming them alongside copies. Or wait, "Low Level Design" seems to suggest you simply disallow transfers for them.)

Transfers would be disallowed. Or rather, only map_revokable and copy are allowed.

Quoted 10 lines
Quoted 10 lines

Low Level Design
================

Grant Table Entry
-----------------

A new GTF_revokable flag is added. A grant reference with this bit set may only be mapped with GNTTABOP_map_revokable or copied with GNTTABOP_grant_copy (subject to the usual permission checks).

Quoted 8 lines
Quoted 4 lines

Attempts to use GNTTABOP_map_grant_ref with such a reference must fail with -EACCESS. Without a replacement page, revoking such a mapping would require clearing the mapping which would allow the granter to trigger faults in the mapper.

What about the inverse (GNTTABOP_map_revokable on non- revokable grant)? Failure, or some kind of indication to the caller that the GFN is not going to be used?

I would disallow it I think. I can't think of a case where this would be useful.

Quoted 12 lines
Quoted 12 lines

### GNTTABOP_revoke

    struct gnttab_revoke {
        grant_ref_t ref;
    };

--------------------------------------------------------------------

Field         Purpose
-----         ------------------------------------------------------
`ref`         The grant reference whose access is being revoked.

--------------------------------------------------------------------

Quoted 5 lines
Quoted 2 lines

The caller must first remove access from the grant reference to prevent any new grant maps or copies from starting.

Is the hypervisor expected to check this, and fail if it's not the case?

No. Because Xen cannot guard against the guest permitting access (e.g., by setting GTF_permit_access again or via another grant reference) while the revoke hypercall is in progress.

Or possibly:

Yes, Because, although this won't catch all incorrect behaviour of the guest, it will catch the most obvious mistake.

I can't decide on which is best.

David

#3 lore raw
Quoted 15 lines
Quoted 1 line
Quoted 1 line · On 28.01.16 at 17:53, <[email protected]> wrote:
Quoted 13 lines · Jan Beulich
Quoted 12 lines
Quoted 1 line
Quoted 1 line · On 25.01.16 at 18:20, <[email protected]> wrote:

Grant Table Entry
-----------------

A new GTF_revokable flag is added. A grant reference with this bit set may only be mapped with GNTTABOP_map_revokable or copied with GNTTABOP_grant_copy (subject to the usual permission checks).

Attempts to use GNTTABOP_map_grant_ref with such a reference must fail with -EACCESS. Without a replacement page, revoking such a mapping would require clearing the mapping which would allow the granter to trigger faults in the mapper.

Quoted 6 lines
Quoted 3 lines

What about the inverse (GNTTABOP_map_revokable on non- revokable grant)? Failure, or some kind of indication to the caller that the GFN is not going to be used?

I would disallow it I think. I can't think of a case where this would be useful.

It would allow mapping code to always use the new op, without needing to be told by the other side.

Quoted 22 lines
Quoted 12 lines
Quoted 12 lines

### GNTTABOP_revoke

    struct gnttab_revoke {
        grant_ref_t ref;
    };

--------------------------------------------------------------------

Field         Purpose
-----         ------------------------------------------------------
`ref`         The grant reference whose access is being revoked.

--------------------------------------------------------------------

Quoted 5 lines
Quoted 2 lines

The caller must first remove access from the grant reference to prevent any new grant maps or copies from starting.

Is the hypervisor expected to check this, and fail if it's not the case?

No. Because Xen cannot guard against the guest permitting access (e.g., by setting GTF_permit_access again or via another grant reference) while the revoke hypercall is in progress.

Quoted 6 lines

Or possibly:

Yes, Because, although this won't catch all incorrect behaviour of the guest, it will catch the most obvious mistake.

I can't decide on which is best.

I lean towards the latter.

Jan