Skip to content

Commit

Permalink
treewide: Replace zero-length arrays with flexible-array
Browse files Browse the repository at this point in the history
There is a regular need in the kernel to provide a way to declare
having a dynamically sized set of trailing elements in a structure.
Kernel code should always use “flexible array members”[1] for these
cases. The older style of one-element or zero-length arrays should
no longer be used[2].

This code was transformed with the help of Coccinelle:
(next-20220214$ spatch --jobs 8 --sp-file script.cocci --include-headers --dir . > output.patch)

@@
identifier S, member, array;
type T1, T2;
@@

struct S {
  ...
  T1 member;
  T2 array[
- 0
  ];
};

UAPI and wireless changes were intentionally excluded from this patch
and will be sent out separately.

[1] https://en.wikipedia.org/wiki/Flexible_array_member
[2] https://www.kernel.org/doc/html/v5.16/process/deprecated.html#zero-length-and-one-element-arrays

Link: KSPP/linux#78
Reviewed-by: Kees Cook <[email protected]>
Signed-off-by: Gustavo A. R. Silva <[email protected]>
Signed-off-by: Namjae Jeon <[email protected]>
  • Loading branch information
GustavoARSilva authored and namjaejeon committed Oct 7, 2024
1 parent 85da158 commit 51480c0
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion ksmbd_netlink.h
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ struct ksmbd_rpc_command {
struct ksmbd_spnego_authen_request {
__u32 handle;
__u16 spnego_blob_len; /* the length of spnego_blob */
__u8 spnego_blob[0]; /*
__u8 spnego_blob[]; /*
* the GSS token from SecurityBuffer of
* SMB2 SESSION SETUP request
*/
Expand Down
6 changes: 3 additions & 3 deletions ntlmssp.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ struct security_buffer {
struct target_info {
__le16 Type;
__le16 Length;
__u8 Content[0];
__u8 Content[];
} __packed;

struct negotiate_message {
Expand All @@ -108,7 +108,7 @@ struct negotiate_message {
* struct security_buffer for version info not present since we
* do not set the version is present flag
*/
char DomainString[0];
char DomainString[];
/* followed by WorkstationString */
} __packed;

Expand Down Expand Up @@ -140,7 +140,7 @@ struct authenticate_message {
* struct security_buffer for version info not present since we
* do not set the version is present flag
*/
char UserString[0];
char UserString[];
} __packed;

struct ntlmv2_resp {
Expand Down
8 changes: 4 additions & 4 deletions smb2pdu.h
Original file line number Diff line number Diff line change
Expand Up @@ -1440,7 +1440,7 @@ struct smb2_file_rename_info { /* encoding of request for level 10 */
__u8 Reserved[7];
__u64 RootDirectory; /* MBZ for network operations (why says spec?) */
__le32 FileNameLength;
char FileName[0]; /* New name to be assigned */
char FileName[]; /* New name to be assigned */
} __packed; /* level 10 Set */

struct smb2_file_link_info { /* encoding of request for level 11 */
Expand All @@ -1449,7 +1449,7 @@ struct smb2_file_link_info { /* encoding of request for level 11 */
__u8 Reserved[7];
__u64 RootDirectory; /* MBZ for network operations (why says spec?) */
__le32 FileNameLength;
char FileName[0]; /* Name to be assigned to new link */
char FileName[]; /* Name to be assigned to new link */
} __packed; /* level 11 Set */

/*
Expand Down Expand Up @@ -1491,15 +1491,15 @@ struct smb2_file_basic_info { /* data block encoding of response to level 18 */

struct smb2_file_alt_name_info {
__le32 FileNameLength;
char FileName[0];
char FileName[];
} __packed;

struct smb2_file_stream_info {
__le32 NextEntryOffset;
__le32 StreamNameLength;
__le64 StreamSize;
__le64 StreamAllocationSize;
char StreamName[0];
char StreamName[];
} __packed;

struct smb2_file_eof_info { /* encoding of request for level 10 */
Expand Down
2 changes: 1 addition & 1 deletion transport_rdma.c
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ struct smb_direct_rdma_rw_msg {
struct list_head list;
struct rdma_rw_ctx rw_ctx;
struct sg_table sgt;
struct scatterlist sg_list[0];
struct scatterlist sg_list[];
};

void init_smbd_max_io_size(unsigned int sz)
Expand Down
2 changes: 1 addition & 1 deletion xattr.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ struct xattr_acl_entry {
struct xattr_smb_acl {
int count;
int next;
struct xattr_acl_entry entries[0];
struct xattr_acl_entry entries[];
};

/* 64bytes hash in xattr_ntacl is computed with sha256 */
Expand Down

0 comments on commit 51480c0

Please sign in to comment.