From patchwork Mon Aug 8 02:58:30 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oliver O'Halloran X-Patchwork-Id: 656525 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3s72Dn6ZZXz9sDk for ; Mon, 8 Aug 2016 12:59:05 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b=tZxQ4SIb; dkim-atps=neutral Received: from ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3s72Dn5byMzDqZn for ; Mon, 8 Aug 2016 12:59:05 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b=tZxQ4SIb; dkim-atps=neutral X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Received: from mail-pf0-x242.google.com (mail-pf0-x242.google.com [IPv6:2607:f8b0:400e:c00::242]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 3s72DV4mWxzDqS5 for ; Mon, 8 Aug 2016 12:58:50 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b=tZxQ4SIb; dkim-atps=neutral Received: by mail-pf0-x242.google.com with SMTP id h186so24053158pfg.2 for ; Sun, 07 Aug 2016 19:58:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=q8Ac1Z9zAJCtGNOTmqJR0iFPcoSYabFi6Ih8IoyeVHU=; b=tZxQ4SIbc7w70LDtf1cSwuY/7rvz+PjKb7lu+XmckoKuDIiMbViojOBavyyA70zIfd MG6TXrYzFKErs3ZhvOsdNNGukvP1XRXQJrha5XYEfQgzyeTZJqmQsUoBSKmaSPu885Qu F2gtbbNsg6h2I+fMMxAozpUjRnJYGN/vytlYgKvHKKQLPas36uwruQ0gs1/TJxpavB3e PWObWyonyT1rtrJCCC+d2D1K3iudM6SQrFaJev8/Ms0CWIio2pwyRcwdK2jMm0rsm2Ik 5ldLkeK090G7IJRvTeSGfn09DqlPTpQArei0kexW4/PJPJzjKpMOFK5N/VYQWKMMcoAt 535g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=q8Ac1Z9zAJCtGNOTmqJR0iFPcoSYabFi6Ih8IoyeVHU=; b=RZV6JOQWed3Lk5fpkJE0twaujKvAGb6mnIVL4kIeOjcJiF4hliPpuHqKBfILYkQVS/ Md3sekUpmAjkvczJcMw55JlBg2yv9MM9rQ6g7DAEFto2oFO2vQ+Rlw6cGjFtjWnBqSfB CEjaP4KH+Q9GLdYhxTulrPbi35FjKuVKyOL4H+a18kEHW0gnTPcU3wQiFfutwi8nk94q xRkHi9s4dQN5WQudv+YUFXax3UbRU4guAhRwtkGdMIo0YcSlgYaEsX4qbbIrrSiAIHjA 51YxN+7rOLmCz5UTW8LdRlEAnzyGjrdMqYHxJ5Avhvki+ytNw78CLDgX+rWcqjOvKiKf eltA== X-Gm-Message-State: AEkoouvKtYMAlGCmG4U4IzB/8u2GSkt9Wu6GBZTmg0aSGp+/R6reFTvyHX2TksrTcmcFsg== X-Received: by 10.98.65.139 with SMTP id g11mr159146761pfd.140.1470625128748; Sun, 07 Aug 2016 19:58:48 -0700 (PDT) Received: from canetoad.ozlabs.ibm.com ([122.99.82.10]) by smtp.gmail.com with ESMTPSA id 184sm43374144pfg.20.2016.08.07.19.58.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 07 Aug 2016 19:58:48 -0700 (PDT) From: Oliver O'Halloran To: skiboot@lists.ozlabs.org Date: Mon, 8 Aug 2016 12:58:30 +1000 Message-Id: <1470625113-29275-2-git-send-email-oohall@gmail.com> X-Mailer: git-send-email 2.5.5 In-Reply-To: <1470625113-29275-1-git-send-email-oohall@gmail.com> References: <1470625113-29275-1-git-send-email-oohall@gmail.com> Subject: [Skiboot] [PATCH 2/5] nvram: ibm,skiboot NUL terminator check X-BeenThere: skiboot@lists.ozlabs.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: Mailing list for skiboot development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Skiboot" 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 --- 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");