Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp6125949rdb; Mon, 18 Sep 2023 05:11:36 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEbzPaABgEUn0uZflOvT4jRjwMVHrffeQRKXOomc9Kf8hYMibsqxmlNDkkB4yn822G4X5Mr X-Received: by 2002:a17:902:f0d2:b0:1c4:6b4a:99da with SMTP id v18-20020a170902f0d200b001c46b4a99damr4768603pla.0.1695039096010; Mon, 18 Sep 2023 05:11:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695039095; cv=none; d=google.com; s=arc-20160816; b=CP0sEDWnyBeFJxf6bGs+QlGmdhfk2UvxUQy9D1+vvPjusaxqiHqyGKQTYX8lbhRvB5 CDrL7cgHSyj3CNnNFcSNbu37qzl8LoQQpiI2i5SDn1pEtVgfP9zrH2PAcQi8BSCJ4E7X i3hvRvy74tgG2M3Pga0KEyN3z+aSIkTFg1+/u3kwuHFpH8ul5qyVPMRyjgXIubrsm1k9 IfN6A3UZxtm5Sx/NCrstWoR/cFpiXaIYNQzY/MWCkIQE3/vUGCXonRvwvTsV1jM4AsC3 beyrCD6IW0dBrZzoChHQMmn3pAYztTD1FQ2GCt5oeIeeFp8wQyhBKzovyz4i97bx3Rld hKiQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=nvWwqffCij7ZgOtkwNJMjICe7Ibafj2Zgck2ZKCHj+I=; fh=94jdO6OBfKQL8IhVTfYJWkMaoDyiE6Q4TbKuLNdcbRI=; b=sA0xBc4yXezOGLqKwJzBGc24gNOQxNjRcVmyWgdsgwPyJxKhTBmw8DCLDLVSnkGwEk ZWRmcVeEne19ewLnx3DhMFkwy6QwqKNxavyan5Bw7wodWGYAzpK1XzMkhrQWTah7PQ4T 3H8Xb/nh4pFTzTqpgMwKYIhfGnpK/w2JyTjM2Tj8sy+zB6ppR5vri1druqJeI1clru6/ /mZyms+rieSCMMEdsECEKjuEHGC5F7R/NRLmwIUJSZmNFWrDG7R3+X2isRsAgzrdEIF8 OBDwy8yPqtsWy0aSIi43BLTVglUHQzm1ShC26CtJEM2PFKIvCJH2GNaPZMGSHaquxfPE Hlbw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@embeddedor.com header.s=default header.b=OROfyzdb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id t184-20020a6381c1000000b00578a02ee39fsi180793pgd.334.2023.09.18.05.11.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Sep 2023 05:11:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=fail header.i=@embeddedor.com header.s=default header.b=OROfyzdb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id BAF4D81A1E9E; Mon, 18 Sep 2023 05:00:36 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241827AbjIRMAH (ORCPT + 99 others); Mon, 18 Sep 2023 08:00:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37082 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241895AbjIRL7w (ORCPT ); Mon, 18 Sep 2023 07:59:52 -0400 Received: from omta040.useast.a.cloudfilter.net (omta040.useast.a.cloudfilter.net [44.202.169.39]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 80AF412E for ; Mon, 18 Sep 2023 04:58:23 -0700 (PDT) Received: from eig-obgw-5010a.ext.cloudfilter.net ([10.0.29.199]) by cmsmtp with ESMTP id iAuOqj91PyYOwiCtSqE6Wg; Mon, 18 Sep 2023 11:58:22 +0000 Received: from gator4166.hostgator.com ([108.167.133.22]) by cmsmtp with ESMTPS id iCtRqjUWMYg1hiCtRqz1LF; Mon, 18 Sep 2023 11:58:22 +0000 X-Authority-Analysis: v=2.4 cv=KsReZEaN c=1 sm=1 tr=0 ts=65083b5e a=1YbLdUo/zbTtOZ3uB5T3HA==:117 a=P7XfKmiOJ4/qXqHZrN7ymg==:17 a=OWjo9vPv0XrRhIrVQ50Ab3nP57M=:19 a=dLZJa+xiwSxG16/P+YVxDGlgEgI=:19 a=IkcTkHD0fZMA:10 a=zNV7Rl7Rt7sA:10 a=wYkD_t78qR0A:10 a=x2q-Q_5hSYYoW0-ZbgkA:9 a=QEXdDO2ut3YA:10 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:From:References:Cc:To:Subject:MIME-Version:Date:Message-ID: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=nvWwqffCij7ZgOtkwNJMjICe7Ibafj2Zgck2ZKCHj+I=; b=OROfyzdbVncz6GG+pMxherI3YC FyXaNi6UWptY28NKBaUVsZanCENsl4ntuarg9A9QIckfzZ2eCBd5YWjSAVU/VM8MYiXDtktf27SiG G2StZZy6FlJZ/VEn/oY2pw+ezmtuvTlHfiF3DjoIwcWZxLVJHg0vWJmsaTqwuz+yr2N+l7GIa4Nv2 G56JmDNlXdYMakbrUC3DEuM+53x/gT3AziUxQmAHxq8b7LMtPGmgOx4FzYy9HlqltXrjtNcfvHMdx vw03KcKY1GRfi0E69YfEpMMz7iOLLpY4yPCyahC3Pakfy9xgXGq/+dAHuaSYZYoumwOk7Zl6B/+58 Zc86hBAg==; Received: from [94.239.20.48] (port=44006 helo=[192.168.1.98]) by gator4166.hostgator.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1qiCtQ-000JKv-2L; Mon, 18 Sep 2023 06:58:20 -0500 Message-ID: <4067fb33-2172-b132-e8c4-0ba21c31b42a@embeddedor.com> Date: Sun, 17 Sep 2023 13:59:26 -0600 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.13.0 Subject: Re: [PATCH v2][next] RDMA/core: Use size_{add,mul}() in calls to struct_size() Content-Language: en-US To: Leon Romanovsky Cc: Kees Cook , "Gustavo A. R. Silva" , Jason Gunthorpe , linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org References: <202309142029.D432EEB8C@keescook> <2594c7ff-0301-90aa-d48c-6b4d674f850e@embeddedor.com> <20230918104938.GD13757@unreal> From: "Gustavo A. R. Silva" In-Reply-To: <20230918104938.GD13757@unreal> Content-Type: text/plain; charset=UTF-8; format=flowed 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: 94.239.20.48 X-Source-L: No X-Exim-ID: 1qiCtQ-000JKv-2L X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: ([192.168.1.98]) [94.239.20.48]:44006 X-Source-Auth: gustavo@embeddedor.com X-Email-Count: 2 X-Org: HG=hgshared;ORG=hostgator; X-Source-Cap: Z3V6aWRpbmU7Z3V6aWRpbmU7Z2F0b3I0MTY2Lmhvc3RnYXRvci5jb20= X-Local-Domain: yes X-CMAE-Envelope: MS4xfNXaxzgvaqZ6pf/V6mzfHyGT6SBIU1dtCnUT4pXOFyY9cfmL87fjLzmcVYj5YpvVZsh6C02jakuwOdCS8KA83uTy+8aBXgytr/pZdayM94n6R14d6Hma +Z0qlJw9diTCdAV7X6q9qQRBXOhRXo3ranxm5VW8iTe18VF/M0Tg2Nm1ub45S712rImvbN7F5nB4OnHfsHCTLc3lymB7Olt6etstLNNB1qOKoiIGZ23dbuMm X-Spam-Status: No, score=-3.2 required=5.0 tests=BAYES_00,DATE_IN_PAST_12_24, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A, RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=unavailable 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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Mon, 18 Sep 2023 05:00:37 -0700 (PDT) On 9/18/23 04:49, Leon Romanovsky wrote: > On Fri, Sep 15, 2023 at 12:06:21PM -0600, Gustavo A. R. Silva wrote: >> >> >> On 9/14/23 21:29, Kees Cook wrote: >>> On Mon, Sep 11, 2023 at 05:27:59PM -0600, Gustavo A. R. Silva wrote: >>>> Harden calls to struct_size() with size_add() and size_mul(). >>> >>> Specifically, make sure that open-coded arithmetic cannot cause an >>> overflow/wraparound. (i.e. it will stay saturated at SIZE_MAX.) >> >> Yep; I have another patch where I explain this in similar terms. >> >> I'll send it, shortly. > > You missed other places with similar arithmetic. > drivers/infiniband/core/device.c: pdata_rcu = kzalloc(struct_size(pdata_rcu, pdata, > drivers/infiniband/core/device.c- rdma_end_port(device) + 1), > drivers/infiniband/core/device.c- GFP_KERNEL); > > drivers/infiniband/core/sa_query.c: sa_dev = kzalloc(struct_size(sa_dev, port, e - s + 1), GFP_KERNEL); > drivers/infiniband/core/user_mad.c: umad_dev = kzalloc(struct_size(umad_dev, ports, e - s + 1), GFP_KERNEL); I haven't sent all my patches. -- Gustavo