All of lore.kernel.org
 help / color / mirror / Atom feed
From: Josselin Poiret <dev@jpoiret.xyz>
To: Daniel Kiper <dkiper@net-space.pl>
Cc: development@efficientek.com,
	Daniel Kiper <daniel.kiper@oracle.com>,
	Patrick Steinhardt <ps@pks.im>, Michael Chang <mchang@suse.com>,
	grub-devel@gnu.org, Josselin Poiret <dev@jpoiret.xyz>
Subject: [PATCH v6 0/2] Have LUKS2 cryptomounts be useable with grub-probe
Date: Fri,  8 Jul 2022 12:06:06 +0200	[thread overview]
Message-ID: <cover.1657273978.git.dev@jpoiret.xyz> (raw)
In-Reply-To: <20220705110951.ouqnpcfl5q7d5gy7@tomti.i.net-space.pl>

Hello Daniel,

Thanks for the review.  The following updated patches should contain all the changes you asked for.

>Please add your Signed-off-by here. Same applies to first patch too.
Done.

> Please format comments, here and below, properly [1].
Sorry about that, I missed the empty first line. Fixed.

> This function may fail. Please check the returned value and fail if needed.
> [...]
> Ditto.
Fixed (I've used grub_util_error for all the unrecoverable errors, I
hope that's ok).

>> +              name = dm_tree_node_get_name (node);
> I think same applies here...
Right, it can be "", so added a check and comment about the error mode.

> s/0/NULL/ Please use NULL instead of 0 for pointers. Same below...
Done.

> grub_strndup() may fail. Please check if cipher != NULL.
Right, sorry.  Fixed.

> seek_head = grub_memchr (c, ' ', remaining);
> if (seek_head == NULL)
Done in both places.

> Again, grub_strndup() may fail. In general please do not ignore errors
> from functions which may fail.
Done as above.

Josselin Poiret (2):
  devmapper/getroot: Have devmapper recognize LUKS2
  devmapper/getroot: Set up cheated LUKS2 cryptodisk mount from DM
    parameters

 grub-core/osdep/devmapper/getroot.c | 118 ++++++++++++++++++++++++++--
 1 file changed, 113 insertions(+), 5 deletions(-)

Range-diff against v5:
1:  7af629fca = 1:  f4cbda414 devmapper/getroot: Have devmapper recognize LUKS2
2:  5f9f26118 ! 2:  25ce8bbcc devmapper/getroot: Set up cheated LUKS2 cryptodisk mount from DM parameters
    @@ grub-core/osdep/devmapper/getroot.c: grub_util_pull_devmapper (const char *os_de
      			     lastsubdev, grub_errmsg);
     +          if (strncmp (uuid, "CRYPT-LUKS2-", sizeof ("CRYPT-LUKS2-") - 1) == 0)
     +            {
    -+              /* set LUKS2 cipher from dm parameters, since it is not
    ++              /*
    ++               * set LUKS2 cipher from dm parameters, since it is not
     +               * possible to determine the correct one without
     +               * unlocking, as there might be multiple segments.
     +               */
    @@ grub-core/osdep/devmapper/getroot.c: grub_util_pull_devmapper (const char *os_de
     +              unsigned int remaining;
     +
     +              source = grub_disk_open (grdev);
    ++              if (! source)
    ++                grub_util_error (_("cannot open grub disk `%s'"), grdev);
     +              cryptodisk = grub_cryptodisk_get_by_source_disk (source);
    ++              if (! cryptodisk)
    ++                grub_util_error (_("cannot get cryptodisk from source disk `%s'"), grdev);
     +              grub_disk_close (source);
     +
    ++              /*
    ++               * the following function always returns a non-NULL pointer,
    ++               * but the string may be empty if the relevant info is not present
    ++               */
     +              name = dm_tree_node_get_name (node);
    ++              if (grub_strlen (name) == 0)
    ++                grub_util_error (_("cannot get dm node name for grub dev `%s'"), grdev);
     +
     +              grub_util_info ("populating parameters of cryptomount `%s' from DM device `%s'",
     +                              uuid, name);
     +
     +              dmt = dm_task_create (DM_DEVICE_TABLE);
    -+              if (dmt == 0)
    ++              if (dmt == NULL)
     +                grub_util_error (_("can't create dm task DM_DEVICE_TABLE"));
     +              if (dm_task_set_name (dmt, name) == 0)
     +                grub_util_error (_("can't set dm task name to `%s'"), name);
     +              if (dm_task_run (dmt) == 0)
     +                grub_util_error (_("can't run dm task for `%s'"), name);
    -+              /* dm_get_next_target doesn't have any error modes, everything has
    ++              /*
    ++               * dm_get_next_target doesn't have any error modes, everything has
     +               * been handled by dm_task_run.
     +               */
     +              dm_get_next_target (dmt, NULL, &start, &length,
     +                                  &target_type, &params);
     +              if (strncmp (target_type, "crypt", sizeof ("crypt")) != 0)
    -+                grub_util_error (_("dm target of type `%s' is not `crypt'"),
    -+                                 target_type);
    ++                grub_util_error (_("dm target of type `%s' is not `crypt'"), target_type);
     +
    -+              /* dm target parameters for dm-crypt is
    ++              /*
    ++               * dm target parameters for dm-crypt is
     +               * <cipher> <key> <iv_offset> <device path> <offset> [<#opt_params> <opt_param1> ...]
     +               */
     +              c = params;
     +              remaining = grub_strlen (c);
     +
     +              /* first, get the cipher name from the cipher */
    -+              if (!(seek_head = grub_memchr (c, '-', remaining)))
    ++              seek_head = grub_memchr (c, '-', remaining);
    ++              if (seek_head == NULL)
     +                grub_util_error (_("can't get cipher from dm-crypt parameters `%s'"),
     +                                 params);
     +              cipher = grub_strndup (c, seek_head - c);
    ++              if (cipher == NULL)
    ++                grub_util_error (_("could not strndup cipher of length `%lu'"), seek_head - c);
     +              remaining -= seek_head - c + 1;
     +              c = seek_head + 1;
     +
     +              /* now, the cipher mode */
    -+              if (!(seek_head = grub_memchr (c, ' ', remaining)))
    ++              seek_head = grub_memchr (c, ' ', remaining);
    ++              if (seek_head == NULL)
     +                grub_util_error (_("can't get cipher mode from dm-crypt parameters `%s'"),
     +                                 params);
     +              cipher_mode = grub_strndup (c, seek_head - c);
    ++              if (cipher_mode == NULL)
    ++                grub_util_error (_("could not strndup cipher_mode of length `%lu'"), seek_head - c);
    ++
     +              remaining -= seek_head - c + 1;
     +              c = seek_head + 1;
     +
    @@ grub-core/osdep/devmapper/getroot.c: grub_util_pull_devmapper (const char *os_de
     +              grub_free (cipher);
     +              grub_free (cipher_mode);
     +
    -+              /* This is the only hash usable by PBKDF2, and we don't
    ++              /*
    ++               * This is the only hash usable by PBKDF2, and we don't
     +               * have Argon2 support yet, so set it by default,
     +               * otherwise grub-probe would miss the required
     +               * abstraction
     +               */
     +              cryptodisk->hash = grub_crypto_lookup_md_by_name ("sha256");
    -+              if (cryptodisk->hash == 0)
    ++              if (cryptodisk->hash == NULL)
     +                  grub_util_error (_("can't lookup hash sha256 by name"));
     +
     +              dm_task_destroy (dmt);

base-commit: 351c9c2fd0bcd94c7fda5b697d3283f7f0ff7930
-- 
2.36.1



  reply	other threads:[~2022-07-08 10:06 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-09 17:38 [PATCH 0/2] Have LUKS2 cryptomounts be useable with grub-probe Josselin Poiret
2021-12-09 17:38 ` [PATCH 1/2] devmapper/getroot: Have devmapper recognize LUKS2 Josselin Poiret
2021-12-09 17:38 ` [PATCH 2/2] devmapper/getroot: Set up cheated LUKS2 cryptodisk mount from DM parameters Josselin Poiret
2021-12-09 20:15 ` [PATCH 0/2] Have LUKS2 cryptomounts be useable with grub-probe Glenn Washburn
2021-12-11 12:29   ` [PATCH v2 " Josselin Poiret
2021-12-11 12:29     ` [PATCH v2 1/2] devmapper/getroot: Have devmapper recognize LUKS2 Josselin Poiret
2022-05-12 22:25       ` Glenn Washburn
2021-12-11 12:29     ` [PATCH v2 2/2] devmapper/getroot: Set up cheated LUKS2 cryptodisk mount from DM parameters Josselin Poiret
2022-05-12 22:38       ` Glenn Washburn
2022-05-20 18:20         ` [PATCH v3 0/2] Have LUKS2 cryptomounts be useable with grub-probe Josselin Poiret
2022-05-20 18:20           ` [PATCH v3 1/2] devmapper/getroot: Have devmapper recognize LUKS2 Josselin Poiret
2022-05-20 18:20           ` [PATCH v3 2/2] devmapper/getroot: Set up cheated LUKS2 cryptodisk mount from DM parameters Josselin Poiret
2022-05-21  0:20             ` Glenn Washburn
2022-05-21  9:27               ` Josselin Poiret
2022-06-14 13:47               ` [PATCH v4 0/2] Have LUKS2 cryptomounts be useable with grub-probe Josselin Poiret
2022-06-14 13:47                 ` [PATCH v4 1/2] devmapper/getroot: Have devmapper recognize LUKS2 Josselin Poiret
2022-06-14 13:47                 ` [PATCH v4 2/2] devmapper/getroot: Set up cheated LUKS2 cryptodisk mount from DM parameters Josselin Poiret
2022-06-14 18:28                   ` Glenn Washburn
2022-06-15  3:52                   ` Michael Chang
2022-06-14 18:31                 ` [PATCH v4 0/2] Have LUKS2 cryptomounts be useable with grub-probe Glenn Washburn
2022-06-15 10:01                   ` [PATCH v5 " Josselin Poiret
2022-06-15 10:02                     ` [PATCH v5 1/2] devmapper/getroot: Have devmapper recognize LUKS2 Josselin Poiret
2022-06-15 10:02                     ` [PATCH v5 2/2] devmapper/getroot: Set up cheated LUKS2 cryptodisk mount from DM parameters Josselin Poiret
2022-07-05 11:09                       ` Daniel Kiper
2022-07-08 10:06                         ` Josselin Poiret [this message]
2022-07-08 10:06                           ` [PATCH v6 1/2] devmapper/getroot: Have devmapper recognize LUKS2 Josselin Poiret
2022-07-08 10:06                           ` [PATCH v6 2/2] devmapper/getroot: Set up cheated LUKS2 cryptodisk mount from DM parameters Josselin Poiret
2022-11-08 15:07                             ` Fabian Vogt
2022-08-11 18:18                           ` [PATCH v6 0/2] Have LUKS2 cryptomounts be useable with grub-probe Glenn Washburn
2022-05-12 22:20     ` [PATCH v2 " Glenn Washburn
2022-05-13 11:58       ` Fabian Vogt

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=cover.1657273978.git.dev@jpoiret.xyz \
    --to=dev@jpoiret.xyz \
    --cc=daniel.kiper@oracle.com \
    --cc=development@efficientek.com \
    --cc=dkiper@net-space.pl \
    --cc=grub-devel@gnu.org \
    --cc=mchang@suse.com \
    --cc=ps@pks.im \
    /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.