Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp847768pxb; Wed, 29 Sep 2021 10:55:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz01vfKFklDDSNCg4pb4/4rOsflyhsUXxtu935sw43KVTb5YlnYWQxHC4B61GseGxTilrJL X-Received: by 2002:a17:906:4ace:: with SMTP id u14mr1280941ejt.118.1632938110285; Wed, 29 Sep 2021 10:55:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632938110; cv=none; d=google.com; s=arc-20160816; b=l7or3zZSS+UxVlRWc/s3mdZyYd7lWuQCx1nqyY+pbqo/36AjXDwTqp2jGghjQr5/C2 jRc7cBX881grr17WiVp4eZOTBU7Hjo+7PXuqZU5BUS23b+R5h9UJCAffuh0ciosYb7Oj 0n0rOeqU4qemhrrRslWGhwCY3hYCy4qMr0iv4SGoZxgmzEfkCKgW+Jf618AhM1UAuC5B hN4fqri+R3f9It/M6063xUmA9GBhSjsgZu3784lqRoRRwzAaLbrudKXbktOhqOLhq5NR dZZvi9gC6c6Utk1MPggedXfFhhFhHtFxtqN/e9k67pLIBVuXE0qr/EoQFpBlvrph49KJ hb8w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature; bh=LDYxmYqsjSSaY5qNEcKRB1CAbNpq6pKRJ2FH76OopzQ=; b=EmWh8kR3kvZRTAGND6NUZhj5X5C7LSSYsDoG9838D7uY9VrE9ldsqLHI6cV2436wUw /KMlyU7qBeqGv5KD/vzu8Ty1Mngk+YpgslTbUxDr/xSxLKp/AhpkbWnkv7hvtpusYQRW MAmMB8nydaeApcw7WJpY0cY09tylWKw/UNdseM84aE0ruvVJlPO698wMHdnS7WtdpWgx 1UnXc3+kDpfyUc+LdHC+8MvPpkFCGz9MsiRfV0TQi3ga0dxdVjcWx75twR/JLbowik+Q YZMaTvvm+Ya+KYcuREt/MzIhlud3NY3BhwK2JeajRA6467Iro+PehrebkVSbRV0F263H NL7A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=SL08n0GY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b25si514370ejl.496.2021.09.29.10.54.45; Wed, 29 Sep 2021 10:55:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=SL08n0GY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346167AbhI2RXZ (ORCPT + 99 others); Wed, 29 Sep 2021 13:23:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55782 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343753AbhI2RXT (ORCPT ); Wed, 29 Sep 2021 13:23:19 -0400 Received: from mail-pf1-x436.google.com (mail-pf1-x436.google.com [IPv6:2607:f8b0:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E9469C06161C; Wed, 29 Sep 2021 10:21:30 -0700 (PDT) Received: by mail-pf1-x436.google.com with SMTP id w19so2516308pfn.12; Wed, 29 Sep 2021 10:21:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=LDYxmYqsjSSaY5qNEcKRB1CAbNpq6pKRJ2FH76OopzQ=; b=SL08n0GYQgtLYfC8OeMRTPwz4kyFIBgH5vGSrXVasHm4qVTLleyDxys5Rs66XsHY4l SHYNvDh9nPLfvQCq35o3c637USllorz1K/qgpzlwjz5CXtay3Ot2+hq0ww/+4D1uIGRX Q/Ivgpr6NxxyOzouZ+NJi80Aw2qCYz1WsP6COSLgtPoAnb+Kn8n4q2GoWBcIykUXwybF IDSSPQBOoRc8uMEQ3/ZVG3L6gHwWbzWPjtwLALdLcn5ZTABTMC7DTLhQUU1A1BLpXf6l q0N94Rl4hLdZJ+gkRvhq+gjs8LNt0mWO21e1B5YtB9wjYxWPg9xfuybFUlASvK2DEIaw pH6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=LDYxmYqsjSSaY5qNEcKRB1CAbNpq6pKRJ2FH76OopzQ=; b=fgTzSZJ5AX+mX3912gi5pV9qeZ/AJS9lV3YrGWXf9ncoX40kwEK9XzNaQFOerb+vc6 NdgBUY4zza7MHEw2fNOuAhyKKgFU2iQBUjfUlpMszaGKBk63niTMDb8ERhzrLK5TwJBZ a7xiCjmR7LzhMTBwPY6HgObI7bLwWNELWihogdkRWRwPwNA3Hmub3WTMJZ8VY0hvypCS 0pSW/SqKbflTfrDrAYGPqGT7qOTy4SDzpBFuy21+ImbwQHGFsNmyGQdT7W2R0YBkTYR2 2d5jqzhl0UO7h5jmVU7z47GyNMS+mIzdkWruEXGQYe9Mb6k/QNqOD9ntL6kqmHS2IUuc AKfg== X-Gm-Message-State: AOAM531aBS+/ukKBjfy/ms+zndpUNcKLkkSNfpMNdVfOsbuvQdW2/tWD lHBU0DGERPPQGMwuFZ3QdmHgT4AwIa4= X-Received: by 2002:a63:2b4b:: with SMTP id r72mr931484pgr.57.1632936090207; Wed, 29 Sep 2021 10:21:30 -0700 (PDT) Received: from [192.168.86.235] (c-73-241-150-58.hsd1.ca.comcast.net. [73.241.150.58]) by smtp.gmail.com with ESMTPSA id b7sm386900pfb.20.2021.09.29.10.21.28 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 29 Sep 2021 10:21:29 -0700 (PDT) Subject: Re: [PATCH][net-next] net/mlx4: Use array_size() helper in copy_to_user() To: Tariq Toukan , "Gustavo A. R. Silva" , Tariq Toukan , "David S. Miller" , Jakub Kicinski Cc: netdev@vger.kernel.org, linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org References: <20210928201733.GA268467@embeddedor> <283d239b-9af9-d3a3-72be-9138c032ef63@gmail.com> From: Eric Dumazet Message-ID: <16ae2d2d-3aba-82b2-0bd8-90f7d0367a62@gmail.com> Date: Wed, 29 Sep 2021 10:21:27 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.14.0 MIME-Version: 1.0 In-Reply-To: <283d239b-9af9-d3a3-72be-9138c032ef63@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 9/29/21 3:24 AM, Tariq Toukan wrote: > > > On 9/28/2021 11:17 PM, Gustavo A. R. Silva wrote: >> Use array_size() helper instead of the open-coded version in >> copy_to_user(). These sorts of multiplication factors need >> to be wrapped in array_size(). >> >> Link: https://github.com/KSPP/linux/issues/160 >> Signed-off-by: Gustavo A. R. Silva >> --- >>   drivers/net/ethernet/mellanox/mlx4/cq.c | 3 ++- >>   1 file changed, 2 insertions(+), 1 deletion(-) >> >> diff --git a/drivers/net/ethernet/mellanox/mlx4/cq.c b/drivers/net/ethernet/mellanox/mlx4/cq.c >> index f7053a74e6a8..4d4f9cf9facb 100644 >> --- a/drivers/net/ethernet/mellanox/mlx4/cq.c >> +++ b/drivers/net/ethernet/mellanox/mlx4/cq.c >> @@ -314,7 +314,8 @@ static int mlx4_init_user_cqes(void *buf, int entries, int cqe_size) >>               buf += PAGE_SIZE; >>           } >>       } else { >> -        err = copy_to_user((void __user *)buf, init_ents, entries * cqe_size) ? >> +        err = copy_to_user((void __user *)buf, init_ents, >> +                   array_size(entries, cqe_size)) ? >>               -EFAULT : 0; >>       } >>   > > Thanks for your patch. > Reviewed-by: Tariq Toukan Not sure why avoiding size_t overflows would make this code safer. init_ents contains PAGE_SIZE bytes... BTW Is @entries guaranteed to be a power of two ? This function seems to either copy one chunk ( <= PAGE_SIZE), or a number of full pages.