1 /* 2 * Copyright (C) 2016 The Android Open Source Project 3 * 4 * SPDX-License-Identifier: MIT 5 */ 6 7 #include "avb_kernel_cmdline_descriptor.h" 8 #include "avb_util.h" 9 10 bool avb_kernel_cmdline_descriptor_validate_and_byteswap( 11 const AvbKernelCmdlineDescriptor* src, AvbKernelCmdlineDescriptor* dest) { 12 uint64_t expected_size; 13 14 avb_memcpy(dest, src, sizeof(AvbKernelCmdlineDescriptor)); 15 16 if (!avb_descriptor_validate_and_byteswap((const AvbDescriptor*)src, 17 (AvbDescriptor*)dest)) 18 return false; 19 20 if (dest->parent_descriptor.tag != AVB_DESCRIPTOR_TAG_KERNEL_CMDLINE) { 21 avb_error("Invalid tag for kernel cmdline descriptor.\n"); 22 return false; 23 } 24 25 dest->flags = avb_be32toh(dest->flags); 26 dest->kernel_cmdline_length = avb_be32toh(dest->kernel_cmdline_length); 27 28 /* Check that kernel_cmdline is fully contained. */ 29 expected_size = sizeof(AvbKernelCmdlineDescriptor) - sizeof(AvbDescriptor); 30 if (!avb_safe_add_to(&expected_size, dest->kernel_cmdline_length)) { 31 avb_error("Overflow while adding up sizes.\n"); 32 return false; 33 } 34 if (expected_size > dest->parent_descriptor.num_bytes_following) { 35 avb_error("Descriptor payload size overflow.\n"); 36 return false; 37 } 38 39 return true; 40 } 41