public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Ivan Gorinov <ivan.gorinov@intel.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH] efi_selftest: check for buffer overflow in efi_get_variable
Date: Thu, 24 May 2018 17:09:25 -0700	[thread overview]
Message-ID: <20180525000925.GA33845@intel.com> (raw)

Check if GetVariable writes past the end of the output data buffer.

Signed-off-by: Ivan Gorinov <ivan.gorinov@intel.com>
---
 lib/efi_selftest/efi_selftest_variables.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/lib/efi_selftest/efi_selftest_variables.c b/lib/efi_selftest/efi_selftest_variables.c
index f5e8eb6..8a02dbc 100644
--- a/lib/efi_selftest/efi_selftest_variables.c
+++ b/lib/efi_selftest/efi_selftest_variables.c
@@ -72,6 +72,22 @@ static int execute(void)
 		efi_st_error("SetVariable failed\n");
 		return EFI_ST_FAILURE;
 	}
+	data[3] = 0xff;
+	len = 3;
+	ret = runtime->get_variable(L"efi_st_var0", &guid_vendor0,
+				    &attr, &len, data);
+	if (ret != EFI_SUCCESS) {
+		efi_st_error("GetVariable failed\n");
+		return EFI_ST_FAILURE;
+	}
+	if (efi_st_memcmp(data, v + 4, 3)) {
+		efi_st_error("GetVariable returned wrong value\n");
+		return EFI_ST_FAILURE;
+	}
+	if (data[3] != 0xff) {
+		efi_st_error("GetVariable wrote past the end of the buffer\n");
+		return EFI_ST_FAILURE;
+	}
 	/* Set variable 1 */
 	ret = runtime->set_variable(L"efi_st_var1", &guid_vendor1,
 				    EFI_VARIABLE_BOOTSERVICE_ACCESS,
-- 
2.7.4

             reply	other threads:[~2018-05-25  0:09 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-25  0:09 Ivan Gorinov [this message]
2018-05-25  5:42 ` [U-Boot] [PATCH] efi_selftest: check for buffer overflow in efi_get_variable Heinrich Schuchardt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180525000925.GA33845@intel.com \
    --to=ivan.gorinov@intel.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox