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: <1d2e9f40-708d-49b2-b0ee-a1d775f6fd23@icloud.com>
Date: Tue, 8 Apr 2025 19:34:41 +0800
From: Zijun Hu <zijun_hu@...oud.com>
To: Kees Cook <kees@...nel.org>
Cc: Andy Shevchenko <andy@...nel.org>,
 Andrew Morton <akpm@...ux-foundation.org>, linux-hardening@...r.kernel.org,
 linux-kernel@...r.kernel.org, Zijun Hu <quic_zijuhu@...cinc.com>,
 "Rob Herring (Arm)" <robh@...nel.org>
Subject: Re: [PATCH 1/2] lib/string: Improve strstarts() performance

On 2025/4/8 00:17, Kees Cook wrote:
>> strstarts() is frequently invoked to test if a string has another string
>> as prefix, but its performance is degraded by the strlen() loop contained.
>>
>> Improve its performance by eliminating the strlen() loop.
> So, as Andy already said: no, this is very unlikely to be a performance
> improvement, and if it is, you'll need to show the numbers (and likely
> the reason _why_, in the form of assembly output, etc).
> 

agree.

> The reason this isn't going to be an improvement is because
> strlen($string_constant) is optimized by the compiler into a integral
> constant value. So you'd be replacing a potentially inline constant with

will confirm if strlen() within strstarts() is compile-time constant.

> an explicit function call. That will be much more expensive.

strstarts() has a strncmp() function call as well even if it is inline

> 
> With almost 300 users:
> $ git grep 'strstarts' | wc -l
> 198
> 
> Only 38 are _not_ using a string constant:
> $ git grep 'strstarts' | grep -v '"' | wc -l
> 38
> 
> Additionally, there is no "loop". strlen() of a runtime string would be
> evaluated once.
> 

strlen() contains a loop which has strlen() char comparisons

> -Kees


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ