[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] x86/hvm: Fix double free from vlapic_init() early error path


  • To: Jan Beulich <jbeulich@xxxxxxxx>
  • From: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
  • Date: Thu, 1 Apr 2021 14:20:46 +0100
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=citrix.com; dmarc=pass action=none header.from=citrix.com; dkim=pass header.d=citrix.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=/OyQ2vrdQax1SqwU6XUja7IVbjW+nUkz7HxDGveAYrc=; b=ZPg2PrUgUKNdBUlRz9V2R1cw6lUe+cjYllO8p22jeIH8HoXcALQ5BLi1/xOS3EcoX5iAV9k9fwkHMH4DUG7kIZwxsiR0zdT6MkpYNCQ0MxRdon9SvwvSt27HEFc9iYOWq8on3zD46AQZYUXzDoMd//shEdMu7R3XwFps2ywYOgg7uhR3H/CX8+aYhdVDkPEvPmdbHfpi55Z+IfSjkAg+8/xy0UPE5VdV5pqYP9LtOHQPMJOXd4IS53NhSmR+KQBM3mhdI8dUaKcwpPpdQqb+vuoEwkeNFW99hrySUN/Cxt+G0YHKgQ7HIGNVML5ZbCu1XRDRV2fZkhbkXXDl+P0fhQ==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mLLnjO1dPcifTSOHaIGs8xIisJ7GBNJ4ftASX4+aUadtB9ZIWhr/XmwRd6BSMqG7BQMzfSCjrsiI8lNuSqdxLqbqLG0sHmJGf/DPeczg1h04Wi8CpRvoq9qKFwMxS9C7uPvKJkGgzamTAAyc8v+bUtWdYW8sCnHPoy52Z/ZIP7yHztBbq2VvUNaEQmLbGI8fnqzalRXOCrCpojgEHLY9N9hXZwL1iKvaVxXrCRvNdesfu4gYxSGppnAUIaUTtNq4jZMCxRxhorefWIndERRzN75UmVEw8Qpr3u/94BVcprJ537JwbgFPkjfk9P3EEd308+dlwM0zH4LWgxiJI4v9Fg==
  • Authentication-results: esa5.hc3370-68.iphmx.com; dkim=pass (signature verified) header.i=@citrix.onmicrosoft.com
  • Cc: Roger Pau Monné <roger.pau@xxxxxxxxxx>, Wei Liu <wl@xxxxxxx>, Xen-devel <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • Delivery-date: Thu, 01 Apr 2021 13:21:24 +0000
  • Ironport-hdrordr: A9a23:/rmui6vkQ73CWQaucu7UOrth7skC2YYji2hD6mlwRA09T+WxrO rrtOgH1BPylTYaUGwhn9fFA6WbXXbA7/dOj7U5FYyJGC3ronGhIo0n14vtxDX8Bzbzn9Qz6Y 5JSII7MtH5CDFB4frSyBWkEtom3dmM+L2pg+Cb9Ht2UQR2cchbjztRICzzKDwTeCBtA50lGJ 2Aou9OoDS9cXoaB/7LeEUtde7FutHNidbaehYAHREq802jijmv5b78HXGjr2gjehlIxqov9n WArhzh6syYwo2G4zL/90uW1ZRZn9P91sBObfbstuE5Iijh4zzYH7hJdKaFuFkO0YeSwXYs1O LBuhIxe/l0gkmhA12dhTvI903e3C0163nkoGXo80fLhcDiXjo1B45gqOtiA2PkwnEttt19z6 5Htljx3/E8YGKi7UaNk+TgbB1kmlG5pnAvi4co/htieLATdaNLqsgn9F5Vea1wbx7S0pwtE+ VlEajnlY9rWG6dBkqp21VH/MahRTAaEBuAXyE5y7ao+gkTtnV4w0wE/dcYj3cN+bksIqM0l9 jsA+BGkqpDQdQRar84LOAdQdGvAmiIeh7UNnmOSG6XWp0vCjbokdra8b817OaldNghy4Yzoo 3IVBd9uXQpc0zjJMWS1PRwg1HwaVT4eQ6o5tBV5pB/tLG5bqHsKze/RFcnlNbli+kDA+XAMs zDeq5+MrvGFy/DCIxJ1wrxV915Mn8FSvAYvd49Rhanvt/LEIv3rebWGcyjZ4bFIHIBYCfSE3 EDVD/8KIFr9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8/ACH6bC6LhX62nOPGs+ek2xBULTZk33UNQtq1 7DDpYICwWd6xqi79VcmEX1xJNyJNKKonPIM66fKbxrKi38eTVxa12AIXrtw3EBTFrpN0ZKJyNM Yi48d4COgGHn08inHlZudWHDcMJrvLG5X/CQkmd+xvf0xcQ6KEhIbDVbZjmTFo4YzPSCoAR5xI z0E=
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 31/03/2021 15:03, Jan Beulich wrote:
> On 31.03.2021 15:31, Andrew Cooper wrote:
>> vlapic_init()'s caller calls vlapic_destroy() on error.  Therefore, the error
>> path from __map_domain_page_global() failing would doubly free
>> vlapic->regs_page.
> I'm having difficulty seeing this. What I find at present is
>
>     rc = vlapic_init(v);
>     if ( rc != 0 ) /* teardown: vlapic_destroy */
>         goto fail2;
>
> and then
>
>  fail3:
>     vlapic_destroy(v);
>  fail2:
>
> Am I missing some important aspect?

No - I'm blind.  (although I do blame the code comment for being
actively misleading.)

I retract the patch at this point.  It needs to be part of a bigger
series making changes like this consistently across the callers.

>> Rework vlapic_destroy() to be properly idempotent, introducing the necessary
>> UNMAP_DOMAIN_PAGE_GLOBAL() and FREE_DOMHEAP_PAGE() wrappers.
>>
>> Rearrange vlapic_init() to group all trivial initialisation, and leave all
>> cleanup to the caller, in line with our longer term plans.
> Cleanup functions becoming idempotent is what I understand is the
> longer term plan. I didn't think this necessarily included leaving
> cleanup after failure in a function to it caller(s).

That's literally the point of the exercise.

>  At least in the
> general case I think it would be quite a bit better if functions
> cleaned up after themselves - perhaps (using the example here) by
> vlapic_init() calling vlapic_destroy() in such a case.

That pattern is the cause of code duplication (not a problem per say),
and many bugs (the problem needing solving) caused by the duplicated
logic not being equivalent.

We've got the start of the top-level pattern in progress, with
{domain,vcpu}_create() calling {d,v}_teardown() then {d,v}_destroy() for
errors.

This top-level pattern is also necessary so we can remove the need to
put partially constructed objects into full view of the system, and wait
for a subsequent hypercall to clean them up.  This series of bugs is
still active, and there are still a load of NULL pointer deferences
reachable from out-of-order toolstack hypercalls in failure cases.

We've also got some subsystems (vmtrace) moved into the new pattern, and
some minor parts of existing mess moved over too, but the end goal is to
have exactly one create() path and exactly one cleanup path, so its
impossible to introduce mismatched duplicate cleanup logic.

~Andrew




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.