aboutsummaryrefslogtreecommitdiff
path: root/core/nvram-format.c
diff options
context:
space:
mode:
authorOliver O'Halloran <oohall@gmail.com>2016-09-28 14:56:29 +1000
committerStewart Smith <stewart@linux.vnet.ibm.com>2016-10-14 16:41:39 +1100
commita18e2809afa0e649224b40bf5b4bbe1d87193a89 (patch)
treebcaeb8408e51479979290a254aec12aef6fc7d6f /core/nvram-format.c
parent5a1da9a008724586433107ad9576c4fa0191307e (diff)
downloadskiboot-a18e2809afa0e649224b40bf5b4bbe1d87193a89.zip
skiboot-a18e2809afa0e649224b40bf5b4bbe1d87193a89.tar.gz
skiboot-a18e2809afa0e649224b40bf5b4bbe1d87193a89.tar.bz2
nvram: force re-verification after writing
The running OS is free to re-write the contents of NVRAM. The skiboot NVRAM parser relies on the NVRAM contents being valid so we need to force the NVRAM contents to be revalidated after the host OS has written to it. 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.c23
1 files changed, 19 insertions, 4 deletions
diff --git a/core/nvram-format.c b/core/nvram-format.c
index 227147e..b98aee1 100644
--- a/core/nvram-format.c
+++ b/core/nvram-format.c
@@ -208,12 +208,27 @@ static const char *find_next_key(const char *start, const char *end)
*/
const char *nvram_query(const char *key)
{
- const char *part_end = (const char *) skiboot_part_hdr +
- skiboot_part_hdr->len * 16 - 1;
- const char *start = (const char *) skiboot_part_hdr +
- sizeof(*skiboot_part_hdr);
+ const char *part_end, *start;
int key_len = strlen(key);
+ /*
+ * The running OS can modify the NVRAM as it pleases so we need to be
+ * a little paranoid and check that it's ok before we try parse it.
+ *
+ * NB: nvram_validate() can update skiboot_part_hdr
+ */
+ if (!nvram_validate()) {
+ prerror("NVRAM: Look up for '%s' failed due to bad format!\n",
+ key);
+ return NULL;
+ }
+
+ part_end = (const char *) skiboot_part_hdr
+ + skiboot_part_hdr->len * 16 - 1;
+
+ start = (const char *) skiboot_part_hdr
+ + sizeof(*skiboot_part_hdr);
+
if (!key_len) {
prlog(PR_WARNING, "NVRAM: search key is empty!\n");
return NULL;