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: <CACSyD1PmGFru7RBPOhSqKDhec6Zf06rkRHvk0os_5LBGFkq2Xw@mail.gmail.com>
Date: Wed, 7 May 2025 11:27:57 +0800
From: Zhongkun He <hezhongkun.hzk@...edance.com>
To: Dan Carpenter <dan.carpenter@...aro.org>
Cc: akpm@...ux-foundation.org, hannes@...xchg.org, mhocko@...e.com, 
	yosry.ahmed@...ux.dev, muchun.song@...ux.dev, yuzhao@...gle.com, 
	linux-mm@...ck.org, linux-kernel@...r.kernel.org
Subject: Re: [External] Re: [PATCH V3 2/3] mm: add max swappiness arg to
 lru_gen for anonymous memory only

On Fri, May 2, 2025 at 2:59 PM Dan Carpenter <dan.carpenter@...aro.org> wrote:
>
> On Thu, May 01, 2025 at 09:56:57AM +0800, Zhongkun He wrote:
> > Hi Dan
> >
> > On Wed, Apr 30, 2025 at 3:59 PM Dan Carpenter <dan.carpenter@...aro.org> wrote:
> > >
> > > On Wed, Apr 09, 2025 at 03:06:19PM +0800, Zhongkun He wrote:
> > > > +             /* set by userspace for anonymous memory only */
> > > > +             if (!strncmp("max", swap_string, sizeof("max"))) {
> > >
> > > This pattern of strncmp("foo", str, sizeof("foo")) is exactly the same
> > > as strcmp().  It doesn't provide any additional security.  The strncmp()
> > > function is meant for matching string prefixes and it's a relatively
> > > common bug to do this:
> > >
> > > intended: if (strcmp(string, "prefix", sizeof("prefix") - 1) == 0) {
> > >   actual: if (strcmp(string, "prefix", sizeof("prefix")) == 0) {
> > >
> >
> > Yes, I understand the difference.
> >
> > > I have a static checker warning for these:
> > > https://lore.kernel.org/all/30210ed77b40b4b6629de659cb56b9ec7832c447.1744452787.git.dan.carpenter@linaro.org/
> > >
> > > If people deliberately misuse the function then it makes it trickier
> > > to tell accidental mistakes from deliberate mistakes.
> > >
> >
> > if (!strncmp("max", swap_string, sizeof("max"))) {
> >
> > The length of swap_string is 5 because it's read using sscanf, which
> > will add the null terminator \0
> > at the end of the string. If we input max into the interface,
> > swap_string will contain max\0, which is
> > equivalent to the string "max". Since we only need to compare the
> > first few characters(There are other
> > possible inputs as well.) — effectively treating it as a prefix match
> > — I used strncmp.
>
> I'm a not sure I understand.  You say you are treating it as a "prefix
> match", but sizeof("max") is 4 so this is not treated as a prefix.  Did
> you mean to write strlen("max") which does not include the NUL
> terminator?
>

Hi Dan,  sorry for the late reply.

I agree with you that we should use strncmp for prefix matches
and I will update it later.

Thanks.

> regards,
> dan carpenter
>
>

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ