Thread (11 messages) 11 messages, 3 authors, 2022-11-02

RE: [PATCH v3 2/2] igb: Proactively round up to kmalloc bucket size

From: Ruhl, Michael J <hidden>
Date: 2022-11-02 14:22:21
Also in: intel-wired-lan, linux-hardening, lkml

-----Original Message-----
From: Kees Cook <redacted>
Sent: Tuesday, November 1, 2022 5:37 PM
To: Ruhl, Michael J <redacted>
Cc: Brandeburg, Jesse <redacted>; Nguyen, Anthony L
[off-list ref]; David S. Miller [off-list ref];
Eric Dumazet [off-list ref]; Jakub Kicinski [off-list ref];
Paolo Abeni [off-list ref]; intel-wired-lan@lists.osuosl.org;
netdev@vger.kernel.org; linux-kernel@vger.kernel.org; linux-
hardening@vger.kernel.org
Subject: Re: [PATCH v3 2/2] igb: Proactively round up to kmalloc bucket size

On Mon, Oct 31, 2022 at 08:42:36PM +0000, Ruhl, Michael J wrote:
quoted
Looking at the size usage (from elixir), I see:

--
	if (!q_vector) {
		q_vector = kzalloc(size, GFP_KERNEL);
	} else if (size > ksize(q_vector)) {
		kfree_rcu(q_vector, rcu);
		q_vector = kzalloc(size, GFP_KERNEL);
	} else {
		memset(q_vector, 0, size);
	}
--

If the size is rounded up, will the (size > ksize()) check ever be true?

I.e. have you eliminated this check (and maybe getting rid of the need for
first patch?)?

Hi!

It looked like igb_alloc_q_vector() was designed to be called multiple
times on the same q_vector (i.e. to grow its allocation size over time).
So for that case, yes, the "size > ksize(q_vector)" check is needed. If
it's only ever called once (which is hard for me to tell), then no. (And
if "no", why was the alloc/free case even there in the first place?)
Ahh, Ok, I missed the fact that size is based on ring_count.  When I saw
the "struct_size" I assumed that size would be the same every time and
missed this point.

So can vary over time, and this ksize check is needed.

With that in mind these patches look good to me.

Reviewed-by: Michael J. Ruhl <redacted>

Mike
-Kees

--
Kees Cook
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help