mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: George Kennedy <george.kennedy@oracle.com>
To: Greg KH <gregkh@linuxfoundation.org>
Cc: jejb@linux.ibm.com, martin.petersen@oracle.com,
	linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org,
	dan.carpenter@oracle.com
Subject: Re: [PATCH] scsi: scsi_debug: fix return checks for kcalloc
Date: Thu, 4 Nov 2021 11:21:36 -0400	[thread overview]
Message-ID: <5a8772c3-7999-4675-59fe-c20ee2d66510@oracle.com> (raw)
In-Reply-To: <YYN81hZyBZ2dU3Wu@kroah.com>



On 11/4/2021 2:25 AM, Greg KH wrote:
> On Wed, Nov 03, 2021 at 02:01:42PM -0500, George Kennedy wrote:
>> Change return checks from kcalloc() to now check for NULL and
>> ZERO_SIZE_PTR using the ZERO_OR_NULL_PTR macro or the following
>> crash can occur if ZERO_SIZE_PTR indicator is returned.
> That seems really broken in the api, why is kcalloc() returning
> ZERO_SIZE_PTR?
See Dan Carpenter's explanation.

kcalloc() purposely returns ZERO_SIZE_PTR if its size arg is zero.

See commit: 6cb8f91320d3e720351c21741da795fed580b21b

>
> Please fix that, otherwise you need to fix all callers in the kernel
> tree.

Here are the kcalloc() args:
/**
  * kcalloc - allocate memory for an array. The memory is set to zero.
  * @n: number of elements.
  * @size: element size.
  * @flags: the type of memory to allocate (see kmalloc).
  */
static inline void *kcalloc(size_t n, size_t size, gfp_t flags)

Any call to kcalloc() where the size arg (the 2nd arg) can possibly be 
zero needs to check for ZERO_SIZE_PTR being returned along with checking 
for NULL being returned, which the ZERO_OR_NULL_PTR macro does.

In most cases throughout the kernel the calls to kcalloc() are with the 
size arg set to a sizeof some data structure, so ZERO_SIZE_PTR will not 
be returned and a following check for NULL being returned is all that is 
needed.

Thank you,
George

>
> thanks,
>
> greg k-h


  reply	other threads:[~2021-11-04 15:21 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-03 19:01 George Kennedy
2021-11-04  6:25 ` Greg KH
2021-11-04 15:21   ` George Kennedy [this message]
2021-11-04 10:47 ` Dan Carpenter
2021-11-04 16:04 ` Joe Perches
2021-11-04 17:22   ` George Kennedy
2021-11-04 17:50 ` Douglas Gilbert

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5a8772c3-7999-4675-59fe-c20ee2d66510@oracle.com \
    --to=george.kennedy@oracle.com \
    --cc=dan.carpenter@oracle.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=jejb@linux.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®