diff options
author | 2023-10-12 12:25:58 +0000 | |
---|---|---|
committer | 2023-10-12 12:25:58 +0000 | |
commit | 6cda0a19bb64894805b24431728a6c0f6aba183a (patch) | |
tree | df5e71999a8ed9c1d0f04c5d952a121196e50d48 /libfdt | |
parent | 1fe80c59e93a3793b71dec7a138f8bfd061a4115 (diff) | |
parent | 0493daab327ef269a7ab6a8ab61fae15f92e7666 (diff) |
Merge changes I0b17b082,I894051ed,I662a5997 into main
* changes:
FROMLIST: libdft: fdt_next_tag: Harden offset overflow check
FROMGIT: libfdt: prevent integer overflow in fdt_next_tag
ANDROID: Revert "Fix integer wrap sanitisation."
Diffstat (limited to 'libfdt')
-rw-r--r-- | libfdt/fdt.c | 21 |
1 files changed, 10 insertions, 11 deletions
diff --git a/libfdt/fdt.c b/libfdt/fdt.c index c17cad5..b8ffb33 100644 --- a/libfdt/fdt.c +++ b/libfdt/fdt.c @@ -165,7 +165,7 @@ const void *fdt_offset_ptr(const void *fdt, int offset, unsigned int len) uint32_t fdt_next_tag(const void *fdt, int startoffset, int *nextoffset) { const fdt32_t *tagp, *lenp; - uint32_t tag; + uint32_t tag, len, sum; int offset = startoffset; const char *p; @@ -188,23 +188,22 @@ uint32_t fdt_next_tag(const void *fdt, int startoffset, int *nextoffset) break; case FDT_PROP: - lenp = fdt_offset_ptr(fdt, offset, sizeof(struct fdt_property) - FDT_TAGSIZE); + lenp = fdt_offset_ptr(fdt, offset, sizeof(*lenp)); if (!can_assume(VALID_DTB) && !lenp) return FDT_END; /* premature end */ - /* skip name offset, length */ - offset += sizeof(struct fdt_property) - FDT_TAGSIZE; - - if (!can_assume(VALID_DTB) - && !fdt_offset_ptr(fdt, offset, fdt32_to_cpu(*lenp))) + len = fdt32_to_cpu(*lenp); + sum = len + offset; + if (!can_assume(VALID_DTB) && + (INT_MAX <= sum || sum < (uint32_t) offset)) return FDT_END; /* premature end */ - /* skip value */ - offset += fdt32_to_cpu(*lenp); + /* skip-name offset, length and value */ + offset += sizeof(struct fdt_property) - FDT_TAGSIZE + len; if (!can_assume(LATEST) && - fdt_version(fdt) < 0x10 && fdt32_to_cpu(*lenp) >= 8 && - ((offset - fdt32_to_cpu(*lenp)) % 8) != 0) + fdt_version(fdt) < 0x10 && len >= 8 && + ((offset - len) % 8) != 0) offset += 4; break; |