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

Re: [PATCH 2/3] xen/common: llc-coloring: Fix off-by-one in parse_color_config()


  • To: Jan Beulich <jbeulich@xxxxxxxx>, Luca Fancellu <Luca.Fancellu@xxxxxxx>
  • From: "Orzel, Michal" <michal.orzel@xxxxxxx>
  • Date: Fri, 10 Apr 2026 09:04:17 +0200
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=suse.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0)
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=wZn7ErxUd+DKabZl6OfftNVf6LgBJtkKHdjlFuA8pTE=; b=y1kly0zvrQkvNgs+zGXIQAy87tRLNnTKD5wq4DrOG/yKIXoS/ElKshqRpp12PMKXlbUZ98lHje0/VuDbVe8A2wIOK3kPAjhV677Kb0p9ICNd8oyrPHst6cakxmAzJNgJi4mqKvxxr1W+UJS+9djIUne+AVw2PLKK6RaHcYmg2kkLtq2aHf9hwMsvqqpfzQfOOetQXhBRCGxjz8a1JBPu8TK2WvE5GfS+7dxT/VKPdJ+I78LOFMYUiUFXs5dSMLZjpPS1FjshBF17aMbcRySHdK8BWELM2qGMHoMKYR7hQO2PDn344x091TCpJvfD2aNF6pDb4gR7/W0+ZkngVe7dZA==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=rzoeCWKqzdwvQbXcDVFL7pZpcB/VTklR0iUShNLwVIpIVVNoDQw53ayLmjIYRdJKAhnT6n5nKmDsioK7oskA4VdnZQe0NmfM55qQh+MZN1aBhe9KCLpOjR4miTEfonz97qfJRpxY4P+hlbXEejCsU2K8bI0s2LX4RS2y3nCt5zPyJrCs2hUQX2wvY1MPxEGuOQmXkL6fdHDop/wozFBL1EJMNwBKwdz2FFCfioIjPfbKgPX6r40ZCXu1e4bfyxERm5Dwx2KOMy6GFCVoGbvq5xj64ynieMZ9sB9lctU9CWVpJ8J/dBcErCmndzsfIuTM+zxKjEl9e3sTWMUz57ikNQ==
  • Authentication-results: eu.smtp.expurgate.cloud; dkim=pass header.s=selector1 header.d=amd.com header.i="@amd.com" header.h="From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck"
  • Cc: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>, "Andrew Cooper" <andrew.cooper3@xxxxxxxxxx>, Anthony PERARD <anthony.perard@xxxxxxxxxx>, Julien Grall <julien@xxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>
  • Delivery-date: Fri, 10 Apr 2026 07:04:35 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>


On 10/04/2026 08:57, Jan Beulich wrote:
> On 09.04.2026 15:34, Luca Fancellu wrote:
>>> On 9 Apr 2026, at 13:52, Luca Fancellu <Luca.Fancellu@xxxxxxx> wrote:
>>>> On 9 Apr 2026, at 13:48, Jan Beulich <jbeulich@xxxxxxxx> wrote:
>>>> On 09.04.2026 14:22, Luca Fancellu wrote:
>>>>>> On 9 Apr 2026, at 12:39, Michal Orzel <michal.orzel@xxxxxxx> wrote:
>>>>>>
>>>>>> The check uses >= to compare the total number of colors against
>>>>>> max_num_colors (which is ARRAY_SIZE of the colors array).  This
>>>>>> incorrectly rejects input that would exactly fill the array.
>>>>>>
>>>>>> For example, with NR_LLC_COLORS=16, specifying 1 color for Xen and 15
>>>>>> for dom0 would fail.
>>>>>>
>>>>>> Change >= to > so that exactly filling the array is permitted.
>>>>>>
>>>>>> Fixes: 95ef5ddf8a ("xen/arm: add Dom0 cache coloring support")
>>>>>> Signed-off-by: Michal Orzel <michal.orzel@xxxxxxx>
>>>>>> ---
>>>>>
>>>>> Reviewed-by: Luca Fancellu <luca.fancellu@xxxxxxx>
>>>>
>>>> Did you see Andrew's reply? If that earlier (recent) commit was wrong, I
>>>> think a 2nd Fixes: tag may be needed here. For now I can't help the
>>>> impression though that there might have been a re-basing mistake, where
>>>> that re-base may have wanted to result in this patch dissolving into
>>>> nothing. Yet of course I'm all ears to learn otherwise.
>>>
>>> Oh, no I didn’t see that! Thanks for pointing that out, I will have a 
>>> closer look.
>>
>>
>> I had a closer look, I feel that the patch is ok and commit 
>> cba8a584de171c8c4510709c2edc9f1cf86b21ab
>> was missing this corner case.
> 
> If anything, that part of the change there was outright wrong (and hence, as
> said, a 2nd Fixes: tag [actually, see below, simply another one] is needed).
> With overflow excluded,
> 
>     (*num_colors + (end - start + 1)) > max_num_colors
> 
> is the same as
> 
>    (*num_colors + (end - start)) >= max_num_colors
> 
> i.e. the state before that change, isn't it?
> 
> And yes, now that I look again I think I agree that I screwed up there. Yet
> then the (imo) better fix would be to undo that change, rather than switching
> from >= to > . That's one less calculation overall. Michal?
Yes, I do agree. This patch can be modified to just do:

diff --git a/xen/common/llc-coloring.c b/xen/common/llc-coloring.c
index eb7c72b24023..6dc614739a98 100644
--- a/xen/common/llc-coloring.c
+++ b/xen/common/llc-coloring.c
@@ -78,7 +78,7 @@ static int __init parse_color_config(const char *buf, unsigned
int colors[],

         if ( end >= NR_LLC_COLORS || start > end ||
              (end - start) >= (UINT_MAX - *num_colors) ||
-             (*num_colors + (end - start + 1)) >= max_num_colors )
+             (*num_colors + (end - start)) >= max_num_colors )
             return -EINVAL;

         /* Colors are range checked in check_colors() */

I'll do that later on.

~Michal




 


Rackspace

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