The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH][next] smb: smb2pdu.h: Use static_assert() to check struct sizes
@ 2024-08-08 22:04 Gustavo A. R. Silva
  2024-08-09  2:51 ` Namjae Jeon
  0 siblings, 1 reply; 3+ messages in thread
From: Gustavo A. R. Silva @ 2024-08-08 22:04 UTC (permalink / raw)
  To: Namjae Jeon, Steve French, Sergey Senozhatsky, Tom Talpey,
	Paulo Alcantara, Ronnie Sahlberg, Shyam Prasad N, Bharath SM
  Cc: linux-cifs, samba-technical, linux-kernel, Gustavo A. R. Silva,
	linux-hardening

Commit 9f9bef9bc5c6 ("smb: smb2pdu.h: Avoid -Wflex-array-member-not-at-end
warnings") introduced tagged `struct create_context_hdr`. We want to
ensure that when new members need to be added to the flexible structure,
they are always included within this tagged struct.

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 <gustavoars@kernel.org>
---
 fs/smb/common/smb2pdu.h | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/fs/smb/common/smb2pdu.h b/fs/smb/common/smb2pdu.h
index c3ee42188d25..c769f9dbc0b4 100644
--- a/fs/smb/common/smb2pdu.h
+++ b/fs/smb/common/smb2pdu.h
@@ -1216,6 +1216,8 @@ struct create_context {
 	);
 	__u8 Buffer[];
 } __packed;
+static_assert(offsetof(struct create_context, Buffer) == sizeof(struct create_context_hdr),
+	      "struct member likely outside of __struct_group()");
 
 struct smb2_create_req {
 	struct smb2_hdr hdr;
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH][next] smb: smb2pdu.h: Use static_assert() to check struct sizes
  2024-08-08 22:04 [PATCH][next] smb: smb2pdu.h: Use static_assert() to check struct sizes Gustavo A. R. Silva
@ 2024-08-09  2:51 ` Namjae Jeon
  2024-08-09  3:50   ` Steve French
  0 siblings, 1 reply; 3+ messages in thread
From: Namjae Jeon @ 2024-08-09  2:51 UTC (permalink / raw)
  To: Gustavo A. R. Silva
  Cc: Steve French, Sergey Senozhatsky, Tom Talpey, Paulo Alcantara,
	Ronnie Sahlberg, Shyam Prasad N, Bharath SM, linux-cifs,
	samba-technical, linux-kernel, linux-hardening

2024년 8월 9일 (금) 오전 7:04, Gustavo A. R. Silva <gustavoars@kernel.org>님이 작성:
>
> Commit 9f9bef9bc5c6 ("smb: smb2pdu.h: Avoid -Wflex-array-member-not-at-end
> warnings") introduced tagged `struct create_context_hdr`. We want to
> ensure that when new members need to be added to the flexible structure,
> they are always included within this tagged struct.
>
> 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 <gustavoars@kernel.org>
Acked-by: Namjae Jeon <linkinjeon@kernel.org>

Thanks!

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH][next] smb: smb2pdu.h: Use static_assert() to check struct sizes
  2024-08-09  2:51 ` Namjae Jeon
@ 2024-08-09  3:50   ` Steve French
  0 siblings, 0 replies; 3+ messages in thread
From: Steve French @ 2024-08-09  3:50 UTC (permalink / raw)
  To: Namjae Jeon
  Cc: Gustavo A. R. Silva, Steve French, Sergey Senozhatsky, Tom Talpey,
	Paulo Alcantara, Ronnie Sahlberg, Shyam Prasad N, Bharath SM,
	linux-cifs, samba-technical, linux-kernel, linux-hardening

merged into cifs-2.6.git for-next

On Thu, Aug 8, 2024 at 9:51 PM Namjae Jeon <linkinjeon@kernel.org> wrote:
>
> 2024년 8월 9일 (금) 오전 7:04, Gustavo A. R. Silva <gustavoars@kernel.org>님이 작성:
> >
> > Commit 9f9bef9bc5c6 ("smb: smb2pdu.h: Avoid -Wflex-array-member-not-at-end
> > warnings") introduced tagged `struct create_context_hdr`. We want to
> > ensure that when new members need to be added to the flexible structure,
> > they are always included within this tagged struct.
> >
> > 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 <gustavoars@kernel.org>
> Acked-by: Namjae Jeon <linkinjeon@kernel.org>
>
> Thanks!
>


-- 
Thanks,

Steve

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-08-09  3:50 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-08 22:04 [PATCH][next] smb: smb2pdu.h: Use static_assert() to check struct sizes Gustavo A. R. Silva
2024-08-09  2:51 ` Namjae Jeon
2024-08-09  3:50   ` Steve French

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox