Received: by 2002:a05:7412:3b8b:b0:fc:a2b0:25d7 with SMTP id nd11csp2621208rdb; Mon, 12 Feb 2024 10:30:31 -0800 (PST) X-Google-Smtp-Source: AGHT+IGyKC9fahBAi2tVX/uzTmq11BUsPdt+ukQnMdyJ7+zNb71lFSNpQ3TXgh6ZIQ/cfqoO9HSK X-Received: by 2002:a05:6870:1702:b0:219:ac01:d340 with SMTP id h2-20020a056870170200b00219ac01d340mr9923301oae.28.1707762631635; Mon, 12 Feb 2024 10:30:31 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707762631; cv=pass; d=google.com; s=arc-20160816; b=mviXRbGtXziL7/OOMlaVGA/oP4H4DZDmOLK5MJYbt0LN7MW+pAMG5pxPVCdhDlZx8F gHgqDR7ziaJFOkftvM3vv3HnVjpDS3GXsNYUwLtYJPPkRCM2TJaFuSI3LVyyjzoneu47 4knPH8cXQyjlIEv2+TVjJKX3eepBoOVm4KZvfVAJAGrpODdZq06IH5hfjTsyYZ0213Xj xV85shf7nwp7xtqOglcPkGeN6oXC7sqPX61CPdC11U4Iqmoz408nZq1026foujinzu9y ugMrdKFpjU8rR+Zl8KxC/SjIAOAWVZFURrBVgUtdN+jE6sN4lnXn+hfmbCGO4uaFIz5+ MOew== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=N61bSTpFZ2e+PLuAfqmvguTh3fa1HE/2EqLDbYjvwcM=; fh=5qfGD8AAuumtSwN094sK36QXpdTZimjVCTUaZn/oLms=; b=azhFTC1N64CDn5PbkxFCjTTdruFv2ShCCo1h4B3mHPRnSLTGWiWOK2ElZ+chLw3UBz 5OwOkVM/bd/5qZfap/i1rX+HVdMd0q/zSsFG91dyRMkmR5941Z4nXt+VcbDLXZsXSoEd V/IFyFVkCOVp/0P2/sopvSUa031qM6cAAYucSKYYArAWs2CYReFchcBS+Mnvp1KEqApA x39tKkJ+fyeZP79ovP7giOjMzRTRXsOIIPWKQ1YCiadhdOvDOHHPBfWSzkokn/5j/wa4 9rRe9kBoctCg3FSXYbgrljOKlZzR/v22MQW2iWDR1n85sV4DU9p/8JVkIbXlQd61gyzY N28w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=FqvSun7R; arc=pass (i=1 spf=pass spfdomain=chromium.org dkim=pass dkdomain=chromium.org dmarc=pass fromdomain=chromium.org); spf=pass (google.com: domain of linux-kernel+bounces-62181-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62181-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org X-Forwarded-Encrypted: i=2; AJvYcCXqBi0H5V5nP8VstwGz07luaCv9LHDmvkXyMtgbSIubWRXY4A/JBGA0Yeyzfed9Kz+1CdivGbW9s40wDUaA8U3SdMlHoKRAxcbXIFgZ/A== Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id p23-20020a05620a057700b00785bfc9d281si6103971qkp.261.2024.02.12.10.30.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 10:30:31 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-62181-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=FqvSun7R; arc=pass (i=1 spf=pass spfdomain=chromium.org dkim=pass dkdomain=chromium.org dmarc=pass fromdomain=chromium.org); spf=pass (google.com: domain of linux-kernel+bounces-62181-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62181-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 614FA1C22098 for ; Mon, 12 Feb 2024 18:30:31 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0D63F40BE0; Mon, 12 Feb 2024 18:30:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="FqvSun7R" Received: from mail-pg1-f171.google.com (mail-pg1-f171.google.com [209.85.215.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9C44C3EA69 for ; Mon, 12 Feb 2024 18:30:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.171 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707762621; cv=none; b=d1hoNqn7uvXC/qoleupYS1SeootmExGXZfS6gbTi2RTtMjZ8/PFzqHM+hLM7r801FZDqKLETE4GiJ2PlYPbHTP86XTuBpaf1J38lAO0kp4vpKf7Jq6hQIg6X9CDPeH4OtET6JamHRpGKQRbuJ77g5YPE9cksBfyv/ipFLUuwQ+s= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707762621; c=relaxed/simple; bh=ljd3GW0VNxjxHS/gV3+xS6+IJarrBJeh1idhgkjc/cE=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=YuEjnih5vWj/cthLVdNIkOShHbZvpOkAW62sTBssg31ECk0eN/U1FRMaV/49UC2n9T4TX6R2lX3yprwuJN7CY2uN2OcrVWl+Pxuw+v9Kd1oVyg8GJNrbcTxO6kJKLCC0sa28txpN7sORTZG+/xwD6I63y84ASsYCQzDyCoTpaNw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=FqvSun7R; arc=none smtp.client-ip=209.85.215.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Received: by mail-pg1-f171.google.com with SMTP id 41be03b00d2f7-5d8b70b39efso2924508a12.0 for ; Mon, 12 Feb 2024 10:30:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1707762619; x=1708367419; darn=vger.kernel.org; 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=N61bSTpFZ2e+PLuAfqmvguTh3fa1HE/2EqLDbYjvwcM=; b=FqvSun7RXHL/H6ytHAgAmKWDsz3oGmPva50Q6H19bG8jjIIOx6FxGGXp4ixLRgCPaZ MeoscEAT60i59UvzXbazQm9s4td6kToCv/VrgMj2porqbI7enwKZWI2PKD/EpUfnl9de QDgISkSoe7Jziqcf89i6BnKQD1lMeNymJ3tAI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707762619; x=1708367419; 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=N61bSTpFZ2e+PLuAfqmvguTh3fa1HE/2EqLDbYjvwcM=; b=LI0RONlbD2M9dWUX1JTRYLCBLGHt9uwCus+J6lrTcQQTlVgJKYdm5jGzNZAU++LiF4 tewVTh/SFdQfrwXhmIako62IveNEJ77FSCviLd9JaH6/b8pJXEehH0MY+/HJedQEuUX4 47WlpfwgVzu7c9Z/lGY3knvNtes6W+TstiHiiVOCwatrEUky/c+V3ud05/hEHt4ZvI4O Iz0R+LANnl/2/rfLigf5x+hX2pIxe7cM0PF+EvPuFQo0XEmc2NHt8MwGK7T6y2q5Q9fD tPG3QRu+wGUgMsYJF9afrT+t3aSFFv06NRmpjEqFLjLMC1nAeHq076Hljdxgzw71cGk4 /FAw== X-Gm-Message-State: AOJu0YzXHRADcS6LIriZGTbx+BXcnN0+JB+yMIgDL//dhvoqgVbBPho0 zxKEq7Za7SuSq4hTx6FJ3lpLTSXywRRT24R+N7ZpN+9cmr4bflwk5dqMuPjCeA== X-Received: by 2002:a17:90b:1054:b0:297:1779:84fb with SMTP id gq20-20020a17090b105400b00297177984fbmr3738633pjb.43.1707762618832; Mon, 12 Feb 2024 10:30:18 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCWqzXReP3IYediOTpA4Y6OC6ft/joUK+DbNmZ8ShuoIpBTd0/KboIdivDaLOt5vZNYxKdzl+WOvG4XORuhYoNyibYUN9VXp/wkGK0yP4JRewr1UQUplInabN+LEwmrssN1JUWssJN1fsZZw8YsVjHSb62XTqJrpSQdZkEeLCvdtji2RL0fv1JEt9orngC4M0AHbgtdjwRkfJ+3Yktv6qug5esufKhfNneR0h4I+IuajP7KsRdy79020cVEeh0MT+3vHybMHJrxUKak+Y5gkO5ZeqEakCh9ObI+a Received: from www.outflux.net ([198.0.35.241]) by smtp.gmail.com with ESMTPSA id ok5-20020a17090b1d4500b0029703476e9bsm849739pjb.44.2024.02.12.10.30.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 10:30:18 -0800 (PST) Date: Mon, 12 Feb 2024 10:30:17 -0800 From: Kees Cook To: Erick Archer Cc: Jason Gunthorpe , Leon Romanovsky , Edward Srouji , Patrisious Haddad , "Gustavo A. R. Silva" , linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: Re: [PATCH] RDMA/uverbs: Remove flexible arrays from struct *_filter Message-ID: <202402121026.0AF90DBA@keescook> References: <20240211115856.9788-1-erick.archer@gmx.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240211115856.9788-1-erick.archer@gmx.com> On Sun, Feb 11, 2024 at 12:58:56PM +0100, Erick Archer wrote: > When a struct containing a flexible array is included in another struct, > and there is a member after the struct-with-flex-array, there is a > possibility of memory overlap. These cases must be audited [1]. See: > > struct inner { > ... > int flex[]; > }; > > struct outer { > ... > struct inner header; > int overlap; > ... > }; > > This is the scenario for all the "struct *_filter" structures that are > included in the following "struct ib_flow_spec_*" structures: > > struct ib_flow_spec_eth > struct ib_flow_spec_ib > struct ib_flow_spec_ipv4 > struct ib_flow_spec_ipv6 > struct ib_flow_spec_tcp_udp > struct ib_flow_spec_tunnel > struct ib_flow_spec_esp > struct ib_flow_spec_gre > struct ib_flow_spec_mpls > > The pattern is like the one shown below: > > struct *_filter { > ... > u8 real_sz[]; > }; > > struct ib_flow_spec_mpls { > ... > struct *_filter val; > struct *_filter mask; > }; > > In this case, the trailing flexible array "real_sz" is never allocated > and is only used to calculate the size of the structures. Here the use > of the "offsetof" helper can be changed by the "sizeof" operator because > the goal is to get the size of these structures. Therefore, the trailing > flexible arrays can also be removed. > > Link: https://github.com/KSPP/linux/issues/202 [1] > Signed-off-by: Erick Archer > --- > Hi everyone, > > This patch has not been tested. This has only been built-tested. I might suggest doing a binary difference comparison[1], as it's possible that "real_sz" is being used to try to avoid trailing padding on structs. I wasn't able to trivially construct an example, so maybe I'm not understanding its purpose correctly. If, however, there are cases where offsetof(..., real_sz) != sizeof(...), then I would check two alternatives: struct { } real_sz; but that may induce padding still, or: u8 real_sz[0]; which would be a literally zero-sized array, used only for addressing. Or, these can be left as-is, and the "flex array not at end of struct" warnings can be disabled for these targets. -Kees -- Kees Cook