[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <DM5PR11MB13241141BB4C863F1A01D958C1529@DM5PR11MB1324.namprd11.prod.outlook.com>
Date: Mon, 26 Sep 2022 15:49:02 +0000
From: "Ruhl, Michael J" <michael.j.ruhl@...el.com>
To: Kees Cook <keescook@...omium.org>, Vlastimil Babka <vbabka@...e.cz>
CC: "Brandeburg, Jesse" <jesse.brandeburg@...el.com>,
"Nguyen, Anthony L" <anthony.l.nguyen@...el.com>,
"David S. Miller" <davem@...emloft.net>,
"Eric Dumazet" <edumazet@...gle.com>,
Jakub Kicinski <kuba@...nel.org>,
Paolo Abeni <pabeni@...hat.com>,
"intel-wired-lan@...ts.osuosl.org" <intel-wired-lan@...ts.osuosl.org>,
"netdev@...r.kernel.org" <netdev@...r.kernel.org>,
Hyeonggon Yoo <42.hyeyoo@...il.com>,
"Christoph Lameter" <cl@...ux.com>,
Pekka Enberg <penberg@...nel.org>,
David Rientjes <rientjes@...gle.com>,
Joonsoo Kim <iamjoonsoo.kim@....com>,
Andrew Morton <akpm@...ux-foundation.org>,
Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
Nick Desaulniers <ndesaulniers@...gle.com>,
Alex Elder <elder@...nel.org>,
Josef Bacik <josef@...icpanda.com>,
David Sterba <dsterba@...e.com>,
"Sumit Semwal" <sumit.semwal@...aro.org>,
Christian König <christian.koenig@....com>,
Daniel Micay <danielmicay@...il.com>,
"Yonghong Song" <yhs@...com>, Marco Elver <elver@...gle.com>,
Miguel Ojeda <ojeda@...nel.org>,
"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
"linux-mm@...ck.org" <linux-mm@...ck.org>,
"linux-btrfs@...r.kernel.org" <linux-btrfs@...r.kernel.org>,
"linux-media@...r.kernel.org" <linux-media@...r.kernel.org>,
"dri-devel@...ts.freedesktop.org" <dri-devel@...ts.freedesktop.org>,
"linaro-mm-sig@...ts.linaro.org" <linaro-mm-sig@...ts.linaro.org>,
"linux-fsdevel@...r.kernel.org" <linux-fsdevel@...r.kernel.org>,
"dev@...nvswitch.org" <dev@...nvswitch.org>,
"x86@...nel.org" <x86@...nel.org>,
"llvm@...ts.linux.dev" <llvm@...ts.linux.dev>,
"linux-hardening@...r.kernel.org" <linux-hardening@...r.kernel.org>
Subject: RE: [PATCH v2 06/16] igb: Proactively round up to kmalloc bucket size
>-----Original Message-----
>From: Kees Cook <keescook@...omium.org>
>Sent: Friday, September 23, 2022 4:28 PM
>To: Vlastimil Babka <vbabka@...e.cz>
>Cc: Kees Cook <keescook@...omium.org>; Brandeburg, Jesse
><jesse.brandeburg@...el.com>; Nguyen, Anthony L
><anthony.l.nguyen@...el.com>; David S. Miller <davem@...emloft.net>;
>Eric Dumazet <edumazet@...gle.com>; Jakub Kicinski <kuba@...nel.org>;
>Paolo Abeni <pabeni@...hat.com>; intel-wired-lan@...ts.osuosl.org;
>netdev@...r.kernel.org; Ruhl, Michael J <michael.j.ruhl@...el.com>;
>Hyeonggon Yoo <42.hyeyoo@...il.com>; Christoph Lameter
><cl@...ux.com>; Pekka Enberg <penberg@...nel.org>; David Rientjes
><rientjes@...gle.com>; Joonsoo Kim <iamjoonsoo.kim@....com>; Andrew
>Morton <akpm@...ux-foundation.org>; Greg Kroah-Hartman
><gregkh@...uxfoundation.org>; Nick Desaulniers
><ndesaulniers@...gle.com>; Alex Elder <elder@...nel.org>; Josef Bacik
><josef@...icpanda.com>; David Sterba <dsterba@...e.com>; Sumit Semwal
><sumit.semwal@...aro.org>; Christian König <christian.koenig@....com>;
>Daniel Micay <danielmicay@...il.com>; Yonghong Song <yhs@...com>;
>Marco Elver <elver@...gle.com>; Miguel Ojeda <ojeda@...nel.org>; linux-
>kernel@...r.kernel.org; linux-mm@...ck.org; linux-btrfs@...r.kernel.org;
>linux-media@...r.kernel.org; dri-devel@...ts.freedesktop.org; linaro-mm-
>sig@...ts.linaro.org; linux-fsdevel@...r.kernel.org; dev@...nvswitch.org;
>x86@...nel.org; llvm@...ts.linux.dev; linux-hardening@...r.kernel.org
>Subject: [PATCH v2 06/16] igb: Proactively round up to kmalloc bucket size
>
>In preparation for removing the "silently change allocation size"
>users of ksize(), explicitly round up all q_vector allocations so that
>allocations can be correctly compared to ksize().
>
>Additionally fix potential use-after-free in the case of new allocation
>failure: only free memory if the replacement allocation succeeds.
>
>Cc: Jesse Brandeburg <jesse.brandeburg@...el.com>
>Cc: Tony Nguyen <anthony.l.nguyen@...el.com>
>Cc: "David S. Miller" <davem@...emloft.net>
>Cc: Eric Dumazet <edumazet@...gle.com>
>Cc: Jakub Kicinski <kuba@...nel.org>
>Cc: Paolo Abeni <pabeni@...hat.com>
>Cc: intel-wired-lan@...ts.osuosl.org
>Cc: netdev@...r.kernel.org
>Signed-off-by: Kees Cook <keescook@...omium.org>
>---
> drivers/net/ethernet/intel/igb/igb_main.c | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
>
>diff --git a/drivers/net/ethernet/intel/igb/igb_main.c
>b/drivers/net/ethernet/intel/igb/igb_main.c
>index 2796e81d2726..eb51e531c096 100644
>--- a/drivers/net/ethernet/intel/igb/igb_main.c
>+++ b/drivers/net/ethernet/intel/igb/igb_main.c
>@@ -1195,15 +1195,16 @@ static int igb_alloc_q_vector(struct igb_adapter
>*adapter,
> return -ENOMEM;
>
> ring_count = txr_count + rxr_count;
>- size = struct_size(q_vector, ring, ring_count);
>+ size = kmalloc_size_roundup(struct_size(q_vector, ring, ring_count));
This looks good to me...
> /* allocate q_vector and rings */
> q_vector = adapter->q_vector[v_idx];
> 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);
>+ if (q_vector)
>+ kfree_rcu(q_vector, rcu);
Even though this is in the ksize part, this seems like an unrelated change?
Should this be in a different patch?
Also, the kfree_rcu will free q_vector after the RCU grace period?
Is that what you want to do?
How does rcu distinguish between the original q_vector, and the newly kzalloced one?
Thanks,
Mike
> } else {
> memset(q_vector, 0, size);
> }
>--
>2.34.1
Powered by blists - more mailing lists