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: <CAHk-=wgK+PimVukScvVjoqOdOWWG_e+xCurhP_9SvA_+7scYWw@mail.gmail.com>
Date:   Sat, 23 Sep 2023 11:19:08 -0700
From:   Linus Torvalds <torvalds@...ux-foundation.org>
To:     Andy Shevchenko <andriy.shevchenko@...ux.intel.com>
Cc:     brgl@...ev.pl, Linus Walleij <linus.walleij@...aro.org>,
        Kent Gibson <warthog618@...il.com>,
        Alexey Dobriyan <adobriyan@...il.com>,
        Peter Zijlstra <peterz@...radead.org>,
        akpm@...ux-foundation.org, linux-gpio@...r.kernel.org,
        linux-kernel@...r.kernel.org,
        Bartosz Golaszewski <bartosz.golaszewski@...aro.org>
Subject: Re: [PATCH v4] gpio: sim: fix an invalid __free() usage

On Tue, 19 Sept 2023 at 03:49, Andy Shevchenko
<andriy.shevchenko@...ux.intel.com> wrote:
>
> Nope, k*alloc*() returns ZERO or NULL on failure. That's what most developers
> are missing :-)

Absolutely not.

k*alloc() returns NULL on failure. Absolutely nothing else.

On *success*, it can return the special ZERO_SIZE_PTR. But that is
*not* a failure at all. It's very much a successful pointer.

Now, it's a pointer that you can't actually dereference, but that's
very much intentional. You can't dereference it, because you asked for
a zero-sized allocation. You got a zero-sized allocation.

But please never *ever* think it's a failure. It's very much not a
failure case, and it is very much intentional.

It's different from NULL exactly *because* it's successful, and
exactly so that you can write

     ptr = kmalloc(size);
     if (!ptr)
          return -ENOMEM;

without having to worry about the "size is zero" case.

The standard user-space "malloc()" library is misdesigned. Surprise
surprise. The kernel isn't.

                Linus

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ