public inbox for linux-hardening@vger.kernel.org
 help / color / mirror / Atom feed
From: "Gustavo A. R. Silva" <gustavo@embeddedor.com>
To: Rosen Penev <rosenp@gmail.com>, Alex Williamson <alex@shazbot.org>
Cc: kvm@vger.kernel.org, Kees Cook <kees@kernel.org>,
	"Gustavo A. R. Silva" <gustavoars@kernel.org>,
	open list <linux-kernel@vger.kernel.org>,
	open "list:KERNEL" HARDENING "(not" covered by other
	"areas):Keyword:b__counted_by(_le|_be)?b"
	<linux-hardening@vger.kernel.org>,
	Leon Romanovsky <leon@kernel.org>
Subject: Re: [PATCH] vfio: pci: use kzalloc_flex
Date: Mon, 30 Mar 2026 17:46:09 -0600	[thread overview]
Message-ID: <37378f49-437f-438b-ad6c-d60480feb306@embeddedor.com> (raw)
In-Reply-To: <CAKxU2N8rpaLXXsD7sUvw3ffMe8JUREGc9ru_HX0r4Uw4RT_q1g@mail.gmail.com>



On 3/30/26 17:24, Rosen Penev wrote:
> On Mon, Mar 30, 2026 at 4:16 PM Alex Williamson <alex@shazbot.org> wrote:
>>
>> [Cc +Leon]
>>
>> On Wed, 25 Mar 2026 19:37:47 -0700
>> Rosen Penev <rosenp@gmail.com> wrote:
>>
>>> Simplify allocation by using a flexible array member and kzalloc_flex.
>>> Less memory management needed.
>>>
>>> Use __counted_by for extra runtime analysis. Move assignment to after
>>> allocation as required by __counted_by.
>>
>> I don't understand this statement, nr_ranges was previously set after
>> the allocation of phys_vec.  The only reordering was relative to
>> setting vdev, but that appears arbitrary.
> Yes that one. My understanding is __counted_by mandates immediate
> assignment after allocation. Otherwise UBSAN complains.

Not true. However, it's best practice.

The requirement is that the _counter_ must be initialized before
the first reference to the flexible-array member.

-Gustavo

  reply	other threads:[~2026-03-30 23:47 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-26  2:37 [PATCH] vfio: pci: use kzalloc_flex Rosen Penev
2026-03-30 22:19 ` Alex Williamson
2026-03-30 23:24   ` Rosen Penev
2026-03-30 23:46     ` Gustavo A. R. Silva [this message]
2026-03-31  0:18       ` Rosen Penev
2026-03-31  0:51         ` Gustavo A. R. Silva
2026-03-31  0:23     ` Alex Williamson
2026-03-31  5:11       ` Leon Romanovsky

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=37378f49-437f-438b-ad6c-d60480feb306@embeddedor.com \
    --to=gustavo@embeddedor.com \
    --cc=alex@shazbot.org \
    --cc=gustavoars@kernel.org \
    --cc=kees@kernel.org \
    --cc=kvm@vger.kernel.org \
    --cc=leon@kernel.org \
    --cc=linux-hardening@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rosenp@gmail.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