You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by Ruediger Pluem <rp...@apache.org> on 2024/07/01 13:01:44 UTC
Re: svn commit: r1908537 - /httpd/httpd/trunk/modules/ssl/
On 6/27/24 3:48 PM, Ruediger Pluem wrote:
>
>
> On 6/27/24 12:47 PM, Yann Ylavic wrote:
>> On Thu, Jun 27, 2024 at 12:38 PM Yann Ylavic <yl...@gmail.com> wrote:
>>>
>>> On Thu, Jun 27, 2024 at 12:07 PM Ruediger Pluem <rp...@apache.org> wrote:
>>>>
>>>> How about the below? I am yet undecided if I should follow the below approach to have
>>>> two completely separate callbacks depending on the OpenSSL version or one with a lot of
>>>> #If statements in it, but as much shared code as possible. Thoughts?
>>>
>>> Hm, I wouldn't duplicate the whole thing depending on openssl version.
>>>
>>> Something like the attached maybe? modssl_io_cb() will just consider
>>> up to APR_INT32_MAX bytes, more shouldn't happen anyway and it's more
>>> than enough for debug logs..
>>
>> We could even log the real length still if it matters, see attached v2.
>
> Thanks. Unfortunately the meaning of rc varies depending on if we have the ex or the non ex callback.
> This is not in the documentation but only in the OpenSSL code :-(.
> Furthermore the processed amount of data is in *processed in the ex case whereas in the non ex case it is in
> rc. The intended amount of data to be processed is in len in the ex case and in argi in the non ex case.
> Hence I propose the patch below. Of course we can have a longer debate if the len parameter to ssl_io_data_dump
> should be int or size_t :-). And yes dumping more than APR_INT32_MAX bytes to the log might be bad.
Any further comments on whether we should limit the dump to APR_INT32_MAX or not? I would guess that it will not matter
in practice, but I am still open to it.
BTW: I guess
int len = data_len & APR_INT32_MAX;
would be wrong. It would need to be
int len = data_len > APR_INT32_MAX ? APR_INT32_MAX : (int)data_len;
instead.
Regards
Rüdiger
>
>
> Index: modules/ssl/ssl_engine_io.c
> ===================================================================
> --- modules/ssl/ssl_engine_io.c (revision 1918662)
> +++ modules/ssl/ssl_engine_io.c (working copy)
> @@ -2308,7 +2308,7 @@
> #define DUMP_WIDTH 16
>
> static void ssl_io_data_dump(conn_rec *c, server_rec *s,
> - const char *b, long len)
> + const char *b, size_t len)
> {
> char buf[256];
> int i, j, rows, trunc, pos;
> @@ -2361,7 +2361,7 @@
> }
> if (trunc > 0)
> ap_log_cserror(APLOG_MARK, APLOG_TRACE7, 0, c, s,
> - "| %04ld - <SPACES/NULS>", len + trunc);
> + "| %04" APR_SIZE_T_FMT " - <SPACES/NULS>", len + (size_t)trunc);
> ap_log_cserror(APLOG_MARK, APLOG_TRACE7, 0, c, s,
> "+-------------------------------------------------------------------------+");
> }
> @@ -2379,9 +2379,9 @@
> conn_rec *c;
> server_rec *s;
> #if OPENSSL_VERSION_NUMBER >= 0x30000000L
> - (void)len;
> - (void)processed;
> + (void)argi;
> #endif
> + (void)argl;
>
> if ((ssl = (SSL *)BIO_get_callback_arg(bio)) == NULL)
> return rc;
> @@ -2391,7 +2391,20 @@
>
> if ( cmd == (BIO_CB_WRITE|BIO_CB_RETURN)
> || cmd == (BIO_CB_READ |BIO_CB_RETURN) ) {
> +#if OPENSSL_VERSION_NUMBER >= 0x30000000L
> +#define requested_len (len)
> +#define actual_len (*processed)
> + /*
> + * On OpenSSL >= 3 rc uses the meaning of the BIO_read_ex and
> + * BIO_write_ex functions return value and not the one of
> + * BIO_read and BIO_write. Hence 0 indicates an error.
> + */
> + if (rc > 0) {
> +#else
> +#define requested_len ((size_t)argi)
> +#define actual_len ((size_t)rc)
> if (rc >= 0) {
> +#endif
> const char *dump = "";
> if (APLOG_CS_IS_LEVEL(c, s, APLOG_TRACE7)) {
> if (argp != NULL)
> @@ -2400,18 +2413,21 @@
> dump = "(Oops, no memory buffer?)";
> }
> ap_log_cserror(APLOG_MARK, APLOG_TRACE4, 0, c, s,
> - "%s: %s %ld/%d bytes %s BIO#%pp [mem: %pp] %s",
> + "%s: %s %" APR_SIZE_T_FMT "/%" APR_SIZE_T_FMT
> + " bytes %s BIO#%pp [mem: %pp] %s",
> MODSSL_LIBRARY_NAME,
> (cmd == (BIO_CB_WRITE|BIO_CB_RETURN) ? "write" : "read"),
> - (long)rc, argi, (cmd == (BIO_CB_WRITE|BIO_CB_RETURN) ? "to" : "from"),
> + actual_len, requested_len,
> + (cmd == (BIO_CB_WRITE|BIO_CB_RETURN) ? "to" : "from"),
> bio, argp, dump);
> if (*dump != '\0' && argp != NULL)
> - ssl_io_data_dump(c, s, argp, rc);
> + ssl_io_data_dump(c, s, argp, actual_len);
> }
> else {
> ap_log_cserror(APLOG_MARK, APLOG_TRACE4, 0, c, s,
> - "%s: I/O error, %d bytes expected to %s on BIO#%pp [mem: %pp]",
> - MODSSL_LIBRARY_NAME, argi,
> + "%s: I/O error, %" APR_SIZE_T_FMT
> + " bytes expected to %s on BIO#%pp [mem: %pp]",
> + MODSSL_LIBRARY_NAME, requested_len,
> (cmd == (BIO_CB_WRITE|BIO_CB_RETURN) ? "write" : "read"),
> bio, argp);
> }
>
> Regards
>
> Rüdiger
>
>>
>>>
>>> Regards;
>>> Yann.
>
Re: svn commit: r1908537 - /httpd/httpd/trunk/modules/ssl/
Posted by Ruediger Pluem <rp...@apache.org>.
On 7/3/24 11:09 AM, Yann Ylavic wrote:
> On Wed, Jul 3, 2024 at 11:01 AM Yann Ylavic <yl...@gmail.com> wrote:
>>
>> On Wed, Jul 3, 2024 at 10:57 AM Yann Ylavic <yl...@gmail.com> wrote:
>>>
>>> On Wed, Jul 3, 2024 at 8:58 AM Ruediger Pluem <rp...@apache.org> wrote:
>>>>
>>>> On 7/3/24 2:59 AM, Yann Ylavic wrote:
>>>>> On Tue, Jul 2, 2024 at 10:57 AM Ruediger Pluem <rp...@apache.org> wrote:
>>>>>>
>>>>>> Updated patch.
>>> []
>>>>>> const char *dump = "";
>>>>>> if (APLOG_CS_IS_LEVEL(c, s, APLOG_TRACE7)) {
>>>>>> if (argp != NULL)
>>>>>> @@ -2400,23 +2413,28 @@
>>>>>> dump = "(Oops, no memory buffer?)";
>>>>>> }
>>>>>> ap_log_cserror(APLOG_MARK, APLOG_TRACE4, 0, c, s,
>>>>>> - "%s: %s %ld/%d bytes %s BIO#%pp [mem: %pp] %s",
>>>>>> + "%s: %s %" APR_SIZE_T_FMT "/%" APR_SIZE_T_FMT
>>>>>> + " bytes %s BIO#%pp [mem: %pp] %s",
>>>>>> MODSSL_LIBRARY_NAME,
>>>>>> (cmd == (BIO_CB_WRITE|BIO_CB_RETURN) ? "write" : "read"),
>>>>>> - (long)rc, argi, (cmd == (BIO_CB_WRITE|BIO_CB_RETURN) ? "to" : "from"),
>>>>>> + actual_len, requested_len,
>>>>>> + (cmd == (BIO_CB_WRITE|BIO_CB_RETURN) ? "to" : "from"),
>>>>>> bio, argp, dump);
>>>>>> if (*dump != '\0' && argp != NULL)
>>
>> Here we could check for APLOG_CS_IS_LEVEL(c, s, APLOG_TRACE7) too, to
>> save the call when ssl_io_data_dump() is a noop anyway.
>
> In this area, maybe we want to move the check for APLOG_TRACE4 from
> the caller of modssl_set_io_callbacks() to the helper itself (which
> knows better). Something like the attached eventually, feel free to
> use since you are touching this code ;)
>
This is a good idea, but I would handle this separately. Feel free to commit.
Regards
Rüdiger
Re: svn commit: r1908537 - /httpd/httpd/trunk/modules/ssl/
Posted by Yann Ylavic <yl...@gmail.com>.
On Wed, Jul 3, 2024 at 11:01 AM Yann Ylavic <yl...@gmail.com> wrote:
>
> On Wed, Jul 3, 2024 at 10:57 AM Yann Ylavic <yl...@gmail.com> wrote:
> >
> > On Wed, Jul 3, 2024 at 8:58 AM Ruediger Pluem <rp...@apache.org> wrote:
> > >
> > > On 7/3/24 2:59 AM, Yann Ylavic wrote:
> > > > On Tue, Jul 2, 2024 at 10:57 AM Ruediger Pluem <rp...@apache.org> wrote:
> > > >>
> > > >> Updated patch.
> > []
> > > >> const char *dump = "";
> > > >> if (APLOG_CS_IS_LEVEL(c, s, APLOG_TRACE7)) {
> > > >> if (argp != NULL)
> > > >> @@ -2400,23 +2413,28 @@
> > > >> dump = "(Oops, no memory buffer?)";
> > > >> }
> > > >> ap_log_cserror(APLOG_MARK, APLOG_TRACE4, 0, c, s,
> > > >> - "%s: %s %ld/%d bytes %s BIO#%pp [mem: %pp] %s",
> > > >> + "%s: %s %" APR_SIZE_T_FMT "/%" APR_SIZE_T_FMT
> > > >> + " bytes %s BIO#%pp [mem: %pp] %s",
> > > >> MODSSL_LIBRARY_NAME,
> > > >> (cmd == (BIO_CB_WRITE|BIO_CB_RETURN) ? "write" : "read"),
> > > >> - (long)rc, argi, (cmd == (BIO_CB_WRITE|BIO_CB_RETURN) ? "to" : "from"),
> > > >> + actual_len, requested_len,
> > > >> + (cmd == (BIO_CB_WRITE|BIO_CB_RETURN) ? "to" : "from"),
> > > >> bio, argp, dump);
> > > >> if (*dump != '\0' && argp != NULL)
>
> Here we could check for APLOG_CS_IS_LEVEL(c, s, APLOG_TRACE7) too, to
> save the call when ssl_io_data_dump() is a noop anyway.
In this area, maybe we want to move the check for APLOG_TRACE4 from
the caller of modssl_set_io_callbacks() to the helper itself (which
knows better). Something like the attached eventually, feel free to
use since you are touching this code ;)
Re: svn commit: r1908537 - /httpd/httpd/trunk/modules/ssl/
Posted by Yann Ylavic <yl...@gmail.com>.
On Wed, Jul 3, 2024 at 4:40 PM Ruediger Pluem <rp...@apache.org> wrote:
>
> On 7/3/24 3:23 PM, Yann Ylavic wrote:
> > On Wed, Jul 3, 2024 at 2:34 PM Ruediger Pluem <rp...@apache.org> wrote:
> >>
> >> Thanks for the intense review. I hope I captured all stuff in the below.
> >
> > Thanks for working on this.
>
> Committed in r1918880 considering your comments. Feel free to add the patch you provided
> with regards to the move of the trace level checking.
Done in r1918883.
Re: svn commit: r1908537 - /httpd/httpd/trunk/modules/ssl/
Posted by Yann Ylavic <yl...@gmail.com>.
On Wed, Jul 3, 2024 at 4:40 PM Ruediger Pluem <rp...@apache.org> wrote:
>
> On 7/3/24 3:23 PM, Yann Ylavic wrote:
> > On Wed, Jul 3, 2024 at 2:34 PM Ruediger Pluem <rp...@apache.org> wrote:
> >>
> >> Thanks for the intense review. I hope I captured all stuff in the below.
> >
> > Thanks for working on this.
>
> Committed in r1918880 considering your comments. Feel free to add the patch you provided
> with regards to the move of the trace level checking.
Great, thanks Rüdiger!
Re: svn commit: r1908537 - /httpd/httpd/trunk/modules/ssl/
Posted by Ruediger Pluem <rp...@apache.org>.
On 7/3/24 3:23 PM, Yann Ylavic wrote:
> On Wed, Jul 3, 2024 at 2:34 PM Ruediger Pluem <rp...@apache.org> wrote:
>>
>> Thanks for the intense review. I hope I captured all stuff in the below.
>
> Thanks for working on this.
Committed in r1918880 considering your comments. Feel free to add the patch you provided
with regards to the move of the trace level checking.
Regards
Rüdiger
Re: svn commit: r1908537 - /httpd/httpd/trunk/modules/ssl/
Posted by Yann Ylavic <yl...@gmail.com>.
On Wed, Jul 3, 2024 at 2:34 PM Ruediger Pluem <rp...@apache.org> wrote:
>
> Thanks for the intense review. I hope I captured all stuff in the below.
Thanks for working on this.
> I intentionally left the 'len' parameter of ssl_io_data_dump an apr_size_t in case we ever get to the conclusion that we want to
> make MODSSL_IO_DUMP_MAX larger. It will fit then automatically.
>
> Index: modules/ssl/ssl_engine_io.c
> ===================================================================
> --- modules/ssl/ssl_engine_io.c (revision 1918869)
> +++ modules/ssl/ssl_engine_io.c (working copy)
> @@ -2308,7 +2308,7 @@
> #define DUMP_WIDTH 16
>
> static void ssl_io_data_dump(conn_rec *c, server_rec *s,
> - const char *b, long len)
> + const char *b, apr_size_t len)
> {
> char buf[256];
> int i, j, rows, trunc, pos;
The problem is that some of the i,j,.. should apr_size_t too then.
I'd rather we use "int len" here because APR_INT32_MAX is really a
hard limit IMHO, we shouldn't take seconds/minutes to log things to
disk anyway, and it'd avoid thinking about overflows here and keep
things simple.
> @@ -2361,11 +2361,13 @@
> }
> if (trunc > 0)
> ap_log_cserror(APLOG_MARK, APLOG_TRACE7, 0, c, s,
> - "| %04ld - <SPACES/NULS>", len + trunc);
> + "| %04" APR_SIZE_T_FMT " - <SPACES/NULS>", len + (size_t)trunc);
> ap_log_cserror(APLOG_MARK, APLOG_TRACE7, 0, c, s,
> "+-------------------------------------------------------------------------+");
> }
>
> +#define MODSSL_IO_DUMP_MAX APR_UINT16_MAX
> +
> #if OPENSSL_VERSION_NUMBER >= 0x30000000L
> static long modssl_io_cb(BIO *bio, int cmd, const char *argp,
> size_t len, int argi, long argl, int rc,
> @@ -2379,9 +2381,9 @@
> conn_rec *c;
> server_rec *s;
> #if OPENSSL_VERSION_NUMBER >= 0x30000000L
> - (void)len;
> - (void)processed;
> + (void)argi;
> #endif
> + (void)argl;
>
> if ((ssl = (SSL *)BIO_get_callback_arg(bio)) == NULL)
> return rc;
> @@ -2391,27 +2393,58 @@
>
> if ( cmd == (BIO_CB_WRITE|BIO_CB_RETURN)
> || cmd == (BIO_CB_READ |BIO_CB_RETURN) ) {
> - if (rc >= 0) {
> +#if OPENSSL_VERSION_NUMBER >= 0x30000000L
> + apr_size_t requested_len = len;
> + /*
> + * On OpenSSL >= 3 rc uses the meaning of the BIO_read_ex and
> + * BIO_write_ex functions return value and not the one of
> + * BIO_read and BIO_write. Hence 0 indicates an error.
> + */
> + int ok = (rc > 0);
> +#else
> + apr_size_t requested_len = (apr_size_t)argi;
> + int ok = (rc >= 0);
> +#endif
> + if (ok) {
> +#if OPENSSL_VERSION_NUMBER >= 0x30000000L
> + apr_size_t actual_len = *processed;
> +#else
> + apr_size_t actual_len = (apr_size_t)rc;
> +#endif
> const char *dump = "";
> if (APLOG_CS_IS_LEVEL(c, s, APLOG_TRACE7)) {
> - if (argp != NULL)
> + if (argp == NULL)
> + dump = "(Oops, no memory buffer?)";
> + else if (actual_len > MODSSL_IO_DUMP_MAX)
> + dump = "(BIO dump follows, truncated to "
> + APR_STRINGIFY(MODSSL_IO_DUMP_MAX) ")";
> + else
> dump = "(BIO dump follows)";
> - else
> - dump = "(Oops, no memory buffer?)";
> }
> ap_log_cserror(APLOG_MARK, APLOG_TRACE4, 0, c, s,
> - "%s: %s %ld/%d bytes %s BIO#%pp [mem: %pp] %s",
> + "%s: %s %" APR_SIZE_T_FMT "/%" APR_SIZE_T_FMT
> + " bytes %s BIO#%pp [mem: %pp] %s",
> MODSSL_LIBRARY_NAME,
> (cmd == (BIO_CB_WRITE|BIO_CB_RETURN) ? "write" : "read"),
> - (long)rc, argi, (cmd == (BIO_CB_WRITE|BIO_CB_RETURN) ? "to" : "from"),
> + actual_len, requested_len,
> + (cmd == (BIO_CB_WRITE|BIO_CB_RETURN) ? "to" : "from"),
> bio, argp, dump);
> - if (*dump != '\0' && argp != NULL)
> - ssl_io_data_dump(c, s, argp, rc);
> + /*
> + * *dump will only be != '\0' if
> + * APLOG_CS_IS_LEVEL(c, s, APLOG_TRACE7)
> + */
> + if (*dump != '\0' && argp != NULL) {
> + apr_size_t dump_len = (actual_len >= MODSSL_IO_DUMP_MAX
> + ? MODSSL_IO_DUMP_MAX
> + : actual_len);
So "int dump_len" here should be (more than) enough?
> + ssl_io_data_dump(c, s, argp, dump_len);
> + }
> }
> else {
> ap_log_cserror(APLOG_MARK, APLOG_TRACE4, 0, c, s,
> - "%s: I/O error, %d bytes expected to %s on BIO#%pp [mem: %pp]",
> - MODSSL_LIBRARY_NAME, argi,
> + "%s: I/O error, %" APR_SIZE_T_FMT
> + " bytes expected to %s on BIO#%pp [mem: %pp]",
> + MODSSL_LIBRARY_NAME, requested_len,
> (cmd == (BIO_CB_WRITE|BIO_CB_RETURN) ? "write" : "read"),
> bio, argp);
> }
Regards;
Yann.
Re: svn commit: r1908537 - /httpd/httpd/trunk/modules/ssl/
Posted by Ruediger Pluem <rp...@apache.org>.
On 7/3/24 11:01 AM, Yann Ylavic wrote:
> On Wed, Jul 3, 2024 at 10:57 AM Yann Ylavic <yl...@gmail.com> wrote:
>>
>> On Wed, Jul 3, 2024 at 8:58 AM Ruediger Pluem <rp...@apache.org> wrote:
>>>
>>> On 7/3/24 2:59 AM, Yann Ylavic wrote:
>>>> On Tue, Jul 2, 2024 at 10:57 AM Ruediger Pluem <rp...@apache.org> wrote:
>>>>>
>>>>> Updated patch.
>> []
>>>>> const char *dump = "";
>>>>> if (APLOG_CS_IS_LEVEL(c, s, APLOG_TRACE7)) {
>>>>> if (argp != NULL)
>>>>> @@ -2400,23 +2413,28 @@
>>>>> dump = "(Oops, no memory buffer?)";
>>>>> }
>>>>> ap_log_cserror(APLOG_MARK, APLOG_TRACE4, 0, c, s,
>>>>> - "%s: %s %ld/%d bytes %s BIO#%pp [mem: %pp] %s",
>>>>> + "%s: %s %" APR_SIZE_T_FMT "/%" APR_SIZE_T_FMT
>>>>> + " bytes %s BIO#%pp [mem: %pp] %s",
>>>>> MODSSL_LIBRARY_NAME,
>>>>> (cmd == (BIO_CB_WRITE|BIO_CB_RETURN) ? "write" : "read"),
>>>>> - (long)rc, argi, (cmd == (BIO_CB_WRITE|BIO_CB_RETURN) ? "to" : "from"),
>>>>> + actual_len, requested_len,
>>>>> + (cmd == (BIO_CB_WRITE|BIO_CB_RETURN) ? "to" : "from"),
>>>>> bio, argp, dump);
>>>>> if (*dump != '\0' && argp != NULL)
>
> Here we could check for APLOG_CS_IS_LEVEL(c, s, APLOG_TRACE7) too, to
> save the call when ssl_io_data_dump() is a noop anyway.
>
>>>>> - ssl_io_data_dump(c, s, argp, rc);
>>>>> + ssl_io_data_dump(c, s, argp, actual_len);
>>>> And here:
>>>> long dump_len = (actual_len >= APR_UINT16_MAX
>>>> ? APR_UINT16_MAX
>>>> : actual_len);
>>>
>>> Hm. As you point out: SSL records should be of limited length anyway, but if we really truncate the output shouldn't we log this?
>>> A log message like: Dump truncated to first XXX bytes?
>>
>> Something like this to initialize "dump" above?
>>
>> if (APLOG_CS_IS_LEVEL(c, s, APLOG_TRACE7)) {
>> if (argp == NULL)
>> dump = "(Oops, no memory buffer?)";
>> else if (actual_len > MODSSL_IO_DUMP_MAX)
>> dump = "(BIO dump follows, truncated to "
>> APR_STRINGIFY(MODSSL_IO_DUMP_MAX) ")";
>> else
>> dump = "(BIO dump follows)";
>> }
>>
>> where we'd "#define MODSSL_IO_DUMP_MAX APR_UINT16_MAX" and use it
>> everywhere eventually.
>>
>>>
>>>> ssl_io_data_dump(c, s, argp, dump_len);
>>>>> }
>>>>> else {
>>>>> ap_log_cserror(APLOG_MARK, APLOG_TRACE4, 0, c, s,
>>>>> - "%s: I/O error, %d bytes expected to %s on BIO#%pp [mem: %pp]",
>>>>> - MODSSL_LIBRARY_NAME, argi,
>>>>> + "%s: I/O error, %" APR_SIZE_T_FMT
>>>>> + " bytes expected to %s on BIO#%pp [mem: %pp]",
>>>>> + MODSSL_LIBRARY_NAME, requested_len,
>>>>> (cmd == (BIO_CB_WRITE|BIO_CB_RETURN) ? "write" : "read"),
>>>>> bio, argp);
>>>>> }
>>>>> }
>>>>> return rc;
>>>>> +#undef requested_len
>>>>> +#undef actual_len
>>>>> }
>>>> ?
>
Thanks for the intense review. I hope I captured all stuff in the below.
I intentionally left the 'len' parameter of ssl_io_data_dump an apr_size_t in case we ever get to the conclusion that we want to
make MODSSL_IO_DUMP_MAX larger. It will fit then automatically.
Index: modules/ssl/ssl_engine_io.c
===================================================================
--- modules/ssl/ssl_engine_io.c (revision 1918869)
+++ modules/ssl/ssl_engine_io.c (working copy)
@@ -2308,7 +2308,7 @@
#define DUMP_WIDTH 16
static void ssl_io_data_dump(conn_rec *c, server_rec *s,
- const char *b, long len)
+ const char *b, apr_size_t len)
{
char buf[256];
int i, j, rows, trunc, pos;
@@ -2361,11 +2361,13 @@
}
if (trunc > 0)
ap_log_cserror(APLOG_MARK, APLOG_TRACE7, 0, c, s,
- "| %04ld - <SPACES/NULS>", len + trunc);
+ "| %04" APR_SIZE_T_FMT " - <SPACES/NULS>", len + (size_t)trunc);
ap_log_cserror(APLOG_MARK, APLOG_TRACE7, 0, c, s,
"+-------------------------------------------------------------------------+");
}
+#define MODSSL_IO_DUMP_MAX APR_UINT16_MAX
+
#if OPENSSL_VERSION_NUMBER >= 0x30000000L
static long modssl_io_cb(BIO *bio, int cmd, const char *argp,
size_t len, int argi, long argl, int rc,
@@ -2379,9 +2381,9 @@
conn_rec *c;
server_rec *s;
#if OPENSSL_VERSION_NUMBER >= 0x30000000L
- (void)len;
- (void)processed;
+ (void)argi;
#endif
+ (void)argl;
if ((ssl = (SSL *)BIO_get_callback_arg(bio)) == NULL)
return rc;
@@ -2391,27 +2393,58 @@
if ( cmd == (BIO_CB_WRITE|BIO_CB_RETURN)
|| cmd == (BIO_CB_READ |BIO_CB_RETURN) ) {
- if (rc >= 0) {
+#if OPENSSL_VERSION_NUMBER >= 0x30000000L
+ apr_size_t requested_len = len;
+ /*
+ * On OpenSSL >= 3 rc uses the meaning of the BIO_read_ex and
+ * BIO_write_ex functions return value and not the one of
+ * BIO_read and BIO_write. Hence 0 indicates an error.
+ */
+ int ok = (rc > 0);
+#else
+ apr_size_t requested_len = (apr_size_t)argi;
+ int ok = (rc >= 0);
+#endif
+ if (ok) {
+#if OPENSSL_VERSION_NUMBER >= 0x30000000L
+ apr_size_t actual_len = *processed;
+#else
+ apr_size_t actual_len = (apr_size_t)rc;
+#endif
const char *dump = "";
if (APLOG_CS_IS_LEVEL(c, s, APLOG_TRACE7)) {
- if (argp != NULL)
+ if (argp == NULL)
+ dump = "(Oops, no memory buffer?)";
+ else if (actual_len > MODSSL_IO_DUMP_MAX)
+ dump = "(BIO dump follows, truncated to "
+ APR_STRINGIFY(MODSSL_IO_DUMP_MAX) ")";
+ else
dump = "(BIO dump follows)";
- else
- dump = "(Oops, no memory buffer?)";
}
ap_log_cserror(APLOG_MARK, APLOG_TRACE4, 0, c, s,
- "%s: %s %ld/%d bytes %s BIO#%pp [mem: %pp] %s",
+ "%s: %s %" APR_SIZE_T_FMT "/%" APR_SIZE_T_FMT
+ " bytes %s BIO#%pp [mem: %pp] %s",
MODSSL_LIBRARY_NAME,
(cmd == (BIO_CB_WRITE|BIO_CB_RETURN) ? "write" : "read"),
- (long)rc, argi, (cmd == (BIO_CB_WRITE|BIO_CB_RETURN) ? "to" : "from"),
+ actual_len, requested_len,
+ (cmd == (BIO_CB_WRITE|BIO_CB_RETURN) ? "to" : "from"),
bio, argp, dump);
- if (*dump != '\0' && argp != NULL)
- ssl_io_data_dump(c, s, argp, rc);
+ /*
+ * *dump will only be != '\0' if
+ * APLOG_CS_IS_LEVEL(c, s, APLOG_TRACE7)
+ */
+ if (*dump != '\0' && argp != NULL) {
+ apr_size_t dump_len = (actual_len >= MODSSL_IO_DUMP_MAX
+ ? MODSSL_IO_DUMP_MAX
+ : actual_len);
+ ssl_io_data_dump(c, s, argp, dump_len);
+ }
}
else {
ap_log_cserror(APLOG_MARK, APLOG_TRACE4, 0, c, s,
- "%s: I/O error, %d bytes expected to %s on BIO#%pp [mem: %pp]",
- MODSSL_LIBRARY_NAME, argi,
+ "%s: I/O error, %" APR_SIZE_T_FMT
+ " bytes expected to %s on BIO#%pp [mem: %pp]",
+ MODSSL_LIBRARY_NAME, requested_len,
(cmd == (BIO_CB_WRITE|BIO_CB_RETURN) ? "write" : "read"),
bio, argp);
}
Regards
Rüdiger
Re: svn commit: r1908537 - /httpd/httpd/trunk/modules/ssl/
Posted by Yann Ylavic <yl...@gmail.com>.
On Wed, Jul 3, 2024 at 10:57 AM Yann Ylavic <yl...@gmail.com> wrote:
>
> On Wed, Jul 3, 2024 at 8:58 AM Ruediger Pluem <rp...@apache.org> wrote:
> >
> > On 7/3/24 2:59 AM, Yann Ylavic wrote:
> > > On Tue, Jul 2, 2024 at 10:57 AM Ruediger Pluem <rp...@apache.org> wrote:
> > >>
> > >> Updated patch.
> []
> > >> const char *dump = "";
> > >> if (APLOG_CS_IS_LEVEL(c, s, APLOG_TRACE7)) {
> > >> if (argp != NULL)
> > >> @@ -2400,23 +2413,28 @@
> > >> dump = "(Oops, no memory buffer?)";
> > >> }
> > >> ap_log_cserror(APLOG_MARK, APLOG_TRACE4, 0, c, s,
> > >> - "%s: %s %ld/%d bytes %s BIO#%pp [mem: %pp] %s",
> > >> + "%s: %s %" APR_SIZE_T_FMT "/%" APR_SIZE_T_FMT
> > >> + " bytes %s BIO#%pp [mem: %pp] %s",
> > >> MODSSL_LIBRARY_NAME,
> > >> (cmd == (BIO_CB_WRITE|BIO_CB_RETURN) ? "write" : "read"),
> > >> - (long)rc, argi, (cmd == (BIO_CB_WRITE|BIO_CB_RETURN) ? "to" : "from"),
> > >> + actual_len, requested_len,
> > >> + (cmd == (BIO_CB_WRITE|BIO_CB_RETURN) ? "to" : "from"),
> > >> bio, argp, dump);
> > >> if (*dump != '\0' && argp != NULL)
Here we could check for APLOG_CS_IS_LEVEL(c, s, APLOG_TRACE7) too, to
save the call when ssl_io_data_dump() is a noop anyway.
> > >> - ssl_io_data_dump(c, s, argp, rc);
> > >> + ssl_io_data_dump(c, s, argp, actual_len);
> > > And here:
> > > long dump_len = (actual_len >= APR_UINT16_MAX
> > > ? APR_UINT16_MAX
> > > : actual_len);
> >
> > Hm. As you point out: SSL records should be of limited length anyway, but if we really truncate the output shouldn't we log this?
> > A log message like: Dump truncated to first XXX bytes?
>
> Something like this to initialize "dump" above?
>
> if (APLOG_CS_IS_LEVEL(c, s, APLOG_TRACE7)) {
> if (argp == NULL)
> dump = "(Oops, no memory buffer?)";
> else if (actual_len > MODSSL_IO_DUMP_MAX)
> dump = "(BIO dump follows, truncated to "
> APR_STRINGIFY(MODSSL_IO_DUMP_MAX) ")";
> else
> dump = "(BIO dump follows)";
> }
>
> where we'd "#define MODSSL_IO_DUMP_MAX APR_UINT16_MAX" and use it
> everywhere eventually.
>
> >
> > > ssl_io_data_dump(c, s, argp, dump_len);
> > >> }
> > >> else {
> > >> ap_log_cserror(APLOG_MARK, APLOG_TRACE4, 0, c, s,
> > >> - "%s: I/O error, %d bytes expected to %s on BIO#%pp [mem: %pp]",
> > >> - MODSSL_LIBRARY_NAME, argi,
> > >> + "%s: I/O error, %" APR_SIZE_T_FMT
> > >> + " bytes expected to %s on BIO#%pp [mem: %pp]",
> > >> + MODSSL_LIBRARY_NAME, requested_len,
> > >> (cmd == (BIO_CB_WRITE|BIO_CB_RETURN) ? "write" : "read"),
> > >> bio, argp);
> > >> }
> > >> }
> > >> return rc;
> > >> +#undef requested_len
> > >> +#undef actual_len
> > >> }
> > > ?
>
>
> Cheers;
> Yann.
Re: svn commit: r1908537 - /httpd/httpd/trunk/modules/ssl/
Posted by Yann Ylavic <yl...@gmail.com>.
On Wed, Jul 3, 2024 at 8:58 AM Ruediger Pluem <rp...@apache.org> wrote:
>
> On 7/3/24 2:59 AM, Yann Ylavic wrote:
> > On Tue, Jul 2, 2024 at 10:57 AM Ruediger Pluem <rp...@apache.org> wrote:
> >>
> >> Updated patch.
[]
> >> const char *dump = "";
> >> if (APLOG_CS_IS_LEVEL(c, s, APLOG_TRACE7)) {
> >> if (argp != NULL)
> >> @@ -2400,23 +2413,28 @@
> >> dump = "(Oops, no memory buffer?)";
> >> }
> >> ap_log_cserror(APLOG_MARK, APLOG_TRACE4, 0, c, s,
> >> - "%s: %s %ld/%d bytes %s BIO#%pp [mem: %pp] %s",
> >> + "%s: %s %" APR_SIZE_T_FMT "/%" APR_SIZE_T_FMT
> >> + " bytes %s BIO#%pp [mem: %pp] %s",
> >> MODSSL_LIBRARY_NAME,
> >> (cmd == (BIO_CB_WRITE|BIO_CB_RETURN) ? "write" : "read"),
> >> - (long)rc, argi, (cmd == (BIO_CB_WRITE|BIO_CB_RETURN) ? "to" : "from"),
> >> + actual_len, requested_len,
> >> + (cmd == (BIO_CB_WRITE|BIO_CB_RETURN) ? "to" : "from"),
> >> bio, argp, dump);
> >> if (*dump != '\0' && argp != NULL)
> >> - ssl_io_data_dump(c, s, argp, rc);
> >> + ssl_io_data_dump(c, s, argp, actual_len);
> > And here:
> > long dump_len = (actual_len >= APR_UINT16_MAX
> > ? APR_UINT16_MAX
> > : actual_len);
>
> Hm. As you point out: SSL records should be of limited length anyway, but if we really truncate the output shouldn't we log this?
> A log message like: Dump truncated to first XXX bytes?
Something like this to initialize "dump" above?
if (APLOG_CS_IS_LEVEL(c, s, APLOG_TRACE7)) {
if (argp == NULL)
dump = "(Oops, no memory buffer?)";
else if (actual_len > MODSSL_IO_DUMP_MAX)
dump = "(BIO dump follows, truncated to "
APR_STRINGIFY(MODSSL_IO_DUMP_MAX) ")";
else
dump = "(BIO dump follows)";
}
where we'd "#define MODSSL_IO_DUMP_MAX APR_UINT16_MAX" and use it
everywhere eventually.
>
> > ssl_io_data_dump(c, s, argp, dump_len);
> >> }
> >> else {
> >> ap_log_cserror(APLOG_MARK, APLOG_TRACE4, 0, c, s,
> >> - "%s: I/O error, %d bytes expected to %s on BIO#%pp [mem: %pp]",
> >> - MODSSL_LIBRARY_NAME, argi,
> >> + "%s: I/O error, %" APR_SIZE_T_FMT
> >> + " bytes expected to %s on BIO#%pp [mem: %pp]",
> >> + MODSSL_LIBRARY_NAME, requested_len,
> >> (cmd == (BIO_CB_WRITE|BIO_CB_RETURN) ? "write" : "read"),
> >> bio, argp);
> >> }
> >> }
> >> return rc;
> >> +#undef requested_len
> >> +#undef actual_len
> >> }
> > ?
Cheers;
Yann.
Re: svn commit: r1908537 - /httpd/httpd/trunk/modules/ssl/
Posted by Ruediger Pluem <rp...@apache.org>.
On 7/3/24 2:59 AM, Yann Ylavic wrote:
> On Tue, Jul 2, 2024 at 10:57 AM Ruediger Pluem <rp...@apache.org> wrote:
>>
>> On 7/1/24 3:01 PM, Ruediger Pluem wrote:
>>>
>>>
>>> On 6/27/24 3:48 PM, Ruediger Pluem wrote:
>>>>
>>>>
>>>> On 6/27/24 12:47 PM, Yann Ylavic wrote:
>>>>> On Thu, Jun 27, 2024 at 12:38 PM Yann Ylavic <yl...@gmail.com> wrote:
>>>>>>
>>>>>> On Thu, Jun 27, 2024 at 12:07 PM Ruediger Pluem <rp...@apache.org> wrote:
>>>>>>>
>>>>>>> How about the below? I am yet undecided if I should follow the below approach to have
>>>>>>> two completely separate callbacks depending on the OpenSSL version or one with a lot of
>>>>>>> #If statements in it, but as much shared code as possible. Thoughts?
>>>>>>
>>>>>> Hm, I wouldn't duplicate the whole thing depending on openssl version.
>>>>>>
>>>>>> Something like the attached maybe? modssl_io_cb() will just consider
>>>>>> up to APR_INT32_MAX bytes, more shouldn't happen anyway and it's more
>>>>>> than enough for debug logs..
>>>>>
>>>>> We could even log the real length still if it matters, see attached v2.
>>>>
>>>> Thanks. Unfortunately the meaning of rc varies depending on if we have the ex or the non ex callback.
>>>> This is not in the documentation but only in the OpenSSL code :-(.
>>>> Furthermore the processed amount of data is in *processed in the ex case whereas in the non ex case it is in
>>>> rc. The intended amount of data to be processed is in len in the ex case and in argi in the non ex case.
>>>> Hence I propose the patch below. Of course we can have a longer debate if the len parameter to ssl_io_data_dump
>>>> should be int or size_t :-). And yes dumping more than APR_INT32_MAX bytes to the log might be bad.
>>>
>>> Any further comments on whether we should limit the dump to APR_INT32_MAX or not? I would guess that it will not matter
>>> in practice, but I am still open to it.
>>> BTW: I guess
>>>
>>> int len = data_len & APR_INT32_MAX;
>>>
>>> would be wrong. It would need to be
>>>
>>> int len = data_len > APR_INT32_MAX ? APR_INT32_MAX : (int)data_len;
>>>
>>> instead.
>
> Right! Maybe APR_UINT16_MAX is enough, I don't think we should log
> more undecipherable text than that :)
> IIRC an SSL/TLS payload is 16K (still?) anyway so we shouldn't be
> called for more than that (though multiple times)?
>
>>
>> Updated patch.
>>
>> Index: modules/ssl/ssl_engine_io.c
>> ===================================================================
>> --- modules/ssl/ssl_engine_io.c (revision 1918813)
>> +++ modules/ssl/ssl_engine_io.c (working copy)
>> @@ -2308,7 +2308,7 @@
>> #define DUMP_WIDTH 16
>>
>> static void ssl_io_data_dump(conn_rec *c, server_rec *s,
>> - const char *b, long len)
>> + const char *b, size_t len)
>> {
>> char buf[256];
>> int i, j, rows, trunc, pos;
>> @@ -2361,7 +2361,7 @@
>> }
>> if (trunc > 0)
>> ap_log_cserror(APLOG_MARK, APLOG_TRACE7, 0, c, s,
>> - "| %04ld - <SPACES/NULS>", len + trunc);
>> + "| %04" APR_SIZE_T_FMT " - <SPACES/NULS>", len + (size_t)trunc);
>> ap_log_cserror(APLOG_MARK, APLOG_TRACE7, 0, c, s,
>> "+-------------------------------------------------------------------------+");
>> }
>> @@ -2379,9 +2379,9 @@
>> conn_rec *c;
>> server_rec *s;
>> #if OPENSSL_VERSION_NUMBER >= 0x30000000L
>> - (void)len;
>> - (void)processed;
>> + (void)argi;
>> #endif
>> + (void)argl;
>>
>> if ((ssl = (SSL *)BIO_get_callback_arg(bio)) == NULL)
>> return rc;
>> @@ -2391,7 +2391,20 @@
>>
>> if ( cmd == (BIO_CB_WRITE|BIO_CB_RETURN)
>> || cmd == (BIO_CB_READ |BIO_CB_RETURN) ) {
>> +#if OPENSSL_VERSION_NUMBER >= 0x30000000L
>> +#define requested_len (len)
>> +#define actual_len (*processed)
> requested_len = len
>> + /*
>> + * On OpenSSL >= 3 rc uses the meaning of the BIO_read_ex and
>> + * BIO_write_ex functions return value and not the one of
>> + * BIO_read and BIO_write. Hence 0 indicates an error.
>> + */
>> + if (rc > 0) {
>> +#else
>> +#define requested_len ((size_t)argi)
>> +#define actual_len ((size_t)rc)
>> if (rc >= 0) {
>> +#endif
> Maybe use variables like:
> #if OPENSSL_VERSION_NUMBER >= 0x30000000L
> apr_size_t requested_len = len;
> int ok = (rc > 0);
> #else
> apr_size_t requested_len = argi;
> int ok = (rc >= 0);
> #endif
> if (ok) {
> #if OPENSSL_VERSION_NUMBER >= 0x30000000L
> apr_size_t actual_len = *processed;
> #else
> apr_size_t actual_len = rc;
> #endif
I am fine with this. Maybe my desire to save stack memory by not using further
variables was a bit over the top here.
>> const char *dump = "";
>> if (APLOG_CS_IS_LEVEL(c, s, APLOG_TRACE7)) {
>> if (argp != NULL)
>> @@ -2400,23 +2413,28 @@
>> dump = "(Oops, no memory buffer?)";
>> }
>> ap_log_cserror(APLOG_MARK, APLOG_TRACE4, 0, c, s,
>> - "%s: %s %ld/%d bytes %s BIO#%pp [mem: %pp] %s",
>> + "%s: %s %" APR_SIZE_T_FMT "/%" APR_SIZE_T_FMT
>> + " bytes %s BIO#%pp [mem: %pp] %s",
>> MODSSL_LIBRARY_NAME,
>> (cmd == (BIO_CB_WRITE|BIO_CB_RETURN) ? "write" : "read"),
>> - (long)rc, argi, (cmd == (BIO_CB_WRITE|BIO_CB_RETURN) ? "to" : "from"),
>> + actual_len, requested_len,
>> + (cmd == (BIO_CB_WRITE|BIO_CB_RETURN) ? "to" : "from"),
>> bio, argp, dump);
>> if (*dump != '\0' && argp != NULL)
>> - ssl_io_data_dump(c, s, argp, rc);
>> + ssl_io_data_dump(c, s, argp, actual_len);
> And here:
> long dump_len = (actual_len >= APR_UINT16_MAX
> ? APR_UINT16_MAX
> : actual_len);
Hm. As you point out: SSL records should be of limited length anyway, but if we really truncate the output shouldn't we log this?
A log message like: Dump truncated to first XXX bytes?
> ssl_io_data_dump(c, s, argp, dump_len);
>> }
>> else {
>> ap_log_cserror(APLOG_MARK, APLOG_TRACE4, 0, c, s,
>> - "%s: I/O error, %d bytes expected to %s on BIO#%pp [mem: %pp]",
>> - MODSSL_LIBRARY_NAME, argi,
>> + "%s: I/O error, %" APR_SIZE_T_FMT
>> + " bytes expected to %s on BIO#%pp [mem: %pp]",
>> + MODSSL_LIBRARY_NAME, requested_len,
>> (cmd == (BIO_CB_WRITE|BIO_CB_RETURN) ? "write" : "read"),
>> bio, argp);
>> }
>> }
>> return rc;
>> +#undef requested_len
>> +#undef actual_len
>> }
> ?
Regards
Rüdiger
Re: svn commit: r1908537 - /httpd/httpd/trunk/modules/ssl/
Posted by Yann Ylavic <yl...@gmail.com>.
On Tue, Jul 2, 2024 at 10:57 AM Ruediger Pluem <rp...@apache.org> wrote:
>
> On 7/1/24 3:01 PM, Ruediger Pluem wrote:
> >
> >
> > On 6/27/24 3:48 PM, Ruediger Pluem wrote:
> >>
> >>
> >> On 6/27/24 12:47 PM, Yann Ylavic wrote:
> >>> On Thu, Jun 27, 2024 at 12:38 PM Yann Ylavic <yl...@gmail.com> wrote:
> >>>>
> >>>> On Thu, Jun 27, 2024 at 12:07 PM Ruediger Pluem <rp...@apache.org> wrote:
> >>>>>
> >>>>> How about the below? I am yet undecided if I should follow the below approach to have
> >>>>> two completely separate callbacks depending on the OpenSSL version or one with a lot of
> >>>>> #If statements in it, but as much shared code as possible. Thoughts?
> >>>>
> >>>> Hm, I wouldn't duplicate the whole thing depending on openssl version.
> >>>>
> >>>> Something like the attached maybe? modssl_io_cb() will just consider
> >>>> up to APR_INT32_MAX bytes, more shouldn't happen anyway and it's more
> >>>> than enough for debug logs..
> >>>
> >>> We could even log the real length still if it matters, see attached v2.
> >>
> >> Thanks. Unfortunately the meaning of rc varies depending on if we have the ex or the non ex callback.
> >> This is not in the documentation but only in the OpenSSL code :-(.
> >> Furthermore the processed amount of data is in *processed in the ex case whereas in the non ex case it is in
> >> rc. The intended amount of data to be processed is in len in the ex case and in argi in the non ex case.
> >> Hence I propose the patch below. Of course we can have a longer debate if the len parameter to ssl_io_data_dump
> >> should be int or size_t :-). And yes dumping more than APR_INT32_MAX bytes to the log might be bad.
> >
> > Any further comments on whether we should limit the dump to APR_INT32_MAX or not? I would guess that it will not matter
> > in practice, but I am still open to it.
> > BTW: I guess
> >
> > int len = data_len & APR_INT32_MAX;
> >
> > would be wrong. It would need to be
> >
> > int len = data_len > APR_INT32_MAX ? APR_INT32_MAX : (int)data_len;
> >
> > instead.
Right! Maybe APR_UINT16_MAX is enough, I don't think we should log
more undecipherable text than that :)
IIRC an SSL/TLS payload is 16K (still?) anyway so we shouldn't be
called for more than that (though multiple times)?
>
> Updated patch.
>
> Index: modules/ssl/ssl_engine_io.c
> ===================================================================
> --- modules/ssl/ssl_engine_io.c (revision 1918813)
> +++ modules/ssl/ssl_engine_io.c (working copy)
> @@ -2308,7 +2308,7 @@
> #define DUMP_WIDTH 16
>
> static void ssl_io_data_dump(conn_rec *c, server_rec *s,
> - const char *b, long len)
> + const char *b, size_t len)
> {
> char buf[256];
> int i, j, rows, trunc, pos;
> @@ -2361,7 +2361,7 @@
> }
> if (trunc > 0)
> ap_log_cserror(APLOG_MARK, APLOG_TRACE7, 0, c, s,
> - "| %04ld - <SPACES/NULS>", len + trunc);
> + "| %04" APR_SIZE_T_FMT " - <SPACES/NULS>", len + (size_t)trunc);
> ap_log_cserror(APLOG_MARK, APLOG_TRACE7, 0, c, s,
> "+-------------------------------------------------------------------------+");
> }
> @@ -2379,9 +2379,9 @@
> conn_rec *c;
> server_rec *s;
> #if OPENSSL_VERSION_NUMBER >= 0x30000000L
> - (void)len;
> - (void)processed;
> + (void)argi;
> #endif
> + (void)argl;
>
> if ((ssl = (SSL *)BIO_get_callback_arg(bio)) == NULL)
> return rc;
> @@ -2391,7 +2391,20 @@
>
> if ( cmd == (BIO_CB_WRITE|BIO_CB_RETURN)
> || cmd == (BIO_CB_READ |BIO_CB_RETURN) ) {
> +#if OPENSSL_VERSION_NUMBER >= 0x30000000L
> +#define requested_len (len)
> +#define actual_len (*processed)
requested_len = len
> + /*
> + * On OpenSSL >= 3 rc uses the meaning of the BIO_read_ex and
> + * BIO_write_ex functions return value and not the one of
> + * BIO_read and BIO_write. Hence 0 indicates an error.
> + */
> + if (rc > 0) {
> +#else
> +#define requested_len ((size_t)argi)
> +#define actual_len ((size_t)rc)
> if (rc >= 0) {
> +#endif
Maybe use variables like:
#if OPENSSL_VERSION_NUMBER >= 0x30000000L
apr_size_t requested_len = len;
int ok = (rc > 0);
#else
apr_size_t requested_len = argi;
int ok = (rc >= 0);
#endif
if (ok) {
#if OPENSSL_VERSION_NUMBER >= 0x30000000L
apr_size_t actual_len = *processed;
#else
apr_size_t actual_len = rc;
#endif
> const char *dump = "";
> if (APLOG_CS_IS_LEVEL(c, s, APLOG_TRACE7)) {
> if (argp != NULL)
> @@ -2400,23 +2413,28 @@
> dump = "(Oops, no memory buffer?)";
> }
> ap_log_cserror(APLOG_MARK, APLOG_TRACE4, 0, c, s,
> - "%s: %s %ld/%d bytes %s BIO#%pp [mem: %pp] %s",
> + "%s: %s %" APR_SIZE_T_FMT "/%" APR_SIZE_T_FMT
> + " bytes %s BIO#%pp [mem: %pp] %s",
> MODSSL_LIBRARY_NAME,
> (cmd == (BIO_CB_WRITE|BIO_CB_RETURN) ? "write" : "read"),
> - (long)rc, argi, (cmd == (BIO_CB_WRITE|BIO_CB_RETURN) ? "to" : "from"),
> + actual_len, requested_len,
> + (cmd == (BIO_CB_WRITE|BIO_CB_RETURN) ? "to" : "from"),
> bio, argp, dump);
> if (*dump != '\0' && argp != NULL)
> - ssl_io_data_dump(c, s, argp, rc);
> + ssl_io_data_dump(c, s, argp, actual_len);
And here:
long dump_len = (actual_len >= APR_UINT16_MAX
? APR_UINT16_MAX
: actual_len);
ssl_io_data_dump(c, s, argp, dump_len);
> }
> else {
> ap_log_cserror(APLOG_MARK, APLOG_TRACE4, 0, c, s,
> - "%s: I/O error, %d bytes expected to %s on BIO#%pp [mem: %pp]",
> - MODSSL_LIBRARY_NAME, argi,
> + "%s: I/O error, %" APR_SIZE_T_FMT
> + " bytes expected to %s on BIO#%pp [mem: %pp]",
> + MODSSL_LIBRARY_NAME, requested_len,
> (cmd == (BIO_CB_WRITE|BIO_CB_RETURN) ? "write" : "read"),
> bio, argp);
> }
> }
> return rc;
> +#undef requested_len
> +#undef actual_len
> }
?
Regards;
Yann.
Re: svn commit: r1908537 - /httpd/httpd/trunk/modules/ssl/
Posted by Ruediger Pluem <rp...@apache.org>.
On 7/1/24 3:01 PM, Ruediger Pluem wrote:
>
>
> On 6/27/24 3:48 PM, Ruediger Pluem wrote:
>>
>>
>> On 6/27/24 12:47 PM, Yann Ylavic wrote:
>>> On Thu, Jun 27, 2024 at 12:38 PM Yann Ylavic <yl...@gmail.com> wrote:
>>>>
>>>> On Thu, Jun 27, 2024 at 12:07 PM Ruediger Pluem <rp...@apache.org> wrote:
>>>>>
>>>>> How about the below? I am yet undecided if I should follow the below approach to have
>>>>> two completely separate callbacks depending on the OpenSSL version or one with a lot of
>>>>> #If statements in it, but as much shared code as possible. Thoughts?
>>>>
>>>> Hm, I wouldn't duplicate the whole thing depending on openssl version.
>>>>
>>>> Something like the attached maybe? modssl_io_cb() will just consider
>>>> up to APR_INT32_MAX bytes, more shouldn't happen anyway and it's more
>>>> than enough for debug logs..
>>>
>>> We could even log the real length still if it matters, see attached v2.
>>
>> Thanks. Unfortunately the meaning of rc varies depending on if we have the ex or the non ex callback.
>> This is not in the documentation but only in the OpenSSL code :-(.
>> Furthermore the processed amount of data is in *processed in the ex case whereas in the non ex case it is in
>> rc. The intended amount of data to be processed is in len in the ex case and in argi in the non ex case.
>> Hence I propose the patch below. Of course we can have a longer debate if the len parameter to ssl_io_data_dump
>> should be int or size_t :-). And yes dumping more than APR_INT32_MAX bytes to the log might be bad.
>
> Any further comments on whether we should limit the dump to APR_INT32_MAX or not? I would guess that it will not matter
> in practice, but I am still open to it.
> BTW: I guess
>
> int len = data_len & APR_INT32_MAX;
>
> would be wrong. It would need to be
>
> int len = data_len > APR_INT32_MAX ? APR_INT32_MAX : (int)data_len;
>
> instead.
Updated patch.
Index: modules/ssl/ssl_engine_io.c
===================================================================
--- modules/ssl/ssl_engine_io.c (revision 1918813)
+++ modules/ssl/ssl_engine_io.c (working copy)
@@ -2308,7 +2308,7 @@
#define DUMP_WIDTH 16
static void ssl_io_data_dump(conn_rec *c, server_rec *s,
- const char *b, long len)
+ const char *b, size_t len)
{
char buf[256];
int i, j, rows, trunc, pos;
@@ -2361,7 +2361,7 @@
}
if (trunc > 0)
ap_log_cserror(APLOG_MARK, APLOG_TRACE7, 0, c, s,
- "| %04ld - <SPACES/NULS>", len + trunc);
+ "| %04" APR_SIZE_T_FMT " - <SPACES/NULS>", len + (size_t)trunc);
ap_log_cserror(APLOG_MARK, APLOG_TRACE7, 0, c, s,
"+-------------------------------------------------------------------------+");
}
@@ -2379,9 +2379,9 @@
conn_rec *c;
server_rec *s;
#if OPENSSL_VERSION_NUMBER >= 0x30000000L
- (void)len;
- (void)processed;
+ (void)argi;
#endif
+ (void)argl;
if ((ssl = (SSL *)BIO_get_callback_arg(bio)) == NULL)
return rc;
@@ -2391,7 +2391,20 @@
if ( cmd == (BIO_CB_WRITE|BIO_CB_RETURN)
|| cmd == (BIO_CB_READ |BIO_CB_RETURN) ) {
+#if OPENSSL_VERSION_NUMBER >= 0x30000000L
+#define requested_len (len)
+#define actual_len (*processed)
+ /*
+ * On OpenSSL >= 3 rc uses the meaning of the BIO_read_ex and
+ * BIO_write_ex functions return value and not the one of
+ * BIO_read and BIO_write. Hence 0 indicates an error.
+ */
+ if (rc > 0) {
+#else
+#define requested_len ((size_t)argi)
+#define actual_len ((size_t)rc)
if (rc >= 0) {
+#endif
const char *dump = "";
if (APLOG_CS_IS_LEVEL(c, s, APLOG_TRACE7)) {
if (argp != NULL)
@@ -2400,23 +2413,28 @@
dump = "(Oops, no memory buffer?)";
}
ap_log_cserror(APLOG_MARK, APLOG_TRACE4, 0, c, s,
- "%s: %s %ld/%d bytes %s BIO#%pp [mem: %pp] %s",
+ "%s: %s %" APR_SIZE_T_FMT "/%" APR_SIZE_T_FMT
+ " bytes %s BIO#%pp [mem: %pp] %s",
MODSSL_LIBRARY_NAME,
(cmd == (BIO_CB_WRITE|BIO_CB_RETURN) ? "write" : "read"),
- (long)rc, argi, (cmd == (BIO_CB_WRITE|BIO_CB_RETURN) ? "to" : "from"),
+ actual_len, requested_len,
+ (cmd == (BIO_CB_WRITE|BIO_CB_RETURN) ? "to" : "from"),
bio, argp, dump);
if (*dump != '\0' && argp != NULL)
- ssl_io_data_dump(c, s, argp, rc);
+ ssl_io_data_dump(c, s, argp, actual_len);
}
else {
ap_log_cserror(APLOG_MARK, APLOG_TRACE4, 0, c, s,
- "%s: I/O error, %d bytes expected to %s on BIO#%pp [mem: %pp]",
- MODSSL_LIBRARY_NAME, argi,
+ "%s: I/O error, %" APR_SIZE_T_FMT
+ " bytes expected to %s on BIO#%pp [mem: %pp]",
+ MODSSL_LIBRARY_NAME, requested_len,
(cmd == (BIO_CB_WRITE|BIO_CB_RETURN) ? "write" : "read"),
bio, argp);
}
}
return rc;
+#undef requested_len
+#undef actual_len
}
static APR_INLINE void set_bio_callback(BIO *bio, void *arg)
Regards
Rüdiger