| 1 | <!DOCTYPE html> |
| 2 | <html> |
| 3 | <head> |
| 4 | <title>ProFTPD module mod_rlimit</title> |
| 5 | </head> |
| 6 | |
| 7 | <body bgcolor=white> |
| 8 | |
| 9 | <hr> |
| 10 | <center> |
| 11 | <h2><b>ProFTPD module <code>mod_rlimit</code></b></h2> |
| 12 | </center> |
| 13 | <hr><br> |
| 14 | |
| 15 | <p> |
| 16 | The <code>mod_rlimit</code> module handles setting and enforcement of |
| 17 | resource limits such as CPU, memory, and file descriptor usage. |
| 18 | |
| 19 | <p> |
| 20 | By default, the <code>mod_rlimit</code> module will impose one resource |
| 21 | restriction on new session processes: the <code>RLIMIT_NPROC</code> (see |
| 22 | <code>getrlimit(2)</code> limit, which controls the number of processes |
| 23 | which can be forked from this process, is set to zero. There is absolutely |
| 24 | no reason for a <code>proftpd</code> session process to need to create a new |
| 25 | process via <code>fork(2)</code>. |
| 26 | |
| 27 | <p> |
| 28 | This module is contained in the <code>mod_rlimit.c</code> file for |
| 29 | ProFTPD 1.3.<i>x</i>, and is compiled by default. See the |
| 30 | <a href="#Installation">installation</a> section for more details. |
| 31 | |
| 32 | <p> |
| 33 | The most current version of <code>mod_rlimit</code> can be found in the |
| 34 | ProFTPD source distribution: |
| 35 | <pre> |
| 36 | <a href="http://www.proftpd.org/">http://www.proftpd.org/</a> |
| 37 | </pre> |
| 38 | |
| 39 | <h2>Directives</h2> |
| 40 | <ul> |
| 41 | <li><a href="#RLimitChroot">RLimitChroot</a> |
| 42 | <li><a href="#RLimitCPU">RLimitCPU</a> |
| 43 | <li><a href="#RLimitMemory">RLimitMemory</a> |
| 44 | <li><a href="#RLimitOpenFiles">RLimitOpenFiles</a> |
| 45 | </ul> |
| 46 | |
| 47 | <p> |
| 48 | <hr> |
| 49 | <h3><a name="RLimitChroot">RLimitChroot</a></h3> |
| 50 | <strong>Syntax:</strong> RLimitChroot <em>on|off</em><br> |
| 51 | <strong>Default:</strong> RLimitChroot on<br> |
| 52 | <strong>Context:</strong> server config, <code><VirtualHost></code>, <code><Global></code><br> |
| 53 | <strong>Module:</strong> mod_rlimit<br> |
| 54 | <strong>Compatibility:</strong> 1.3.5rc5 |
| 55 | |
| 56 | <p> |
| 57 | The <code>RLimitChroot</code> directive is used to enable/disable checks |
| 58 | for modifications to "sensitive" directories when a session is chrooted. These |
| 59 | checks are designed to mitigate and guard against attacks such as the |
| 60 | "Roaring Beast" attack; see: |
| 61 | <ul> |
| 62 | <li><a href="https://auscert.org.au/15286">https://auscert.org.au/15286</a> |
| 63 | <li><a href="https://auscert.org.au/15526">https://auscert.org.au/15526</a> |
| 64 | </ul> |
| 65 | |
| 66 | <p> |
| 67 | When a session is chrooted, <i>e.g.</i> via the <code>DefaultRoot</code> |
| 68 | directive <i>or</i> by <code><Anonymous></code> login, the checks |
| 69 | for the "sensitive" directories are automatically enabled. To disable these |
| 70 | checks, use: |
| 71 | <pre> |
| 72 | RLimitChroot off |
| 73 | </pre> |
| 74 | <b>Note</b>: We <b>strongly recommend</b> that you do <b>not</b> disable |
| 75 | these checks. |
| 76 | |
| 77 | <p> |
| 78 | The checks in question will specifically prevent any attempts to upload |
| 79 | files into the <code>/etc</code> and <code>/lib</code> directories, or |
| 80 | attempts to delete, create, rename, link, or otherwise try to change anything |
| 81 | in these directories. All attempts to make modifications will be rejected |
| 82 | with "Permission denied" errors. In addition, the following message will |
| 83 | be logged (at debug level 2): |
| 84 | <pre> |
| 85 | WARNING: attempt to use sensitive path '<i>/etc/file</i>' within chroot '<i>/home/user</i>', rejecting |
| 86 | </pre> |
| 87 | |
| 88 | <p> |
| 89 | The <code>RLimitChroot</code> directive is <b>not</b> intended to <b>prevent</b> |
| 90 | "Roaring Beast" style attacks entirely; the guarded <code>/etc</code> and |
| 91 | <code>/lib</code> directories might be created via other means, outside of |
| 92 | ProFTPD, which would also allow for the attack. The <code>RLimitChroot</code> |
| 93 | directive is meant to <em>mitigate</em> (not <em>prevent</em>) the attacks by |
| 94 | making sure it cannot be done using <i>just</i> ProFTPD. |
| 95 | |
| 96 | <p> |
| 97 | <hr> |
| 98 | <h3><a name="RLimitCPU">RLimitCPU</a></h3> |
| 99 | <strong>Syntax:</strong> RLimitCPU <em>[scope] soft-limit|"max" [hard-limit|"max"]</em><br> |
| 100 | <strong>Default:</strong> <em>System defaults</em><br> |
| 101 | <strong>Context:</strong> server config, <code><VirtualHost></code>, <code><Global></code><br> |
| 102 | <strong>Module:</strong> mod_rlimit<br> |
| 103 | <strong>Compatibility:</strong> 1.3.5rc2 |
| 104 | |
| 105 | <p> |
| 106 | The <code>RLimitCPU</code> directive is used to set a limit on the CPU usage, |
| 107 | expressed as a maximum number of seconds. |
| 108 | |
| 109 | <p> |
| 110 | <code>RLimitCPU</code> takes from one to three parameters. The first parameter |
| 111 | is an optional <em>scope</em> parameter, indicating the scope of the resource |
| 112 | limit. The <em>scope</em> parameter may be one of: |
| 113 | <ul> |
| 114 | <li>"daemon" (applies the resource limit only to the <i>daemon</i> process) |
| 115 | <li>"session" (which applies the limit only to <i>session</i> processes handling each client) |
| 116 | <li>"none" (which disables any possibly inherited limits) |
| 117 | </ul> |
| 118 | If none of these keywords are used, the resource limit is assumed to apply to |
| 119 | both daemon and session processes. |
| 120 | |
| 121 | <p> |
| 122 | The next parameters indicate the actual resource limits, both the so-called |
| 123 | "soft limit" and any "hard limit". These parameters may be a number |
| 124 | (indicating the number of seconds), or the value "max" to indicate that |
| 125 | maximum resource limit value allowed is to be used. |
| 126 | |
| 127 | <p> |
| 128 | Example: |
| 129 | <pre> |
| 130 | # Limit a given session to 30 minutes of CPU time (which can take |
| 131 | # considerably longer than 30 minutes of wall time, due to CPU scheduling) |
| 132 | RLimitCPU 1800 |
| 133 | </pre> |
| 134 | |
| 135 | <p> |
| 136 | <hr> |
| 137 | <h3><a name="RLimitMemory">RLimitMemory</a></h3> |
| 138 | <strong>Syntax:</strong> RLimitMemory <em>[scope] soft-limit|"max" [hard-limit|"max"]</em><br> |
| 139 | <strong>Default:</strong> <em>System defaults</em><br> |
| 140 | <strong>Context:</strong> server config, <code><VirtualHost></code>, <code><Global></code><br> |
| 141 | <strong>Module:</strong> mod_rlimit<br> |
| 142 | <strong>Compatibility:</strong> 1.3.5rc2 |
| 143 | |
| 144 | <p> |
| 145 | The <code>RLimitMemory</code> directive is used to set a limit on the |
| 146 | memory usage, expressed as a maximum number of bytes. |
| 147 | |
| 148 | <p> |
| 149 | <code>RLimitMemory</code> takes from one to three parameters. The first |
| 150 | parameter is an optional <em>scope</em> parameter, indicating the scope of the |
| 151 | resource limit. The <em>scope</em> parameter may be one of: |
| 152 | <ul> |
| 153 | <li>"daemon" (applies the resource limit only to the <i>daemon</i> process) |
| 154 | <li>"session" (which applies the limit only to <i>session</i> processes handling each client) |
| 155 | <li>"none" (which disables any possibly inherited limits) |
| 156 | </ul> |
| 157 | If none of these keywords are used, the resource limit is assumed to apply to |
| 158 | both daemon and session processes. |
| 159 | |
| 160 | <p> |
| 161 | The next parameters indicate the actual resource limits, both the so-called |
| 162 | "soft limit" and any "hard limit". These parameters may be a number |
| 163 | (indicating the number of bytes), or the value "max" to indicate that |
| 164 | maximum resource limit value allowed is to be used. |
| 165 | |
| 166 | <p> |
| 167 | Example: |
| 168 | <pre> |
| 169 | # Limit a given session to 128MB minutes of memory |
| 170 | RLimitMemory 128MB |
| 171 | </pre> |
| 172 | |
| 173 | <p> |
| 174 | <b>Note</b>: If you use <code>RLimitMemory</code>, <i>e.g.</i>: |
| 175 | <pre> |
| 176 | <IfModule mod_rlimit.c> |
| 177 | RLimitMemory session 64M |
| 178 | </IfModule> |
| 179 | </pre> |
| 180 | <b>and</b> you use <a href="../contrib/mod_tls.html"><code>mod_tls</code></a> |
| 181 | for FTPS transfers: |
| 182 | <pre> |
| 183 | <IfModule mod_tls.c> |
| 184 | ... |
| 185 | </IfModule> |
| 186 | </pre> |
| 187 | then your transfers are likely to fail. Why? Because OpenSSL will need to |
| 188 | allocate memory for the TLS support, in addition to the memory that ProFTPD |
| 189 | already allocates for data transfers. Depending on the specific ciphersuites |
| 190 | negotiated, and the specific memory limit configured, you are very likely to |
| 191 | hit the <code>RLimitMemory</code> limit. In short, your |
| 192 | <code>RLimitMemory</code> might be too low, and not allowing ProFTPD and |
| 193 | OpenSSL enough memory for the transfer. |
| 194 | |
| 195 | <p> |
| 196 | <hr> |
| 197 | <h3><a name="RLimitOpenFiles">RLimitOpenFiles</a></h3> |
| 198 | <strong>Syntax:</strong> RLimitOpenFiles <em>[scope] soft-limit|"max" [hard-limit|"max"]</em><br> |
| 199 | <strong>Default:</strong> <em>System defaults</em><br> |
| 200 | <strong>Context:</strong> server config, <code><VirtualHost></code>, <code><Global></code><br> |
| 201 | <strong>Module:</strong> mod_rlimit<br> |
| 202 | <strong>Compatibility:</strong> 1.3.5rc2 |
| 203 | |
| 204 | <p> |
| 205 | The <code>RLimitOpenFiles</code> directive is used to set a limit on the |
| 206 | file descriptors, expressed as counts. |
| 207 | |
| 208 | <p> |
| 209 | <code>RLimitOpenFiles</code> takes from one to three parameters. The first |
| 210 | parameter is an optional <em>scope</em> parameter, indicating the scope of the |
| 211 | resource limit. The <em>scope</em> parameter may be one of: |
| 212 | <ul> |
| 213 | <li>"daemon" (applies the resource limit only to the <i>daemon</i> process) |
| 214 | <li>"session" (which applies the limit only to <i>session</i> processes handling each client) |
| 215 | <li>"none" (which disables any possibly inherited limits) |
| 216 | </ul> |
| 217 | If none of these keywords are used, the resource limit is assumed to apply to |
| 218 | both daemon and session processes. |
| 219 | |
| 220 | <p> |
| 221 | The next parameters indicate the actual resource limits, both the so-called |
| 222 | "soft limit" and any "hard limit". These parameters may be a number, or the |
| 223 | value "max" to indicate that maximum resource limit value allowed is to be |
| 224 | used. |
| 225 | |
| 226 | <p> |
| 227 | Example: |
| 228 | <pre> |
| 229 | # Limit a given session to 12 open file descriptors |
| 230 | RLimitOpenFiles session 12 |
| 231 | </pre> |
| 232 | |
| 233 | <p> |
| 234 | <hr> |
| 235 | <h2><a name="Installation">Installation</a></h2> |
| 236 | The <code>mod_rlimit</code> module is compiled into <code>proftpd</code> by |
| 237 | default. |
| 238 | |
| 239 | <p><a name="FAQ">FAQ</a> |
| 240 | <b>Frequently Asked Questions</b><br> |
| 241 | |
| 242 | <p> |
| 243 | <font color=red>Question</font>: Why can't I create directories named "lib" |
| 244 | or "etc" in the root directory? For example, my FTP client fails like so: |
| 245 | <code> |
| 246 | <font color=blue>Command: MKD lib</font> |
| 247 | <font color=green>Response: 550 lib: Permission denied</font> |
| 248 | <font color=blue>Command: MKD /lib</font> |
| 249 | <font color=green>Response: 550 /lib: Permission denied</font> |
| 250 | </code> |
| 251 | Although I don't have anything in my <code>proftpd.conf</code> that would block |
| 252 | these commands, and the filesystem permissions are OK. Why does this |
| 253 | happen?<br> |
| 254 | <font color=blue>Answer</font>: For the answer to this, see the description for |
| 255 | the <a href="#RLimitChroot"><code>RLimitChroot</code></a> directive. |
| 256 | |
| 257 | <p> |
| 258 | <hr> |
| 259 | <font size=2><b><i> |
| 260 | © Copyright 2013-2017 The ProFTPD Project<br> |
| 261 | All Rights Reserved<br> |
| 262 | </i></b></font> |
| 263 | <hr> |
| 264 | |
| 265 | </body> |
| 266 | </html> |