lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CANiq72n0sg_fizEk_kK=p8ROmWTrwdzqu1LD4SQdKUNLbK9ENA@mail.gmail.com>
Date:   Tue, 22 Feb 2022 13:48:16 +0100
From:   Miguel Ojeda <miguel.ojeda.sandonis@...il.com>
To:     Petr Mladek <pmladek@...e.com>
Cc:     Miguel Ojeda <ojeda@...nel.org>,
        Linus Torvalds <torvalds@...ux-foundation.org>,
        Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
        rust-for-linux <rust-for-linux@...r.kernel.org>,
        linux-kernel <linux-kernel@...r.kernel.org>,
        Wedson Almeida Filho <wedsonaf@...gle.com>,
        Alex Gaynor <alex.gaynor@...il.com>,
        Geoffrey Thomas <geofft@...reload.com>,
        Finn Behrens <me@...enk.de>,
        Adam Bratschi-Kaye <ark.email@...il.com>,
        Michael Ellerman <mpe@...erman.id.au>,
        Sumera Priyadarsini <sylphrenadin@...il.com>,
        Sven Van Asbroeck <thesven73@...il.com>,
        Gary Guo <gary@...yguo.net>,
        Boris-Chengbiao Zhou <bobo1239@....de>,
        Boqun Feng <boqun.feng@...il.com>,
        Fox Chen <foxhlchen@...il.com>,
        Dan Robertson <daniel.robertson@...rlab.io>,
        Viktor Garske <viktor@...ar.de>,
        Dariusz Sosnowski <dsosnowski@...snowski.pl>,
        Léo Lanteri Thauvin <leseulartichaut@...il.com>,
        Niklas Mohrin <dev@...lasmohrin.de>,
        Gioh Kim <gurugio@...il.com>, Daniel Xu <dxu@...uu.xyz>,
        Milan Landaverde <milan@...verde.com>,
        Morgan Bartlett <mjmouse9999@...il.com>,
        Maciej Falkowski <m.falkowski@...sung.com>,
        Jiapeng Chong <jiapeng.chong@...ux.alibaba.com>,
        Sergey Senozhatsky <senozhatsky@...omium.org>,
        Steven Rostedt <rostedt@...dmis.org>,
        John Ogness <john.ogness@...utronix.de>
Subject: Re: [PATCH v4 10/20] rust: add `kernel` crate

Hi Petr,

On Tue, Feb 22, 2022 at 10:06 AM Petr Mladek <pmladek@...e.com> wrote:
>
> What exactly should we keep in sync, please?
>
> I see only handling of KERN_* prefix in print.rs. I do not see there
> any counter part of LOG_LINE_MAX, CONSOLE_LOG_MAX, or PREFIX_MAX.

Good catch! We had a buffer on the Rust side in the past, but that is
not the case anymore since commit 9e8bd679ecf2 ("Support Rust
`core::fmt::Argument` in vsprintf") on our side, so we will remove the
comment.

> I am sorry but I am not familiar with rust. What are these limits
> 2 and 10 used for, please?
>
> I guess that 2 is the size of a single KERN_* identifier.
> But what is 10?
>
> Note that printk() format prefix is typically just a single KERN_*
> identifier. But there might be more. Well, in practice only the
> following combination makes sense: KERN_CONT + KERN_<LEVEL>.

What we are doing here is generating compile-time format strings that
are then used by the `pr_*!` macros (which call the C side `printk()`
with one of the strings).

In other words, this is not parsing arbitrary `printk()` format
strings (which I am guessing something like that is your concern --
please let me know if I got it wrong).

To clarify a bit what the code does and what the constants are:

  - `generate()` is called at compile-time.

  - The size of these generated strings is always 10.

  - We compose those strings by using the first 2 bytes of `KERN_*`.
However, we also take the chance to check (at compile-time) they have
the contents we expect, including the third zero byte.

  - Then other 8 bytes are used to complete the 10: either "%pA" plus
0 padding (`CONT` level) or "%s: %pA" (otherwise).

> Finally, is there any way to test whether any change in the printk
> code breaks the rust support?

One way is to compile the code, e.g. the `assert!`s in the `generate`
function run at compile-time, thus they provide a first layer of
defense.

Another way is to use `samples/rust/print.rs` which we run in the CI
as a black box test.

Is that what you had in mind? Or something like unit tests or self tests?

Thanks for taking a look!

Cheers,
Miguel

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ