Received: by 2002:a05:6a10:eb17:0:0:0:0 with SMTP id hx23csp1919647pxb; Sun, 5 Sep 2021 03:24:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyMP5/wLjf70evxMiYgumIa6FPhvHDtzRcp5jfqwTW1NHkyqsi2CoJAAcQwwc6cQ5WWBq58 X-Received: by 2002:a92:c9cd:: with SMTP id k13mr1649435ilq.169.1630837449902; Sun, 05 Sep 2021 03:24:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630837449; cv=none; d=google.com; s=arc-20160816; b=XM6JFeNhoLBh2ZJrrITFYNjLbh93HDRO88cnDexbYxn3OqeJFDd4cUFAoBUUrYLuTp wB5FfXEZH6lSmSjXAJijT9YOKHkz/d8M5T/h41fg3mnBfPcLCt1rqYVA5o+c8ZmyxFfw Px/GJ0enSTCBUUeGS7b8NcCr9sKgyDOh4yia8QwOy33Y2Q1bfEpuaCkc0AN8IdPvTuYZ 8aIR21Wh93SxkThw7DQU6GxR1fnw63G5+KKCkOvOsP9lgrjeYZ0XOYEpDie5FG4jajRZ +cNCrVBnD3kuD+ONTK7RBTP//aMkj2EUpy/qPd6dBb9JgfJNY+gGsxlrsG3kAh1X9z75 DPyw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=+4BqLMnKZ6war09GOU8Tt7ITeCtV2IdJJ9j08rpMr5c=; b=S5YBAhdmE3WRuDEmqC0rS21NGP40DmMPIjGNFQwS0qzP1V8RV56iO6PB+8Tk2GIsPd 9Pmc36xsRjWI5qO9iq+BBPvK0mMpMyT5cIWhHHdz6TqNvEBaUSzPW3/sNrP62hJHoP0U uCLmpRbboX4cL6t61EUmt1jNiL2tydbWOW5dtXP3EjncHw1p03viZPyBAd2bWRoeDFUm b5mxUInwy7Zq1/IVIH4pqjLICV4CBYYPyUsRKDKkU2IzwRZKxdEBc5vIUqglj/0WRkZY vXrgr7RlL1NfOrGpiCdt4HuiTKuVcIkLx4gF/QGVPjlf9OKSXOX2poqPR1+ewuj28akj /KbA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=VxATszSo; 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=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d11si4304212jaf.77.2021.09.05.03.23.58; Sun, 05 Sep 2021 03:24:09 -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=@kernel.org header.s=k20201202 header.b=VxATszSo; 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=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237754AbhIEKWe (ORCPT + 99 others); Sun, 5 Sep 2021 06:22:34 -0400 Received: from mail.kernel.org ([198.145.29.99]:53400 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237710AbhIEKW1 (ORCPT ); Sun, 5 Sep 2021 06:22:27 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id A291F60F90; Sun, 5 Sep 2021 10:21:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1630837284; bh=DSnZOnbbRPZXkAH3bBqJTe+6I0DJq/mBnMcyWhgNpwY=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=VxATszSoiCR151yzRPWZ75xOLZ3nhchNxaCTFyQ3SbsYxC2TO3bgavGMnrV9rRxh/ o7PqfPtdNhXrcmVLOQhAbtw/LsAQR1R5aukHjBlFQguSiSfzwRfVA0EwP02eP34u4V OxymL2gtXULgzXqzBO610L31vzKLseWRm/vhOYJ9EcuGyXOYw+JoRzBmPbeKJaKVXW NE4jxn9s4AXeGQTwzB6F5Q8wPAy9yT1C2vwmgXK5+DMpQTNKy0HiTUXGoPWGa8CIi6 ZgGp3qcXrrTKN1EN64pucM1hM9jtw3gRTHjUUKO7rBantaGzuQMxh2ieLAO68DhFHF qjhR6OzkggVSg== Date: Sun, 5 Sep 2021 13:21:20 +0300 From: Leon Romanovsky To: Len Baker Cc: Selvin Xavier , Naresh Kumar PBS , Doug Ledford , Jason Gunthorpe , Kees Cook , linux-rdma@vger.kernel.org, linux-hardening@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] RDMA/bnxt_re: Prefer kcalloc over open coded arithmetic Message-ID: References: <20210905081812.17113-1-len.baker@gmx.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210905081812.17113-1-len.baker@gmx.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Sep 05, 2021 at 10:18:12AM +0200, Len Baker wrote: > As noted in the "Deprecated Interfaces, Language Features, Attributes, > and Conventions" documentation [1], size calculations (especially > multiplication) should not be performed in memory allocator (or similar) > function arguments due to the risk of them overflowing. This could lead > to values wrapping around and a smaller allocation being made than the > caller was expecting. Using those allocations could lead to linear > overflows of heap memory and other misbehaviors. > > In this case this is not actually dynamic sizes: both sides of the > multiplication are constant values. However it is best to refactor this > anyway, just to keep the open-coded math idiom out of code. > > So, use the purpose specific kcalloc() function instead of the argument > size * count in the kzalloc() function. > > Also, remove the unnecessary initialization of the sqp_tbl variable > since it is set a few lines later. > > [1] https://www.kernel.org/doc/html/v5.14/process/deprecated.html#open-coded-arithmetic-in-allocator-arguments > > Signed-off-by: Len Baker > --- > drivers/infiniband/hw/bnxt_re/ib_verbs.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > Thanks, Reviewed-by: Leon Romanovsky