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

Re: [PATCH v2 01/12] xen/trace: Don't over-read trace objects


  • To: Jan Beulich <jbeulich@xxxxxxxx>
  • From: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
  • Date: Tue, 21 Sep 2021 18:51:20 +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; bh=K96rXa87K4HaHxHM6TIZjQQ6d9h87yfh/rTKv1iNmJE=; b=n5N7j7Qfc/OIW8pLYNWEubmobmEJd8TsJ0efBFav9MS8OeNP3DtkMs0TVX9WOE8lNwQWX7joIFgOsiQVe4+KKp1qCk/FBIjQr5NHT/8jm2KfLyy3VsrnMrhIEeSuxBb6Rp6BNkDBouRUwPHRRuqRS4EFSvVocLCpvfRlxLtHOah9ggCczOi+gDsa8XXLWlkWH/nIUjgJAwExc6k+sqKME4zyKrPmoBeXJEdsHn/iRW0MNljoZHE+dWYX+f+qm/H39IrGBUy3qCzwTdSngR7D0Xhsm5irAU3rLwVjDfI+7Qkvxd65HPKydUQdh4PrpDIfLS2DDVxIu6c69gkp8kB7Yw==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=OxKD7uWNY87koeu5wl3r4yoqGJydEK7Ib9TD3sf2BLiYN2myqDA3f8TuJv359lsme4GEzyFVun1nATsYtp6ZOLzmcMq388XUjziuPHAVPs4PBT7QwrrSKMWvA5lHT6SNtWt+g5nEzS/fLgX8afRYTcbEcaosOTMSHo8ZOrF4QE4M7g+h5PvzzKpS9amtsWdKtP8YIn5lgZUlY803sBV+UBfPP0fb+l17BE6FzCO0e6sGZNPgbYLxovIqg0DjC+fAVEXvgUEoCgW4REFx/yN3dgMIkceeAoNz8CmjrkZQ7ZW/Wm1mOqjBWzpRLyODP4BQAGlbRCctOLmv1UNQy0NkOg==
  • Authentication-results: esa2.hc3370-68.iphmx.com; dkim=pass (signature verified) header.i=@citrix.onmicrosoft.com
  • Cc: George Dunlap <George.Dunlap@xxxxxxxxxxxxx>, Ian Jackson <iwj@xxxxxxxxxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Wei Liu <wl@xxxxxxx>, Julien Grall <julien@xxxxxxx>, Dario Faggioli <dfaggioli@xxxxxxxx>, Meng Xu <mengxu@xxxxxxxxxxxxx>, Xen-devel <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • Delivery-date: Tue, 21 Sep 2021 17:51:48 +0000
  • Ironport-data: A9a23:uzKuOaLD9qFHvHvlFE+RUpIlxSXFcZb7ZxGr2PjKsXjdYENS32cGz jEYXzjSa/iNNzOgctp3O9vg8h8AuMTRz4BkSgtlqX01Q3x08seUXt7xwmUcns+xwm8vaGo9s q3yv/GZdJhcokcxIn5BC5C5xZVG/fjgqoHUVaiUZ0ideSc+EH140UM5wrZj6mJVqYPR7z2l6 IuaT/L3YDdJ6xYsWo7Dw/vewP/HlK2aVAIw5jTSV9gS1LPtvyB94KYkDbOwNxPFrrx8RYZWc QphIIaRpQs19z91Yj+sfy2SnkciGtY+NiDW4pZatjTLbrGvaUXe345iXMfwZ3u7hB2Zhdk29 OVE7aaTRB8gLofrxvsYbwRHRnQW0a1uoNcrIFC6uM2XiUbHb2Ht07NlC0Re0Y8wo7gtRzsUr LpBdW5LPkvra+GemdpXTsFFgMg5IdatF4QYonx6lhnSDOo8QICFSKLPjTNd9Gpr3JwXRqiDD yYfQQtBbznQcjBlAW1JOqolruSZplijTxQN/Tp5ooJoujOOnWSdyoPFK8HJc9aHQcFUmEewp W/c+Wn9RBYAO7S31j6t4n+qwOjVkkvTWogfCbm5/f5Cm0CIyyoYDxh+fVqko9Gph0imQdVdJ kcIvC00osAa8UGtQcngdxa5uziZphMaXZ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yTdaoguCMc6AxxZJkh8erwXZVoMkmsiqKdhrNhQYtKPTOWxVdASbsN0WKM+UyZJ8STzJ876U 4kSdkFNDSSNykLsS+Z2njALz9I+rDum8rJ9ISuvEuFDzsaD52Ihz0JezpzeXcGIjWua6BJdq Z0qvA33AZJLh8sH7qG7zQ+LqT+juyOsKijTQ8NBhYh5gXLpTS06ITiGxzd+hsFSTtAzZor7G CAymXCl+uemsD+7iWZ+37Y7pxQltek4txfBPaUgsxQDjn3kA6naKloRrXHljEop+OE7kosjb D30lgdFvU2z0mUUnC+oBPr1QWl+DEy60X6wVvdunfnqdyRfkNwN+NxwaZiNjfJ4Uspu99xlI hR2XiCipZRBRTc2Azg+tnhTXhR5wmJiEtntdRWo21UUIMYZrMUh5cY5llpHJAJGz+/wJw7Ed NpENrX6J9tABOnhkjizyxSKeGXLzAO9k/seDlEhiXV6UkWoJlB9Tpb+CRF9U1wsq7USPF/lq z52+pT5ehzpmJ/V9MLOA47e7rDNoX6e2OEDIujGyWUKEg5AQO4l3fW2sR+2Aj4Qu1E8HMN8K 6xJm+w81RCI37TNQ==
  • Ironport-sdr: KqbLzqBhpEPFOZHmiscBjdJa5b3URDtanGTW7cWiXR4cNO4OiOHjKF8VL9isgpgOcrRAMJ2/y1 bZU+izv0vSXyLy6pVVFy8rm7Zz1hQ6xT7jDYrZKmWsWj1tAPEhhp9Ga4jjJvz97yvQDg8B65aL YjpJz5vpUitof3D+vmb1a94uThnpbyEpoSIFjD/SO95w58UpdKEwXA1Dg4ktxqym2yHP8RkRoA SICFvhNhFXi+GMVnm3HJXnSHmmukDc18QY/1zU36hgHXSqp5G94m5zTTqxIhIJ2d8q5UIJuSPK kGCdw80wOl8nhmIad6k6ev9q
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 21/09/2021 07:53, Jan Beulich wrote:
> On 20.09.2021 19:25, Andrew Cooper wrote:
>> In the case that 'extra' isn't a multiple of uint32_t, the calculation rounds
>> the number of bytes up, causing later logic to read unrelated bytes beyond 
>> the
>> end of the object.
>>
>> Also, asserting that the object is within TRACE_EXTRA_MAX, but truncating it
>> in release builds is rude.  Instead, reject any out-of-spec records, leaving
>> enough of a message to identify the faulty caller.
>>
>> There is one buggy race record, TRC_RTDS_BUDGET_BURN.  As it must remain
> Nit: I guess s/race/trace/ ?

Oops yes.

>
>> __packed (as cur_budget is misaligned), change bool has_extratime to uint32_t
>> to compensate.
>>
>> The new printk() can also be hit by HVMOP_xentrace, although no over-read is
>> possible.  This has no business being a hypercall in the first place, as it
>> can't be used outside of custom local debugging, so extend the uint32_t
>> requirement to HVMOP_xentrace too.
>>
>> Signed-off-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
> Reviewed-by: Jan Beulich <jbeulich@xxxxxxxx>
>
> Two remarks (plus further not directly related ones), nevertheless:
>
>> --- a/xen/arch/x86/hvm/hvm.c
>> +++ b/xen/arch/x86/hvm/hvm.c
>> @@ -5063,8 +5063,9 @@ long do_hvm_op(unsigned long op, 
>> XEN_GUEST_HANDLE_PARAM(void) arg)
>>          if ( copy_from_guest(&tr, arg, 1 ) )
>>              return -EFAULT;
>>  
>> -        if ( tr.extra_bytes > sizeof(tr.extra)
>> -             || (tr.event & ~((1u<<TRC_SUBCLS_SHIFT)-1)) )
>> +        if ( tr.extra_bytes % sizeof(uint32_t) ||
>> +             tr.extra_bytes > sizeof(tr.extra) ||
>> +             tr.event >> TRC_SUBCLS_SHIFT )
>>              return -EINVAL;
> Despite this being a function that supposedly no-one is to really
> use, you're breaking the interface here when really there would be a
> way to be backwards compatible: Instead of failing, pad the data to
> a 32-bit boundary. As the interface struct is large enough, this
> would look to be as simple as a memset() plus aligning extra_bytes
> upwards. Otherwise the deliberate breaking of potential existing
> callers wants making explicit in the respective paragraph of the
> description.

It is discussed, along with a justification for why an ABI change is fine.

But I could do

tr.extra_bytes = ROUNDUP(tr.extra_bytes, sizeof(uint32_t));

if you'd really prefer.


> As an aside I think at the very least the case block wants enclosing
> in "#ifdef CONFIG_TRACEBUFFER", such that builds without the support
> would indicate so to callers (albeit that indication would then be
> accompanied by a bogus log message in debug builds).

That message really needs deleting.

As a better alternative,

if ( !IS_ENABLED(CONFIG_TRACEBUFFER) )
    return -EOPNOTSUPP;

The call to __trace_var() is safe in !CONFIG_TRACEBUFFER builds.

>
> Seeing the adjacent HVMOP_get_time I also wonder who the intended
> users of that one are.

There is a very large amount of junk in hvm_op(), and to a first
approximation, I would include HVMOP_get_time in that category.

But c/s b91391491c58ac40a935e10cf0703b87d8733c38 explains why it is
necessary.  This just goes to demonstrate how broken our time handling
is.  I'll add this to the pile of things needing fixing in ABI-v2.

>
>> --- a/xen/common/sched/rt.c
>> +++ b/xen/common/sched/rt.c
>> @@ -968,18 +968,20 @@ burn_budget(const struct scheduler *ops, struct 
>> rt_unit *svc, s_time_t now)
>>      /* TRACE */
>>      {
>>          struct __packed {
>> -            unsigned unit:16, dom:16;
>> +            uint16_t unit, dom;
>>              uint64_t cur_budget;
>> -            int delta;
>> -            unsigned priority_level;
>> -            bool has_extratime;
>> -        } d;
>> -        d.dom = svc->unit->domain->domain_id;
>> -        d.unit = svc->unit->unit_id;
>> -        d.cur_budget = (uint64_t) svc->cur_budget;
>> -        d.delta = delta;
>> -        d.priority_level = svc->priority_level;
>> -        d.has_extratime = svc->flags & RTDS_extratime;
>> +            uint32_t delta;
> The original field was plain int, and aiui for a valid reason. I
> don't see why you couldn't use int32_t here.

delta can't be negative, because there is a check earlier in the function.

What is a problem is the 63=>32 bit truncation, and uint32_t here is
half as bad as int32_t.

~Andrew




 


Rackspace

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