Re: [PATCH] rbd: remove VLA usage

2018-03-30 Thread Gustavo A. R. Silva



On 03/30/2018 03:29 PM, Ilya Dryomov wrote:

On Fri, Mar 30, 2018 at 9:17 PM, Gustavo A. R. Silva
 wrote:

In preparation to enabling -Wvla, remove the use of stack VLA.

In this particular case, variable buf_size is replaced with a constant
expression that can be computed at preprocessing time. This avoids two
VLA warnings. Also, as a consequence of the mentioned change, some code
was slightly refactored.

The use of stack Variable Length Arrays needs to be avoided, as they
can be a vector for stack exhaustion, which can be both a runtime bug
or a security flaw. Also, in general, as code evolves it is easy to
lose track of how big a VLA can get. Thus, we can end up having runtime
failures that are hard to debug.

Also, fixed as part of the directive to remove all VLAs from
the kernel: https://lkml.org/lkml/2018/3/7/621

Signed-off-by: Gustavo A. R. Silva 
---
  drivers/block/rbd.c | 15 +++
  1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c
index 1e03b04..5133122 100644
--- a/drivers/block/rbd.c
+++ b/drivers/block/rbd.c
@@ -3091,20 +3091,20 @@ static int __rbd_notify_op_lock(struct rbd_device 
*rbd_dev,
  {
 struct ceph_osd_client *osdc = _dev->rbd_client->client->osdc;
 struct rbd_client_id cid = rbd_get_cid(rbd_dev);
-   int buf_size = 4 + 8 + 8 + CEPH_ENCODING_START_BLK_LEN;
-   char buf[buf_size];
+   char buf[4 + 8 + 8 + CEPH_ENCODING_START_BLK_LEN];
 void *p = buf;

 dout("%s rbd_dev %p notify_op %d\n", __func__, rbd_dev, notify_op);

 /* encode *LockPayload NotifyMessage (op + ClientId) */
-   ceph_start_encoding(, 2, 1, buf_size - CEPH_ENCODING_START_BLK_LEN);
+   ceph_start_encoding(, 2, 1,
+   sizeof(buf) - CEPH_ENCODING_START_BLK_LEN);
 ceph_encode_32(, notify_op);
 ceph_encode_64(, cid.gid);
 ceph_encode_64(, cid.handle);

 return ceph_osdc_notify(osdc, _dev->header_oid,
-   _dev->header_oloc, buf, buf_size,
+   _dev->header_oloc, buf, sizeof(buf),
 RBD_NOTIFY_TIMEOUT, preply_pages, preply_len);
  }

@@ -3610,19 +3610,18 @@ static void __rbd_acknowledge_notify(struct rbd_device 
*rbd_dev,
  u64 notify_id, u64 cookie, s32 *result)
  {
 struct ceph_osd_client *osdc = _dev->rbd_client->client->osdc;
-   int buf_size = 4 + CEPH_ENCODING_START_BLK_LEN;
-   char buf[buf_size];
+   char buf[4 + CEPH_ENCODING_START_BLK_LEN];
+   int buf_size = 0;
 int ret;

 if (result) {
 void *p = buf;

+   buf_size = sizeof(buf);
 /* encode ResponseMessage */
 ceph_start_encoding(, 1, 1,
 buf_size - CEPH_ENCODING_START_BLK_LEN);
 ceph_encode_32(, *result);
-   } else {
-   buf_size = 0;
 }

 ret = ceph_osdc_notify_ack(osdc, _dev->header_oid,


Already fixed:

   
https://github.com/ceph/ceph-client/commit/2474e77e75215a3cad3b652d2f55ba5b123cb119



Oh, that's great.

Good to know. :)

Thanks
--
Gustavo



Re: [PATCH] rbd: remove VLA usage

2018-03-30 Thread Gustavo A. R. Silva



On 03/30/2018 03:29 PM, Ilya Dryomov wrote:

On Fri, Mar 30, 2018 at 9:17 PM, Gustavo A. R. Silva
 wrote:

In preparation to enabling -Wvla, remove the use of stack VLA.

In this particular case, variable buf_size is replaced with a constant
expression that can be computed at preprocessing time. This avoids two
VLA warnings. Also, as a consequence of the mentioned change, some code
was slightly refactored.

The use of stack Variable Length Arrays needs to be avoided, as they
can be a vector for stack exhaustion, which can be both a runtime bug
or a security flaw. Also, in general, as code evolves it is easy to
lose track of how big a VLA can get. Thus, we can end up having runtime
failures that are hard to debug.

Also, fixed as part of the directive to remove all VLAs from
the kernel: https://lkml.org/lkml/2018/3/7/621

Signed-off-by: Gustavo A. R. Silva 
---
  drivers/block/rbd.c | 15 +++
  1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c
index 1e03b04..5133122 100644
--- a/drivers/block/rbd.c
+++ b/drivers/block/rbd.c
@@ -3091,20 +3091,20 @@ static int __rbd_notify_op_lock(struct rbd_device 
*rbd_dev,
  {
 struct ceph_osd_client *osdc = _dev->rbd_client->client->osdc;
 struct rbd_client_id cid = rbd_get_cid(rbd_dev);
-   int buf_size = 4 + 8 + 8 + CEPH_ENCODING_START_BLK_LEN;
-   char buf[buf_size];
+   char buf[4 + 8 + 8 + CEPH_ENCODING_START_BLK_LEN];
 void *p = buf;

 dout("%s rbd_dev %p notify_op %d\n", __func__, rbd_dev, notify_op);

 /* encode *LockPayload NotifyMessage (op + ClientId) */
-   ceph_start_encoding(, 2, 1, buf_size - CEPH_ENCODING_START_BLK_LEN);
+   ceph_start_encoding(, 2, 1,
+   sizeof(buf) - CEPH_ENCODING_START_BLK_LEN);
 ceph_encode_32(, notify_op);
 ceph_encode_64(, cid.gid);
 ceph_encode_64(, cid.handle);

 return ceph_osdc_notify(osdc, _dev->header_oid,
-   _dev->header_oloc, buf, buf_size,
+   _dev->header_oloc, buf, sizeof(buf),
 RBD_NOTIFY_TIMEOUT, preply_pages, preply_len);
  }

@@ -3610,19 +3610,18 @@ static void __rbd_acknowledge_notify(struct rbd_device 
*rbd_dev,
  u64 notify_id, u64 cookie, s32 *result)
  {
 struct ceph_osd_client *osdc = _dev->rbd_client->client->osdc;
-   int buf_size = 4 + CEPH_ENCODING_START_BLK_LEN;
-   char buf[buf_size];
+   char buf[4 + CEPH_ENCODING_START_BLK_LEN];
+   int buf_size = 0;
 int ret;

 if (result) {
 void *p = buf;

+   buf_size = sizeof(buf);
 /* encode ResponseMessage */
 ceph_start_encoding(, 1, 1,
 buf_size - CEPH_ENCODING_START_BLK_LEN);
 ceph_encode_32(, *result);
-   } else {
-   buf_size = 0;
 }

 ret = ceph_osdc_notify_ack(osdc, _dev->header_oid,


Already fixed:

   
https://github.com/ceph/ceph-client/commit/2474e77e75215a3cad3b652d2f55ba5b123cb119



Oh, that's great.

Good to know. :)

Thanks
--
Gustavo



Re: [PATCH] rbd: remove VLA usage

2018-03-30 Thread Ilya Dryomov
On Fri, Mar 30, 2018 at 9:17 PM, Gustavo A. R. Silva
 wrote:
> In preparation to enabling -Wvla, remove the use of stack VLA.
>
> In this particular case, variable buf_size is replaced with a constant
> expression that can be computed at preprocessing time. This avoids two
> VLA warnings. Also, as a consequence of the mentioned change, some code
> was slightly refactored.
>
> The use of stack Variable Length Arrays needs to be avoided, as they
> can be a vector for stack exhaustion, which can be both a runtime bug
> or a security flaw. Also, in general, as code evolves it is easy to
> lose track of how big a VLA can get. Thus, we can end up having runtime
> failures that are hard to debug.
>
> Also, fixed as part of the directive to remove all VLAs from
> the kernel: https://lkml.org/lkml/2018/3/7/621
>
> Signed-off-by: Gustavo A. R. Silva 
> ---
>  drivers/block/rbd.c | 15 +++
>  1 file changed, 7 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c
> index 1e03b04..5133122 100644
> --- a/drivers/block/rbd.c
> +++ b/drivers/block/rbd.c
> @@ -3091,20 +3091,20 @@ static int __rbd_notify_op_lock(struct rbd_device 
> *rbd_dev,
>  {
> struct ceph_osd_client *osdc = _dev->rbd_client->client->osdc;
> struct rbd_client_id cid = rbd_get_cid(rbd_dev);
> -   int buf_size = 4 + 8 + 8 + CEPH_ENCODING_START_BLK_LEN;
> -   char buf[buf_size];
> +   char buf[4 + 8 + 8 + CEPH_ENCODING_START_BLK_LEN];
> void *p = buf;
>
> dout("%s rbd_dev %p notify_op %d\n", __func__, rbd_dev, notify_op);
>
> /* encode *LockPayload NotifyMessage (op + ClientId) */
> -   ceph_start_encoding(, 2, 1, buf_size - CEPH_ENCODING_START_BLK_LEN);
> +   ceph_start_encoding(, 2, 1,
> +   sizeof(buf) - CEPH_ENCODING_START_BLK_LEN);
> ceph_encode_32(, notify_op);
> ceph_encode_64(, cid.gid);
> ceph_encode_64(, cid.handle);
>
> return ceph_osdc_notify(osdc, _dev->header_oid,
> -   _dev->header_oloc, buf, buf_size,
> +   _dev->header_oloc, buf, sizeof(buf),
> RBD_NOTIFY_TIMEOUT, preply_pages, preply_len);
>  }
>
> @@ -3610,19 +3610,18 @@ static void __rbd_acknowledge_notify(struct 
> rbd_device *rbd_dev,
>  u64 notify_id, u64 cookie, s32 *result)
>  {
> struct ceph_osd_client *osdc = _dev->rbd_client->client->osdc;
> -   int buf_size = 4 + CEPH_ENCODING_START_BLK_LEN;
> -   char buf[buf_size];
> +   char buf[4 + CEPH_ENCODING_START_BLK_LEN];
> +   int buf_size = 0;
> int ret;
>
> if (result) {
> void *p = buf;
>
> +   buf_size = sizeof(buf);
> /* encode ResponseMessage */
> ceph_start_encoding(, 1, 1,
> buf_size - CEPH_ENCODING_START_BLK_LEN);
> ceph_encode_32(, *result);
> -   } else {
> -   buf_size = 0;
> }
>
> ret = ceph_osdc_notify_ack(osdc, _dev->header_oid,

Already fixed:

  
https://github.com/ceph/ceph-client/commit/2474e77e75215a3cad3b652d2f55ba5b123cb119

Thanks,

Ilya


Re: [PATCH] rbd: remove VLA usage

2018-03-30 Thread Ilya Dryomov
On Fri, Mar 30, 2018 at 9:17 PM, Gustavo A. R. Silva
 wrote:
> In preparation to enabling -Wvla, remove the use of stack VLA.
>
> In this particular case, variable buf_size is replaced with a constant
> expression that can be computed at preprocessing time. This avoids two
> VLA warnings. Also, as a consequence of the mentioned change, some code
> was slightly refactored.
>
> The use of stack Variable Length Arrays needs to be avoided, as they
> can be a vector for stack exhaustion, which can be both a runtime bug
> or a security flaw. Also, in general, as code evolves it is easy to
> lose track of how big a VLA can get. Thus, we can end up having runtime
> failures that are hard to debug.
>
> Also, fixed as part of the directive to remove all VLAs from
> the kernel: https://lkml.org/lkml/2018/3/7/621
>
> Signed-off-by: Gustavo A. R. Silva 
> ---
>  drivers/block/rbd.c | 15 +++
>  1 file changed, 7 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c
> index 1e03b04..5133122 100644
> --- a/drivers/block/rbd.c
> +++ b/drivers/block/rbd.c
> @@ -3091,20 +3091,20 @@ static int __rbd_notify_op_lock(struct rbd_device 
> *rbd_dev,
>  {
> struct ceph_osd_client *osdc = _dev->rbd_client->client->osdc;
> struct rbd_client_id cid = rbd_get_cid(rbd_dev);
> -   int buf_size = 4 + 8 + 8 + CEPH_ENCODING_START_BLK_LEN;
> -   char buf[buf_size];
> +   char buf[4 + 8 + 8 + CEPH_ENCODING_START_BLK_LEN];
> void *p = buf;
>
> dout("%s rbd_dev %p notify_op %d\n", __func__, rbd_dev, notify_op);
>
> /* encode *LockPayload NotifyMessage (op + ClientId) */
> -   ceph_start_encoding(, 2, 1, buf_size - CEPH_ENCODING_START_BLK_LEN);
> +   ceph_start_encoding(, 2, 1,
> +   sizeof(buf) - CEPH_ENCODING_START_BLK_LEN);
> ceph_encode_32(, notify_op);
> ceph_encode_64(, cid.gid);
> ceph_encode_64(, cid.handle);
>
> return ceph_osdc_notify(osdc, _dev->header_oid,
> -   _dev->header_oloc, buf, buf_size,
> +   _dev->header_oloc, buf, sizeof(buf),
> RBD_NOTIFY_TIMEOUT, preply_pages, preply_len);
>  }
>
> @@ -3610,19 +3610,18 @@ static void __rbd_acknowledge_notify(struct 
> rbd_device *rbd_dev,
>  u64 notify_id, u64 cookie, s32 *result)
>  {
> struct ceph_osd_client *osdc = _dev->rbd_client->client->osdc;
> -   int buf_size = 4 + CEPH_ENCODING_START_BLK_LEN;
> -   char buf[buf_size];
> +   char buf[4 + CEPH_ENCODING_START_BLK_LEN];
> +   int buf_size = 0;
> int ret;
>
> if (result) {
> void *p = buf;
>
> +   buf_size = sizeof(buf);
> /* encode ResponseMessage */
> ceph_start_encoding(, 1, 1,
> buf_size - CEPH_ENCODING_START_BLK_LEN);
> ceph_encode_32(, *result);
> -   } else {
> -   buf_size = 0;
> }
>
> ret = ceph_osdc_notify_ack(osdc, _dev->header_oid,

Already fixed:

  
https://github.com/ceph/ceph-client/commit/2474e77e75215a3cad3b652d2f55ba5b123cb119

Thanks,

Ilya


[PATCH] rbd: remove VLA usage

2018-03-30 Thread Gustavo A. R. Silva
In preparation to enabling -Wvla, remove the use of stack VLA.

In this particular case, variable buf_size is replaced with a constant
expression that can be computed at preprocessing time. This avoids two
VLA warnings. Also, as a consequence of the mentioned change, some code
was slightly refactored.

The use of stack Variable Length Arrays needs to be avoided, as they
can be a vector for stack exhaustion, which can be both a runtime bug
or a security flaw. Also, in general, as code evolves it is easy to
lose track of how big a VLA can get. Thus, we can end up having runtime
failures that are hard to debug.

Also, fixed as part of the directive to remove all VLAs from
the kernel: https://lkml.org/lkml/2018/3/7/621

Signed-off-by: Gustavo A. R. Silva 
---
 drivers/block/rbd.c | 15 +++
 1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c
index 1e03b04..5133122 100644
--- a/drivers/block/rbd.c
+++ b/drivers/block/rbd.c
@@ -3091,20 +3091,20 @@ static int __rbd_notify_op_lock(struct rbd_device 
*rbd_dev,
 {
struct ceph_osd_client *osdc = _dev->rbd_client->client->osdc;
struct rbd_client_id cid = rbd_get_cid(rbd_dev);
-   int buf_size = 4 + 8 + 8 + CEPH_ENCODING_START_BLK_LEN;
-   char buf[buf_size];
+   char buf[4 + 8 + 8 + CEPH_ENCODING_START_BLK_LEN];
void *p = buf;
 
dout("%s rbd_dev %p notify_op %d\n", __func__, rbd_dev, notify_op);
 
/* encode *LockPayload NotifyMessage (op + ClientId) */
-   ceph_start_encoding(, 2, 1, buf_size - CEPH_ENCODING_START_BLK_LEN);
+   ceph_start_encoding(, 2, 1,
+   sizeof(buf) - CEPH_ENCODING_START_BLK_LEN);
ceph_encode_32(, notify_op);
ceph_encode_64(, cid.gid);
ceph_encode_64(, cid.handle);
 
return ceph_osdc_notify(osdc, _dev->header_oid,
-   _dev->header_oloc, buf, buf_size,
+   _dev->header_oloc, buf, sizeof(buf),
RBD_NOTIFY_TIMEOUT, preply_pages, preply_len);
 }
 
@@ -3610,19 +3610,18 @@ static void __rbd_acknowledge_notify(struct rbd_device 
*rbd_dev,
 u64 notify_id, u64 cookie, s32 *result)
 {
struct ceph_osd_client *osdc = _dev->rbd_client->client->osdc;
-   int buf_size = 4 + CEPH_ENCODING_START_BLK_LEN;
-   char buf[buf_size];
+   char buf[4 + CEPH_ENCODING_START_BLK_LEN];
+   int buf_size = 0;
int ret;
 
if (result) {
void *p = buf;
 
+   buf_size = sizeof(buf);
/* encode ResponseMessage */
ceph_start_encoding(, 1, 1,
buf_size - CEPH_ENCODING_START_BLK_LEN);
ceph_encode_32(, *result);
-   } else {
-   buf_size = 0;
}
 
ret = ceph_osdc_notify_ack(osdc, _dev->header_oid,
-- 
2.7.4



[PATCH] rbd: remove VLA usage

2018-03-30 Thread Gustavo A. R. Silva
In preparation to enabling -Wvla, remove the use of stack VLA.

In this particular case, variable buf_size is replaced with a constant
expression that can be computed at preprocessing time. This avoids two
VLA warnings. Also, as a consequence of the mentioned change, some code
was slightly refactored.

The use of stack Variable Length Arrays needs to be avoided, as they
can be a vector for stack exhaustion, which can be both a runtime bug
or a security flaw. Also, in general, as code evolves it is easy to
lose track of how big a VLA can get. Thus, we can end up having runtime
failures that are hard to debug.

Also, fixed as part of the directive to remove all VLAs from
the kernel: https://lkml.org/lkml/2018/3/7/621

Signed-off-by: Gustavo A. R. Silva 
---
 drivers/block/rbd.c | 15 +++
 1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c
index 1e03b04..5133122 100644
--- a/drivers/block/rbd.c
+++ b/drivers/block/rbd.c
@@ -3091,20 +3091,20 @@ static int __rbd_notify_op_lock(struct rbd_device 
*rbd_dev,
 {
struct ceph_osd_client *osdc = _dev->rbd_client->client->osdc;
struct rbd_client_id cid = rbd_get_cid(rbd_dev);
-   int buf_size = 4 + 8 + 8 + CEPH_ENCODING_START_BLK_LEN;
-   char buf[buf_size];
+   char buf[4 + 8 + 8 + CEPH_ENCODING_START_BLK_LEN];
void *p = buf;
 
dout("%s rbd_dev %p notify_op %d\n", __func__, rbd_dev, notify_op);
 
/* encode *LockPayload NotifyMessage (op + ClientId) */
-   ceph_start_encoding(, 2, 1, buf_size - CEPH_ENCODING_START_BLK_LEN);
+   ceph_start_encoding(, 2, 1,
+   sizeof(buf) - CEPH_ENCODING_START_BLK_LEN);
ceph_encode_32(, notify_op);
ceph_encode_64(, cid.gid);
ceph_encode_64(, cid.handle);
 
return ceph_osdc_notify(osdc, _dev->header_oid,
-   _dev->header_oloc, buf, buf_size,
+   _dev->header_oloc, buf, sizeof(buf),
RBD_NOTIFY_TIMEOUT, preply_pages, preply_len);
 }
 
@@ -3610,19 +3610,18 @@ static void __rbd_acknowledge_notify(struct rbd_device 
*rbd_dev,
 u64 notify_id, u64 cookie, s32 *result)
 {
struct ceph_osd_client *osdc = _dev->rbd_client->client->osdc;
-   int buf_size = 4 + CEPH_ENCODING_START_BLK_LEN;
-   char buf[buf_size];
+   char buf[4 + CEPH_ENCODING_START_BLK_LEN];
+   int buf_size = 0;
int ret;
 
if (result) {
void *p = buf;
 
+   buf_size = sizeof(buf);
/* encode ResponseMessage */
ceph_start_encoding(, 1, 1,
buf_size - CEPH_ENCODING_START_BLK_LEN);
ceph_encode_32(, *result);
-   } else {
-   buf_size = 0;
}
 
ret = ceph_osdc_notify_ack(osdc, _dev->header_oid,
-- 
2.7.4



Re: [PATCH] rbd: Remove VLA usage

2018-03-12 Thread Ilya Dryomov
On Sat, Mar 10, 2018 at 6:14 AM, Kyle Spiers <k...@spiers.me> wrote:
> From 4198ebe2e8058ff676d8e2f993d8806d6ca29c11 Mon Sep 17 00:00:00 2001
> From: Kyle Spiers <k...@spiers.me>
> Date: Fri, 9 Mar 2018 12:34:15 -0800
> Subject: [PATCH] rbd: Remove VLA usage
>
> As part of the effort to remove VLAs from the kernel[1], this moves
> the literal values into the stack array calculation instead of using a
> variable for the sizing. The resulting size can be found from
> sizeof(buf).
>
> [1] https://lkml.org/lkml/2018/3/7/621
>
> Signed-off-by: Kyle Spiers <k...@spiers.me>
>
> ---
>  drivers/block/rbd.c | 8 
>  1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c
> index 8e40da0..0e94e1f 100644
> --- a/drivers/block/rbd.c
> +++ b/drivers/block/rbd.c
> @@ -3100,8 +3100,8 @@ static int __rbd_notify_op_lock(struct rbd_device
> *rbd_dev,
>  {
>  struct ceph_osd_client *osdc = _dev->rbd_client->client->osdc;
>  struct rbd_client_id cid = rbd_get_cid(rbd_dev);
> -int buf_size = 4 + 8 + 8 + CEPH_ENCODING_START_BLK_LEN;
> -char buf[buf_size];
> +char buf[4 + 4 + 8 + 8 + CEPH_ENCODING_START_BLK_LEN];
> +int buf_size = sizeof(buf);
>  void *p = buf;
>
>  dout("%s rbd_dev %p notify_op %d\n", __func__, rbd_dev, notify_op);
> @@ -3619,8 +3619,8 @@ static void __rbd_acknowledge_notify(struct
> rbd_device *rbd_dev,
>   u64 notify_id, u64 cookie, s32 *result)
>  {
>  struct ceph_osd_client *osdc = _dev->rbd_client->client->osdc;
> -int buf_size = 4 + CEPH_ENCODING_START_BLK_LEN;
> -char buf[buf_size];
> +char buf[4 + CEPH_ENCODING_START_BLK_LEN];
> +int buf_size = sizeof(buf);
>  int ret;
>
>  if (result) {

This patch is mangled -- tabs, etc.  See

  https://www.kernel.org/doc/html/v4.15/process/email-clients.html

Thanks,

Ilya


Re: [PATCH] rbd: Remove VLA usage

2018-03-12 Thread Ilya Dryomov
On Sat, Mar 10, 2018 at 6:14 AM, Kyle Spiers  wrote:
> From 4198ebe2e8058ff676d8e2f993d8806d6ca29c11 Mon Sep 17 00:00:00 2001
> From: Kyle Spiers 
> Date: Fri, 9 Mar 2018 12:34:15 -0800
> Subject: [PATCH] rbd: Remove VLA usage
>
> As part of the effort to remove VLAs from the kernel[1], this moves
> the literal values into the stack array calculation instead of using a
> variable for the sizing. The resulting size can be found from
> sizeof(buf).
>
> [1] https://lkml.org/lkml/2018/3/7/621
>
> Signed-off-by: Kyle Spiers 
>
> ---
>  drivers/block/rbd.c | 8 
>  1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c
> index 8e40da0..0e94e1f 100644
> --- a/drivers/block/rbd.c
> +++ b/drivers/block/rbd.c
> @@ -3100,8 +3100,8 @@ static int __rbd_notify_op_lock(struct rbd_device
> *rbd_dev,
>  {
>  struct ceph_osd_client *osdc = _dev->rbd_client->client->osdc;
>  struct rbd_client_id cid = rbd_get_cid(rbd_dev);
> -int buf_size = 4 + 8 + 8 + CEPH_ENCODING_START_BLK_LEN;
> -char buf[buf_size];
> +char buf[4 + 4 + 8 + 8 + CEPH_ENCODING_START_BLK_LEN];
> +int buf_size = sizeof(buf);
>  void *p = buf;
>
>  dout("%s rbd_dev %p notify_op %d\n", __func__, rbd_dev, notify_op);
> @@ -3619,8 +3619,8 @@ static void __rbd_acknowledge_notify(struct
> rbd_device *rbd_dev,
>   u64 notify_id, u64 cookie, s32 *result)
>  {
>  struct ceph_osd_client *osdc = _dev->rbd_client->client->osdc;
> -int buf_size = 4 + CEPH_ENCODING_START_BLK_LEN;
> -char buf[buf_size];
> +char buf[4 + CEPH_ENCODING_START_BLK_LEN];
> +int buf_size = sizeof(buf);
>  int ret;
>
>  if (result) {

This patch is mangled -- tabs, etc.  See

  https://www.kernel.org/doc/html/v4.15/process/email-clients.html

Thanks,

Ilya


Re: [PATCH] rbd: Remove VLA usage

2018-03-10 Thread Kees Cook
On Fri, Mar 9, 2018 at 9:14 PM, Kyle Spiers <k...@spiers.me> wrote:
> From 4198ebe2e8058ff676d8e2f993d8806d6ca29c11 Mon Sep 17 00:00:00 2001
> From: Kyle Spiers <k...@spiers.me>
> Date: Fri, 9 Mar 2018 12:34:15 -0800
> Subject: [PATCH] rbd: Remove VLA usage
>
> As part of the effort to remove VLAs from the kernel[1], this moves
> the literal values into the stack array calculation instead of using a
> variable for the sizing. The resulting size can be found from
> sizeof(buf).
>
> [1] https://lkml.org/lkml/2018/3/7/621
>
> Signed-off-by: Kyle Spiers <k...@spiers.me>

Thanks!

Reviewed-by: Kees Cook <keesc...@chromium.org>

-Kees

>
> ---
>  drivers/block/rbd.c | 8 
>  1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c
> index 8e40da0..0e94e1f 100644
> --- a/drivers/block/rbd.c
> +++ b/drivers/block/rbd.c
> @@ -3100,8 +3100,8 @@ static int __rbd_notify_op_lock(struct rbd_device
> *rbd_dev,
>  {
>  struct ceph_osd_client *osdc = _dev->rbd_client->client->osdc;
>  struct rbd_client_id cid = rbd_get_cid(rbd_dev);
> -int buf_size = 4 + 8 + 8 + CEPH_ENCODING_START_BLK_LEN;
> -char buf[buf_size];
> +char buf[4 + 4 + 8 + 8 + CEPH_ENCODING_START_BLK_LEN];
> +int buf_size = sizeof(buf);
>  void *p = buf;
>
>  dout("%s rbd_dev %p notify_op %d\n", __func__, rbd_dev, notify_op);
> @@ -3619,8 +3619,8 @@ static void __rbd_acknowledge_notify(struct
> rbd_device *rbd_dev,
>   u64 notify_id, u64 cookie, s32 *result)
>  {
>  struct ceph_osd_client *osdc = _dev->rbd_client->client->osdc;
> -int buf_size = 4 + CEPH_ENCODING_START_BLK_LEN;
> -char buf[buf_size];
> +char buf[4 + CEPH_ENCODING_START_BLK_LEN];
> +int buf_size = sizeof(buf);
>  int ret;
>
>  if (result) {
> -- 2.7.4
>



-- 
Kees Cook
Pixel Security


Re: [PATCH] rbd: Remove VLA usage

2018-03-10 Thread Kees Cook
On Fri, Mar 9, 2018 at 9:14 PM, Kyle Spiers  wrote:
> From 4198ebe2e8058ff676d8e2f993d8806d6ca29c11 Mon Sep 17 00:00:00 2001
> From: Kyle Spiers 
> Date: Fri, 9 Mar 2018 12:34:15 -0800
> Subject: [PATCH] rbd: Remove VLA usage
>
> As part of the effort to remove VLAs from the kernel[1], this moves
> the literal values into the stack array calculation instead of using a
> variable for the sizing. The resulting size can be found from
> sizeof(buf).
>
> [1] https://lkml.org/lkml/2018/3/7/621
>
> Signed-off-by: Kyle Spiers 

Thanks!

Reviewed-by: Kees Cook 

-Kees

>
> ---
>  drivers/block/rbd.c | 8 
>  1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c
> index 8e40da0..0e94e1f 100644
> --- a/drivers/block/rbd.c
> +++ b/drivers/block/rbd.c
> @@ -3100,8 +3100,8 @@ static int __rbd_notify_op_lock(struct rbd_device
> *rbd_dev,
>  {
>  struct ceph_osd_client *osdc = _dev->rbd_client->client->osdc;
>  struct rbd_client_id cid = rbd_get_cid(rbd_dev);
> -int buf_size = 4 + 8 + 8 + CEPH_ENCODING_START_BLK_LEN;
> -char buf[buf_size];
> +char buf[4 + 4 + 8 + 8 + CEPH_ENCODING_START_BLK_LEN];
> +int buf_size = sizeof(buf);
>  void *p = buf;
>
>  dout("%s rbd_dev %p notify_op %d\n", __func__, rbd_dev, notify_op);
> @@ -3619,8 +3619,8 @@ static void __rbd_acknowledge_notify(struct
> rbd_device *rbd_dev,
>   u64 notify_id, u64 cookie, s32 *result)
>  {
>  struct ceph_osd_client *osdc = _dev->rbd_client->client->osdc;
> -int buf_size = 4 + CEPH_ENCODING_START_BLK_LEN;
> -char buf[buf_size];
> +char buf[4 + CEPH_ENCODING_START_BLK_LEN];
> +int buf_size = sizeof(buf);
>  int ret;
>
>  if (result) {
> -- 2.7.4
>



-- 
Kees Cook
Pixel Security


[PATCH] rbd: Remove VLA usage

2018-03-09 Thread Kyle Spiers
>From 4198ebe2e8058ff676d8e2f993d8806d6ca29c11 Mon Sep 17 00:00:00 2001
From: Kyle Spiers <k...@spiers.me>
Date: Fri, 9 Mar 2018 12:34:15 -0800
Subject: [PATCH] rbd: Remove VLA usage

As part of the effort to remove VLAs from the kernel[1], this moves
the literal values into the stack array calculation instead of using a
variable for the sizing. The resulting size can be found from
sizeof(buf).

[1] https://lkml.org/lkml/2018/3/7/621

Signed-off-by: Kyle Spiers <k...@spiers.me>

---
 drivers/block/rbd.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c
index 8e40da0..0e94e1f 100644
--- a/drivers/block/rbd.c
+++ b/drivers/block/rbd.c
@@ -3100,8 +3100,8 @@ static int __rbd_notify_op_lock(struct rbd_device
*rbd_dev,
 {
 struct ceph_osd_client *osdc = _dev->rbd_client->client->osdc;
 struct rbd_client_id cid = rbd_get_cid(rbd_dev);
-    int buf_size = 4 + 8 + 8 + CEPH_ENCODING_START_BLK_LEN;
-    char buf[buf_size];
+    char buf[4 + 4 + 8 + 8 + CEPH_ENCODING_START_BLK_LEN];
+    int buf_size = sizeof(buf);
 void *p = buf;
 
 dout("%s rbd_dev %p notify_op %d\n", __func__, rbd_dev, notify_op);
@@ -3619,8 +3619,8 @@ static void __rbd_acknowledge_notify(struct
rbd_device *rbd_dev,
              u64 notify_id, u64 cookie, s32 *result)
 {
 struct ceph_osd_client *osdc = _dev->rbd_client->client->osdc;
-    int buf_size = 4 + CEPH_ENCODING_START_BLK_LEN;
-    char buf[buf_size];
+    char buf[4 + CEPH_ENCODING_START_BLK_LEN];
+    int buf_size = sizeof(buf);
 int ret;
 
 if (result) {
-- 2.7.4



[PATCH] rbd: Remove VLA usage

2018-03-09 Thread Kyle Spiers
>From 4198ebe2e8058ff676d8e2f993d8806d6ca29c11 Mon Sep 17 00:00:00 2001
From: Kyle Spiers 
Date: Fri, 9 Mar 2018 12:34:15 -0800
Subject: [PATCH] rbd: Remove VLA usage

As part of the effort to remove VLAs from the kernel[1], this moves
the literal values into the stack array calculation instead of using a
variable for the sizing. The resulting size can be found from
sizeof(buf).

[1] https://lkml.org/lkml/2018/3/7/621

Signed-off-by: Kyle Spiers 

---
 drivers/block/rbd.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c
index 8e40da0..0e94e1f 100644
--- a/drivers/block/rbd.c
+++ b/drivers/block/rbd.c
@@ -3100,8 +3100,8 @@ static int __rbd_notify_op_lock(struct rbd_device
*rbd_dev,
 {
 struct ceph_osd_client *osdc = _dev->rbd_client->client->osdc;
 struct rbd_client_id cid = rbd_get_cid(rbd_dev);
-    int buf_size = 4 + 8 + 8 + CEPH_ENCODING_START_BLK_LEN;
-    char buf[buf_size];
+    char buf[4 + 4 + 8 + 8 + CEPH_ENCODING_START_BLK_LEN];
+    int buf_size = sizeof(buf);
 void *p = buf;
 
 dout("%s rbd_dev %p notify_op %d\n", __func__, rbd_dev, notify_op);
@@ -3619,8 +3619,8 @@ static void __rbd_acknowledge_notify(struct
rbd_device *rbd_dev,
              u64 notify_id, u64 cookie, s32 *result)
 {
 struct ceph_osd_client *osdc = _dev->rbd_client->client->osdc;
-    int buf_size = 4 + CEPH_ENCODING_START_BLK_LEN;
-    char buf[buf_size];
+    char buf[4 + CEPH_ENCODING_START_BLK_LEN];
+    int buf_size = sizeof(buf);
 int ret;
 
 if (result) {
-- 2.7.4