ceph: Replace zero-length array with flexible array member
Subsystems (3)
PATCH 1/1 ceph: Replace zero-length array with flexible array member
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].
Notice that, in this case, sizeof(au->reply_buf) translates to zero, becase in the original code reply_buf is a zero-length array. Now that reply_buf is transformed into a flexible array, the mentioned line of code is now replaced by a literal 0.
Also, as a safeguard, explicitly assign NULL to auth->authorizer_reply_buf, as no heap is allocated for it, therefore it should not be accessible.
[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
--- net/ceph/auth_none.c | 4 ++-- net/ceph/auth_none.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-)
net/ceph/auth_none.c +2 -2
@@ -111,8 +111,8 @@ static int ceph_auth_none_create_authorizer( auth->authorizer = (struct ceph_authorizer *) au; auth->authorizer_buf = au->buf; auth->authorizer_buf_len = au->buf_len; - auth->authorizer_reply_buf = au->reply_buf; - auth->authorizer_reply_buf_len =sizeof (au->reply_buf); + auth->authorizer_reply_buf_len =0 ; + auth->authorizer_reply_buf =NULL ;return 0 ; }
net/ceph/auth_none.h +1 -1
@@ -16,7 +16,7 @@ struct ceph_none_authorizer {struct ceph_authorizer base;char buf[128 ];int buf_len; -char reply_buf[0 ]; +char reply_buf[]; };struct ceph_auth_none_info {
Signature · 1 line
2.27.0
Ilya Dryomov
maintainerQuoted 45 lines · Gustavo A. R. Silva
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].
Notice that, in this case,
sizeof(au->reply_buf)translates to zero, becase in the original codereply_bufis a zero-length array. Now thatreply_bufis transformed into a flexible array, the mentioned line of code is now replaced by a literal 0.Also, as a safeguard, explicitly assign NULL to
auth->authorizer_reply_buf, as no heap is allocated for it, therefore it should not be accessible.[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-arraysSigned-off-by Gustavo A. R. Silva <[email protected]>--- net/ceph/auth_none.c | 4 ++-- net/ceph/auth_none.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-)net/ceph/auth_none.c +2
-2@@ -111,8 +111,8 @@ static int ceph_auth_none_create_authorizer( auth->authorizer = (struct ceph_authorizer *) au; auth->authorizer_buf = au->buf; auth->authorizer_buf_len = au->buf_len; - auth->authorizer_reply_buf = au->reply_buf; - auth->authorizer_reply_buf_len =sizeof (au->reply_buf); + auth->authorizer_reply_buf_len =0 ; + auth->authorizer_reply_buf =NULL ;return 0 ; }net/ceph/auth_none.h +0
-0
net/ceph/auth_none.h struct ceph_none_authorizer { · line 22
Quoted 8 lines
net/ceph/auth_none.h +1
-1@@ -16,7 +16,7 @@ struct ceph_none_authorizer {struct ceph_authorizer base;char buf[128 ];int buf_len; -char reply_buf[0 ]; +char reply_buf[]; };struct ceph_auth_none_info {
Hi Gustavo,
I went ahead and removed reply_buf. We never receive authorizer replies in auth_none mode, so patching it to be a flexible array is rather pointless.
Thanks,
Ilya
Quoted 6 lines · Ilya Dryomov
Hi Gustavo,
I went ahead and removed
reply_buf. We never receive authorizer replies inauth_nonemode, so patching it to be a flexible array is rather pointless.
Sounds great. :)
Thanks, Ilya.
--
Gustavo