Received: by 2002:ab2:3141:0:b0:1ed:23cc:44d1 with SMTP id i1csp624258lqg; Fri, 1 Mar 2024 16:17:11 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWZ73BugCQrobl3QAGX7M/9uphiGzrHqZtuxgkSKlYhiaYbLypAq2VBW6mQnm/05NE1MPVc1nNm+fEkk4sAh/wF8ha2zrHMn18H1E486Q== X-Google-Smtp-Source: AGHT+IE54FdrsSvhCOAxlOg62alKS+RGkfXWTAHS0kvDAzZIjNUsRhYaCIOZt6RNUYZ3aJxWqnEJ X-Received: by 2002:a17:906:6817:b0:a40:189d:c5bd with SMTP id k23-20020a170906681700b00a40189dc5bdmr2074449ejr.13.1709338631048; Fri, 01 Mar 2024 16:17:11 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709338631; cv=pass; d=google.com; s=arc-20160816; b=TEQh0ZhTbF/M99CW9edKt6sd5o/6Zh88SzeUS3d+4QTT9Oy6XCWBZ2m24ICL/e4qKD ruJuknbih+9rn0GwGRtWJ7l9i/KpvxXw7B3dPFhMbA5bDqDsHzRapXsTCWQo0lr43CKW nwLkb97cOcrsTZ7HHmsGVr0lLbpTPbwfxgdoYb5eyZaGUkCczkQY0IgFbC0aglUFA3q7 VScvXDbGdYFvS9LMrvpRLqatfwoDH5P+IlkX0Y++x0Z3SsY3TTR8HPhsai/42TyQ9CJA f4Xxa4LmUh+s1UNmntJOYS1plfHjK+E70SlcUx3Anqt7tFRYEM2X9SFu0C1LW9hJl85F /87w== 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=FF4IiXm7A+T8Frcn1xhwOocDaZJ/4WKQwj1y8lgr4F8=; fh=BhoQxVQifjTH65fc0XLCRYtESuthlI0Eo1K8U4TLZVU=; b=Jf0AHKM+kbpvRYnhlGfn/E3FXKLb1MTIwE0z5Am54DDb4NE8wjVnnhGU7of9f2aJ3U BJCZCst+sPlAE169jAfoLgCfJYwRBmhOJxRkSvaJ8RHadWWZRxxCPEw79/00RaF4c36H zVH+dPLwq65ivR4siShEJE8MQeGvQ+u4c/a2tAjMJEGmwu3RrDp/ZgkniouhaH8rbWaD soDVJuJYdVDC0g8qzgIg0/KJIqZnIpv6ZiUP9EUogxI0jDXXe4DaWINtmZtwpjcHxHAp Rv+Py1lgH1/C1YO3UUo3JPJQrGGXOSOZmN22kpO1xQHGZlgLqXx88Y2PmDdy9jJo66U8 uURQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=gOkPtCKn; 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-89256-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-89256-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id w14-20020a170906130e00b00a448f2a95e0si880323ejb.226.2024.03.01.16.17.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Mar 2024 16:17:11 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-89256-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=gOkPtCKn; 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-89256-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-89256-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 9E4951F2179D for ; Sat, 2 Mar 2024 00:17:10 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DA5351FB2; Sat, 2 Mar 2024 00:14:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="gOkPtCKn" Received: from mail-pf1-f169.google.com (mail-pf1-f169.google.com [209.85.210.169]) (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 965B010E6 for ; Sat, 2 Mar 2024 00:14:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.169 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709338490; cv=none; b=Wb6zDeOj7tzxFmyrFXxq+b9nNm8k/jGGcntpDNLQlPo9VwWulEHanvMjiEung8MHrR0HCDVe6ve/EV01mtmxtDeVsKI18BGQo4WAMxM+kG5LA0HP+AuVNgaFBRoJpj0VPJHhexaB7/nioi+j+5g8e/Xb9JHMFbVFYONeHwrg668= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709338490; c=relaxed/simple; bh=J9RecM11zoh+0vCDfzEiQKHVBWqECX6ysWPdITOtwpg=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=n2ubKgqnH15s27loEP0dtxVAyHGaK8LainqeffrS0sl6II7zBtqocfdjJnVrc25BiUMtDX7zGzvTLvw6kfX5YegFSipC7rVAezutgzicgOjcad2fjw2s1r2zfv63vgOOf7+gpu5eBRbBp4pe2e9ryI5xFCE/bjSUWXfuqu7Y6tg= 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=gOkPtCKn; arc=none smtp.client-ip=209.85.210.169 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-pf1-f169.google.com with SMTP id d2e1a72fcca58-6e5760eeb7aso2370592b3a.1 for ; Fri, 01 Mar 2024 16:14:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1709338488; x=1709943288; 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=FF4IiXm7A+T8Frcn1xhwOocDaZJ/4WKQwj1y8lgr4F8=; b=gOkPtCKnpB1O7rMJ+Q7MkzCYfrC0Wn69S0rpH6FJKIwtblME4dUFVbWIl4EddOq/dh 3CdOIeZ0NkfIpc89Q2u4BDeZ2B9azSNDl9OOPCoeLU/qTTvQTHj8X0O1nn40rqm8n7um p9oXDZuOFCJDgP0i/u1VtIg4d6ymgM4cN5AnQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709338488; x=1709943288; 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=FF4IiXm7A+T8Frcn1xhwOocDaZJ/4WKQwj1y8lgr4F8=; b=GyR4QGDJr55CiU7d0P+ls9dblc2x2EiHMd0y9tY/uuoTI2j0V7Hetkw2ptyrTgeEiJ ZoipsbFilUPrJVurcuietz0vyvVB/jm/9AyjJaYCeG2n+GFF61qNDIXXTQaAcGJJzcfi 9bvL03+XfrCwk1WVDIKwanroIJGi9jUrBTQ0pnOgt+IaQ/wyq4Thqf95rcRptzdC0Qbd 812ly9/Cj3zKMa+jnrR3eIihen4ja8wzKKKSuLA7isiZdv6/DpaCQlwutN36sUNhMvM3 uaHpX4/U4Z1BT5sDWabABfN3eoZcmYd7sxSv/hc5MKCjBta79f2MX6430JWWYKX0o6JK prNw== X-Forwarded-Encrypted: i=1; AJvYcCXnBZtMsjwXGtaGZsQdrmqgOtK616SPZnrw15j/mRGjgltHefIRdNN6C0T0hzCAJUDfxBpke3zvpmaONP181NDq1JF/TcAdLs4vgcuO X-Gm-Message-State: AOJu0Yz6eKSBrqoQZUMaX+mKHxSxt9Nr6h/1ErE/hRcfKlKbqHx1jO/m s0wLkOJXC5fOYvdANf9KUVPgOlKLklPSAFcM2G/DtEXX2d2NdEr4ouKpCRrjlQ== X-Received: by 2002:a05:6a00:1916:b0:6e5:e8ee:38f2 with SMTP id y22-20020a056a00191600b006e5e8ee38f2mr628578pfi.23.1709338488017; Fri, 01 Mar 2024 16:14:48 -0800 (PST) Received: from www.outflux.net ([198.0.35.241]) by smtp.gmail.com with ESMTPSA id e29-20020aa7981d000000b006e592a2d073sm3423740pfl.161.2024.03.01.16.14.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Mar 2024 16:14:47 -0800 (PST) Date: Fri, 1 Mar 2024 16:14:46 -0800 From: Kees Cook To: "Gustavo A. R. Silva" Cc: Jason Gunthorpe , Leon Romanovsky , linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: Re: [PATCH][next] RDMA/uverbs: Avoid -Wflex-array-member-not-at-end warnings Message-ID: <202403011613.BB548211F3@keescook> References: 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: On Fri, Mar 01, 2024 at 12:37:45PM -0600, Gustavo A. R. Silva wrote: > -Wflex-array-member-not-at-end is coming in GCC-14, and we are getting > ready to enable it globally. > > There are currently a couple of objects (`alloc_head` and `bundle`) in > `struct bundle_priv` that contain a couple of flexible structures: > > struct bundle_priv { > /* Must be first */ > struct bundle_alloc_head alloc_head; > > ... > > /* > * Must be last. bundle ends in a flex array which overlaps > * internal_buffer. > */ > struct uverbs_attr_bundle bundle; > u64 internal_buffer[32]; > }; > > So, in order to avoid ending up with a couple of flexible-array members > in the middle of a struct, we use the `struct_group_tagged()` helper to > separate the flexible array from the rest of the members in the flexible > structures: > > struct uverbs_attr_bundle { > struct_group_tagged(uverbs_attr_bundle_hdr, hdr, > ... the rest of the members > ); > struct uverbs_attr attrs[]; > }; > > With the change described above, we now declare objects of the type of > the tagged struct without embedding flexible arrays in the middle of > another struct: > > struct bundle_priv { > /* Must be first */ > struct bundle_alloc_head_hdr alloc_head; > > ... > > struct uverbs_attr_bundle_hdr bundle; > u64 internal_buffer[32]; > }; > > We also use `container_of()` whenever we need to retrieve a pointer > to the flexible structures. > > Notice that the `bundle_size` computed in `uapi_compute_bundle_size()` > remains the same. > > So, with these changes, fix the following warnings: > > drivers/infiniband/core/uverbs_ioctl.c:45:34: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end] > 45 | struct bundle_alloc_head alloc_head; > | ^~~~~~~~~~ > drivers/infiniband/core/uverbs_ioctl.c:67:35: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end] > 67 | struct uverbs_attr_bundle bundle; > | ^~~~~~ > > Signed-off-by: Gustavo A. R. Silva This looks complex, but I think it's simpler that other changes that would have much more collateral impact. Thanks for figuring out a workable solution! Reviewed-by: Kees Cook -- Kees Cook