Received: by 2002:a05:7412:37c9:b0:e2:908c:2ebd with SMTP id jz9csp167987rdb; Mon, 18 Sep 2023 11:10:31 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEcrtD3Y40k2FN6DiasCxOMSe2274SW5Nwl1Km7NKFundU5QZZKiHIQfrpaoexnIaCdL5tu X-Received: by 2002:a17:90a:d596:b0:26b:5461:8dd5 with SMTP id v22-20020a17090ad59600b0026b54618dd5mr7232832pju.42.1695060631164; Mon, 18 Sep 2023 11:10:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695060631; cv=none; d=google.com; s=arc-20160816; b=k34/5mLaOtcB9IcKp47ZOCy8cJTZ0JJO0gu+y1C9fmNhnBVHsSt6kKMyD8J+ginxyw JKjZQhmThz+vLkuhzq2VLK4zlWY/KsN5DFRG5nZZPhgHvSc0mI9xLpUZbPb24ykcdo7o BysFFAFusQSsUyl0OcBy2iLEl0K3wkGk9wJ5LsIsnadZkOVNLGheuEnV3uceqhv2cagK vTxKHdYlxwmJsxVNtsAyo+9LkflN436uvnoSUhBKoiP/e/FeP9V/yxKjYiM6Wn9F+xb9 UIMgYBFwS+sHl8PwjHySnm0WxR1M4ibmDoPF9U85fGqRfNho5lBkiooDNufcY8hWq+1/ 24ng== 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=cNTm+n0prBabhDiuzBL/lY2C7Js3MHb27iGHM7ixly0=; fh=94jdO6OBfKQL8IhVTfYJWkMaoDyiE6Q4TbKuLNdcbRI=; b=XrtbrPxpxpt+XPfMM4gxzrWrq5gUikPTmkneUH3MQomSryt3V6+OLZYQfOE9JwvJo/ Dfq5oR4R1s4w+APtsW+dL7H4fwdtBYRY+8baTEq8XP9tFIdKzUGsblsY7gFT2418hL5/ /6ElwMoEky3F2T3xR4ZyG391Bz7POFF0xtB+1fDHvB3RlHHiKwFUJ+dpxHk5/EwsWJs9 7XF9rUUMOMr/HUvqN2G1SVAmDPu33FBu4QesagV3AjrwLdqfTa0UVg+ZMID0VhyDjmiK 9PHszvpWWXluJQuM6Fya3ciZ6L/VgLijwqFhHYCnECZluGFT9nRH9khGnbSQRAK5rFUI kl+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@embeddedor.com header.s=default header.b=LK0LfAMn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id kx10-20020a17090b228a00b002768ab837bfsi625941pjb.48.2023.09.18.11.10.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Sep 2023 11:10:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; dkim=fail header.i=@embeddedor.com header.s=default header.b=LK0LfAMn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 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 morse.vger.email (Postfix) with ESMTP id B3109801F983; Mon, 18 Sep 2023 10:57:37 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229969AbjIRR5c (ORCPT + 99 others); Mon, 18 Sep 2023 13:57:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54414 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229473AbjIRR5a (ORCPT ); Mon, 18 Sep 2023 13:57:30 -0400 Received: from omta40.uswest2.a.cloudfilter.net (omta40.uswest2.a.cloudfilter.net [35.89.44.39]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 18450106 for ; Mon, 18 Sep 2023 10:57:24 -0700 (PDT) Received: from eig-obgw-5002a.ext.cloudfilter.net ([10.0.29.215]) by cmsmtp with ESMTP id iH7Uqui4fbK1ViIUsq2HVo; Mon, 18 Sep 2023 17:57:22 +0000 Received: from gator4166.hostgator.com ([108.167.133.22]) by cmsmtp with ESMTPS id iIUrqbcxnbPRviIUrquNid; Mon, 18 Sep 2023 17:57:21 +0000 X-Authority-Analysis: v=2.4 cv=IeuU5Ema c=1 sm=1 tr=0 ts=65088f81 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=VwQbUJbxAAAA:8 a=x2q-Q_5hSYYoW0-ZbgkA:9 a=QEXdDO2ut3YA:10 a=AjGcO6oz07-iQ99wixmX:22 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=cNTm+n0prBabhDiuzBL/lY2C7Js3MHb27iGHM7ixly0=; b=LK0LfAMnALG/1sjjcruihPHoEZ OTtfwOPkW6PUJGAWj2eXVP3UjJmv7lDTtICahD2p7cthn3tjspNMk9k5Pzgq9IWSzoD2Xo+Qg+BtQ lehOsScxQXPCaf+vbHtHOlImY4Ldkm2ug2CHM1o80BPt1u54UMyaudk2EjMDBEW87B1egQrrJ0wrs IV+W7WrVmn+M9J/f4j3YL1vzDARkCBHUynsPaWBc+L44UTXBhYFuNgoVRDzkaL+tJ4j4efn2hAbCS MmF0FJ2+Xd9NK92h8XxjCP1Hpfw+nCFSTkWUu7KJhJnbjNpQe1sqDvlI89GdiF6bIU48NsAzt8e1j 2l0mLBiw==; Received: from [94.239.20.48] (port=59520 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 1qiIUq-002041-0k; Mon, 18 Sep 2023 12:57:20 -0500 Message-ID: <93f70187-3992-ee22-843e-e3912d169875@embeddedor.com> Date: Sun, 17 Sep 2023 19:58: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> <4067fb33-2172-b132-e8c4-0ba21c31b42a@embeddedor.com> <20230918124120.GE103601@unreal> From: "Gustavo A. R. Silva" In-Reply-To: <20230918124120.GE103601@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: 1qiIUq-002041-0k X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: ([192.168.1.98]) [94.239.20.48]:59520 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: MS4xfPzy2Ob4l1zcaw5N5xnc7gGzPZWqqlCWF9/XXaeHBXDA6U3maSr7kJNP22HRkJBKP/vW65GvNzuWctDHLITnMvGhPBEqnrxKeRCoHKeZ9/ChNVIGZ6KZ wMjH0CdBz+UUV+968ryfvxfhOdR4NIqz99xDceelBgWYckLaJeykbGP1fHpLGMYRw0Yb7LTbu1O83zYwOCC8N4XlXxLESApXspQwHZt3qedSIT5RDyxwQhqt X-Spam-Status: No, score=-1.2 required=5.0 tests=DATE_IN_PAST_12_24, DKIM_INVALID,DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,NICE_REPLY_A,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 morse.vger.email 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 (morse.vger.email [0.0.0.0]); Mon, 18 Sep 2023 10:57:37 -0700 (PDT) On 9/18/23 06:41, Leon Romanovsky wrote: > On Sun, Sep 17, 2023 at 01:59:26PM -0600, Gustavo A. R. Silva wrote: >> >> >> 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. > > Please sent one patch for whole drivers/infiniband/core/ folder as your > title: "RDMA/core ..." suggests. OK. Done: https://lore.kernel.org/linux-hardening/ZQdt4NsJFwwOYxUR@work/ Thanks -- Gustavo