Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp1051672pxb; Tue, 14 Sep 2021 15:13:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwxY/iTRlrNxFJYDcJw2XnKRDU8SckT35sIMDQoE6SOtH7nu3bT1VYVD7gsgdVV82gv8xQh X-Received: by 2002:a05:6512:31d3:: with SMTP id j19mr2040697lfe.368.1631657622703; Tue, 14 Sep 2021 15:13:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631657622; cv=none; d=google.com; s=arc-20160816; b=M8thqkBTdu+00XBJ34x8ZtwLjyFUmq4RlcAJ9peDwRLbzg6Eszxx3RXxf/cVjK442z e4HbJ1TRYXdRsPAZfwF2Ebk2fd2K/YSRhBQUZwQJM1ADrl43ZjUxa+gZ9CQCL5mcHDtT G+BYKsh/54kFhY9APkTsnOoG8Y9Qy7hQ94NnZWlyuHXBkheIExPfvEmNwcls29RXTcoc v8hTy3FxgDWFyCJ0kAtH/Y3XX1ErKA0sO/BVfax5TjCp5A5Bk0sPyeMlnlJvaPrDN6bn CpAoE5/dehN9ho0L33A0H609CfCU7UOOKRNugtSQt13g7Lqk9f01/svz6k4RssP19cSt 3pDQ== 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=2vSlWpDlgQ1WCtKW+iJxypZWQ+3srQCmJtCimsZZbKQ=; b=kTZ7xxYP3+1gF5QTsSnZcxw9tDWKxPxjvQVotqDUNUcyMeVYl9ivcUCZbX+pSLlmpp /6CNbzqMv4vqPeEXwKI8zvyifS+skWsM0ohmHYiLmVoyUds8IfomSPgHPyRz+oDuudE5 kN3FAVQGxgl6QS3e2pkHuQKhTfixvZp+akA+aip7O25NXX1wuYPmMASBD93XmBUBjHei z5VFqC9Ht7fBywIkjfBDlSt5Jd++reoxzUAB8MXkZ7khvBVLrsOCrlOpytqPvTnRs3bK XQaBaG58bjw4VR7giOfPbytv+pRZiONkVTvmTT895EvhZKdIjBK2zzkadF1e7sBaJZcX 0ItQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@embeddedor.com header.s=default header.b=ccvX3c8v; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m26si16567468ljg.281.2021.09.14.15.13.15; Tue, 14 Sep 2021 15:13:42 -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=fail header.i=@embeddedor.com header.s=default header.b=ccvX3c8v; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235326AbhINWKK (ORCPT + 99 others); Tue, 14 Sep 2021 18:10:10 -0400 Received: from gateway20.websitewelcome.com ([192.185.68.24]:11685 "EHLO gateway20.websitewelcome.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231559AbhINWKJ (ORCPT ); Tue, 14 Sep 2021 18:10:09 -0400 X-Greylist: delayed 1387 seconds by postgrey-1.27 at vger.kernel.org; Tue, 14 Sep 2021 18:10:09 EDT Received: from cm11.websitewelcome.com (cm11.websitewelcome.com [100.42.49.5]) by gateway20.websitewelcome.com (Postfix) with ESMTP id 5973F40120C4E for ; Tue, 14 Sep 2021 16:27:11 -0500 (CDT) Received: from gator4166.hostgator.com ([108.167.133.22]) by cmsmtp with SMTP id QGFLmweYeK61iQGFLm4PpO; Tue, 14 Sep 2021 16:45:43 -0500 X-Authority-Reason: nr=8 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=embeddedor.com; s=default; h=Content-Transfer-Encoding:Content-Type: In-Reply-To:MIME-Version:Date:Message-ID:From:References:Cc:To:Subject:Sender :Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=2vSlWpDlgQ1WCtKW+iJxypZWQ+3srQCmJtCimsZZbKQ=; b=ccvX3c8vYx2soiyQjSD3Y3K9ld 9n8goroyewasfqmu9ivOOmOTa9INFz7yHnPJ9azhVmUGNyiekWz9n/lTDaBAAJuN7TXnRQnQewfra yLoOnkE78oNRJR2Dt8+zAiXw/iUMCXDZPWQiDx8DCpCova0lD/z5VLA83pYB8s0ZJz0pAqCGlp4Tz JaRPSkMp/vCIeWhkRSJOGwpOh6FbNWPWAxjwL8JbFfGGOBjbORla0GnVQ9kHpwVOfjCErxqoD0XVl x279Qwh5Mjb2yhVQHWf93gTuFWGPWS2nccT1D3QueiBPvKXsaQiE12MeTd1YhutRZJDtmVAXyDsBh FPleGuxw==; Received: from 187-162-31-110.static.axtel.net ([187.162.31.110]:35226 helo=[192.168.15.9]) by gator4166.hostgator.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1mQGFK-003opJ-Uw; Tue, 14 Sep 2021 16:45:42 -0500 Subject: Re: [PATCH] Input: omap-keypad - prefer struct_size over open coded arithmetic To: Len Baker , Dmitry Torokhov Cc: Kees Cook , linux-hardening@vger.kernel.org, linux-input@vger.kernel.org, linux-kernel@vger.kernel.org References: <20210911112716.10067-1-len.baker@gmx.com> From: "Gustavo A. R. Silva" Message-ID: <32777a69-297a-f68a-d0c3-e5920035531b@embeddedor.com> Date: Tue, 14 Sep 2021 16:49:31 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.13.0 MIME-Version: 1.0 In-Reply-To: <20210911112716.10067-1-len.baker@gmx.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - gator4166.hostgator.com X-AntiAbuse: Original Domain - vger.kernel.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - embeddedor.com X-BWhitelist: no X-Source-IP: 187.162.31.110 X-Source-L: No X-Exim-ID: 1mQGFK-003opJ-Uw X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 187-162-31-110.static.axtel.net ([192.168.15.9]) [187.162.31.110]:35226 X-Source-Auth: gustavo@embeddedor.com X-Email-Count: 6 X-Source-Cap: Z3V6aWRpbmU7Z3V6aWRpbmU7Z2F0b3I0MTY2Lmhvc3RnYXRvci5jb20= X-Local-Domain: yes Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 9/11/21 06:27, 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. > > So, use the struct_size() helper to do the arithmetic instead of the > argument "size + count * size" in the kzalloc() function. > > [1] https://www.kernel.org/doc/html/v5.14/process/deprecated.html#open-coded-arithmetic-in-allocator-arguments > > Signed-off-by: Len Baker Reviewed-by: Gustavo A. R. Silva Thanks -- Gustavo > --- > drivers/input/keyboard/omap-keypad.c | 3 +-- > 1 file changed, 1 insertion(+), 2 deletions(-) > > diff --git a/drivers/input/keyboard/omap-keypad.c b/drivers/input/keyboard/omap-keypad.c > index dbe836c7ff47..eb3a687796e7 100644 > --- a/drivers/input/keyboard/omap-keypad.c > +++ b/drivers/input/keyboard/omap-keypad.c > @@ -190,8 +190,7 @@ static int omap_kp_probe(struct platform_device *pdev) > row_shift = get_count_order(pdata->cols); > keycodemax = pdata->rows << row_shift; > > - omap_kp = kzalloc(sizeof(struct omap_kp) + > - keycodemax * sizeof(unsigned short), GFP_KERNEL); > + omap_kp = kzalloc(struct_size(omap_kp, keymap, keycodemax), GFP_KERNEL); > input_dev = input_allocate_device(); > if (!omap_kp || !input_dev) { > kfree(omap_kp); > -- > 2.25.1 > > > >