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] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250113234643.GA3631169-robh@kernel.org>
Date: Mon, 13 Jan 2025 17:46:43 -0600
From: Rob Herring <robh@...nel.org>
To: Zijun Hu <zijun_hu@...oud.com>
Cc: Saravana Kannan <saravanak@...gle.com>,
	Maxime Ripard <mripard@...nel.org>,
	Robin Murphy <robin.murphy@....com>,
	Grant Likely <grant.likely@...retlab.ca>,
	Marc Zyngier <maz@...nel.org>,
	Andreas Herrmann <andreas.herrmann@...xeda.com>,
	Marek Szyprowski <m.szyprowski@...sung.com>,
	Catalin Marinas <catalin.marinas@....com>,
	Mike Rapoport <rppt@...nel.org>,
	Oreoluwa Babatunde <quic_obabatun@...cinc.com>,
	devicetree@...r.kernel.org, linux-kernel@...r.kernel.org,
	Zijun Hu <quic_zijuhu@...cinc.com>
Subject: Re: [PATCH v4 14/14] of: Improve __of_add_property_sysfs()
 readability

On Mon, Jan 13, 2025 at 11:00:12PM +0800, Zijun Hu wrote:
> On 2025/1/11 04:41, Rob Herring wrote:
> >> From: Zijun Hu <quic_zijuhu@...cinc.com>
> >>
> >> __of_add_property_sysfs() hard codes string "security-" length as 9, but
> >> that is not obvious for readers.
> >>
> >> Improve its readability by using strlen().
> > Does the compiler optimize the strlen call away? Maybe, maybe not. If 
> > not, that's N calls to strlen() where N is the number of properties in 
> > your DT. That's in the 1000s easily.
> > 
> > Do you really want to go test enough compiler versions we support to 
> > feel confident this is optimized away. I don't.
> 
> i understand your concern about performance.
> 
> what about below solution ?

See 72921427d46b ("string.h: Add str_has_prefix() helper function"). 

Though we already had strstarts(), but that lacks __always_inline which 
seems is important for eliminating the strlen(). Also, since that 
commit, clang has become more common and need to make sure the same 
optimization happens on it.

> 
>  int __of_add_property_sysfs(struct device_node *np, struct property *pp)
>  {
> +#define SECURITY_PREFIX "security-"
>         int rc;
> 
>         /* Important: Don't leak passwords */
> -       bool secure = strncmp(pp->name, "security-", 9) == 0;
> +       bool secure = strncmp(pp->name, SECURITY_PREFIX,
> sizeof(SECURITY_PREFIX) - 1) == 0;
> 
>         if (!IS_ENABLED(CONFIG_SYSFS))
>                 return 0;
> 
> 
> 

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ