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]
Date: Fri, 9 Feb 2024 21:39:49 +0200
From: Andy Shevchenko <andriy.shevchenko@...ux.intel.com>
To: Abhishek Pandit-Subedi <abhishekpandit@...omium.org>
Cc: Heikki Krogerus <heikki.krogerus@...ux.intel.com>,
	linux-usb@...r.kernel.org, jthies@...gle.com, pmalani@...omium.org,
	Neil Armstrong <neil.armstrong@...aro.org>,
	Dmitry Baryshkov <dmitry.baryshkov@...aro.org>,
	Fabrice Gasnier <fabrice.gasnier@...s.st.com>,
	Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
	Hans de Goede <hdegoede@...hat.com>,
	Rajaram Regupathy <rajaram.regupathy@...el.com>,
	Saranya Gopal <saranya.gopal@...el.com>,
	linux-kernel@...r.kernel.org
Subject: Re: [PATCH v4 1/3] usb: typec: ucsi: Limit read size on v1.2

On Fri, Feb 09, 2024 at 10:01:07AM -0800, Abhishek Pandit-Subedi wrote:
> On Fri, Feb 9, 2024 at 6:28 AM Andy Shevchenko
> <andriy.shevchenko@...ux.intel.com> wrote:
> > On Thu, Feb 08, 2024 at 10:02:38PM -0800, Abhishek Pandit-Subedi wrote:

..

> > > +     if (ucsi->version <= UCSI_VERSION_1_2)
> > > +             buf_size = min_t(size_t, 16, buf_size);
> >
> > Please, avoid using min_t(). Here the clamp() can be used.
> I think this is likely the 4th time I've been tripped up by an
> undocumented practice in this patch series. <linux/minmax.h> says
> nothing about avoiding min_t -- why prefer clamp()?

While in this case it will work correctly, the size_t is unsigned type and 16
is signed, while buf_size is unknown in this context. It means if buf_size is
signed, the min_t gives wrong result. clamp() is better choice.

See also, e.g., https://lore.kernel.org/all/20231004064220.31452-1-biju.das.jz@bp.renesas.com/.

> Please add the
> recommendation here
> (https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/include/linux/minmax.h#n10)
> and I am more than happy to change it after.

It's not my recommendation :-)

https://lore.kernel.org/all/CAHk-=whwEAc22wm8h9FESPB5X+P4bLDgv0erBQMa1buTNQW7tA@mail.gmail.com/

Feel free to submit a patch.

..

> > Shouldn't magic number be defined?
> The comment right above this line documents the number.
> As this is the only use right now, I don't see a need to make it a
> macro/constant yet.

OK.

-- 
With Best Regards,
Andy Shevchenko



Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ