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

Re: [PATCH 5/6] xen/dt-overlay: support phandle-based targeting in overlay_get_nodes_info


  • To: "Orzel, Michal" <Michal.Orzel@xxxxxxx>
  • From: Luca Fancellu <Luca.Fancellu@xxxxxxx>
  • Date: Thu, 16 Apr 2026 08:21:55 +0000
  • Accept-language: en-GB, en-US
  • Arc-authentication-results: i=2; mx.microsoft.com 1; spf=pass (sender ip is 4.158.2.129) smtp.rcpttodomain=amd.com smtp.mailfrom=arm.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=arm.com; dkim=pass (signature was verified) header.d=arm.com; arc=pass (0 oda=1 ltdi=1 spf=[1,1,smtp.mailfrom=arm.com] dkim=[1,1,header.d=arm.com] dmarc=[1,1,header.from=arm.com])
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none
  • Arc-message-signature: i=2; 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=nfok6GtyZbB92DO23LCWQJIQ0G1lbsbdtCxjgOCANBI=; b=BQ3I9ooFbaaFXE3pyu66mIW0OQ8GZJmRMlZ4dYB8k0hJu/Qo3MOlgXcBWukkTY5hTqb7hpWwE+iWX3FR1AIGisfmqFS7zBDcatLN+uMG/nL2k7wfh+TtXpXLsDHSCQmncv/Py4jH0Rr3hnCba6guzXXRuX1PPJWIgGhx2zIDgu90BzPcGnFWtorIlIplaBbLiMdc3ucTNaDXjU6nlXY/eCyN5MarunrsKMymH4Azpy9GuLV/xS3QJEzGvg+4OMyAvzA/q6wh1eUtZIvJGnE9EPZOiZCkrwo7tVwF0yAeg1KGhcoxqRdu6UQvkRzNo1XF+zOul3a3AjqduMa0rSNF5A==
  • 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=nfok6GtyZbB92DO23LCWQJIQ0G1lbsbdtCxjgOCANBI=; b=fd8RI6JAjbtFrCtnD9vX3bpgPuXZapa9+g/dfsDiF23LoKlDXJAhMYbvQDJcddQk/ozjTe55InOFs74Ktk1iMZomKVFooqMvgq1/keDWuSGOlzPVqMZHX9MaVAWVmuYMwBvpL1bB4huPNH4+padKMIzsun7FYvyhyHm+KJZ7aELi7cMB94PQzpgt4P7HLrte1Iryh3O2kbJFkQIO+WYkfJI2xn/Y1TKOvTl5RjVwNwCUb4F2KxFF2/xPc+aRq8GRRFHGDtj0ghnYHWCw1sQYmvwZOtlp2ltrdMdnfSxmmrCJXcjMMCAzHNovQMegH9nUZCuhWNg55lZ0VuNGAJa4kw==
  • Arc-seal: i=2; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=pass; b=t7cLBJZe/SO6m8+Dlpeisa7x1CaigaZuLm4L+6/vh6xYEkIKz9CnGL1nHheKUSKW6mvYWVsRGcJdzOPqUM1TErl6VefLimZ2AkUNvSLIGtMwvebbTFS6OHSBj+M9zfyHXuAS1lWLcZIARL4gfZJYy3bpPu/ce58f/+WDmm3zr97DLtKg4Mm6TZdjwUnYsfCWMX92l6egxTVx9fNLb6MV5Qf9Zz+hteTFzfpo/zXmZVruiUN4u+owvMoKW38RrotEF6+2XRcp2daeVbpOyYWyD+o9kqkxIAo0vl1iFOu0hjlcJ0wMISdR15bkBORri9YOg1UL4YZhTV114vQDdLGBLw==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=nkqC7rOkQRZXaAZDZPFUOYNK99VPVdq7Vw4WVnyLz05f1OeA7vARWwssW08h8vn1Fa3jUl0SUhTjdw07cGHbU+0jiSKWv0rymxJrNiMAtzDuvfZkB5tAvS3fDJo92pf8MSn5X43hB/QbHpckL/bluEU5XH/xrihmAWWHC+cCK6+2LCEq6Mo1wQnlgDO8HNRnaHSlm/F0n/Ne24cGQkOrAWaYj+O2W94yI3rJEE4VhnVa9M+c9eAQo04OlbSVIOx4ZwTJ8RART0vUg9DaeCeQ9ycQ6wtUrIvej0rk5SN9Rv/VtwWZvqstRmepsArptBL32bpacvY1mAYH0sk/lc0v8Q==
  • Authentication-results: eu.smtp.expurgate.cloud; dkim=pass header.s=selector1 header.d=arm.com header.i="@arm.com" header.h="From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck"; dkim=pass header.s=selector1 header.d=arm.com header.i="@arm.com" header.h="From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck"
  • Authentication-results-original: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com;
  • Cc: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Julien Grall <julien@xxxxxxx>, Bertrand Marquis <Bertrand.Marquis@xxxxxxx>
  • Delivery-date: Thu, 16 Apr 2026 08:23:07 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Nodisclaimer: true
  • Thread-index: AQHczMxJn1pwTu5+sUmN2MgYtFAQK7XgQWaAgAELlQCAAA1zAA==
  • Thread-topic: [PATCH 5/6] xen/dt-overlay: support phandle-based targeting in overlay_get_nodes_info

>>> 
>>> diff --git a/xen/common/device-tree/dt-overlay.c 
>>> b/xen/common/device-tree/dt-overlay.c
>>> index d3d4669718ac..a0dee7edb7e5 100644
>>> --- a/xen/common/device-tree/dt-overlay.c
>>> +++ b/xen/common/device-tree/dt-overlay.c
>>> @@ -286,6 +286,63 @@ static unsigned int overlay_node_count(const void 
>>> *overlay_fdt)
>>>    return num_overlay_nodes;
>>> }
>>> 
>>> +/*
>>> + * Resolve the target path for an overlay fragment.
>>> + *
>>> + * This is called before fdt_overlay_apply(), so phandle-based targets
>>> + * (target = <&label>) are still unresolved (compiled as 0xffffffff by 
>>> DTC).
>>> + * Handle the two cases that actually occur:
>>> + *  - target-path property: the path string is used directly,
>>> + *  - target = <&label>: the label is looked up in the overlay's __fixups__
>>> + *    node, then resolved to a path via the base DTB's __symbols__ node.
>>> + *
>>> + * Returns a pointer into the FDT on success, NULL on failure.
>>> + */
>>> +static const char *overlay_get_target_path(const void *fdt, const void 
>>> *fdto,
>>> +                                           int fragment)
>>> +{
>>> +    const char *path, *fragment_name;
>>> +    int fixups_off, symbols_off, property;
>>> +    int fragment_name_len;
>>> +
>>> +    /* Try target-path first (string-based targeting) */
>>> +    path = fdt_getprop(fdto, fragment, "target-path", NULL);
>>> +    if ( path )
>>> +        return path;
>>> +
>>> +    /* Phandle-based target: resolve via __fixups__ and __symbols__ */
>>> +    fixups_off = fdt_path_offset(fdto, "/__fixups__");
>>> +    if ( fixups_off < 0 )
>>> +        return NULL;
>>> +
>>> +    symbols_off = fdt_path_offset(fdt, "/__symbols__");
>>> +    if ( symbols_off < 0 )
>>> +        return NULL;
>>> +
>>> +    fragment_name = fdt_get_name(fdto, fragment, &fragment_name_len);
>>> +    if ( !fragment_name )
>>> +        return NULL;
>>> +
>>> +    fdt_for_each_property_offset(property, fdto, fixups_off)
>>> +    {
>>> +        const char *val, *label, *p;
>>> +        int val_len;
>>> +
>>> +        val = fdt_getprop_by_offset(fdto, property, &label, &val_len);
>>> +        if ( !val )
>>> +            continue;
>>> +
>>> +        /* Match entries of the form "/<fragment_name>:target:0" */
>>> +        for ( p = val; p < (val + val_len); p += (strlen(p) + 1) )
>> 
>> what guarantees us that p will be null terminated, if a malformed overlay
>> is passed this strlen can read past the string, we can use strnlen having as
>> upper bound a counter=val_len? decreasing counter each iteration.
>> 
>> Or do you think it can never happen?
> In theory it can happen, in practice this is something not usually taken into
> account. But we can surely stay on the defensive side and do a single check
> right after fdt_getprop_by_offset to catch not-NUL terminated stringlist:
> if ( !val || !val_len || val[val_len - 1] != '\0' )

Ok, do we also want to print a warning in case of malformed properties instead
of ignoring and continue?

> 
> In case of no other remarks, I'd do that on commit.
> 
> ~Michal
> 

Cheers,
Luca




 


Rackspace

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