Skip to contentSkip to conversation

libfdt: fix fdt_check_node_offset_ w/ VALID_INPUT

PATCH Applied Frank Mehnert 2 participants 5 messages Aug 13, 2020 – Aug 14, 2020 2 messages not in the archive

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libfdt: fix fdt_check_node_offset_ w/ VALID_INPUT

fdt_check_node_offset_() checks for a valid offset but also changes the offset by calling fdt_next_tag(). Hence, do not skip this function if ASSUME_VALID_INPUT is set.

Actually this works similar to fdt_check_prop_offset_().

---
 libfdt/fdt.c | 2 --
 1 file changed, 2 deletions(-)
libfdt/fdt.c +0 -2
index c28fcc1..39ed8ed 100644
@@ -206,8 +206,6 @@ uint32_t fdt_next_tag(const void *fdt, int startoffset, int *nextoffset)
 
 int fdt_check_node_offset_(const void *fdt, int offset)
 {
-       if (can_assume(VALID_INPUT))
-               return offset;
        if ((offset < 0) || (offset % FDT_TAGSIZE)
            || (fdt_next_tag(fdt, offset, &offset) != FDT_BEGIN_NODE))
                return -FDT_ERR_BADOFFSET;
#1 lore raw
Quoted 5 lines · Frank Mehnert

fdt_check_node_offset_() checks for a valid offset but also changes the offset by calling fdt_next_tag(). Hence, do not skip this function if ASSUME_VALID_INPUT is set.

Actually this works similar to fdt_check_prop_offset_().

Correct, but we can do better. We can still elide the checks for offset < 0 and offset % FDT_TAGSIZE when VALID_INPUT is set.

Quoted 17 lines
---
 libfdt/fdt.c | 2 --
 1 file changed, 2 deletions(-)
libfdt/fdt.c +0 -2
index c28fcc1..39ed8ed 100644
@@ -206,8 +206,6 @@ uint32_t fdt_next_tag(const void *fdt, int startoffset, int *nextoffset)
 
 int fdt_check_node_offset_(const void *fdt, int offset)
 {
-       if (can_assume(VALID_INPUT))
-               return offset;
        if ((offset < 0) || (offset % FDT_TAGSIZE)
            || (fdt_next_tag(fdt, offset, &offset) != FDT_BEGIN_NODE))
                return -FDT_ERR_BADOFFSET;
Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson

A message that is not in the archive (sent off-list or not yet received): [email protected]

#3 lore raw

fdt_check_node_offset_() checks for a valid offset but also changes the offset by calling fdt_next_tag(). Hence, do not skip this function if ASSUME_VALID_INPUT is set but only omit the initial offset check in that case.

As this function works very similar to fdt_check_prop_offset_(), do the offset check there as well depending on ASSUME_VALID_INPUT.

---
 libfdt/fdt.c | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)
libfdt/fdt.c +10 -6
index c28fcc1..37b7b93 100644
@@ -206,10 +206,11 @@ uint32_t fdt_next_tag(const void *fdt, int startoffset, int *nextoffset)
 
 int fdt_check_node_offset_(const void *fdt, int offset)
 {
-       if (can_assume(VALID_INPUT))
-               return offset;
-       if ((offset < 0) || (offset % FDT_TAGSIZE)
-           || (fdt_next_tag(fdt, offset, &offset) != FDT_BEGIN_NODE))
+       if (!can_assume(VALID_INPUT)
+           && ((offset < 0) || (offset % FDT_TAGSIZE)))
+               return -FDT_ERR_BADOFFSET;
+
+       if (fdt_next_tag(fdt, offset, &offset) != FDT_BEGIN_NODE)
                return -FDT_ERR_BADOFFSET;
 
        return offset;
@@ -217,8 +218,11 @@ int fdt_check_node_offset_(const void *fdt, int offset)
 
 int fdt_check_prop_offset_(const void *fdt, int offset)
 {
-       if ((offset < 0) || (offset % FDT_TAGSIZE)
-           || (fdt_next_tag(fdt, offset, &offset) != FDT_PROP))
+       if (!can_assume(VALID_INPUT)
+           && ((offset < 0) || (offset % FDT_TAGSIZE)))
+               return -FDT_ERR_BADOFFSET;
+
+       if (fdt_next_tag(fdt, offset, &offset) != FDT_PROP)
                return -FDT_ERR_BADOFFSET;
 
        return offset;
Applied
#4 lore raw
Quoted 7 lines · Frank Mehnert

fdt_check_node_offset_() checks for a valid offset but also changes the offset by calling fdt_next_tag(). Hence, do not skip this function if ASSUME_VALID_INPUT is set but only omit the initial offset check in that case.

As this function works very similar to fdt_check_prop_offset_(), do the offset check there as well depending on ASSUME_VALID_INPUT.

So, it looks like your mailer has mangled the patch (replacing tabs with spaces). Since it's simple, I fixed it up this time, though.

Applied.

Quoted 38 lines
---
 libfdt/fdt.c | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)
libfdt/fdt.c +10 -6
index c28fcc1..37b7b93 100644
@@ -206,10 +206,11 @@ uint32_t fdt_next_tag(const void *fdt, int startoffset, int *nextoffset)
 
 int fdt_check_node_offset_(const void *fdt, int offset)
 {
-       if (can_assume(VALID_INPUT))
-               return offset;
-       if ((offset < 0) || (offset % FDT_TAGSIZE)
-           || (fdt_next_tag(fdt, offset, &offset) != FDT_BEGIN_NODE))
+       if (!can_assume(VALID_INPUT)
+           && ((offset < 0) || (offset % FDT_TAGSIZE)))
+               return -FDT_ERR_BADOFFSET;
+
+       if (fdt_next_tag(fdt, offset, &offset) != FDT_BEGIN_NODE)
                return -FDT_ERR_BADOFFSET;
 
        return offset;
@@ -217,8 +218,11 @@ int fdt_check_node_offset_(const void *fdt, int offset)
 
 int fdt_check_prop_offset_(const void *fdt, int offset)
 {
-       if ((offset < 0) || (offset % FDT_TAGSIZE)
-           || (fdt_next_tag(fdt, offset, &offset) != FDT_PROP))
+       if (!can_assume(VALID_INPUT)
+           && ((offset < 0) || (offset % FDT_TAGSIZE)))
+               return -FDT_ERR_BADOFFSET;
+
+       if (fdt_next_tag(fdt, offset, &offset) != FDT_PROP)
                return -FDT_ERR_BADOFFSET;
 
        return offset;
Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson

A message that is not in the archive (sent off-list or not yet received): [email protected]

#6 lore raw
Quoted 6 lines · On Freitag, 14. August 2020 05:17:48 CEST David Gibson wrote:
Quoted 5 lines · Frank Mehnert

fdt_check_node_offset_() checks for a valid offset but also changes the offset by calling fdt_next_tag(). Hence, do not skip this function if ASSUME_VALID_INPUT is set but only omit the initial offset check in that case.

Quoted 7 lines
Quoted 2 lines

As this function works very similar to fdt_check_prop_offset_(), do the offset check there as well depending on ASSUME_VALID_INPUT.

So, it looks like your mailer has mangled the patch (replacing tabs with spaces). Since it's simple, I fixed it up this time, though.

Applied.

Thanks!

Frank

Signature · 4 lines
Dr.-Ing. Frank Mehnert, [email protected], +49-351-41 883 224

Kernkonzept GmbH.  Sitz: Dresden.  Amtsgericht Dresden, HRB 31129.
Geschäftsführer: Dr.-Ing. Michael Hohmuth