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: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <87le5o9ed9.fsf@intel.com>
Date: Mon, 08 Apr 2024 16:24:18 +0300
From: Jani Nikula <jani.nikula@...el.com>
To: Michal Wajdeczko <michal.wajdeczko@...el.com>, Kees Cook
 <keescook@...omium.org>
Cc: linux-kernel@...r.kernel.org, Andy Shevchenko
 <andriy.shevchenko@...ux.intel.com>, Alexey Dobriyan <adobriyan@...il.com>
Subject: Re: [PATCH 1/2] wordpart.h: Helpers for making u16/u32/u64 values

On Tue, 26 Mar 2024, Michal Wajdeczko <michal.wajdeczko@...el.com> wrote:
> On 15.02.2024 23:47, Kees Cook wrote:
>> On Thu, Feb 15, 2024 at 09:40:40PM +0100, Michal Wajdeczko wrote:
>>> On 14.02.2024 23:09, Kees Cook wrote:
>>>> On Wed, Feb 14, 2024 at 10:46:53PM +0100, Michal Wajdeczko wrote:
>>>>> It is quite common practice to make u16, u32 or u64 values from
>>>>> smaller words.  Add simple helpers for that.
>>>>>
>>>>> Signed-off-by: Michal Wajdeczko <michal.wajdeczko@...el.com>
>>>>> ---
>>>>> v2: new macro names due to conflict with crypto/aria.h
>>>>>     explicit cast and truncation everywhere (Alexey)
>>>>>     moved to wordpart.h (Andy)
>>>>> ---
>>>>> Cc: Kees Cook <keescook@...omium.org>
>>>>> Cc: Andy Shevchenko <andriy.shevchenko@...ux.intel.com>
>>>>> Cc: Alexey Dobriyan <adobriyan@...il.com>
>>>>> Cc: Jani Nikula <jani.nikula@...el.com>
>>>>> ---
>>>>>  include/linux/wordpart.h | 32 ++++++++++++++++++++++++++++++++
>>>>>  1 file changed, 32 insertions(+)
>>>>>
>>>>> diff --git a/include/linux/wordpart.h b/include/linux/wordpart.h
>>>>> index f6f8f83b15b0..8c75a5355112 100644
>>>>> --- a/include/linux/wordpart.h
>>>>> +++ b/include/linux/wordpart.h
>>>>> @@ -31,6 +31,38 @@
>>>>>   */
>>>>>  #define lower_16_bits(n) ((u16)((n) & 0xffff))
>>>>>  
>>>>> +/**
>>>>> + * make_u16_from_u8 - make u16 value from two u8 values
>>>>> + * @hi: value representing upper 8 bits
>>>>> + * @lo: value representing lower 8 bits
>>>>> + */
>>>>> +#define make_u16_from_u8(hi, lo) ((u16)((u16)(u8)(hi) << 8 | (u8)(lo)))
>>>>
>>>> Do we want to actually do type validation here? Right now it's just
>>>> cast/truncating, which based on the version log is by design. Is silent
>>>> truncation the right thing to do?

Doesn't the name imply strongly enough that we're only interested in the
N bits from each parameter? I think not truncating makes these harder to
use (if it means e.g. casting on the caller side).

>>>
>>> note that even FIELD_PREP() is doing silent truncation and these macros
>>> here could be treated as specialized/simplified variants of FIELD_PREP()
>>> as alternate implementation can look like:
>> 
>> Also, isn't all of this endian-specific?

None of this assumes endianness.

> endianness shouldn't matter here
>
> so I guess the only question now is whether we want to have simple
> direct macros like lower|upper_bits() or go with macros build on top of
> the FIELD_PREP_CONST() or drop the idea completely and force the drivers
> to invent the wheel on its own

Yeah, please let's do this so we don't have to keep adding them to
drivers.

BR,
Jani.


-- 
Jani Nikula, Intel

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ