From: "Gustavo A. R. Silva" <gustavo@embeddedor.com>
To: Ilya Dryomov <idryomov@gmail.com>
Cc: Sage Weil <sage@redhat.com>, Alex Elder <elder@kernel.org>,
Jens Axboe <axboe@kernel.dk>,
Ceph Development <ceph-devel@vger.kernel.org>,
linux-block <linux-block@vger.kernel.org>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] rbd: remove VLA usage
Date: Fri, 30 Mar 2018 15:34:39 -0500 [thread overview]
Message-ID: <0e56a59e-6dbe-a4c9-f761-e7e7d63db297@embeddedor.com> (raw)
In-Reply-To: <CAOi1vP8jzp9s4Qj9rBf90eU1TVY9C3W8ezThUXcSHUOX-B=pQg@mail.gmail.com>
On 03/30/2018 03:29 PM, Ilya Dryomov wrote:
> On Fri, Mar 30, 2018 at 9:17 PM, Gustavo A. R. Silva
> <gustavo@embeddedor.com> 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 <gustavo@embeddedor.com>
>> ---
>> 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 = &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,
>> + sizeof(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, 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 = &rbd_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(&p, 1, 1,
>> buf_size - CEPH_ENCODING_START_BLK_LEN);
>> ceph_encode_32(&p, *result);
>> - } else {
>> - buf_size = 0;
>> }
>>
>> ret = ceph_osdc_notify_ack(osdc, &rbd_dev->header_oid,
>
> Already fixed:
>
> https://github.com/ceph/ceph-client/commit/2474e77e75215a3cad3b652d2f55ba5b123cb119
>
Oh, that's great.
Good to know. :)
Thanks
--
Gustavo
next prev parent reply other threads:[~2018-03-30 20:58 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-03-30 19:17 Gustavo A. R. Silva
2018-03-30 20:29 ` Ilya Dryomov
2018-03-30 20:34 ` Gustavo A. R. Silva [this message]
-- strict thread matches above, loose matches on Subject: below --
2018-03-10 5:14 [PATCH] rbd: Remove " Kyle Spiers
2018-03-10 15:24 ` Kees Cook
2018-03-12 9:45 ` Ilya Dryomov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=0e56a59e-6dbe-a4c9-f761-e7e7d63db297@embeddedor.com \
--to=gustavo@embeddedor.com \
--cc=axboe@kernel.dk \
--cc=ceph-devel@vger.kernel.org \
--cc=elder@kernel.org \
--cc=idryomov@gmail.com \
--cc=linux-block@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=sage@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®