Project

General

Profile

Actions

Bug #2778

closed

larger memory usage for file uploads via SSL on embedded system

Added by ste about 8 years ago. Updated about 8 years ago.

Status:
Fixed
Priority:
Normal
Category:
core
Target version:
ASK QUESTIONS IN Forums:

Description

After upgrading lighttpd from 1.4.39 to 1.4.44 we can no longer upload larger files via SSL.

This is an embedded system with only some MB of free memory.

Uploading a 3MB file fails with

(mod_cgi.c.1213) fork failed: Cannot allocate memory

I tracked the regression down to the following commit:

commit a95aaa9de984dc004dd1d4302147e8a0c23efb10
Author: Glenn Strauss <gstrauss@gluelogic.com>
Date:   Wed Jul 27 05:54:25 2016 -0400

    [TLS] read all available records from SSL_read()

    read all available records from SSL_read(), even if larger than
    MAX_READ_LIMIT, since the data is already in memory.  openssl is
    configured with SSL_MODE_RELEASE_BUFFERS and will release openssl
    buffers once records have been read.

    Without reading available data, there was a chance that the connection
    would hang waiting for a read event on the fd, even though all the
    data had already been read from kernel socket buffers and was in openssl
    memory waiting to be read with SSL_read().

    (thx glen and avij)

In older versions at most MAX_READ_LIMIT bytes were read into the internal buffer before flushing them into tempfiles in server.upload-dirs.

In the commit above the MAX_READ_LIMIT was removed. Now several MB are buffered before they are written to temp files. This behaviour exhausts the memory on our small system.

This issue only affects SSL connections, unencrypted connections are correctly limited by MAX_READ_LIMIT.

Currently we are using the attached patch as a workaround. It basically reverts the commit above and parts of two other commits.


Files

ssl-read-limit.patch (1.34 KB) ssl-read-limit.patch ste, 2017-01-09 14:52
ssl.read-ahead.patch (3.56 KB) ssl.read-ahead.patch gstrauss, 2017-01-10 13:24

Added by gstrauss about 8 years ago

Revision b03c4962 (diff)

[TLS] ssl.read-ahead = "disable" for low mem (fixes #2778)

new directive ssl.read-ahead = "enable"/"disable" to control
SSL_CTX_set_read_ahead(). Default "enable". The "disable" setting
is intended for use on low memory systems with a slow CPU which is
unable to keep up with decryption of large request bodies.

x-ref:
"larger memory usage for file uploads via SSL on embedded system"
https://redmine.lighttpd.net/issues/2778

Actions

Also available in: Atom