From patchwork Thu Aug 8 22:04:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gustavo A. R. Silva" X-Patchwork-Id: 13758228 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 708B82A1DF; Thu, 8 Aug 2024 22:05:02 +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=1723154702; cv=none; b=FBSVdOgNnVM+gXbdDOT/hRLLFUMhVLZIFdwaysfMwlk+X6EuYCtcmLHfINT6/XddkSF0fgicGF1lxYGzoTFU3pWlv7qqTVzgcjn/nXbQNdtS8nWSdKFXw8l9dMJ9qnUGDq28C2ahOZELLEtMNi3n5VNynDp2+3QvJSCq89axXdA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723154702; c=relaxed/simple; bh=qnpZw+lFbLx8fiwo3zs7XLa7SwYU5KxtlLxuoVA7qLU=; h=Date:From:To:Cc:Subject:Message-ID:MIME-Version:Content-Type: Content-Disposition; b=J6dnK7A+Stxz2syexvSHk6l3U2IYPtMzMEbYBybSWWBi6CkDh8O9YYjkFjgsu17ZhyjUgZoBS3pdIQz5p491ystBxA3XuMDvznTO6+GdaG9wQya2V24HYgKXWjox90Tg+plIk+L+Dx8c662/ij11y6h2oBlfuSwxBVeIjr2H+EU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=EShAfoJi; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="EShAfoJi" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 06378C32782; Thu, 8 Aug 2024 22:05:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1723154702; bh=qnpZw+lFbLx8fiwo3zs7XLa7SwYU5KxtlLxuoVA7qLU=; h=Date:From:To:Cc:Subject:From; b=EShAfoJi5V3DpuVchMO7eZNgNNT4VJ9FiGfBB6cdBOC2cPVddqPrWRSuRIB5u1WQJ GDDUegjSxWTNGxZ0aQjkc82DR7bUcjiuBKXUUehGhpLCLJL1d6wKbybV5L2Ws4Izdm k4hYsxJcPR8TL5DNmCWyfvfc1Rh8jhZufMAvZMHu5wkE4RGl0kAjOeBhXNQcLayo3c CTJmSb3EhUAfVuZFK3RPgalpgkVq4H83Ns74mrceou6oDZi0+F0JUqArh+FDTcdIla RzwKBDuqM9wxup9VwyW6WVPMumasLGINrO1guidJGhFtcMRyll/OXb81RdYNPkMe3m 0AfRlQjPIw5mA== Date: Thu, 8 Aug 2024 16:04:59 -0600 From: "Gustavo A. R. Silva" To: Mimi Zohar , Roberto Sassu , Dmitry Kasatkin , Eric Snowberg , Paul Moore , James Morris , "Serge E. Hallyn" Cc: linux-integrity@vger.kernel.org, linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org, "Gustavo A. R. Silva" , linux-hardening@vger.kernel.org Subject: [PATCH][next] integrity: Use static_assert() to check struct sizes Message-ID: Precedence: bulk X-Mailing-List: linux-hardening@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline Commit 38aa3f5ac6d2 ("integrity: Avoid -Wflex-array-member-not-at-end warnings") introduced tagged `struct evm_ima_xattr_data_hdr` and `struct ima_digest_data_hdr`. We want to ensure that when new members need to be added to the flexible structures, they are always included within these tagged structs. So, we use `static_assert()` to ensure that the memory layout for both the flexible structure and the tagged struct is the same after any changes. Signed-off-by: Gustavo A. R. Silva Tested-by: Roberto Sassu Reviewed-by: Roberto Sassu --- security/integrity/integrity.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/security/integrity/integrity.h b/security/integrity/integrity.h index 660f76cb69d3..c2c2da691123 100644 --- a/security/integrity/integrity.h +++ b/security/integrity/integrity.h @@ -37,6 +37,8 @@ struct evm_ima_xattr_data { ); u8 data[]; } __packed; +static_assert(offsetof(struct evm_ima_xattr_data, data) == sizeof(struct evm_ima_xattr_data_hdr), + "struct member likely outside of __struct_group()"); /* Only used in the EVM HMAC code. */ struct evm_xattr { @@ -65,6 +67,8 @@ struct ima_digest_data { ); u8 digest[]; } __packed; +static_assert(offsetof(struct ima_digest_data, digest) == sizeof(struct ima_digest_data_hdr), + "struct member likely outside of __struct_group()"); /* * Instead of wrapping the ima_digest_data struct inside a local structure