Doubt about memory realloc logic in BUF_MEM_grow_clean and BUF_MEM_grow

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Doubt about memory realloc logic in BUF_MEM_grow_clean and BUF_MEM_grow

Raja ashok

Hi All,

 

I am having a doubt BUF_MEM_grow and BUF_MEM_grow_clean. After reallocation of buffer we are memsetting the buffer from “str->length” index.

 

    } else {

        str->data = ret;

        str->max = n;

        memset(&str->data[str->length], 0, len - str->length);

        str->length = len;

    }

 

I feel we should memset from “str->max”.

1)      One usage of this BUF_MEM is init buffer (s->init_buf) in SSL handshake for storing peer’s message and framing response message.

2)      Initially in ssl3_connect and ssl3_accept we are creating this s->init_buf of size 16348 bytes.

3)      Later in ssl3_get_message we are using this buffer for receiving peer’s handshake message of length “l”. Here we are calling BUF_MEM_grow_clean with “(l + 4 + 16)” as length. If (l + 4 +16) is lesser than 16348, then “init_buf->length” is set to that.

4)      After parsing the received msg and we are framing the response message on the same s->init_buf. For example consider ssl3_send_certificate_request, here we are copying Cert types and sign hash algorithm, after that we are calling mem grow before copying X509 name of CA cert.

5)      Here, if the data (cert types and sign hash alg) copied before calling mem grow is more than (l + 4 + 16) of previously received msg, then it will leads to some data loss inside BUF_MEM_grow_clean we are memsetting from “data[str->length]”.

 

In OpenSSL, BUF_MEM is used in many modules like ASN, PEM and SSL. So as per my understanding better we should memset from “max” index in case of realloc, like below pseudocode.

 

    } else {

        str->data = ret;

        memset(&str->data[str->max], 0, n �C str->max);

        str->max = n;

        str->length = len;

    }

 

This we should not do for OPENSSL_malloc, in that case we can memset complete buffer.

 

Regards,

Ashok

 


Company_logo

Raja Ashok V K
Huawei Technologies
Bangalore, India
http://www.huawei.com


本邮件及其附件含有华为公司的保密信息,仅限于发送给上面地址中列出的个人或群组。禁
止任何其他人以任何形式使用(包括但不限于全部或部分地泄露、复制、或散发)本邮件中
的信息。如果您错收了本邮件,请您立即电话或邮件通知发件人并删除本邮件!
This e-mail and its attachments contain confidential information from HUAWEI, which
is intended only for the person or entity whose address is listed above. Any use of the
information contained herein in any way (including, but not limited to, total or partial
disclosure, reproduction, or dissemination) by persons other than the intended
recipient(s) is prohibited. If you receive this e-mail in error, please notify the sender by
phone or email immediately and delete it!

 


--
openssl-dev mailing list
To unsubscribe: https://mta.openssl.org/mailman/listinfo/openssl-dev
Reply | Threaded
Open this post in threaded view
|

Re: Doubt about memory realloc logic in BUF_MEM_grow_clean and BUF_MEM_grow

OpenSSL - Dev mailing list
>??????? memset(&str->data[str->length], 0, len - str->length);

The intent is to blank out everything from what was currently written.  This "covers up" possible pointer over-runs.

We could do just from the old max.
--
openssl-dev mailing list
To unsubscribe: https://mta.openssl.org/mailman/listinfo/openssl-dev
Reply | Threaded
Open this post in threaded view
|

Re: Doubt about memory realloc logic in BUF_MEM_grow_clean and BUF_MEM_grow

Raja ashok
Hi Salz,

I raised a PR for this change. Already got some comments from Kurt. Requesting you also to check and provide your suggestions on it.
https://github.com/openssl/openssl/pull/3255

Currently raised PR on only 1.0.2. Once its reviewed, I can raise on other branches (1.1.0 and Master).


Raja Ashok V K
Huawei Technologies
Bangalore, India
http://www.huawei.com 

本邮件及其附件含有华为公司的保密信息,仅限于发送给上面地址中列出的个人或群组。禁
止任何其他人以任何形式使用(包括但不限于全部或部分地泄露、复制、或散发)本邮件中
的信息。如果您错收了本邮件,请您立即电话或邮件通知发件人并删除本邮件!
This e-mail and its attachments contain confidential information from HUAWEI, which
is intended only for the person or entity whose address is listed above. Any use of the
information contained herein in any way (including, but not limited to, total or partial
disclosure, reproduction, or dissemination) by persons other than the intended
recipient(s) is prohibited. If you receive this e-mail in error, please notify the sender by
phone or email immediately and delete it!

-----Original Message-----
From: openssl-dev [mailto:[hidden email]] On Behalf Of Salz, Rich via openssl-dev
Sent: 17 April 2017 22:02
To: [hidden email]
Subject: Re: [openssl-dev] Doubt about memory realloc logic in BUF_MEM_grow_clean and BUF_MEM_grow

>??????? memset(&str->data[str->length], 0, len - str->length);

The intent is to blank out everything from what was currently written.  This "covers up" possible pointer over-runs.

We could do just from the old max.
--
openssl-dev mailing list
To unsubscribe: https://mta.openssl.org/mailman/listinfo/openssl-dev
--
openssl-dev mailing list
To unsubscribe: https://mta.openssl.org/mailman/listinfo/openssl-dev
Reply | Threaded
Open this post in threaded view
|

Re: Doubt about memory realloc logic in BUF_MEM_grow_clean and BUF_MEM_grow

OpenSSL - Dev mailing list
> Requesting you also to check and provide your suggestions on it.
> https://github.com/openssl/openssl/pull/3255

As Matt and Kurt have said, this seems to be 'covering up' real bugs in the source.   It doesn't seem like a good idea.
--
openssl-dev mailing list
To unsubscribe: https://mta.openssl.org/mailman/listinfo/openssl-dev