From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E78DFC001DB for ; Fri, 4 Aug 2023 08:29:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233330AbjHDI3n (ORCPT ); Fri, 4 Aug 2023 04:29:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59448 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233173AbjHDI32 (ORCPT ); Fri, 4 Aug 2023 04:29:28 -0400 Received: from mail-pf1-x42e.google.com (mail-pf1-x42e.google.com [IPv6:2607:f8b0:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5A7E94C2D for ; Fri, 4 Aug 2023 01:29:03 -0700 (PDT) Received: by mail-pf1-x42e.google.com with SMTP id d2e1a72fcca58-686efb9ee0cso1653542b3a.3 for ; Fri, 04 Aug 2023 01:29:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1691137742; x=1691742542; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=7Lzp3ZkP17GT5v8YT6Q8PsfBgtBwszbchO+h+FYy3w4=; b=gz/zjWqM3uu/9WJf25raD3sRvhSeY7TJLSIXkLtJ5Q9CbU2Fg9UlZPPg31KTkF5Say h+zm8lyW0sWyiNhFbYjYNzovIj483N3sguC+1cDwqAfMGZm5likBeIBTtFQiZx7wjjw/ 6I+iYb810hAMUm38IIs4yM3G1df4qSUj79J1Q= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691137742; x=1691742542; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=7Lzp3ZkP17GT5v8YT6Q8PsfBgtBwszbchO+h+FYy3w4=; b=XuAz8Pm67DbSKGwBqYATmIHIb7+gbc6wwo6SEuW97VhwOn++gO4ftLYqZ0rGcyqpfY JrjglpnxhSvLJrz/19/KwJC+jL+CICL1mZXBzbqntvymnF4pJ76Qip1a8HDXrZj4G32g sfsQEoZMzzTkg7eBjBB0SBjHKncP+hQ/LiwEPqQvhGBIfTmy3HwpWJGXAe4IfwJ/uBp1 dTA5KmOtPHp0DupcwVMV/Ef6BShwRS8D3as45NN4z0u1coLTCZGfawYj3M1ox58pOOkp BOyLSa9bQ7Jz/bASYofsVWDfjCMNIrlxCP+Mvdbge5HH13acaXmAJ9tw7JzyMyFzATyj IkPQ== X-Gm-Message-State: AOJu0YzbwdcGSYFrq1YBvDzo1+ftaP8+l8Yl4ePUop8wcIWySXQCJGBJ Rmai2apojGz95FKU71MEw+WHxw== X-Google-Smtp-Source: AGHT+IEb8NJZukwkOLv+8X4gGyv5xuEMYnojzUqQ9CiQkM6If6hOvgmAM+Cd3GLl5BacdLQgN3RxVw== X-Received: by 2002:a05:6a20:244f:b0:138:64d4:b040 with SMTP id t15-20020a056a20244f00b0013864d4b040mr1274551pzc.54.1691137742585; Fri, 04 Aug 2023 01:29:02 -0700 (PDT) Received: from www.outflux.net (198-0-35-241-static.hfc.comcastbusiness.net. [198.0.35.241]) by smtp.gmail.com with ESMTPSA id v19-20020a62a513000000b006870721fcc5sm1101722pfm.175.2023.08.04.01.29.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Aug 2023 01:29:02 -0700 (PDT) Date: Fri, 4 Aug 2023 01:29:01 -0700 From: Kees Cook To: Alexander Lobakin Cc: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Larysa Zaremba , Andy Shevchenko , "Gustavo A. R. Silva" , netdev@vger.kernel.org, linux-hardening@vger.kernel.org, intel-wired-lan@lists.osuosl.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH net-next 2/3] virtchnl: fix fake 1-elem arrays in structures allocated as `nents + 1` Message-ID: <202308040128.667940394B@keescook> References: <20230728155207.10042-1-aleksander.lobakin@intel.com> <20230728155207.10042-3-aleksander.lobakin@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230728155207.10042-3-aleksander.lobakin@intel.com> Precedence: bulk List-ID: X-Mailing-List: linux-hardening@vger.kernel.org On Fri, Jul 28, 2023 at 05:52:06PM +0200, Alexander Lobakin wrote: > There are five virtchnl structures, which are allocated and checked in > the code as `nents + 1`, meaning that they always have memory for one > excessive element regardless of their actual number. This comes from > that their sizeof() includes space for 1 element and then they get > allocated via struct_size() or its open-coded equivalents, passing > the actual number of elements. > Expand virtchnl_struct_size() to handle such structures and replace > those 1-elem arrays with proper flex ones. Also fix several places > which open-code %IAVF_VIRTCHNL_VF_RESOURCE_SIZE. Finally, let the > virtchnl_ether_addr_list size be computed automatically when there's > no enough space for the whole list, otherwise we have to open-code > reverse struct_size() logics. > > Signed-off-by: Alexander Lobakin I remain a fan of _Generic uses. :) Reviewed-by: Kees Cook -- Kees Cook