Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp2537265rwr; Fri, 21 Apr 2023 10:09:09 -0700 (PDT) X-Google-Smtp-Source: AKy350atI3rDG2OThu0ns6j/Ik001ag//UVgWciT3L7P7NFyR0en7Hf/Pkk53QHytpgI83swDTdh X-Received: by 2002:a05:6a20:54a2:b0:f0:8707:2bc5 with SMTP id i34-20020a056a2054a200b000f087072bc5mr8111339pzk.5.1682096948613; Fri, 21 Apr 2023 10:09:08 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1682096948; cv=pass; d=google.com; s=arc-20160816; b=PluMp6PiSK9KbV2cHYIa5Wuy1EyGw1g+neOTQxf0W1icwnlUeSkf6H+EEhZKkwg1q8 sRpOEgRJyrzFYckDmlNwLBi488tCPHibsZLR5c0yLltSeEGn7o7svAQxfOJAXFeSadwh lyJAJNmjzJf09/1IAOUTp7hVQD6bYAYfcJJ1a6JLJWQZ+oTnb/ko2MOIU3SwbwEfi7sP FEzskrNNrDBQW2ySCgdazvcIYQN1eFYqJ+BUeIAPQ5taqDlva/vrHVb8rcPXjglH5Cl7 wIHNYoFZNoxHtz3PHq+LYIcR/3png5pwhT+OoJyryoLyaEZix8OR8iaQw7UuDv211xBM YBHA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=k1HmhJxV6cmUgswVaDI/a//1gqwtqv777RmGSU5xq7I=; b=QHcvHxKBeN2ERzcKrccU6deXaYeJ7P+3cUHrgMVwyN9ydx5g2GIHT2v/Z2kzTxNpT7 8L20GvSBCZCCcde04/Ij3zpvQ2ZgNeQPH58WI1sE0qPqulZnayS+YuGzCyOTSmev7/yd dLVptOWEjn3jr6glMxtb/oguaYhF2i9XlPId6hKt75obH7hQfzkE8X3GMC03sS9KMj+i zOjYeBu86U42Nnn0x6rVz8Z/XSkyMB2umiph0GehlNlirYIZfURRQ0Mugy30yG5qwp2Q PT1kIGcJPMVKWRTCLs5OiQ0H9dUPhaTf2LsleSbYcoIOhYUxp6p5Oe7BFiIKw9b/wIVR FhqA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector2 header.b=SREZIXHH; arc=pass (i=1 spf=pass spfdomain=microsoft.com dkim=pass dkdomain=microsoft.com dmarc=pass fromdomain=microsoft.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=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a72-20020a63904b000000b0051f8817a308si770277pge.5.2023.04.21.10.08.56; Fri, 21 Apr 2023 10:09:08 -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=@microsoft.com header.s=selector2 header.b=SREZIXHH; arc=pass (i=1 spf=pass spfdomain=microsoft.com dkim=pass dkdomain=microsoft.com dmarc=pass fromdomain=microsoft.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=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231282AbjDURIr (ORCPT + 99 others); Fri, 21 Apr 2023 13:08:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51604 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231936AbjDURIp (ORCPT ); Fri, 21 Apr 2023 13:08:45 -0400 Received: from DM6FTOPR00CU001.outbound.protection.outlook.com (mail-cusazon11020020.outbound.protection.outlook.com [52.101.61.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A67652D56; Fri, 21 Apr 2023 10:08:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lvH3/riMhqTqmpeSKabzGExQw/rkSfJcl7yNDYrx0DwcHtqjqD6POsx8HdkXYHucYN0SndRroKqLa2wH2w9w3vQTKaAjrnGd0f+zurO/vnyTM/gKvaGWlz8x7aMkBfXcp0grrbxyvWyj3PWYoeO2ZVe7bB9XQwJs+9F01fzQA4qmVbdnBa+w5dj9I++s5AGVErMJj80KzFB8B3k+D5XQkLKiZ/mcR4VwTzo9S1Mcyi085OatZapaAk3OjmQX0BWGDT/gR2xSZArmPj25wGMjVfd23Xtv2opqcZtN3jsakI9nzEe60mMLEhL/LREexdhMoeLQev/lP5XeyDsRQ+75kA== 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=k1HmhJxV6cmUgswVaDI/a//1gqwtqv777RmGSU5xq7I=; b=MfDWTYDEMgx+2m/+gX+Lcc4uwsduwlAjBO2Y+e5bqc41XGpLob4ui3kjXsYk7qad/UdZKvYkr985R9XGIjM+hQos9507boWqj1N4X3vfHT2vjr2VRtSqkRcPsoNmrULKMvXDb637/Z9ho7tWMLMC3Gy93Uw5DY4Fu9wzPpZXDCoriPea3oQT3RPPwevak84/gXziR75JqTbLpG3y8dA5wtM3HTuCZgnjg6S04/A15cP1omWQAqVt1KheNAnjcv9WJVDzMwmhZ2Kpo6428gjBxG1iFxgjC+O7Pq7PbaDBsHCDxOkqbD9eST2Bf3ls1LXX5arV/BhCCz8FJ5mcK3+m/g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=microsoft.com; dmarc=pass action=none header.from=microsoft.com; dkim=pass header.d=microsoft.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=k1HmhJxV6cmUgswVaDI/a//1gqwtqv777RmGSU5xq7I=; b=SREZIXHHMM8LuERNkIXC28+cP3oRLsNs+jKUZ5e0eLbEW+gpl8hsi8qAAzZyYlSM5GnR++/4mCnn2bjyAZMe4ljZoiMuyNYTMv28I6BjeIW6KLClRv0jJpe/AL6bragv4X1x6wr6AQtUz3If2OGX2vOm18JE0DHA5nzvOABGfrM= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=microsoft.com; Received: from BY5PR21MB1443.namprd21.prod.outlook.com (2603:10b6:a03:21f::18) by CO1PR21MB1316.namprd21.prod.outlook.com (2603:10b6:303:153::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6340.11; Fri, 21 Apr 2023 17:08:02 +0000 Received: from BY5PR21MB1443.namprd21.prod.outlook.com ([fe80::3e5b:6d93:ceab:b4c6]) by BY5PR21MB1443.namprd21.prod.outlook.com ([fe80::3e5b:6d93:ceab:b4c6%4]) with mapi id 15.20.6340.015; Fri, 21 Apr 2023 17:08:02 +0000 From: Haiyang Zhang To: linux-hyperv@vger.kernel.org, netdev@vger.kernel.org Cc: haiyangz@microsoft.com, decui@microsoft.com, kys@microsoft.com, paulros@microsoft.com, olaf@aepfle.de, vkuznets@redhat.com, davem@davemloft.net, wei.liu@kernel.org, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, leon@kernel.org, longli@microsoft.com, ssengar@linux.microsoft.com, linux-rdma@vger.kernel.org, daniel@iogearbox.net, john.fastabend@gmail.com, bpf@vger.kernel.org, ast@kernel.org, sharmaajay@microsoft.com, hawk@kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next, 2/2] net: mana: Check if netdev/napi_alloc_frag returns single page Date: Fri, 21 Apr 2023 10:06:58 -0700 Message-Id: <1682096818-30056-3-git-send-email-haiyangz@microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1682096818-30056-1-git-send-email-haiyangz@microsoft.com> References: <1682096818-30056-1-git-send-email-haiyangz@microsoft.com> Content-Type: text/plain X-ClientProxiedBy: MW4PR03CA0102.namprd03.prod.outlook.com (2603:10b6:303:b7::17) To BY5PR21MB1443.namprd21.prod.outlook.com (2603:10b6:a03:21f::18) MIME-Version: 1.0 Sender: LKML haiyangz X-MS-Exchange-MessageSentRepresentingType: 2 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BY5PR21MB1443:EE_|CO1PR21MB1316:EE_ X-MS-Office365-Filtering-Correlation-Id: 3a78a2f4-ef35-4113-78c7-08db428af71a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Wba/7GADcIhlqE372dLxFMN2Ro2+btQwLEUSRjv4tZACp5rhgjQ23Yrk3zVREnVw8i2ssoKY7mivMJLYPTQgWeeB0jiKuQRBrA9BW/zt/Q3wiiDMeTFt5xT3jnCubC+lI4jPdJIBVR24wz1tBsFfeRvAQeZDdLe5Iy9J/ElyE+y9lgTB4ZkwE7AvGJv2HpkyYO4dV8dhFzpw5kq6Bl40R2WoNaZuWOTCOt4dvdRIYoIqhhg+j1aVdGbVigawF1zJC/GGZ1lOrdW6yyeX/uHf3Mc+EgvLwCPNNjDua287612XHECZR1DhKHh9wZHfLBUa83nxfcR/RCwjn9VkEv+aRegeopXVd6evIMqgo+gHSsQzn0NFxA5ZBkaOWujqfWZGdXG1D2696eLHL9IjVcUnptJC+L/TBQ55Qty70IDLxAQ5oAWFH62MvSD2gPY2on4+3FadWG7eQVmNCbWkv0VsOYYqxxzzHPAtskZHbLD8agbl9PxJSmFE8hCov6g4jBE6ucoOjmeYwsh2BLJSnEUQzFR2hk2fhW4WRDMVBo7b4fWRIX7Ek8nlsBdiZnRzqQvVBGcyj6OtqBpPGKWa0xCFs97NJtmrj1TXhTfSVebVXDNc30EdRyChMzcfWBQf/I/KSjsCAqkXCv08v9YEJoOjoF8SguU9HaLFJsMNzqV/IDk= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BY5PR21MB1443.namprd21.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(4636009)(376002)(396003)(136003)(346002)(366004)(39860400002)(451199021)(4326008)(66946007)(7846003)(66556008)(786003)(66476007)(316002)(36756003)(6506007)(26005)(82960400001)(38350700002)(38100700002)(82950400001)(6512007)(2616005)(186003)(83380400001)(5660300002)(41300700001)(8676002)(8936002)(478600001)(52116002)(10290500003)(6666004)(6486002)(7416002)(2906002);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?76mTHPZBkMQoZMTX4AhCw/ko7perv+ya4Tlc+mGY4Od3b6j8lniZm1C53edd?= =?us-ascii?Q?c3LAF7USQlAYSBAHEo7EFwrFU8/FS8jakWWT+RdWOJ/b0PLIh9zxp6IRKpdX?= =?us-ascii?Q?ofu4eIhu8pLlovu4+3iQ3W6pQC3N+lRR+Gncwv54BhVSkYRFr82YfAjGpUKI?= =?us-ascii?Q?m+XUI8EvWAZgRBxsE5kr6HPCNZwHqRy72EIYbasOMORfIRxOF2pauOcDMB8S?= =?us-ascii?Q?WPsnARrXjzvI3fRPNUidIZmfC0vicj2X9DSse63/hyLZ47rJMvPLKusU4/3D?= =?us-ascii?Q?Ayu0/D30fjjYbzvJ37/N20Ru/+s35ZmWUrFIkazRLaKCdA1hrRwvINL7k8U7?= =?us-ascii?Q?3+Kpvrwg2iHaH33PdUSOEWJ05mICZGCFIGK5nOTjPm92dTE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EcE9qPwmC4htEST5BGQs6GaPSTRSTMQxF6JKYjrWRx/EYTkI9J?= =?us-ascii?Q?WoPKEZ4wRN15mS9oGARnzhaVtTxzkUa3tSikOrLhjxY6xa1Tv1awKzjk6uT1?= =?us-ascii?Q?kzSn85Nt3NjDcgAeuDMTtBrz5LQzVeujinZUO/YDlY7AwRoXx9mT8J/pZL/K?= =?us-ascii?Q?dgNoYKF71bGviCoG44QVtTbhv/SfHvK1Px4ih3qbwqgJELqKvVUbbgomozqu?= =?us-ascii?Q?yZYaqsuh/9egvHXuZgcKjPXHofHSK2n1vI2H5ARC/6syqSYiAJByhbEa16bF?= =?us-ascii?Q?ZWtGAt18O1P6ze9DgrkYXXrM3nQl+h7fSx49WSsD?= X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3a78a2f4-ef35-4113-78c7-08db428af71a X-MS-Exchange-CrossTenant-AuthSource: BY5PR21MB1443.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Apr 2023 17:08:02.2854 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 0V3mpMbzuAt4yHlJy7q8xx4Ro+przExRNcllL+IsMVGqAVfOb43c9vkbeF2UjrEKuWHKVoY7Iqze/71OYjGTrg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO1PR21MB1316 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE 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 netdev/napi_alloc_frag() may fall back to single page which is smaller than the requested size. Add error checking to avoid memory overwritten. Signed-off-by: Haiyang Zhang --- drivers/net/ethernet/microsoft/mana/mana_en.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/drivers/net/ethernet/microsoft/mana/mana_en.c b/drivers/net/ethernet/microsoft/mana/mana_en.c index db2887e25714..06d6292e09b3 100644 --- a/drivers/net/ethernet/microsoft/mana/mana_en.c +++ b/drivers/net/ethernet/microsoft/mana/mana_en.c @@ -553,6 +553,14 @@ static int mana_pre_alloc_rxbufs(struct mana_port_context *mpc, int new_mtu) va = netdev_alloc_frag(mpc->rxbpre_alloc_size); if (!va) goto error; + + page = virt_to_head_page(va); + /* Check if the frag falls back to single page */ + if (compound_order(page) < + get_order(mpc->rxbpre_alloc_size)) { + put_page(page); + goto error; + } } else { page = dev_alloc_page(); if (!page) @@ -1504,6 +1512,13 @@ static void *mana_get_rxfrag(struct mana_rxq *rxq, struct device *dev, if (!va) return NULL; + + page = virt_to_head_page(va); + /* Check if the frag falls back to single page */ + if (compound_order(page) < get_order(rxq->alloc_size)) { + put_page(page); + return NULL; + } } else { page = dev_alloc_page(); if (!page) -- 2.25.1