All of lore.kernel.org
 help / color / mirror / Atom feed
From: Christoph Hellwig <hch@infradead.org>
To: Nikolai Merinov <n.merinov@inango-systems.com>
Cc: hch@infradead.org, Davidlohr Bueso <dave@stgolabs.net>,
	Jens Axboe <axboe@kernel.dk>, Ard Biesheuvel <ardb@kernel.org>,
	linux-efi@vger.kernel.org, linux-block@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3] partitions/efi: Fix partition name parsing in GUID partition entry
Date: Tue, 18 Feb 2020 10:53:36 -0800	[thread overview]
Message-ID: <20200218185336.GA14242@infradead.org> (raw)
In-Reply-To: <26f7bd89f212f68b03a4b207e96d8702c9049015.1578910723.git.n.merinov@inango-systems.com>

On Mon, Jan 13, 2020 at 03:27:23PM +0500, Nikolai Merinov wrote:
> 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>
> ---
>  block/partitions/efi.c | 3 ++-
>  block/partitions/efi.h | 2 +-
>  include/linux/efi.h    | 5 +++++
>  3 files changed, 8 insertions(+), 2 deletions(-)
> 
> diff --git a/block/partitions/efi.c b/block/partitions/efi.c
> index db2fef7dfc47..f1d0820de844 100644
> --- a/block/partitions/efi.c
> +++ b/block/partitions/efi.c
> @@ -715,7 +715,8 @@ int efi_partition(struct parsed_partitions *state)
>  				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;
> +			u8 c = 0xff & efi_char16le_to_cpu(
> +					ptes[i].partition_name[label_count]);

Why are you swapping the order of the comparism to an unusual one here?

> -	efi_char16_t partition_name[72 / sizeof (efi_char16_t)];
> +	efi_char16le_t partition_name[72 / sizeof(efi_char16le_t)];
>  } __packed gpt_entry;
>  
>  typedef struct _gpt_mbr_record {
> diff --git a/include/linux/efi.h b/include/linux/efi.h
> index aa54586db7a5..47882f2d45db 100644
> --- a/include/linux/efi.h
> +++ b/include/linux/efi.h
> @@ -45,9 +45,14 @@
>  typedef unsigned long efi_status_t;
>  typedef u8 efi_bool_t;
>  typedef u16 efi_char16_t;		/* UNICODE character */
> +typedef __le16 efi_char16le_t;		/* UTF16-LE */
> +typedef __be16 efi_char16be_t;		/* UTF16-BE */
>  typedef u64 efi_physical_addr_t;
>  typedef void *efi_handle_t;
>  
> +#define efi_char16le_to_cpu le16_to_cpu
> +#define efi_char16be_to_cpu be16_to_cpu

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

  parent reply	other threads:[~2020-02-18 18:53 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-24 16:21 [PATCH] partitions/efi: Fix partition name parsing in GUID partition entry Nikolai Merinov
2018-11-25 21:16 ` kbuild test robot
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 [this message]
2020-02-24 11:38         ` Nikolai Merinov
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=20200218185336.GA14242@infradead.org \
    --to=hch@infradead.org \
    --cc=ardb@kernel.org \
    --cc=axboe@kernel.dk \
    --cc=dave@stgolabs.net \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-efi@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=n.merinov@inango-systems.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.