mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Nikolai Merinov <n.merinov@inango-systems.com>
To: hch <hch@infradead.org>
Cc: Davidlohr Bueso <dave@stgolabs.net>, Jens Axboe <axboe@kernel.dk>,
	Ard Biesheuvel <ardb@kernel.org>,
	linux-efi <linux-efi@vger.kernel.org>,
	linux-block <linux-block@vger.kernel.org>,
	linux-kernel <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v3] partitions/efi: Fix partition name parsing in GUID partition entry
Date: Mon, 24 Feb 2020 13:38:39 +0200 (IST)	[thread overview]
Message-ID: <797777312.1324734.1582544319435.JavaMail.zimbra@inango-systems.com> (raw)
In-Reply-To: <20200218185336.GA14242@infradead.org>

[-- Attachment #1: Type: text/plain, Size: 549 bytes --]

Hi Christoph, 

> I'd rather use plain __le16 and le16_to_cpu here. Also the be 
> variants seems to be entirely unused. 

Looks like I misunderstood your comment from https://patchwork.kernel.org/patch/11309223/: 

> Please add a an efi_char_from_cpu or similarly named helper 
> to encapsulate this logic. 

The "le16_to_cpu(ptes[i].partition_name[label_count])" call is the 
full implementation of the "efi_char_from_cpu" logic. Do you want 
to encapsulate "utf16_le_to_7bit_string" logic entirely like in
the attached version?

Regards,
Nikolai

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: v4-0001-partitions-efi-Fix-partition-name-parsing-in-GUID.patch --]
[-- Type: text/x-patch; name=v4-0001-partitions-efi-Fix-partition-name-parsing-in-GUID.patch, Size: 3292 bytes --]

From 842cf22d6f6f91872bcb04ac6abe7794fede23fd Mon Sep 17 00:00:00 2001
From: Nikolai Merinov <n.merinov@inango-systems.com>
Date: Sat, 24 Nov 2018 20:42:27 +0500
Subject: [PATCH v4] partitions/efi: Fix partition name parsing in GUID
 partition entry

GUID partition entry defined to have a partition name as 36 UTF-16LE
code units. This means that on big-endian platforms ASCII symbols
would be read with 0xXX00 efi_char16_t character code. In order to
correctly extract ASCII characters from a partition name field we
should be converted from 16LE to CPU architecture.

The problem exists on all big endian platforms.

Signed-off-by: Nikolai Merinov <n.merinov@inango-systems.com>
Fixes: eec7ecfede74 ("genhd, efi: add efi partition metadata to hd_structs")
---
 block/partitions/efi.c | 35 ++++++++++++++++++++++++++---------
 block/partitions/efi.h |  2 +-
 2 files changed, 27 insertions(+), 10 deletions(-)

diff --git a/block/partitions/efi.c b/block/partitions/efi.c
index db2fef7dfc47..d26a0654d7ca 100644
--- a/block/partitions/efi.c
+++ b/block/partitions/efi.c
@@ -656,6 +656,30 @@ static int find_valid_gpt(struct parsed_partitions *state, gpt_header **gpt,
         return 0;
 }
 
+/**
+ * utf16_le_to_7bit(): Naively converts UTF-16LE string to 7bit characters
+ * @in: input UTF-16LE string
+ * @size: size of the input string
+ * @out: output string ptr, should be capable to store @size+1 characters
+ *
+ * Description: Converts @size UTF16-LE symbols from @in string to 7bit
+ * characters and store them to @out. Adds trailing zero to @out array.
+ */
+static void utf16_le_to_7bit(const __le16 *in, unsigned int size, u8 *out)
+{
+	unsigned int i = 0;
+
+	out[size] = 0;
+	while (i < size) {
+		u8 c = le16_to_cpu(in[i]) & 0xff;
+
+		if (c && !isprint(c))
+			c = '!';
+		out[i] = c;
+		i++;
+	}
+}
+
 /**
  * efi_partition(struct parsed_partitions *state)
  * @state: disk parsed partitions
@@ -692,7 +716,6 @@ int efi_partition(struct parsed_partitions *state)
 
 	for (i = 0; i < le32_to_cpu(gpt->num_partition_entries) && i < state->limit-1; i++) {
 		struct partition_meta_info *info;
-		unsigned label_count = 0;
 		unsigned label_max;
 		u64 start = le64_to_cpu(ptes[i].starting_lba);
 		u64 size = le64_to_cpu(ptes[i].ending_lba) -
@@ -713,14 +736,8 @@ int efi_partition(struct parsed_partitions *state)
 		/* Naively convert UTF16-LE to 7 bits. */
 		label_max = min(ARRAY_SIZE(info->volname) - 1,
 				ARRAY_SIZE(ptes[i].partition_name));
-		info->volname[label_max] = 0;
-		while (label_count < label_max) {
-			u8 c = ptes[i].partition_name[label_count] & 0xff;
-			if (c && !isprint(c))
-				c = '!';
-			info->volname[label_count] = c;
-			label_count++;
-		}
+		utf16_le_to_7bit(ptes[i].partition_name, label_max,
+				 info->volname);
 		state->parts[i + 1].has_info = true;
 	}
 	kfree(ptes);
diff --git a/block/partitions/efi.h b/block/partitions/efi.h
index 3e8576157575..0b6d5b7be111 100644
--- a/block/partitions/efi.h
+++ b/block/partitions/efi.h
@@ -88,7 +88,7 @@ typedef struct _gpt_entry {
 	__le64 starting_lba;
 	__le64 ending_lba;
 	gpt_entry_attributes attributes;
-	efi_char16_t partition_name[72 / sizeof (efi_char16_t)];
+	__le16 partition_name[72 / sizeof (__le16)];
 } __packed gpt_entry;
 
 typedef struct _gpt_mbr_record {
-- 
2.17.1


  reply	other threads:[~2020-02-24 11:38 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-24 16:21 [PATCH] " Nikolai Merinov
2018-11-25 21:16 ` kbuild test robot
2019-12-24  9:21 ` [PATCH v2] " Nikolai Merinov
2019-12-24  9:51   ` Ard Biesheuvel
2020-01-08 13:39   ` Christoph Hellwig
2020-01-13 10:27     ` [PATCH v3] " Nikolai Merinov
2020-02-18 13:34       ` Nikolai Merinov
2020-02-18 18:53       ` Christoph Hellwig
2020-02-24 11:38         ` Nikolai Merinov [this message]
2020-02-24 17:08           ` hch
2020-03-06  8:43             ` Nikolai Merinov
2020-03-06  9:25               ` Ard Biesheuvel
2020-03-06 10:14                 ` Ard Biesheuvel

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=797777312.1324734.1582544319435.JavaMail.zimbra@inango-systems.com \
    --to=n.merinov@inango-systems.com \
    --cc=ardb@kernel.org \
    --cc=axboe@kernel.dk \
    --cc=dave@stgolabs.net \
    --cc=hch@infradead.org \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-efi@vger.kernel.org \
    --cc=linux-kernel@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

Powered by JetHome