Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add dm-verity parser from kernel command line #217

Closed
wants to merge 9 commits into from

Conversation

alexmwu
Copy link
Contributor

@alexmwu alexmwu commented Jul 6, 2022

  • Add DmVerityState.
    • DmVerityState will contain the attested dm-verity hash algorithms, root
      digests, and salts required for validating a dm-verity mounted device
      (e.g., root fs).
  • Add parseArgs and nextArg translated from kernel source

This is currently limited to the syntax of the ChromeOS, non-upstreamed fork of dm-verity. It can currently only parse out one dm-verity hash.

alexmwu added 9 commits June 30, 2022 17:45
We will use this message to parse the command line passed from the
bootloader.
This supports reading the kernel cmdline from all of the GRUB commands.
DmVerityState will contain the attested dm-verity hash algorithms, root
digests, and salts required for validating a dm-verity mounted device
(e.g., root fs).
This uses much of what the kernel does for a cmdline string, except it
does not actually parse the args into kernel_param structs. Rather,
parseArgs returns a map of param strings to val strings.

parseArg uses nextArg, which should copy the exact behavior of the
kernel in
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/lib/cmdline.c.
The server package now supports reading the kernel command line and
parsing it, using the same parsing logic as the kernel. This
functionality currently only supports parsing a single root hash;
multiple dm entries will cause undefined behavior.
@alexmwu alexmwu mentioned this pull request Jul 6, 2022
// nextArgs must receive a null-terminated string.
if len(commandline) == 0 || commandline[len(commandline)-1] != 0 {
args = make([]byte, len(commandline)+1)
args[len(args)-1] = 0
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from @jkl73:
Can directly append() a 0 at the end? args = append(args, byte(0))

seen = true
cmdline = command[suffixAt:]

verity, err = tryGetDmVerityStateFromCmdline(parseArgs(cmdBytes))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from @jkl73 in #144:
Instead of parsing both kernel cmdline and dmverity stuff in the same function, can they be done in two separate functions? I fell like it can make things more clear.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kernel.commandline, err = getKernelCMDFromGRUB...
kernel.verity, err = getDmVerityFromGRUB...

@alexmwu alexmwu closed this Sep 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant