mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jiri Slaby <jslaby@suse.cz>
To: stable@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, Peter Jones <pjones@redhat.com>,
	Matt Fleming <matt@codeblueprint.co.uk>,
	Jiri Slaby <jslaby@suse.cz>
Subject: [PATCH 3.12 47/58] efi: Do variable name validation tests in utf8
Date: Wed, 16 Mar 2016 11:59:32 +0100	[thread overview]
Message-ID: <9b73e95fe04b78c8d507c4e193cfe30bd9f1f1fc.1458125909.git.jslaby@suse.cz> (raw)
In-Reply-To: <377b71e18f20d69b0df301ce7040554f40ba9651.1458125909.git.jslaby@suse.cz>
In-Reply-To: <cover.1458121137.git.jslaby@suse.cz>

From: Peter Jones <pjones@redhat.com>

3.12-stable review patch.  If anyone has any objections, please let me know.

===============

commit 3dcb1f55dfc7631695e69df4a0d589ce5274bd07 upstream.

Actually translate from ucs2 to utf8 before doing the test, and then
test against our other utf8 data, instead of fudging it.

Signed-off-by: Peter Jones <pjones@redhat.com>
Acked-by: Matthew Garrett <mjg59@coreos.com>
Tested-by: Lee, Chun-Yi <jlee@suse.com>
Signed-off-by: Matt Fleming <matt@codeblueprint.co.uk>
Signed-off-by: Jiri Slaby <jslaby@suse.cz>
---
 drivers/firmware/efi/efivars.c |  4 +--
 drivers/firmware/efi/vars.c    | 58 +++++++++++++++++++++++++-----------------
 include/linux/efi.h            |  6 +++--
 3 files changed, 40 insertions(+), 28 deletions(-)

diff --git a/drivers/firmware/efi/efivars.c b/drivers/firmware/efi/efivars.c
index 0d33f42de731..b4d5eeb78ffd 100644
--- a/drivers/firmware/efi/efivars.c
+++ b/drivers/firmware/efi/efivars.c
@@ -219,7 +219,7 @@ efivar_store_raw(struct efivar_entry *entry, const char *buf, size_t count)
 	}
 
 	if ((new_var->Attributes & ~EFI_VARIABLE_MASK) != 0 ||
-	    efivar_validate(new_var, new_var->Data, new_var->DataSize) == false) {
+	    efivar_validate(new_var->VariableName, new_var->Data, new_var->DataSize) == false) {
 		printk(KERN_ERR "efivars: Malformed variable content\n");
 		return -EINVAL;
 	}
@@ -334,7 +334,7 @@ static ssize_t efivar_create(struct file *filp, struct kobject *kobj,
 		return -EACCES;
 
 	if ((new_var->Attributes & ~EFI_VARIABLE_MASK) != 0 ||
-	    efivar_validate(new_var, new_var->Data, new_var->DataSize) == false) {
+	    efivar_validate(new_var->VariableName, new_var->Data, new_var->DataSize) == false) {
 		printk(KERN_ERR "efivars: Malformed variable content\n");
 		return -EINVAL;
 	}
diff --git a/drivers/firmware/efi/vars.c b/drivers/firmware/efi/vars.c
index e6125522860a..aad48b99553f 100644
--- a/drivers/firmware/efi/vars.c
+++ b/drivers/firmware/efi/vars.c
@@ -42,7 +42,7 @@ DECLARE_WORK(efivar_work, NULL);
 EXPORT_SYMBOL_GPL(efivar_work);
 
 static bool
-validate_device_path(struct efi_variable *var, int match, u8 *buffer,
+validate_device_path(efi_char16_t *var_name, int match, u8 *buffer,
 		     unsigned long len)
 {
 	struct efi_generic_dev_path *node;
@@ -75,7 +75,7 @@ validate_device_path(struct efi_variable *var, int match, u8 *buffer,
 }
 
 static bool
-validate_boot_order(struct efi_variable *var, int match, u8 *buffer,
+validate_boot_order(efi_char16_t *var_name, int match, u8 *buffer,
 		    unsigned long len)
 {
 	/* An array of 16-bit integers */
@@ -86,18 +86,18 @@ validate_boot_order(struct efi_variable *var, int match, u8 *buffer,
 }
 
 static bool
-validate_load_option(struct efi_variable *var, int match, u8 *buffer,
+validate_load_option(efi_char16_t *var_name, int match, u8 *buffer,
 		     unsigned long len)
 {
 	u16 filepathlength;
 	int i, desclength = 0, namelen;
 
-	namelen = ucs2_strnlen(var->VariableName, sizeof(var->VariableName));
+	namelen = ucs2_strnlen(var_name, EFI_VAR_NAME_LEN);
 
 	/* Either "Boot" or "Driver" followed by four digits of hex */
 	for (i = match; i < match+4; i++) {
-		if (var->VariableName[i] > 127 ||
-		    hex_to_bin(var->VariableName[i] & 0xff) < 0)
+		if (var_name[i] > 127 ||
+		    hex_to_bin(var_name[i] & 0xff) < 0)
 			return true;
 	}
 
@@ -132,12 +132,12 @@ validate_load_option(struct efi_variable *var, int match, u8 *buffer,
 	/*
 	 * And, finally, check the filepath
 	 */
-	return validate_device_path(var, match, buffer + desclength + 6,
+	return validate_device_path(var_name, match, buffer + desclength + 6,
 				    filepathlength);
 }
 
 static bool
-validate_uint16(struct efi_variable *var, int match, u8 *buffer,
+validate_uint16(efi_char16_t *var_name, int match, u8 *buffer,
 		unsigned long len)
 {
 	/* A single 16-bit integer */
@@ -148,7 +148,7 @@ validate_uint16(struct efi_variable *var, int match, u8 *buffer,
 }
 
 static bool
-validate_ascii_string(struct efi_variable *var, int match, u8 *buffer,
+validate_ascii_string(efi_char16_t *var_name, int match, u8 *buffer,
 		      unsigned long len)
 {
 	int i;
@@ -166,7 +166,7 @@ validate_ascii_string(struct efi_variable *var, int match, u8 *buffer,
 
 struct variable_validate {
 	char *name;
-	bool (*validate)(struct efi_variable *var, int match, u8 *data,
+	bool (*validate)(efi_char16_t *var_name, int match, u8 *data,
 			 unsigned long len);
 };
 
@@ -189,10 +189,19 @@ static const struct variable_validate variable_validate[] = {
 };
 
 bool
-efivar_validate(struct efi_variable *var, u8 *data, unsigned long len)
+efivar_validate(efi_char16_t *var_name, u8 *data, unsigned long data_size)
 {
 	int i;
-	u16 *unicode_name = var->VariableName;
+	unsigned long utf8_size;
+	u8 *utf8_name;
+
+	utf8_size = ucs2_utf8size(var_name);
+	utf8_name = kmalloc(utf8_size + 1, GFP_KERNEL);
+	if (!utf8_name)
+		return false;
+
+	ucs2_as_utf8(utf8_name, var_name, utf8_size);
+	utf8_name[utf8_size] = '\0';
 
 	for (i = 0; variable_validate[i].validate != NULL; i++) {
 		const char *name = variable_validate[i].name;
@@ -200,28 +209,29 @@ efivar_validate(struct efi_variable *var, u8 *data, unsigned long len)
 
 		for (match = 0; ; match++) {
 			char c = name[match];
-			u16 u = unicode_name[match];
-
-			/* All special variables are plain ascii */
-			if (u > 127)
-				return true;
+			char u = utf8_name[match];
 
 			/* Wildcard in the matching name means we've matched */
-			if (c == '*')
-				return variable_validate[i].validate(var,
-							     match, data, len);
+			if (c == '*') {
+				kfree(utf8_name);
+				return variable_validate[i].validate(var_name,
+							match, data, data_size);
+			}
 
 			/* Case sensitive match */
 			if (c != u)
 				break;
 
 			/* Reached the end of the string while matching */
-			if (!c)
-				return variable_validate[i].validate(var,
-							     match, data, len);
+			if (!c) {
+				kfree(utf8_name);
+				return variable_validate[i].validate(var_name,
+							match, data, data_size);
+			}
 		}
 	}
 
+	kfree(utf8_name);
 	return true;
 }
 EXPORT_SYMBOL_GPL(efivar_validate);
@@ -805,7 +815,7 @@ int efivar_entry_set_get_size(struct efivar_entry *entry, u32 attributes,
 
 	*set = false;
 
-	if (efivar_validate(&entry->var, data, *size) == false)
+	if (efivar_validate(name, data, *size) == false)
 		return -EINVAL;
 
 	/*
diff --git a/include/linux/efi.h b/include/linux/efi.h
index 094ddd0f5d1c..68a4410fc9e6 100644
--- a/include/linux/efi.h
+++ b/include/linux/efi.h
@@ -769,8 +769,10 @@ struct efivars {
  * and we use a page for reading/writing.
  */
 
+#define EFI_VAR_NAME_LEN	1024
+
 struct efi_variable {
-	efi_char16_t  VariableName[1024/sizeof(efi_char16_t)];
+	efi_char16_t  VariableName[EFI_VAR_NAME_LEN/sizeof(efi_char16_t)];
 	efi_guid_t    VendorGuid;
 	unsigned long DataSize;
 	__u8          Data[1024];
@@ -834,7 +836,7 @@ int efivar_entry_iter(int (*func)(struct efivar_entry *, void *),
 struct efivar_entry *efivar_entry_find(efi_char16_t *name, efi_guid_t guid,
 				       struct list_head *head, bool remove);
 
-bool efivar_validate(struct efi_variable *var, u8 *data, unsigned long len);
+bool efivar_validate(efi_char16_t *var_name, u8 *data, unsigned long len);
 
 extern struct work_struct efivar_work;
 void efivar_run_worker(void);
-- 
2.7.3

  parent reply	other threads:[~2016-03-16 11:04 UTC|newest]

Thread overview: 68+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-16 10:58 [PATCH 3.12 00/58] 3.12.57-stable review Jiri Slaby
2016-03-16 10:58 ` [PATCH 3.12 01/58] nfsd: fix problem with setting ACL on directories Jiri Slaby
2016-03-16 12:24   ` Sergio Gelato
2016-03-18  6:29     ` NeilBrown
2016-03-16 10:58 ` [PATCH 3.12 02/58] unix: properly account for FDs passed over unix sockets Jiri Slaby
2016-03-16 10:58 ` [PATCH 3.12 03/58] unix: correctly track in-flight fds in sending process user_struct Jiri Slaby
2016-03-16 10:58 ` [PATCH 3.12 04/58] USB: cp210x: flush device queues at close Jiri Slaby
2016-03-16 10:58 ` [PATCH 3.12 05/58] USB: cp210x: relocate private data from USB interface to port Jiri Slaby
2016-03-16 10:58 ` [PATCH 3.12 06/58] USB: cp210x: work around cp2108 GET_LINE_CTL bug Jiri Slaby
2016-03-16 10:58 ` [PATCH 3.12 07/58] [media] usbvision fix overflow of interfaces array Jiri Slaby
2016-03-16 10:58 ` [PATCH 3.12 08/58] usb: Add connected retry on resume for non SS devices Jiri Slaby
2016-03-16 10:58 ` [PATCH 3.12 09/58] ixgbe: use correct FCoE DDP max check Jiri Slaby
2016-03-16 10:58 ` [PATCH 3.12 10/58] ixgbe: fix broken PFC with X550 Jiri Slaby
2016-03-16 10:58 ` [PATCH 3.12 11/58] genksyms: Handle string literals with spaces in reference files Jiri Slaby
2016-03-16 10:58 ` [PATCH 3.12 12/58] cifs: fix out-of-bounds access in lease parsing Jiri Slaby
2016-03-16 10:58 ` [PATCH 3.12 13/58] CIFS: Fix SMB2+ interim response processing for read requests Jiri Slaby
2016-03-16 10:58 ` [PATCH 3.12 14/58] iommu/amd: Fix boot warning when device 00:00.0 is not iommu covered Jiri Slaby
2016-03-16 10:59 ` [PATCH 3.12 15/58] x86/entry/compat: Add missing CLAC to entry_INT80_32 Jiri Slaby
2016-03-16 10:59 ` [PATCH 3.12 16/58] drm/ast: Fix incorrect register check for DRAM width Jiri Slaby
2016-03-16 10:59 ` [PATCH 3.12 17/58] libata: fix HDIO_GET_32BIT ioctl Jiri Slaby
2016-03-16 10:59 ` [PATCH 3.12 18/58] libata: Align ata_device's id on a cacheline Jiri Slaby
2016-03-16 10:59 ` [PATCH 3.12 19/58] PM / sleep / x86: Fix crash on graph trace through x86 suspend Jiri Slaby
2016-03-16 10:59 ` [PATCH 3.12 20/58] Revert "jffs2: Fix lock acquisition order bug in jffs2_write_begin" Jiri Slaby
2016-03-16 10:59 ` [PATCH 3.12 21/58] jffs2: Fix page lock / f->sem deadlock Jiri Slaby
2016-03-16 10:59 ` [PATCH 3.12 22/58] Fix directory hardlinks from deleted directories Jiri Slaby
2016-03-16 10:59 ` [PATCH 3.12 23/58] ALSA: ctl: Fix ioctls for X32 ABI Jiri Slaby
2016-03-16 10:59 ` [PATCH 3.12 24/58] ALSA: rawmidi: Fix ioctls " Jiri Slaby
2016-03-16 10:59 ` [PATCH 3.12 25/58] ALSA: timer: Fix ioctls for " Jiri Slaby
2016-03-16 10:59 ` [PATCH 3.12 26/58] ALSA: seq: oss: Don't drain at closing a client Jiri Slaby
2016-03-16 10:59 ` [PATCH 3.12 27/58] ALSA: hdspm: Fix wrong boolean ctl value accesses Jiri Slaby
2016-03-16 10:59 ` [PATCH 3.12 28/58] ALSA: hdsp: " Jiri Slaby
2016-03-16 10:59 ` [PATCH 3.12 29/58] ALSA: hdspm: Fix zero-division Jiri Slaby
2016-03-16 10:59 ` [PATCH 3.12 30/58] ALSA: timer: Fix broken compat timer user status ioctl Jiri Slaby
2016-03-16 10:59 ` [PATCH 3.12 31/58] USB: cp210x: Add ID for Parrot NMEA GPS Flight Recorder Jiri Slaby
2016-03-16 10:59 ` [PATCH 3.12 32/58] USB: serial: option: add support for Telit LE922 PID 0x1045 Jiri Slaby
2016-03-16 10:59 ` [PATCH 3.12 33/58] USB: serial: option: add support for Quectel UC20 Jiri Slaby
2016-03-16 10:59 ` [PATCH 3.12 34/58] MIPS: traps: Fix SIGFPE information leak from `do_ov' and `do_trap_or_bp' Jiri Slaby
2016-03-16 10:59 ` [PATCH 3.12 35/58] ubi: Fix out of bounds write in volume update code Jiri Slaby
2016-03-16 10:59 ` [PATCH 3.12 36/58] Revert "drm/radeon: hold reference to fences in radeon_sa_bo_new" Jiri Slaby
2016-03-16 19:41   ` Nicolai Hähnle
2016-03-16 10:59 ` [PATCH 3.12 37/58] KVM: VMX: disable PEBS before a guest entry Jiri Slaby
2016-03-16 10:59 ` [PATCH 3.12 38/58] tracing: Fix check for cpu online when event is disabled Jiri Slaby
2016-03-16 10:59 ` [PATCH 3.12 39/58] ASoC: wm8994: Fix enum ctl accesses in a wrong type Jiri Slaby
2016-03-16 10:59 ` [PATCH 3.12 40/58] ASoC: wm8958: " Jiri Slaby
2016-03-16 10:59 ` [PATCH 3.12 41/58] wext: fix message delay/ordering Jiri Slaby
2016-03-16 10:59 ` [PATCH 3.12 42/58] mac80211: minstrel_ht: set default tx aggregation timeout to 0 Jiri Slaby
2016-03-16 10:59 ` [PATCH 3.12 43/58] powerpc: Fix dedotify for binutils >= 2.26 Jiri Slaby
2016-03-16 10:59 ` [PATCH 3.12 44/58] KVM: x86: move steal time initialization to vcpu entry time Jiri Slaby
2016-03-16 10:59 ` [PATCH 3.12 45/58] lib/ucs2_string: Add ucs2 -> utf8 helper functions Jiri Slaby
2016-03-16 10:59 ` [PATCH 3.12 46/58] efi: Use ucs2_as_utf8 in efivarfs instead of open coding a bad version Jiri Slaby
2016-03-16 10:59 ` Jiri Slaby [this message]
2016-03-16 10:59 ` [PATCH 3.12 48/58] efi: Make our variable validation list include the guid Jiri Slaby
2016-03-16 10:59 ` [PATCH 3.12 49/58] efi: Make efivarfs entries immutable by default Jiri Slaby
2016-03-16 10:59 ` [PATCH 3.12 50/58] efi: Add pstore variables to the deletion whitelist Jiri Slaby
2016-03-16 10:59 ` [PATCH 3.12 51/58] lib/ucs2_string: Correct ucs2 -> utf8 conversion Jiri Slaby
2016-03-16 10:59 ` [PATCH 3.12 52/58] modules: fix longstanding /proc/kallsyms vs module insertion race Jiri Slaby
2016-03-16 10:59 ` [PATCH 3.12 53/58] xen/pciback: Return error on XEN_PCI_OP_enable_msi when device has MSI or MSI-X enabled Jiri Slaby
2016-03-16 10:59 ` [PATCH 3.12 54/58] xen/pciback: Return error on XEN_PCI_OP_enable_msix " Jiri Slaby
2016-03-16 10:59 ` [PATCH 3.12 55/58] xen/pciback: Do not install an IRQ handler for MSI interrupts Jiri Slaby
2016-03-16 10:59 ` [PATCH 3.12 56/58] xen/pciback: For XEN_PCI_OP_disable_msi[|x] only disable if device has MSI(X) enabled Jiri Slaby
2016-03-16 10:59 ` [PATCH 3.12 57/58] xen/pciback: Don't allow MSI-X ops if PCI_COMMAND_MEMORY is not set Jiri Slaby
2016-03-16 10:59 ` [PATCH 3.12 58/58] xen/pciback: Check PF instead of VF for PCI_COMMAND_MEMORY Jiri Slaby
2016-03-16 15:41 ` [PATCH 3.12 00/58] 3.12.57-stable review Shuah Khan
2016-03-18  8:21   ` Jiri Slaby
2016-03-16 17:58 ` Guenter Roeck
2016-03-16 18:16   ` Jiri Slaby
2016-03-17  3:23     ` Guenter Roeck
2016-03-18  8:21       ` Jiri Slaby

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=9b73e95fe04b78c8d507c4e193cfe30bd9f1f1fc.1458125909.git.jslaby@suse.cz \
    --to=jslaby@suse.cz \
    --cc=linux-kernel@vger.kernel.org \
    --cc=matt@codeblueprint.co.uk \
    --cc=pjones@redhat.com \
    --cc=stable@vger.kernel.org \
    /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

all inboxes | Powered by JetHome®