diff options
author | Oliver O'Halloran <oohall@gmail.com> | 2016-08-17 15:32:49 +1000 |
---|---|---|
committer | Stewart Smith <stewart@linux.vnet.ibm.com> | 2016-08-30 16:59:47 +1000 |
commit | 6024e93adf62fab2fb725e9e98fd853b57a35bc4 (patch) | |
tree | cc4a95173ddbc1b655a9535acb3e5a75d89adf57 /core/nvram-format.c | |
parent | ad461cc7a45ac2f8ed6f2c6373545d402e936502 (diff) | |
download | blackbird-skiboot-6024e93adf62fab2fb725e9e98fd853b57a35bc4.tar.gz blackbird-skiboot-6024e93adf62fab2fb725e9e98fd853b57a35bc4.zip |
nvram: ibm,skiboot NUL terminator check
NVRAM configuration strings are required to be NUL terminated and unused
data bytes in the partition should be set to NUL. Badly behaved system
software may not do this so same sanity checking is required. Ensuring
that the final data byte in a partition is a NUL should be sufficient.
Signed-off-by: Oliver O'Halloran <oohall@gmail.com>
Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
Diffstat (limited to 'core/nvram-format.c')
-rw-r--r-- | core/nvram-format.c | 27 |
1 files changed, 22 insertions, 5 deletions
diff --git a/core/nvram-format.c b/core/nvram-format.c index a81663ce..5d15a60f 100644 --- a/core/nvram-format.c +++ b/core/nvram-format.c @@ -28,6 +28,8 @@ struct chrp_nvram_hdr { char name[12]; }; +struct chrp_nvram_hdr *skiboot_part_hdr; + #define NVRAM_SIG_FW_PRIV 0x51 #define NVRAM_SIG_SYSTEM 0x70 #define NVRAM_SIG_FREE 0x7f @@ -115,7 +117,8 @@ int nvram_check(void *nvram_image, const uint32_t nvram_size) { unsigned int offset = 0; bool found_common = false; - bool found_skiboot = false; + + skiboot_part_hdr = NULL; while (offset + sizeof(struct chrp_nvram_hdr) < nvram_size) { struct chrp_nvram_hdr *h = nvram_image + offset; @@ -138,7 +141,7 @@ int nvram_check(void *nvram_image, const uint32_t nvram_size) if (h->sig == NVRAM_SIG_FW_PRIV && strcmp(h->name, NVRAM_NAME_FW_PRIV) == 0) - found_skiboot = true; + skiboot_part_hdr = h; offset += h->len << 4; if (offset > nvram_size) { @@ -151,10 +154,24 @@ int nvram_check(void *nvram_image, const uint32_t nvram_size) prerror("NVRAM: Common partition not found !\n"); goto failed; } - if (!found_skiboot) { - prerror("NVRAM: Skiboot private partition " - "not found !\n"); + + if (!skiboot_part_hdr) { + prerror("NVRAM: Skiboot private partition not found !\n"); goto failed; + } else { + /* + * The OF NVRAM format requires config strings to be NUL + * terminated and unused memory to be set to zero. Well behaved + * software should ensure this is done for us, but we should + * always check. + */ + const char *last_byte = (const char *) skiboot_part_hdr + + skiboot_part_hdr->len * 16 - 1; + + if (*last_byte != 0) { + prerror("NVRAM: Skiboot private partition is not NUL terminated"); + goto failed; + } } prlog(PR_INFO, "NVRAM: Layout appears sane\n"); |