public inbox for linux-integrity@vger.kernel.org
 help / color / mirror / Atom feed
From: Mimi Zohar <zohar@linux.ibm.com>
To: "Gustavo A. R. Silva" <gustavoars@kernel.org>,
	Roberto Sassu <roberto.sassu@huawei.com>,
	Dmitry Kasatkin <dmitry.kasatkin@gmail.com>,
	Eric Snowberg <eric.snowberg@oracle.com>,
	Paul Moore <paul@paul-moore.com>,
	James Morris <jmorris@namei.org>,
	"Serge E. Hallyn" <serge@hallyn.com>
Cc: linux-integrity@vger.kernel.org,
	linux-security-module@vger.kernel.org,
	linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org
Subject: Re: [PATCH v5][next] integrity: Avoid -Wflex-array-member-not-at-end warnings
Date: Thu, 04 Apr 2024 16:11:54 -0400	[thread overview]
Message-ID: <b3956fd36307d33ebbf0e4633e0d2389860cf720.camel@linux.ibm.com> (raw)
In-Reply-To: <27d36ec8e0539c5d6bc760de7305299a2142f9f1.camel@linux.ibm.com>

On Thu, 2024-04-04 at 12:49 -0400, Mimi Zohar wrote:
> Hi Gustavo,
> 
> On Thu, 2024-04-04 at 09:00 -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 is currently an object (`hdr)` in `struct ima_max_digest_data`
> > that contains a flexible structure (`struct ima_digest_data`):
> > 
> >  struct ima_max_digest_data {
> >         struct ima_digest_data hdr;
> >         u8 digest[HASH_MAX_DIGESTSIZE];
> >  } __packed;
> > 
> > So, in order to avoid ending up with a flexible-array member in the
> > middle of a struct, we use the `__struct_group()` helper to separate
> > the flexible array from the rest of the members in the flexible
> > structure:
> > 
> > struct ima_digest_data {
> >         __struct_group(ima_digest_data_hdr, hdr, __packed,
> > 
> >         ... the rest of the members
> > 
> >         );
> >         u8 digest[];
> > } __packed;
> > 
> > And similarly for `struct evm_ima_xattr_data`.
> > 
> > With the change described above, we can now declare an object of the
> > type of the tagged `struct ima_digest_data_hdr`, without embedding the
> > flexible array in the middle of another struct:
> > 
> >  struct ima_max_digest_data {
> >         struct ima_digest_data_hdr hdr;
> >         u8 digest[HASH_MAX_DIGESTSIZE];
> >  } __packed;
> > 
> > And similarly for `struct evm_digest` and `struct evm_xattr`.
> > 
> > We also use `container_of()` whenever we need to retrieve a pointer to
> > the flexible structure.
> > 
> > So, with these changes, fix the following warnings:
> > 
> > security/integrity/evm/evm.h:64:32: warning: structure containing a flexible
> > array member is not at the end of another structure [-Wflex-array-member-
> > not-
> > at-end]
> > security/integrity/evm/../integrity.h:40:35: warning: structure containing a
> > flexible array member is not at the end of another structure [-Wflex-array-
> > member-not-at-end]
> > security/integrity/evm/../integrity.h:68:32: warning: structure containing a
> > flexible array member is not at the end of another structure [-Wflex-array-
> > member-not-at-end]
> > security/integrity/ima/../integrity.h:40:35: warning: structure containing a
> > flexible array member is not at the end of another structure [-Wflex-array-
> > member-not-at-end]
> > security/integrity/ima/../integrity.h:68:32: warning: structure containing a
> > flexible array member is not at the end of another structure [-Wflex-array-
> > member-not-at-end]
> > security/integrity/integrity.h:40:35: warning: structure containing a
> > flexible
> > array member is not at the end of another structure [-Wflex-array-member-
> > not-
> > at-end]
> > security/integrity/integrity.h:68:32: warning: structure containing a
> > flexible
> > array member is not at the end of another structure [-Wflex-array-member-
> > not-
> > at-end]
> > security/integrity/platform_certs/../integrity.h:40:35: warning: structure
> > containing a flexible array member is not at the end of another structure [-
> > Wflex-array-member-not-at-end]
> > security/integrity/platform_certs/../integrity.h:68:32: warning: structure
> > containing a flexible array member is not at the end of another structure [-
> > Wflex-array-member-not-at-end]
> > 
> > Link: https://github.com/KSPP/linux/issues/202
> > Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
> 
> Reviewed-by: Mimi Zohar <zohar@linux.ibm.com>
> 
> Thanks, Gustavo.  I already applied and tested v4, but was trying to actually
> see the errors with before pushing it out.

With GCC-14, I'm seeing the "warning: structure containing a flexible array
member is not at the end of another structure [-Wflex-array-member-not-at-end]"
messages.  As expected, with the patch no warnings.

"checkpatch.pl --strict" complains "CHECK: Alignment should match open
parenthesis".  I'll queue the patch, but how about teaching checkpatch.pl to
ignore __struct_group()?

thanks,

Mimi


  reply	other threads:[~2024-04-04 20:12 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-04 15:00 [PATCH v5][next] integrity: Avoid -Wflex-array-member-not-at-end warnings Gustavo A. R. Silva
2024-04-04 16:49 ` Mimi Zohar
2024-04-04 20:11   ` Mimi Zohar [this message]
2024-04-05  0:56     ` Gustavo A. R. Silva
2024-04-05 14:17       ` Mimi Zohar

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=b3956fd36307d33ebbf0e4633e0d2389860cf720.camel@linux.ibm.com \
    --to=zohar@linux.ibm.com \
    --cc=dmitry.kasatkin@gmail.com \
    --cc=eric.snowberg@oracle.com \
    --cc=gustavoars@kernel.org \
    --cc=jmorris@namei.org \
    --cc=linux-hardening@vger.kernel.org \
    --cc=linux-integrity@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-security-module@vger.kernel.org \
    --cc=paul@paul-moore.com \
    --cc=roberto.sassu@huawei.com \
    --cc=serge@hallyn.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox