Received: by 2002:a05:6358:700f:b0:131:369:b2a3 with SMTP id 15csp3338802rwo; Fri, 4 Aug 2023 03:25:27 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG7mDqJaqVNMcwpdSxVaAnS+VfcZXBI200RFSsu0lyLX41zELHF4dY5QGs075+Dw5qianHd X-Received: by 2002:a05:6870:c20d:b0:1bf:1346:63e with SMTP id z13-20020a056870c20d00b001bf1346063emr1169504oae.49.1691144727416; Fri, 04 Aug 2023 03:25:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691144727; cv=none; d=google.com; s=arc-20160816; b=q60t6B1vJandZjmaIpuigpTfCPE62dkUxh2876osoXExdw2vlD+AFFbVswZBZonU+z EcGYWN1v+5TiYFMMJXu0parnONmBhL/nbLb8YlWaRYcPofYkfceAzhwH4DweFJBsI8Y1 jkrH9Q2axsZngJwkqwtiJjGViU6R4LRyI09KkZu7MgCmiJVQgh5nP3W319U9tYqiDJz/ P9B7UrO1dvMJtG2TXhn+vLSQUi4Ppl0uFiVmDrZnV6TzyI/8Jx9Kc0WpEkynd0L8s0rC cIPTyN9YLrbeRMs8SPqQnkY0UjNiEdv+g1nKOfqCgk0KZd3iVeN+gCozNrM2Us/46R1X wJvA== 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=PUS4uE91dvG7NiA03WNNZdSwC3Poo9mFt4/nET0m0dg=; fh=rnxgUeED1PuDkKleRgvzY4huzu0vsEb9Vf219P/zV8Q=; b=BgrouhpYraTREsjblV0WubADQQZh5tokIoWLdcM49kcMCOgdG0Ri3H2MHa5PLfvuRm XJoZO5eXUnsGzIYaMuUjnYAsdJZlkzXqXgodp17oIwWpTR477jDzuzbgIWl+YmnR3RRu ahAGuYyXhT4a9iQ5pODKv1rNSqgw6cS2ipXlYaYNllR+tMMjXrguHEOKQ8WmHtGzHm8+ 364wjVEX99unpznfxLUlvCRI+n0E++1TdA5TjE7x7s1d/17cKGRrmsfFDnlRBWclfvD0 NhK6F9ilwz9FID5J+m1ZgT9U+qu1owQ2hPgxGCAzGjrr/1G6bhA/7QCx0eQAvGHlAvtH 7MzQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=S89d4M3D; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g9-20020a17090a290900b00263baf744dfsi4922419pjd.139.2023.08.04.03.25.15; Fri, 04 Aug 2023 03:25:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=S89d4M3D; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234692AbjHDI2N (ORCPT + 99 others); Fri, 4 Aug 2023 04:28:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60176 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234587AbjHDI1t (ORCPT ); Fri, 4 Aug 2023 04:27:49 -0400 Received: from mail-pf1-x435.google.com (mail-pf1-x435.google.com [IPv6:2607:f8b0:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 911394EC9 for ; Fri, 4 Aug 2023 01:27:23 -0700 (PDT) Received: by mail-pf1-x435.google.com with SMTP id d2e1a72fcca58-686fc0d3c92so1330395b3a.0 for ; Fri, 04 Aug 2023 01:27:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1691137623; x=1691742423; 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=PUS4uE91dvG7NiA03WNNZdSwC3Poo9mFt4/nET0m0dg=; b=S89d4M3DnOXOCpVn6+SsXsaln+b1CDkwN+Wc8iZfQIJp/5Mg31YkipDnIpZFJ8WT22 6KDDkE6N/Q9+Z1OSckAI2AGnB0jNWeeiAnARi+3bxQCjA0MVKMlkSTzRdpiegjDdjzs9 alwHeWzqeeo6oSaTxIIaxPIaZMlivjqD7xdio= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691137623; x=1691742423; 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=PUS4uE91dvG7NiA03WNNZdSwC3Poo9mFt4/nET0m0dg=; b=ern6O10/1sGun6iD245AS9whQMo9pvCv+vn3/pI1LbbJIBfk4C9SSRmyeJcNrAdBAs oyF2AS6P/xyFKIzwv1FRtC0ymS5HWapmWkp72hyrwav2mvK8d9QHOC7WwbSaT/Ab8Qdf c0OVmDaPEpG6OsBt+Z8LH/cFd2EifMlLdzgCDSSyI6Z41uxK3YgKjsn140FzqqbLHIxj Trs+P6TyNZkCUnZWXFbej4jcSjB2puS5egTPXEgCs+d5SdzILUvOeq7hCmlQF2bttObt MLmXsuqHSaUsTkk+XQ0PkZwmELlaUpFQdLdTO4euCI9Wad3JV2A8IH9cas3YGqVKDfvM L6bQ== X-Gm-Message-State: AOJu0YzJFeLO7pzPCf3U/MQPhnE7lT0vAFK34AcXzfash9uVSlyikAsP u28bqSZF7s/h49ift72iG7qvpw== X-Received: by 2002:a05:6a20:8f02:b0:13f:8855:d5a0 with SMTP id b2-20020a056a208f0200b0013f8855d5a0mr1071535pzk.50.1691137623268; Fri, 04 Aug 2023 01:27:03 -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 t14-20020a1709028c8e00b0019ee045a2b3sm1138162plo.308.2023.08.04.01.27.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Aug 2023 01:27:02 -0700 (PDT) Date: Fri, 4 Aug 2023 01:27:02 -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 1/3] virtchnl: fix fake 1-elem arrays in structs allocated as `nents + 1` - 1 Message-ID: <202308040126.ADDA993@keescook> References: <20230728155207.10042-1-aleksander.lobakin@intel.com> <20230728155207.10042-2-aleksander.lobakin@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230728155207.10042-2-aleksander.lobakin@intel.com> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED 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 On Fri, Jul 28, 2023 at 05:52:05PM +0200, Alexander Lobakin wrote: > The two most problematic virtchnl structures are virtchnl_rss_key and > virtchnl_rss_lut. Their "flex" arrays have the type of u8, thus, when > allocating / checking, the actual size is calculated as `sizeof + > nents - 1 byte`. But their sizeof() is not 1 byte larger than the size > of such structure with proper flex array, it's two bytes larger due to > the padding. That said, their size is always 1 byte larger unless > there are no tail elements -- then it's +2 bytes. > Add virtchnl_struct_size() macro which will handle this case (and later > other cases as well). Make its calling conv the same as we call > struct_size() to allow it to be drop-in, even though it's unlikely to > become possible to switch to generic API. The macro will calculate a > proper size of a structure with a flex array at the end, so that it > becomes transparent for the compilers, but add the difference from the > old values, so that the real size of sorta-ABI-messages doesn't change. > Use it on the allocation side in IAVF and the receiving side (defined > as static inline in virtchnl.h) for the mentioned two structures. > > Signed-off-by: Alexander Lobakin This is a novel approach to solving the ABI issues for a 1-elem conversion, but I have been convinced it's a workable approach here. :) Thanks for doing this conversion! Reviewed-by: Kees Cook -- Kees Cook