]> xenbits.xensource.com Git - unikraft/unikraft.git/commitdiff
plat/linuxu: Add check for memory region index out of range
authorDiego Alejandro Parra Guzman <diego-alejandro.parra-guzman@tttech.com>
Wed, 10 May 2023 11:12:01 +0000 (14:12 +0300)
committerUnikraft <monkey@unikraft.io>
Wed, 10 May 2023 11:23:43 +0000 (11:23 +0000)
Ensure that we do not try to fetch a memory region descriptor by an
index that is larger than our current memory region descriptor count.

Furthermore, this guarantees that `ukplat_memregion_count` is always
called before `ukplat_memregion_get` is executed fully. This way we
will always have the memory region descriptors as well as their count
set up and available before we try to fetch one.

Co-authored-by: Sergiu Moga <sergiu.moga@protonmail.com>
Signed-off-by: Sergiu Moga <sergiu.moga@protonmail.com>
Signed-off-by: Diego Alejandro Parra Guzman <diego-alejandro.parra-guzman@tttech.com>
GitHub-Fixes: #766
Reviewed-by: Razvan Deaconescu <razvand@unikraft.io>
Approved-by: Razvan Deaconescu <razvand@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #878

plat/linuxu/memory.c

index 4a0653649b1c15d66061fadf4955e0fcea5c6690..42426044807657e05b905e8d0bd5d346671e99f6 100644 (file)
@@ -157,6 +157,9 @@ int ukplat_memregion_get(int i, struct ukplat_memregion_desc **m)
 
        UK_ASSERT(m);
 
+       if (i >= ukplat_memregion_count())
+               return -1;
+
        if (i == 0 && _liblinuxuplat_opts.heap.base) {
                mrd[0].pbase = (__paddr_t)_liblinuxuplat_opts.heap.base;
                mrd[0].vbase = mrd[0].pbase;