Received: by 2002:a05:6358:111d:b0:dc:6189:e246 with SMTP id f29csp4207128rwi; Wed, 2 Nov 2022 08:03:34 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5nTvY83FecyTDgJxvuuk8I8o6vWbluGbDzoVOHJ702zY4NRYBAOzkgEdNcVR6f+0fxe9GH X-Received: by 2002:a05:6a00:1941:b0:56c:c987:99c5 with SMTP id s1-20020a056a00194100b0056cc98799c5mr25677929pfk.57.1667401414516; Wed, 02 Nov 2022 08:03:34 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1667401414; cv=pass; d=google.com; s=arc-20160816; b=nicCBY35kmAdhwuKB1/exhiDiVOgMBJOTmn8DjfTyersxT/+iplrFaxXqn4qe9lmot sa58rkq0WxSjVUK/Sao47+9aq3MX7O3CSdbAvVbX1dmpJN0PIDLjcOQTu1UCYKnZcyox +DyRCEBzeUPdVkRlvmGZCdV9jbu8s7JWF04B/osr040bg4WX/saicgImZ43j68iXQHjq Dy/V4JIHDyzdhm2zzJ8oBdG83NZ5u4TmZE1Zk9G7dhVd+b4+JPBmbaOeieWVHfT7SECt o7ac4uH3rEajM1Ekd49LMyRDLvFaRENW4/lG7zAdiUawTzX4Cm6sXZbPUi+PmTzjDpda DQqA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :dlp-version:dlp-reaction:dlp-product:content-language :accept-language:in-reply-to:references:message-id:date:thread-index :thread-topic:subject:cc:to:from:dkim-signature; bh=mib06KMeC8JMgIImcc338NJT7S4nFrlXi4Dl03XcuWg=; b=JW80mekntWvRFAudrmzdPnQz8YMHU4DD18ij6X9RNoQ+oEU5X5BA2BioDJDJ5Xzc8A U+foK+8IN8V9zYALcHBzlYEkaDOLkeJg9lRhsC0k8U2yg5POe8AN3n8eJ5qMKDHuFJoS yiNt59aUGebls/IFW/MJOQkdG58zK/QbNQkamuFVdfTMEk7kAv9fNIRzjCRYj5vkgAeG xUjabDmsDpmYREBT/SSPa0ebsuNjKOE/p6c1yKLfm7RvRrxfHnjqJiOhNXhN4MBUkAq4 pwSoH9gOT4xrNDTW83jfpUYRfrzfpIBAvxhQwcIgQ2TKlmnKH47FopyxPopL2uQaQ7gM Do9g== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=QxLmjb77; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id iz18-20020a170902ef9200b00178b95aa01fsi15170908plb.614.2022.11.02.08.03.16; Wed, 02 Nov 2022 08:03:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=QxLmjb77; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231500AbiKBOWR (ORCPT + 98 others); Wed, 2 Nov 2022 10:22:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49336 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231616AbiKBOVz (ORCPT ); Wed, 2 Nov 2022 10:21:55 -0400 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ADF041F9D3; Wed, 2 Nov 2022 07:21:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1667398911; x=1698934911; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-transfer-encoding:mime-version; bh=retV7GdxqEb0pUxQrkzguKcTO5briOZRQGZ+OOkTEXM=; b=QxLmjb77DeQmg39n28GyPj534PR72/X34LfgOVXrF9QKEhhZ+i+pSgCj U+oncv9DO4VctN9kdsICbp6zuDJ5bim76t0yCdP0VWLazA3BvdAQQ/SST WLIx364R9k8i45LHzqcaXZ8fqawnvp09ba5AfUc9OJ6ytnrb/DPHEurE5 CHhNMYwkNzDk3ZqLxFPmdXIYd224zCIgw4XnCPdAVhlOZkepSqmb3qT8y jO32qpC7Tsj8t7xQD04SsqUNgzyYrUaREB9GOVi5PJdgxT7cPj+J8C1/A VCezASjDFNAju5oL+cJDusAeD6EShM8f3i+I3oqcrIYaE8GWMrOvJWwr3 w==; X-IronPort-AV: E=McAfee;i="6500,9779,10519"; a="308136976" X-IronPort-AV: E=Sophos;i="5.95,234,1661842800"; d="scan'208";a="308136976" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Nov 2022 07:12:36 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10519"; a="703279820" X-IronPort-AV: E=Sophos;i="5.95,234,1661842800"; d="scan'208";a="703279820" Received: from orsmsx602.amr.corp.intel.com ([10.22.229.15]) by fmsmga004.fm.intel.com with ESMTP; 02 Nov 2022 07:12:36 -0700 Received: from orsmsx610.amr.corp.intel.com (10.22.229.23) by ORSMSX602.amr.corp.intel.com (10.22.229.15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Wed, 2 Nov 2022 07:12:35 -0700 Received: from ORSEDG601.ED.cps.intel.com (10.7.248.6) by orsmsx610.amr.corp.intel.com (10.22.229.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31 via Frontend Transport; Wed, 2 Nov 2022 07:12:35 -0700 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (104.47.57.168) by edgegateway.intel.com (134.134.137.102) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2375.31; Wed, 2 Nov 2022 07:12:35 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bTWK4Jj4JVW/JAMWPqCX1BEf39Qq/F1GiNXYNXk1b0G1uHs7U+hDPEErTfSaUYhUqFZq3xTSQ75gKXGBgylmTTJ6rZLmw5hs1P0orzD7aBlYLKqjhldVVFnddcmqFBzlEAUA2cQRVEQ5HrtGY0LDZqTn/ChquhiXkGQbDZhQN+a9HFiIk2pCQTEox5odKpX0AqLnZH6VI0kSEZh0jNNmu1VCJZZhDpoTggeArV9hag5+ytYOFHu7WXC3Z6AYqPTQyLoKIl25pAIqoAEq6MLgLuqg1Tlp6+QGJdHdnxMPtK35zz137lw2UZXvSiN0DrslSj4/L6/FxegvY+WCqORbdQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=mib06KMeC8JMgIImcc338NJT7S4nFrlXi4Dl03XcuWg=; b=iNLuRgQ+33GgzaCmSuUn1qcb9+pEtvJMap9cuEEiHT/HbSAAq4RQu3qb231qLt5VyvWSkHsymvMzzv1hBxINPE142gh7uBpBk84k3begov+KuNNs1j8RSptMtuxwU+9J6YTYDEPemEs2E1E/ARfqAh2e2EEbASNUZdYVwmdMbiL/s5TIUUWJ/ZhPrBfYQVzfqOOgSLkP2mwSdoEF/awn4Lw+H8ub2pkFZOaMnSfA+9ak7Oxx/d9LMw3Lupxk+ufa7PZ4ktpdjv1ybeQV7SmGt0UmYrOUzkjudyndgdVNAmFzE/RsJXTkBDTclsLvsvMuUvApayCsuJs4sCOaDA8IrA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none Received: from DM5PR11MB1324.namprd11.prod.outlook.com (2603:10b6:3:15::14) by BL1PR11MB5237.namprd11.prod.outlook.com (2603:10b6:208:310::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5769.19; Wed, 2 Nov 2022 14:12:34 +0000 Received: from DM5PR11MB1324.namprd11.prod.outlook.com ([fe80::793f:3870:4550:8aee]) by DM5PR11MB1324.namprd11.prod.outlook.com ([fe80::793f:3870:4550:8aee%8]) with mapi id 15.20.5791.022; Wed, 2 Nov 2022 14:12:33 +0000 From: "Ruhl, Michael J" To: Kees Cook CC: "Brandeburg, Jesse" , "Nguyen, Anthony L" , "David S. Miller" , "Eric Dumazet" , Jakub Kicinski , Paolo Abeni , "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 Thread-Topic: [PATCH v3 2/2] igb: Proactively round up to kmalloc bucket size Thread-Index: AQHY60UEuvCQ5/6nqkOEi2jDwjCFAa4o+uNAgAGizYCAARDSsA== Date: Wed, 2 Nov 2022 14:12:33 +0000 Message-ID: References: <20221018092340.never.556-kees@kernel.org> <20221018092526.4035344-2-keescook@chromium.org> <202210282013.82F28AE92@keescook> <202211011433.A64BF17F46@keescook> In-Reply-To: <202211011433.A64BF17F46@keescook> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: dlp-product: dlpe-windows dlp-reaction: no-action dlp-version: 11.6.500.17 authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=intel.com; x-ms-publictraffictype: Email x-ms-traffictypediagnostic: DM5PR11MB1324:EE_|BL1PR11MB5237:EE_ x-ms-office365-filtering-correlation-id: 82403c92-d89a-40b0-e08d-08dabcdc4988 x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: MMTZNsJOnyR3BwG/4ugpQqbbuz5Rc+4RMcOgOTGvTD/ZudBbwX8UbTQYDbYqk02/96Z8bPf0yhYeaMT0F43IWSHZgtdtZKjdn+1Qdj22aUEBcrm+t71IXuPwrQhnHXL0JIfgs5oB5V7ml63c/p7IuT96T05wyax471zYOUy8953YE6C9UlOusmZj9Skx4VlBcmpTPoGe+GCOiQqrR5SFBdgvIblXDEdosNDJPSBCqX6S0hzEE5uCn0OojH1dQfALWhjl1Z1WEy4KQQfgADYomeRRf1EP2K+EPK9y/QoBMSkAE3SB7dz5rGY3uLNnZjwz1foa/iL+5iptyZlJ+KVAnkHq2lQ/YilLMzMzxkD5A5MOxLLkOxNSgLrMirfxowsfxFCVLqPjNnSb0Mg26Emf7ic6PDWBxWlCS4ypzYH0FP8Iu2wSORJ7OJX2MNPUtPQynFOV1FnTctZIu3WRNhccUW7qlWnXIMuz0wt4CDggsc7ql9fC1C2p3Gjjh79DvDiq/zKtExtSGxBLznvoVCJWRA3bkOL+sc8nDu7UMdcYERkMACNj0Umi8+VV4mWiMZQnIS1uQTc1/4pwK3Ej5Ud6EKIXBDy5HIPQ409dvB/+wJ7Xx96xhgBYMAkt4qFgtUW0mLSQdIeznmWGIB8xf8fFtbYMIV1bCUyGXiORiqR/xvbFQOQutp4yby55nG2iscHtMSwXO1Jx6Tj3hSyj0XQNsSnXjofoTnwOlH7lJg8qrYgvGS7fxlrL2zfQuS8YsN8atggM9LaGFna/IoE23IUHJw== x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM5PR11MB1324.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(366004)(346002)(136003)(396003)(39860400002)(376002)(451199015)(122000001)(83380400001)(2906002)(71200400001)(478600001)(82960400001)(38100700002)(9686003)(66946007)(38070700005)(64756008)(66556008)(76116006)(66476007)(4326008)(8676002)(66446008)(7696005)(41300700001)(55016003)(186003)(86362001)(6506007)(6916009)(33656002)(5660300002)(52536014)(316002)(54906003)(26005)(8936002);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?5DRUZsBrwLWpq0POZNu7gUJ/VDIWkmj4U2UT63069JcpRn6Pd08H2QyvtkqL?= =?us-ascii?Q?qlWqT3VAzhpWZ2mlIokIuC+qiO2enEqq94uhOCcxmhQjcJpVFmNt8KA1A4Ld?= =?us-ascii?Q?jvht6UNYGSqzGH1/7QO+eEgDb0gi/73+SU5GO0PIErnrWHdx/mUv02ouPmmh?= =?us-ascii?Q?RxDx5TP4WRu6OH7K5417t2XUGQZcHRprvGZErcxleRd7o5yRwDpZoF26wanS?= =?us-ascii?Q?ZjGT3lYkl9jr6RSSmHWfhHEiPtZveFYOeQF29fsKqTrAQPjcJKcS10F931oK?= =?us-ascii?Q?Qb1/lhvlSvlBLIod1wgMnU048m+jjzWq49zhF59rf+Y6ttbicoPH7b8JBqLz?= =?us-ascii?Q?h9uNxG+ihiYVp8zolayzlfsIndREXngs7fzas9m51Z9MvnP8DrlmuSeCEdtC?= =?us-ascii?Q?F2sOHfYY7jiE/nMi/pLQBu6/iM0l4XuLoil9oBDbaG2h34AGkXnP3TBCtS2c?= =?us-ascii?Q?AyilW0+fEeK0nmiALEy94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ascii?Q?rHActq8IwOC9zUvZRlAHP0s2NrRvFCJgujzkrTb8JjC6OTkHWIqUcM73+YZg?= =?us-ascii?Q?Ni66Qhf4OZ4AqDSI3C40M3Pp4OxJUEQ0odCZ5grRenWuvqrPEk6/Jrep19x0?= =?us-ascii?Q?wKQP4C8hji5TJUsWZMeoBArszbXg/yQxi+hp6UZ9Nga6X0G8cVLlkVZLr83p?= =?us-ascii?Q?R4W2T8dbxLtOoxBqfSBiZfCrJNfWDRcipsewv3jp?= Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: DM5PR11MB1324.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 82403c92-d89a-40b0-e08d-08dabcdc4988 X-MS-Exchange-CrossTenant-originalarrivaltime: 02 Nov 2022 14:12:33.8255 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: yLsdh5FPRDaD1PP32O+y9N+e7COoiyA1nPBDVyzqmZaF+AnEXHM2YcmThZN4iLgM/Qb27+nqZM2UnCHohn6NrIXMqIrXw8rDx8vOzU5pEfY= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL1PR11MB5237 X-OriginatorOrg: intel.com X-Spam-Status: No, score=-5.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org >-----Original Message----- >From: Kees Cook >Sent: Tuesday, November 1, 2022 5:37 PM >To: Ruhl, Michael J >Cc: Brandeburg, Jesse ; Nguyen, Anthony L >; David S. Miller ; >Eric Dumazet ; Jakub Kicinski ; >Paolo Abeni ; 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 si= ze > >On Mon, Oct 31, 2022 at 08:42:36PM +0000, Ruhl, Michael J wrote: >> Looking at the size usage (from elixir), I see: >> >> -- >> if (!q_vector) { >> q_vector =3D kzalloc(size, GFP_KERNEL); >> } else if (size > ksize(q_vector)) { >> kfree_rcu(q_vector, rcu); >> q_vector =3D 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 f= or >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 Mike >-Kees > >-- >Kees Cook