public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] rbd: Remove VLA stack usage
@ 2018-03-12  4:49 Tobin C. Harding
  2018-03-12  5:02 ` Eric Biggers
  0 siblings, 1 reply; 4+ messages in thread
From: Tobin C. Harding @ 2018-03-12  4:49 UTC (permalink / raw)
  To: Ilya Dryomov, Sage Weil, Alex Elder
  Cc: Tobin C. Harding, ceph-devel, linux-kernel, kernel-hardening,
	Tycho Andersen, Kees Cook

The kernel would like to have all stack VLA usage removed[1].  Here the
array is declared using a variable that is declared using a constant
statement but the compiler still emits a warning.  We can clear the
warning bu using the constant statement directly.  In place of later
usage of the size variable we can use the ARRAY_SIZE() macro.

Use constant statement to declare array.

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

Signed-off-by: Tobin C. Harding <me@tobin.cc>
---
 drivers/block/rbd.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c
index 0016170cde0a..927ecd9a2511 100644
--- a/drivers/block/rbd.c
+++ b/drivers/block/rbd.c
@@ -3100,20 +3100,19 @@ static int __rbd_notify_op_lock(struct rbd_device *rbd_dev,
 {
 	struct ceph_osd_client *osdc = &rbd_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(&p, 2, 1, buf_size - CEPH_ENCODING_START_BLK_LEN);
+	ceph_start_encoding(&p, 2, 1, ARRAY_SIZE(buf) - CEPH_ENCODING_START_BLK_LEN);
 	ceph_encode_32(&p, notify_op);
 	ceph_encode_64(&p, cid.gid);
 	ceph_encode_64(&p, cid.handle);
 
 	return ceph_osdc_notify(osdc, &rbd_dev->header_oid,
-				&rbd_dev->header_oloc, buf, buf_size,
+				&rbd_dev->header_oloc, buf, ARRAY_SIZE(buf),
 				RBD_NOTIFY_TIMEOUT, preply_pages, preply_len);
 }
 
-- 
2.7.4

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

* Re: [PATCH] rbd: Remove VLA stack usage
  2018-03-12  4:49 [PATCH] rbd: Remove VLA stack usage Tobin C. Harding
@ 2018-03-12  5:02 ` Eric Biggers
  2018-03-12  5:06   ` Tobin C. Harding
  0 siblings, 1 reply; 4+ messages in thread
From: Eric Biggers @ 2018-03-12  5:02 UTC (permalink / raw)
  To: Tobin C. Harding
  Cc: Ilya Dryomov, Sage Weil, Alex Elder, ceph-devel, linux-kernel,
	kernel-hardening, Tycho Andersen, Kees Cook

On Mon, Mar 12, 2018 at 03:49:40PM +1100, Tobin C. Harding wrote:
> The kernel would like to have all stack VLA usage removed[1].

Can you please stop writing this?  The Linux kernel isn't sentient; it doesn't
"like" anything.  You need to explain why *you* (and other people) believe these
changes should be made.

Eric

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

* Re: [PATCH] rbd: Remove VLA stack usage
  2018-03-12  5:02 ` Eric Biggers
@ 2018-03-12  5:06   ` Tobin C. Harding
  2018-03-12  9:57     ` Ilya Dryomov
  0 siblings, 1 reply; 4+ messages in thread
From: Tobin C. Harding @ 2018-03-12  5:06 UTC (permalink / raw)
  To: Eric Biggers
  Cc: Ilya Dryomov, Sage Weil, Alex Elder, ceph-devel, linux-kernel,
	kernel-hardening, Tycho Andersen, Kees Cook

On Sun, Mar 11, 2018 at 10:02:04PM -0700, Eric Biggers wrote:
> On Mon, Mar 12, 2018 at 03:49:40PM +1100, Tobin C. Harding wrote:
> > The kernel would like to have all stack VLA usage removed[1].
> 
> Can you please stop writing this?  The Linux kernel isn't sentient; it doesn't
> "like" anything.  You need to explain why *you* (and other people) believe these
> changes should be made.

No worries, will re-spin with better description.

thanks,
Tobin.

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

* Re: [PATCH] rbd: Remove VLA stack usage
  2018-03-12  5:06   ` Tobin C. Harding
@ 2018-03-12  9:57     ` Ilya Dryomov
  0 siblings, 0 replies; 4+ messages in thread
From: Ilya Dryomov @ 2018-03-12  9:57 UTC (permalink / raw)
  To: Tobin C. Harding
  Cc: Eric Biggers, Sage Weil, Alex Elder, Ceph Development,
	linux-kernel, kernel-hardening, Tycho Andersen, Kees Cook

On Mon, Mar 12, 2018 at 6:06 AM, Tobin C. Harding <me@tobin.cc> wrote:
> On Sun, Mar 11, 2018 at 10:02:04PM -0700, Eric Biggers wrote:
>> On Mon, Mar 12, 2018 at 03:49:40PM +1100, Tobin C. Harding wrote:
>> > The kernel would like to have all stack VLA usage removed[1].
>>
>> Can you please stop writing this?  The Linux kernel isn't sentient; it doesn't
>> "like" anything.  You need to explain why *you* (and other people) believe these
>> changes should be made.
>
> No worries, will re-spin with better description.

I'd prefer a single patch covering both functions.

Also, as these are char arrays, use sizeof instead of ARRAY_SIZE.

Thanks,

                Ilya

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

end of thread, other threads:[~2018-03-12  9:57 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-03-12  4:49 [PATCH] rbd: Remove VLA stack usage Tobin C. Harding
2018-03-12  5:02 ` Eric Biggers
2018-03-12  5:06   ` Tobin C. Harding
2018-03-12  9:57     ` Ilya Dryomov

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