Received: by 2002:a89:2c3:0:b0:1ed:23cc:44d1 with SMTP id d3csp727487lqs; Tue, 5 Mar 2024 14:57:12 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVxFHuWo8wBePc/72NJ3lT1GBqZ5R8H6+EtWsBF38R7Lov4lrkNPmYfcznce6Qwnlyk238Zf0GUPxe26T2kISyfpuuMLQ9ik1Z7czxMDw== X-Google-Smtp-Source: AGHT+IEpCHDxbuhdKl06Lu+PD81HuvD7r1F8MNl5Og7zxxp2pSC0+z1F/6QbxfbZGvAvVIJ3pyi7 X-Received: by 2002:a17:902:c146:b0:1db:9a69:293d with SMTP id 6-20020a170902c14600b001db9a69293dmr3011342plj.24.1709679432345; Tue, 05 Mar 2024 14:57:12 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709679432; cv=pass; d=google.com; s=arc-20160816; b=hXC8praYwLAXB8YqnchpFsQOIq3+VfS7qGkppGHOMmUpbUh5QgIDmZ63Zz/7tI90o3 aI4LGwTyVHzQUSl2oAK0HegOGjys52y8A7nmBBtvRUttWmX3yqLQm7DQUcvDUFFPpfeg zRTrWnwoQVkTNFiHk26rNJpu2IOJqumlkKyi9mo62aHEuLGMgPOPmlBAH/RaBwDgDFEt 9Od43/Q+lX7v4CkADeIR+Et8zpyvYb7ASzA/nxTXa/CHoRdL1UKBihwy8Jdm3GbrCaMF VffdsNslM6JzdqPqIAoPszaBp/9D2/I4HSxscvrmXali0hwlU6JnitwETyhNGjXQv1xY 7Viw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:content-disposition:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:message-id :subject:cc:to:from:date:dkim-signature; bh=ezQKadVMguqBfZSAUvlyCFO3aa/LiVqJjkBrGPyl5zo=; fh=KH72xgsr5j2/GovdDw+PrlxEdXL/cpWdafQAWDwPfM0=; b=ydrGfbrAEsk+6FQ4ZLuULByzEssvvoIhNa6/EO/PAX1KUjoQ/ZYtfIR7EMJsIvudCY 9iHm5tGpQKxX76yK+UfnDrbYneBLul/AGTW2j7o1ENKiZnncMtM2ViXm2wURU9u2u19J l43vgtQYPmUyxIKR2GBbrPV4oS6SvtArt9vNOJIpHRm5zKnH6GHrRpRiSzxBWUCNx6Jw HAqyAGxKe7TgxHWBtyYQLip2vIC0pGPXUoLF6nk5AwE/PbCKTdE24xC4/qo/xxpOfdMQ Blb6Cc4FLldYFIP+nBPBT+Z11iUEVHh5Qdow8JhWHDy91LG7AB9MsdTPliGTezAqVZ05 p1sA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=IdimvUrN; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-93042-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-93042-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id p13-20020a170902ebcd00b001dd07f48a50si5137918plg.334.2024.03.05.14.57.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Mar 2024 14:57:12 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-93042-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=IdimvUrN; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-93042-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-93042-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 4A234B23FE2 for ; Tue, 5 Mar 2024 22:19:46 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 77AA512E1EA; Tue, 5 Mar 2024 22:18:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="IdimvUrN" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 85B8912E1C5; Tue, 5 Mar 2024 22:18:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709677129; cv=none; b=X9vFW1pQR32BkkEx6tCoyujsBdQ0FKpoG2vJjN1VVvovUqc/ClqN0p9oTf/zmd/9SJUUhQPH0DGPsXD7IwPdDykM21okjmdMaD5ZRum6zgYUMLFPZWuqkEOMEpZJnL1KJinR00oZejReQJhA/dOpBetznb7IdiYnH8TMr9MmINo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709677129; c=relaxed/simple; bh=iTV6eJf8dPD4YV3fq9RsQkZcP6Jo/J8HHPmDs3eIbuA=; h=Date:From:To:Cc:Subject:Message-ID:MIME-Version:Content-Type: Content-Disposition; b=Ea/URaHRxAzGBbs3E5zvvZvsFDmp9uC4VSdMKJJ8CVs8Bu6NSR5kkObGU3AaxnqXDTpaG5Z4t0XH3qLMkfA0WtRrXXEQXiFt8ZcVJGhfkmncgOpJCD1YJUEcz9Z+RdOFy7Nl7+sgkFatO81mlG3NKhQNFGXtLToOkt4pz38dk4A= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=IdimvUrN; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 451E6C43394; Tue, 5 Mar 2024 22:18:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1709677129; bh=iTV6eJf8dPD4YV3fq9RsQkZcP6Jo/J8HHPmDs3eIbuA=; h=Date:From:To:Cc:Subject:From; b=IdimvUrNFp9Jf7lRs7ECBbFx7mh+9YgqxFqBEfQKxNR8viJm6rZnc/RTYXac8Diu1 63Itc3bLl3E6o3lqXS8sBG4g9gzajZmRm/IusPKLHEn72SIdpBtls1VcTquwyIgi0H TWHbNNbjjsOimHLa11fUe5RwjF+lJAMpr785GQ/rULMiqVcsACg5StUYC6ye6/BLK7 VLea6ydfrvu4qjqyLJ775bq7aYR7mZqX7tu8C7JNkGtTQosUUxrPs8fveKr1QTTZuJ aUsNydoBRNU05f4/1UHhIBl6I2D0c5XQD3M/aov/ynUqC7RCInxq2KzsNdbDdXREcz yroGEG5ulIthQ== Date: Tue, 5 Mar 2024 16:18:46 -0600 From: "Gustavo A. R. Silva" To: Jan Kara , Amir Goldstein , Alexander Viro , Christian Brauner Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, "Gustavo A. R. Silva" , linux-hardening@vger.kernel.org, Kees Cook Subject: [PATCH][next] fsnotify: Avoid -Wflex-array-member-not-at-end warning Message-ID: 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=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit -Wflex-array-member-not-at-end is coming in GCC-14, and we are getting ready to enable it globally. There is currently a local structure `f` that is using a flexible `struct file_handle` as header for an on-stack place-holder for the flexible-array member `unsigned char f_handle[];`. struct { struct file_handle handle; u8 pad[MAX_HANDLE_SZ]; } f; However, we are deprecating flexible arrays in the middle of another struct. So, in order to avoid this, we use the `struct_group_tagged()` helper to separate the flexible array from the rest of the members in the flexible structure: struct file_handle { struct_group_tagged(file_handle_hdr, hdr, ... the rest of the members ); unsigned char f_handle[]; }; With the change described above, we can now declare an object of the type of the tagged struct, without embedding the flexible array in the middle of another struct: struct { struct file_handle_hdr handle; u8 pad[MAX_HANDLE_SZ]; } f; We also use `container_of()` whenever we need to retrieve a pointer to the flexible structure, through which the flexible-array member can be accessed, as in this case. So, with these changes, fix the following warning: fs/notify/fdinfo.c: In function ‘show_mark_fhandle’: fs/notify/fdinfo.c:45:36: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end] 45 | struct file_handle handle; | ^~~~~~ Signed-off-by: Gustavo A. R. Silva --- fs/notify/fdinfo.c | 8 +++++--- include/linux/fs.h | 6 ++++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/fs/notify/fdinfo.c b/fs/notify/fdinfo.c index 5c430736ec12..740f5e68b397 100644 --- a/fs/notify/fdinfo.c +++ b/fs/notify/fdinfo.c @@ -42,15 +42,17 @@ static void show_fdinfo(struct seq_file *m, struct file *f, static void show_mark_fhandle(struct seq_file *m, struct inode *inode) { struct { - struct file_handle handle; + struct file_handle_hdr handle; u8 pad[MAX_HANDLE_SZ]; } f; + struct file_handle *handle = container_of(&f.handle, + struct file_handle, hdr); int size, ret, i; f.handle.handle_bytes = sizeof(f.pad); size = f.handle.handle_bytes >> 2; - ret = exportfs_encode_fid(inode, (struct fid *)f.handle.f_handle, &size); + ret = exportfs_encode_fid(inode, (struct fid *)handle->f_handle, &size); if ((ret == FILEID_INVALID) || (ret < 0)) { WARN_ONCE(1, "Can't encode file handler for inotify: %d\n", ret); return; @@ -63,7 +65,7 @@ static void show_mark_fhandle(struct seq_file *m, struct inode *inode) f.handle.handle_bytes, f.handle.handle_type); for (i = 0; i < f.handle.handle_bytes; i++) - seq_printf(m, "%02x", (int)f.handle.f_handle[i]); + seq_printf(m, "%02x", (int)handle->f_handle[i]); } #else static void show_mark_fhandle(struct seq_file *m, struct inode *inode) diff --git a/include/linux/fs.h b/include/linux/fs.h index 00fc429b0af0..7c131bcd948f 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -1030,8 +1030,10 @@ struct file { __attribute__((aligned(4))); /* lest something weird decides that 2 is OK */ struct file_handle { - __u32 handle_bytes; - int handle_type; + struct_group_tagged(file_handle_hdr, hdr, + __u32 handle_bytes; + int handle_type; + ); /* file identifier */ unsigned char f_handle[]; }; -- 2.34.1