Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp6151088rdb; Mon, 18 Sep 2023 05:52:29 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH43h1nLx5Rb5zXcX+CUzdjjvBP51P2eofQuQ5CgTwaOCZFdXC6gvtJncwS1OAGFx7nl6J2 X-Received: by 2002:a9d:62c4:0:b0:6be:fd1c:c228 with SMTP id z4-20020a9d62c4000000b006befd1cc228mr9407449otk.1.1695041549338; Mon, 18 Sep 2023 05:52:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695041549; cv=none; d=google.com; s=arc-20160816; b=PiZZ9PjKeGIjzhsO0Z75b7DMGWIF0ZZV/Sag8PGOJ/2S8cWfreeKO6FDuafX21M+3y hES0gqKtXpRGof0yPzpFUtOtuCyWnqz9HUZIbcTKm83ZiMy9Mnn+269eCzZR7updh+3I mzY2AfokyNswtG2H3XOyPUbTMlUvdZGnF5gfjJFq0x8djnLb9qGU8EVxMvT9Do9mOJl5 m6Wu+UE5ZCh6S+S9774zYLWQKHi4R2qJrHUCI3vZe10plUsjVkE0y/zZ0g9+4AXebH9E H20e1KjYVB0rogpRMyTqZ/T9fksuAsbvBg+MuKbXHReUB77IfLYUIq5DvE5+Iq/slJLf c70Q== 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=a6Qqag8fcnjmG16vMcgCY9ti/E0ZQBEBdPy4vzUAFFY=; fh=BvWMyIpB0auEmHZdNNZMtM50aCQ6CFhK3WUpXuNjkbQ=; b=tVH5M0We3b1PiXgDi2dSXA4xDD3SuhTAeaY7sF11eQ6nF1I/iYvLBnLEkHxm1GWpoA /+DShng/wuph0ucR6fJ7sEynPFJq2hmzducDtdqv9AsvEYHIBWwJ4/CygY58lj2UheDk MX30gUgpFTkuAb2YZsTv+4TEF7VJhEE8dBIyEAo6gekAfeSTh02rpk6u0K6qZdwf/xwY Sd0IP/5bo7B6o0zt9noT36CgaeFNO8FKtatUmahjnqNZtF5+TMwSxT4vVnSaMpcH1wFc 6uwXwYi0qmi7Yrf7DXc7BWiga74BIcYMTIpZzCU/Hc9EUc6i55S4dPU6MaoCJolJEp3M NvzQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=hnxoIlQa; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id s21-20020a63af55000000b00573fd75b486si8169291pgo.658.2023.09.18.05.52.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Sep 2023 05:52:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=hnxoIlQa; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 05F29804C619; Mon, 18 Sep 2023 05:42:32 -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 S241386AbjIRMl6 (ORCPT + 99 others); Mon, 18 Sep 2023 08:41:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50220 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240412AbjIRMla (ORCPT ); Mon, 18 Sep 2023 08:41:30 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 97BD99F; Mon, 18 Sep 2023 05:41:24 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 74DCEC433C8; Mon, 18 Sep 2023 12:41:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1695040884; bh=L0kx5zWcm3nLfzQqEDKgwBhllqI/l0iyZyQ1GJ/RMc8=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=hnxoIlQalA9WBLb/+g0l4ZE42Oslamk1PsylnXOYXKwDy6+IO4pQAFwSBbjHvj5UX wHLpfQ5vUtOEOd57dH1GD8J/f/1NeSlzgo85xHswPejKHcbu8nxJPkcgCiPa4ShPgL azkergikZqdxrdsPKIRVeBhGGESO3ePD133FZHob8dqQtFDZjNhvdVGTigUSDAyxrU qZZ0T73uKBFPRXgYbcfRRpV5ExIm/DrCt6qQOiSQ0qhEJEZH/U6rRlvzKeQWC9DVeJ hbgAKxOZKiy3P63R3fx/QdaTdGEHfDWwYeXm6FDJQ3Rn+fy0etINQW8ElEw/JAGj7b jl4o1yKUIMxNw== Date: Mon, 18 Sep 2023 15:41:20 +0300 From: Leon Romanovsky To: "Gustavo A. R. Silva" Cc: Kees Cook , "Gustavo A. R. Silva" , Jason Gunthorpe , linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: Re: [PATCH v2][next] RDMA/core: Use size_{add,mul}() in calls to struct_size() Message-ID: <20230918124120.GE103601@unreal> References: <202309142029.D432EEB8C@keescook> <2594c7ff-0301-90aa-d48c-6b4d674f850e@embeddedor.com> <20230918104938.GD13757@unreal> <4067fb33-2172-b132-e8c4-0ba21c31b42a@embeddedor.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <4067fb33-2172-b132-e8c4-0ba21c31b42a@embeddedor.com> X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS autolearn=ham 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:42:32 -0700 (PDT) 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. Thanks > > -- > Gustavo