fdt: fix fdtdec_get_addr_size not to require any size cells
PATCH 1/1 fdt: fix fdtdec_get_addr_size not to require any size cells
From: Stephen Warren <[email protected]>
fdtdec_get_addr_size() may be used in two cases:
a) With sizep supplied, in which case both an address and a size are parsed from DT. In this case, the DT property must be large enough to contain both values.
b) With sizep NULL, in which case only an address is parsed from DT. In this case, the DT property only need be large enough to contain this address value. Commit 02464e386bb5 "fdt: add new fdt address parsing functions" broke this relaxed checking, and required the DT property to contain both an address and a size value in all cases.
Fix fdtdec_get_addr_size() to vary ns based on whether the size value is being parsed from the DT or not. This is safe since the function only parses the first entry in the property, so the overall value of (na + ns) need not be accurate, since it is never used to step through the property data to find other entries. Besides, this fixed behaviour essentially matches the original behaviour before the patch this patch fixes. (The original code validated that the property was exactly the length of either na or (na + ns), whereas the current code only validates that the property is at least that long. For non-failure cases, the two behaviours are identical).
--- lib/fdtdec.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
lib/fdtdec.c +3 -2
@@ -180,10 +180,11 @@ fdt_addr_t fdtdec_get_addr_size_auto_noparent(const void *blob, int node,fdt_addr_t fdtdec_get_addr_size (const void *blob,int node,const char *prop_name,fdt_size_t *sizep) { +int ns = sizep ? (sizeof (fdt_size_t) /sizeof (fdt32_t)) :0 ; +return fdtdec_get_addr_size_fixed (blob, node, prop_name,0 ,sizeof (fdt_addr_t) /sizeof (fdt32_t), -sizeof (fdt_size_t) /sizeof (fdt32_t), - sizep); + ns, sizep); } fdt_addr_t fdtdec_get_addr(const void *blob, int node,
Signature · 1 line
1.9.1
PATCH 1/1 fdt: fix fdtdec_get_addr_size not to require any size cells
Hello Stephen,
Quoted 44 lines · Stephen Warren
From: Stephen Warren <[email protected]>
fdtdec_get_addr_size()may be used in two cases:
a) With sizep supplied, in which case both an address and a size are parsed from DT. In this case, the DT property must be large enough to contain both values.
b) With sizep NULL, in which case only an address is parsed from DT. In this case, the DT property only need be large enough to contain this address value. Commit02464e386bb5"fdt: add new fdt address parsing functions" broke this relaxed checking, and required the DT property to contain both an address and a size value in all cases.Fix
fdtdec_get_addr_size()to vary ns based on whether the size value is being parsed from the DT or not. This is safe since the function only parses the first entry in the property, so the overall value of (na + ns) need not be accurate, since it is never used to step through the property data to find other entries. Besides, this fixed behaviour essentially matches the original behaviour before the patch this patch fixes. (The original code validated that the property was exactly the length of either na or (na + ns), whereas the current code only validates that the property is at least that long. For non-failure cases, the two behaviours are identical).Cc Przemyslaw Marczak <[email protected]>Cc Simon Glass <[email protected]>Cc Thierry Reding <[email protected]>Cc Bin Meng <[email protected]>Cc Michal Suchanek <[email protected]>Fixes 02464e386bb5 ("fdt: add new fdt address parsing functions")Reported-by Przemyslaw Marczak <[email protected]>Signed-off-by Stephen Warren <[email protected]>--- lib/fdtdec.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)lib/fdtdec.c +0
-0@@ -180,10 +180,11 @@ fdt_addr_t fdtdec_get_addr_size_auto_noparent(const void *blob, int node,fdt_addr_t fdtdec_get_addr_size (const void *blob,int node,const char *prop_name,fdt_size_t *sizep) {
lib/fdtdec.c fdt_addr_t fdtdec_get_addr_size_auto_noparent(const void *blob, int node, · line 190
Quoted 10 lines
lib/fdtdec.c +3
-2+int ns = sizep ? (sizeof (fdt_size_t) /sizeof (fdt32_t)) :0 ; +return fdtdec_get_addr_size_fixed (blob, node, prop_name,0 ,sizeof (fdt_addr_t) /sizeof (fdt32_t), -sizeof (fdt_size_t) /sizeof (fdt32_t), - sizep); + ns, sizep); } fdt_addr_t fdtdec_get_addr(const void *blob, int node,
I tested this on top of latest mainline and it fixes the issue for use of fdtdec_get_addr(), however my fixes should be also applied.
Best regards,
Signature · 4 lines
Przemyslaw Marczak Samsung R&D Institute Poland Samsung Electronics p.marczak at samsung.com
PATCH 1/1 fdt: fix fdtdec_get_addr_size not to require any size cells
Quoted 39 lines · Przemyslaw Marczak
Hello Stephen,
Quoted 35 lines · Stephen Warren
From: Stephen Warren <[email protected]>
fdtdec_get_addr_size()may be used in two cases:
a) With sizep supplied, in which case both an address and a size are parsed from DT. In this case, the DT property must be large enough to contain both values.
b) With sizep NULL, in which case only an address is parsed from DT. In this case, the DT property only need be large enough to contain this address value. Commit02464e386bb5"fdt: add new fdt address parsing functions" broke this relaxed checking, and required the DT property to contain both an address and a size value in all cases.Fix
fdtdec_get_addr_size()to vary ns based on whether the size value is being parsed from the DT or not. This is safe since the function only parses the first entry in the property, so the overall value of (na + ns) need not be accurate, since it is never used to step through the property data to find other entries. Besides, this fixed behaviour essentially matches the original behaviour before the patch this patch fixes. (The original code validated that the property was exactly the length of either na or (na + ns), whereas the current code only validates that the property is at least that long. For non-failure cases, the two behaviours are identical).Cc Przemyslaw Marczak <[email protected]>Cc Simon Glass <[email protected]>Cc Thierry Reding <[email protected]>Cc Bin Meng <[email protected]>Cc Michal Suchanek <[email protected]>Fixes 02464e386bb5 ("fdt: add new fdt address parsing functions")Reported-by Przemyslaw Marczak <[email protected]>Signed-off-by Stephen Warren <[email protected]>--- lib/fdtdec.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
PATCH 1/1 fdt: fix fdtdec_get_addr_size not to require any size cells
Quoted 41 lines · Simon Glass
Quoted 39 lines · Przemyslaw Marczak
Hello Stephen,
Quoted 35 lines · Stephen Warren
From: Stephen Warren <[email protected]>
fdtdec_get_addr_size()may be used in two cases:
a) With sizep supplied, in which case both an address and a size are parsed from DT. In this case, the DT property must be large enough to contain both values.
b) With sizep NULL, in which case only an address is parsed from DT. In this case, the DT property only need be large enough to contain this address value. Commit02464e386bb5"fdt: add new fdt address parsing functions" broke this relaxed checking, and required the DT property to contain both an address and a size value in all cases.Fix
fdtdec_get_addr_size()to vary ns based on whether the size value is being parsed from the DT or not. This is safe since the function only parses the first entry in the property, so the overall value of (na + ns) need not be accurate, since it is never used to step through the property data to find other entries. Besides, this fixed behaviour essentially matches the original behaviour before the patch this patch fixes. (The original code validated that the property was exactly the length of either na or (na + ns), whereas the current code only validates that the property is at least that long. For non-failure cases, the two behaviours are identical).Cc Przemyslaw Marczak <[email protected]>Cc Simon Glass <[email protected]>Cc Thierry Reding <[email protected]>Cc Bin Meng <[email protected]>Cc Michal Suchanek <[email protected]>Fixes 02464e386bb5 ("fdt: add new fdt address parsing functions")Reported-by Przemyslaw Marczak <[email protected]>Signed-off-by Stephen Warren <[email protected]>--- lib/fdtdec.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
Quoted 1 line
Acked-by Simon Glass <[email protected]>
Applied to u-boot-fdt, thanks!