[Skiboot] [PATCH 2/5] nvram: ibm,skiboot NUL terminator check

Oliver O'Halloran oohall at gmail.com
Mon Aug 8 12:58:30 AEST 2016


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 sufficent.

Signed-off-by: Oliver O'Halloran <oohall at gmail.com>
---
 core/nvram-format.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/core/nvram-format.c b/core/nvram-format.c
index a81663ceb35f..be8d77f8394b 100644
--- a/core/nvram-format.c
+++ b/core/nvram-format.c
@@ -155,6 +155,20 @@ int nvram_check(void *nvram_image, const uint32_t nvram_size)
 		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 ot zero. Well behaved
+		 * software should ensure this is done for us, but we should
+		 * always check.
+		 */
+		const char *c = (const char *) skiboot_part_hdr +
+			skiboot_part_hdr->len * 16 - 1;
+
+		if (*c != 0) {
+			prerror("NVRAM: Skiboot private partition is not NUL terminated");
+			goto failed;
+		}
 	}
 
 	prlog(PR_INFO, "NVRAM: Layout appears sane\n");
-- 
2.5.5



More information about the Skiboot mailing list