linux-cifs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH][next] cifs: cifspdu.h: Replace one-element array with flexible-array member
@ 2021-03-26  1:11 Gustavo A. R. Silva
  2021-03-26 15:54 ` Aurélien Aptel
  0 siblings, 1 reply; 5+ messages in thread
From: Gustavo A. R. Silva @ 2021-03-26  1:11 UTC (permalink / raw)
  To: Steve French
  Cc: linux-cifs, samba-technical, linux-kernel, Gustavo A. R. Silva,
	linux-hardening

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].

Also, this helps with the ongoing efforts to enable -Warray-bounds by
fixing the following warning:

  CC [M]  fs/cifs/cifssmb.o
fs/cifs/cifssmb.c: In function ‘CIFSFindNext’:
fs/cifs/cifssmb.c:4636:23: warning: array subscript 1 is above array bounds of ‘char[1]’ [-Warray-bounds]
 4636 |   pSMB->ResumeFileName[name_len+1] = 0;
      |   ~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~

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

Link: https://github.com/KSPP/linux/issues/79
Link: https://github.com/KSPP/linux/issues/109
Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
---
 fs/cifs/cifspdu.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/cifs/cifspdu.h b/fs/cifs/cifspdu.h
index 64fe5a47b5e8..475a517360e5 100644
--- a/fs/cifs/cifspdu.h
+++ b/fs/cifs/cifspdu.h
@@ -1898,7 +1898,7 @@ typedef struct smb_com_transaction2_fnext_req {
 	__le16 InformationLevel;
 	__u32 ResumeKey;
 	__le16 SearchFlags;
-	char ResumeFileName[1];
+	char ResumeFileName[];
 } __attribute__((packed)) TRANSACTION2_FNEXT_REQ;
 
 typedef struct smb_com_transaction2_fnext_rsp {
-- 
2.27.0


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

* Re: [PATCH][next] cifs: cifspdu.h: Replace one-element array with flexible-array member
  2021-03-26 15:54 ` Aurélien Aptel
@ 2021-03-26 15:13   ` Gustavo A. R. Silva
  2021-04-09  4:23     ` Steve French
  0 siblings, 1 reply; 5+ messages in thread
From: Gustavo A. R. Silva @ 2021-03-26 15:13 UTC (permalink / raw)
  To: Aurélien Aptel, Gustavo A. R. Silva, Steve French
  Cc: linux-cifs, samba-technical, linux-kernel, linux-hardening



On 3/26/21 10:54, Aurélien Aptel wrote:
> "Gustavo A. R. Silva" <gustavoars@kernel.org> writes:
>> 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].
> 
> I've checked the usages of the struct, looks OK (we don't allocate it
> directly, we use memory from the small/big buff pools).

Awesome. :)

> Reviewed-by: Aurelien Aptel <aaptel@suse.com>

Thank you, Aurelien.
--
Gustavo

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

* Re: [PATCH][next] cifs: cifspdu.h: Replace one-element array with flexible-array member
  2021-03-26  1:11 [PATCH][next] cifs: cifspdu.h: Replace one-element array with flexible-array member Gustavo A. R. Silva
@ 2021-03-26 15:54 ` Aurélien Aptel
  2021-03-26 15:13   ` Gustavo A. R. Silva
  0 siblings, 1 reply; 5+ messages in thread
From: Aurélien Aptel @ 2021-03-26 15:54 UTC (permalink / raw)
  To: Gustavo A. R. Silva, Steve French
  Cc: linux-cifs, samba-technical, linux-kernel, Gustavo A. R. Silva,
	linux-hardening

"Gustavo A. R. Silva" <gustavoars@kernel.org> writes:
> 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].

I've checked the usages of the struct, looks OK (we don't allocate it
directly, we use memory from the small/big buff pools).

Reviewed-by: Aurelien Aptel <aaptel@suse.com>

Cheers,
-- 
Aurélien Aptel / SUSE Labs Samba Team
GPG: 1839 CB5F 9F5B FB9B AA97  8C99 03C8 A49B 521B D5D3
SUSE Software Solutions Germany GmbH, Maxfeldstr. 5, 90409 Nürnberg, DE
GF: Felix Imendörffer, Mary Higgins, Sri Rasiah HRB 247165 (AG München)


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

* Re: [PATCH][next] cifs: cifspdu.h: Replace one-element array with flexible-array member
  2021-03-26 15:13   ` Gustavo A. R. Silva
@ 2021-04-09  4:23     ` Steve French
  2021-04-09  7:06       ` Gustavo A. R. Silva
  0 siblings, 1 reply; 5+ messages in thread
From: Steve French @ 2021-04-09  4:23 UTC (permalink / raw)
  To: Gustavo A. R. Silva
  Cc: Aurélien Aptel, Gustavo A. R. Silva, Steve French, CIFS,
	samba-technical, LKML, linux-hardening

merged into cifs-2.6.git for-next

On Fri, Mar 26, 2021 at 12:02 PM Gustavo A. R. Silva
<gustavo@embeddedor.com> wrote:
>
>
>
> On 3/26/21 10:54, Aurélien Aptel wrote:
> > "Gustavo A. R. Silva" <gustavoars@kernel.org> writes:
> >> 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].
> >
> > I've checked the usages of the struct, looks OK (we don't allocate it
> > directly, we use memory from the small/big buff pools).
>
> Awesome. :)
>
> > Reviewed-by: Aurelien Aptel <aaptel@suse.com>
>
> Thank you, Aurelien.
> --
> Gustavo



-- 
Thanks,

Steve

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

* Re: [PATCH][next] cifs: cifspdu.h: Replace one-element array with flexible-array member
  2021-04-09  4:23     ` Steve French
@ 2021-04-09  7:06       ` Gustavo A. R. Silva
  0 siblings, 0 replies; 5+ messages in thread
From: Gustavo A. R. Silva @ 2021-04-09  7:06 UTC (permalink / raw)
  To: Steve French
  Cc: Aurélien Aptel, Gustavo A. R. Silva, Steve French, CIFS,
	samba-technical, LKML, linux-hardening



On 4/8/21 23:23, Steve French wrote:
> merged into cifs-2.6.git for-next

Great. :)

Thanks, Steve.

--
Gustavo

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

end of thread, other threads:[~2021-04-09  7:30 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-26  1:11 [PATCH][next] cifs: cifspdu.h: Replace one-element array with flexible-array member Gustavo A. R. Silva
2021-03-26 15:54 ` Aurélien Aptel
2021-03-26 15:13   ` Gustavo A. R. Silva
2021-04-09  4:23     ` Steve French
2021-04-09  7:06       ` Gustavo A. R. Silva

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).