Posts
4835
Following
322
Followers
492
Linux kernel hacker and maintainer etc.

OpenPGP: 3AB05486C7752FE1

Jarkko Sakkinen

Edited 26 days ago

awesome “cast” version of tpm_enum!:

tpm_enum_cast! {
    name: TpmRcBaseCast,
    repr: TpmUint32,
    value_enum: TpmRcBaseEnumCast,
    value_repr: u32,
    variants: {
        (Success, 0x0000, "TPM_RC_SUCCESS"),
        (BadTag, 0x001E, "TPM_RC_BAD_TAG"),
        (Initialize, TPM_RC_VER1, "TPM_RC_INITIALIZE"),
        (Failure, TPM_RC_VER1 | 0x001, "TPM_RC_FAILURE"),
 // ...
0
0
0

Jarkko Sakkinen

I think zerocopy semantics goes to the level of implementation that using 3rd party crate like Google's "zerocopy" is essentially a PoC quality solution.

I could implement e.g. tpm2-protocol by using that as dependency but never could reach optimal results for the underlying data.
0
0
0

Jarkko Sakkinen

Edited 27 days ago

Cast version TPM structures starts to shape:

use crate::{tpm_struct_cast, TpmUint32, TpmUint64, TpmUint8};

tpm_struct_cast! {
    name: TpmsClockInfoCast,
    field_enum: TpmsClockInfoField,
    field_ref_enum: TpmsClockInfoFieldRef,
    fields: {
        (pub clock: TpmUint64<'a>),
        (pub reset_count: TpmUint32<'a>),
        (pub restart_count: TpmUint32<'a>),
        (pub safe: TpmUint8<'a>),
    }
}

And after migration is completed:

use crate::{tpm_struct_cast, TpmUint32, TpmUint64, TpmUint8};

tpm_struct! {
    name: TpmsClockInfo,
    field_enum: TpmsClockInfoField,
    field_ref_enum: TpmsClockInfoFieldRef,
    fields: {
        (pub clock: TpmUint64<'a>),
        (pub reset_count: TpmUint32<'a>),
        (pub restart_count: TpmUint32<'a>),
        (pub safe: TpmUint8<'a>),
    }
}
1
0
0

Jarkko Sakkinen

If you are C programmer and hate Rust, I'd give a shot on binary protocols. It's really objectively where Rust shines as you can easily go down to single bit level in granularity. I could never have implemented tpm2-protocol in C or even C++, it's simply out of the territory. This project has been for me like "OK, I can cope with this" type of project.
1
0
1

Jarkko Sakkinen

making sense of shit now definitely:

https://git.kernel.org/pub/scm/linux/kernel/git/jarkko/tpm2-protocol.git/commit/?id=a0f2b3b7f70f6d1151a85c1fadaac5f181e09d91

I'm just learning Rust while doing, really discovered Deref and DerefMut while doing this transformation.
1
0
0

Jarkko Sakkinen

My favorite filesystems:

1. Ext4
2. FAT (and its various upgrades)

There's no operating system that could not read them I'm aware of.

Within last 20 years I've never had a situation where I'm in trouble because my machine does not have "advanced filesystem" :-) And basing backup strategy to local snapshots, well good luck with that. I have NAS.
2
0
0

Jarkko Sakkinen

does any of the ext4 crates for rust *initialize* a partition? I don't care of being able to read or write it, only "mkfs" part is interesting.
1
0
0

Jarkko Sakkinen

no SIZE constant anymore in the new TpmSized as no stack allocation is required:

/// Provides a `dyn`-safe way to get the exact size of a zero-copy cast object.
pub trait TpmSizedCast {
    /// Returns the exact serialized size of the object.
    fn len(&self) -> usize;

    /// Returns `true` if the object has a serialized length of zero.
    fn is_empty(&self) -> bool {
        self.len() == 0
    }
}

This ought to be renamed as TpmSized as full migration is over :-) Applies also to all other *Cast.

0
0
0

Jarkko Sakkinen

from nothing to something type of commit considering zerocopy semantics:

https://git.kernel.org/pub/scm/linux/kernel/git/jarkko/tpm2-protocol.git/commit/?id=28664f46cdcf2c5527d0c3e409a292dad2501bba

now it will be downhill :-)

#linux #rust #tpm
1
0
0

Jarkko Sakkinen

i've finally found my preference for command line arguments in rust: argh. it's like "between the extremes". does not get in the way but neither does "overdo"
0
0
0

Jarkko Sakkinen

i created an experimental "slice and compose" style disk image builder just to build appropriate EFI bootable disk images for kernel testing. i might release this at some point once it "productizes"
0
0
1

Jarkko Sakkinen

Even tho still only "compile-tested" code the from_slice implementation in TpmList and associated iterator is enough evidence that the approach is in fact effective:

https://git.kernel.org/pub/scm/linux/kernel/git/jarkko/tpm2-protocol.git/tree/src/list.rs
1
0
0

Jarkko Sakkinen

In the end of the day this is superior despite adding up a new trick to my sack of random macro hacks:

tpm_integer!(u8, TpmUint8, Unsigned);
tpm_integer!(i8, TpmInt8, Signed);
tpm_integer!(u16, TpmUint16, Unsigned);
tpm_integer!(i32, TpmInt32, Signed);
tpm_integer!(u32, TpmUint32, Unsigned);
tpm_integer!(u64, TpmUint64, Unsigned);

Now the names match TCG specification names, and they are also first fully zerocopy migrated types. This way previously redundant looking field now is actually self-documenting field.

Other zerocopy types will get the nasty “Cast” postfix up until migration is complete (e.g., TpmBufferCast).

For the record, the last field is used to address exactly one quirk related to TCG specs: TPM_CLOCK_TIME, meaning that “invalid discriminant error” needs too versions :-/

I’m sure we would get numbers going from zero to six, and “get this complex science” as e.g., most of have ability to read, and understand nuances such as the difference between slower and faster… This is DailyWTF proximity enough level bad definition that I tend to like that TPM_CLOCK_TIME exist…

1
0
0

Jarkko Sakkinen

Edited 1 month ago

Great now I think I have solid base traits in place i.e., TpmCast, TpmCastMut, TpmHasCast and TpmHasCastMut:

https://git.kernel.org/pub/scm/linux/kernel/git/jarkko/tpm2-protocol.git/commit/?id=815f08de3d7efccd23d9a334cb8f6e8e46e3c9fd

I also relaxed the contribution guidelines just a little bit:

 //! * `alloc` is disallowed.
 //! * Dependencies are disallowed.
 //! * Developer dependencies are disallowed.
-//! * Panics are disallowed.
+//! * Panics are allowed disallowed by default, except concrete type casts in
+//!   `TpmCast::as_slice` is allowed to use `unwrap` as long as
+//!   `TpmCast::from_slice` meets the documented contract.
0
0
0

Jarkko Sakkinen

Edited 1 month ago
In various situations ability model RS-232 link for testing tools that e.g., access FPGA is an asset.

What would be a simple stochastis model that I could apply to my serial link emulator to add "realistic line noise", and don't have climb mountains to implement the algorithm?
0
0
0

Jarkko Sakkinen

Edited 1 month ago
With Rust I find the old (non-neo) vim still the most efficient text editor especially wtih complex macro declarations the static nature of the editor is an advantage.

Modern IDEs feel like ransomware. They completely destroy the screen when there's like one punctation mark missing or something and only thing that auto-complete accomplishes for me is the lost focus on task.

I tried in Sublime Text with Copilot only because Microsoft provides me a free pro license for it and it was even worse than normal autocomplete given it's wrong and fallible suggestions that completely destroy focus. I just wanted to see what it is like and it was piece of shit tbh.

Rust macros are actually a bit like "autocomplete all my objects with traits" type of tool where you write a recipe on how to auto-complete.
0
0
1

Jarkko Sakkinen

still as relevant song as it was in 2014 ;-)

https://www.youtube.com/watch?v=NWxISwEBU0U
0
0
0

Jarkko Sakkinen

Edited 1 month ago
Great landed kickoff commit for casting TPM data to the main branch:

https://git.kernel.org/pub/scm/linux/kernel/git/jarkko/tpm2-protocol.git/commit/?id=03ffb2a9fc5026dbbedd2e1bbdf52bb3cc7dc564

@Dr_Emann, and yep:

- ($ty:ty, $variant:ident) => {
+ ($ty:ident, $variant:ident) => {

EDIT: extended further to lists (and commit ID above updated) as TpmList was a pretty good test case for the trait definition itself. Luckily I had used PhantomData a few times when contributing to Enarx few years ago so I was able to make this stretch :-) Now I have like the baseline for doing zercopy in place.
1
0
0

Jarkko Sakkinen

This starts to “feel right” when it comes to “zerocopy”:

pub trait TpmCast<'a>: Sized {
    fn cast(slice: &'a [u8]) -> TpmResult<Self>;
    fn as_slice(&self) -> &'a [u8];
}

And pretty analogus to pre-existing TpmBuild and TpmParse i.e., they provide clone semantics and this is like hierarchical pointer.

It’s pretty easy to squeeze in because I only really have to edit macros for the most part. I have already basic types, and buffers and lists will follow the same patterns.

0
0
0

Jarkko Sakkinen

Another more fun Rust related activity is figuring out how to nail batch file transfer test planning with emulated serial port that throttles the speed to a target BPS (in future also should have also signal noise emulation):

const ADJECTIVES: &[&str] = &["Quiet", "Loud", "Fast", "Slow", "Bright", "Dark"];
const NOUNS: &[&str] = &["One", "Two", "Three", "Four", "Five,", "Six"];
const EXTENSIONS: &[&str] = &["dat", "BIN", "log", "TMP", "txt"];

struct MockPort<R: Read, W: Write> {
    r: R,
    w: W,
    bits_per_second: u32,
    next_byte_due: Instant,
}

It generates 10 pseudorandom filenames and 100 KiB payloads.

0
0
0
Show older