pam_fail_delay.3.xml 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN"
  3. "http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd">
  4. <refentry id="pam_fail_delay">
  5. <refmeta>
  6. <refentrytitle>pam_fail_delay</refentrytitle>
  7. <manvolnum>3</manvolnum>
  8. <refmiscinfo class='setdesc'>Linux-PAM Manual</refmiscinfo>
  9. </refmeta>
  10. <refnamediv id="pam_fail_delay-name">
  11. <refname>pam_fail_delay</refname>
  12. <refpurpose>request a delay on failure</refpurpose>
  13. </refnamediv>
  14. <!-- body begins here -->
  15. <refsynopsisdiv>
  16. <funcsynopsis id="pam_fail_delay-synopsis">
  17. <funcsynopsisinfo>#include &lt;security/pam_appl.h&gt;</funcsynopsisinfo>
  18. <funcprototype>
  19. <funcdef>int <function>pam_fail_delay</function></funcdef>
  20. <paramdef>pam_handle_t *<parameter>pamh</parameter></paramdef>
  21. <paramdef>unsigned int <parameter>usec</parameter></paramdef>
  22. </funcprototype>
  23. </funcsynopsis>
  24. </refsynopsisdiv>
  25. <refsect1 id='pam_fail_delay-description'>
  26. <title>DESCRIPTION</title>
  27. <para>
  28. The <function>pam_fail_delay</function> function provides a
  29. mechanism by which an application or module can suggest a minimum
  30. delay of <emphasis>usec</emphasis> micro-seconds. The
  31. function keeps a record of the longest time requested with this
  32. function. Should
  33. <citerefentry>
  34. <refentrytitle>pam_authenticate</refentrytitle><manvolnum>3</manvolnum>
  35. </citerefentry> fail, the failing return to the application is
  36. delayed by an amount of time randomly distributed (by up to 50%)
  37. about this longest value.
  38. </para>
  39. <para>
  40. Independent of success, the delay time is reset to its zero
  41. default value when the PAM service module returns control to
  42. the application. The delay occurs <emphasis>after</emphasis> all
  43. authentication modules have been called, but <emphasis>before</emphasis>
  44. control is returned to the service application.
  45. </para>
  46. <para>
  47. When using this function the programmer should check if it is
  48. available with:
  49. </para>
  50. <programlisting>
  51. #ifdef HAVE_PAM_FAIL_DELAY
  52. ....
  53. #endif /* HAVE_PAM_FAIL_DELAY */
  54. </programlisting>
  55. <para>
  56. For applications written with a single thread that are event
  57. driven in nature, generating this delay may be undesirable.
  58. Instead, the application may want to register the delay in some
  59. other way. For example, in a single threaded server that serves
  60. multiple authentication requests from a single event loop, the
  61. application might want to simply mark a given connection as
  62. blocked until an application timer expires. For this reason
  63. the delay function can be changed with the
  64. <emphasis>PAM_FAIL_DELAY</emphasis> item. It can be queried and
  65. set with
  66. <citerefentry>
  67. <refentrytitle>pam_get_item</refentrytitle><manvolnum>3</manvolnum>
  68. </citerefentry>
  69. and
  70. <citerefentry>
  71. <refentrytitle>pam_set_item</refentrytitle><manvolnum>3</manvolnum>
  72. </citerefentry> respectively. The value used to set it should be
  73. a function pointer of the following prototype:
  74. <programlisting>
  75. void (*delay_fn)(int retval, unsigned usec_delay, void *appdata_ptr);
  76. </programlisting>
  77. The arguments being the <emphasis>retval</emphasis> return code
  78. of the module stack, the <emphasis>usec_delay</emphasis>
  79. micro-second delay that libpam is requesting and the
  80. <emphasis>appdata_ptr</emphasis> that the application has associated
  81. with the current <emphasis>pamh</emphasis>. This last value was set
  82. by the application when it called
  83. <citerefentry>
  84. <refentrytitle>pam_start</refentrytitle><manvolnum>3</manvolnum>
  85. </citerefentry> or explicitly with
  86. <citerefentry>
  87. <refentrytitle>pam_set_item</refentrytitle><manvolnum>3</manvolnum>
  88. </citerefentry>.
  89. </para>
  90. <para>
  91. Note that the PAM_FAIL_DELAY item is set to NULL by default. This
  92. indicates that PAM should perform a random delay as described
  93. above when authentication fails and a delay has been suggested.
  94. If an application does not want the PAM library to perform any
  95. delay on authentication failure, then the application must define
  96. a custom delay function that executes no statements and set
  97. the PAM_FAIL_DELAY item to point to this function.
  98. </para>
  99. </refsect1>
  100. <refsect1 id='pam_fail_delay-rationale'>
  101. <title>RATIONALE</title>
  102. <para>
  103. It is often possible to attack an authentication scheme by exploiting
  104. the time it takes the scheme to deny access to an applicant user. In
  105. cases of <emphasis>short</emphasis> timeouts, it may prove possible
  106. to attempt a <emphasis>brute force</emphasis> dictionary attack --
  107. with an automated process, the attacker tries all possible passwords
  108. to gain access to the system. In other cases, where individual
  109. failures can take measurable amounts of time (indicating the nature
  110. of the failure), an attacker can obtain useful information about the
  111. authentication process. These latter attacks make use of procedural
  112. delays that constitute a <emphasis>covert channel</emphasis>
  113. of useful information.
  114. </para>
  115. <para>
  116. To minimize the effectiveness of such attacks, it is desirable to
  117. introduce a random delay in a failed authentication process.
  118. Preferable this value should be set by the application or a special
  119. PAM module. Standard PAM modules should not modify the delay
  120. unconditional.
  121. </para>
  122. </refsect1>
  123. <refsect1 id='pam_fail_delay-example'>
  124. <title>EXAMPLE</title>
  125. <para>
  126. For example, a login application may require a failure delay of
  127. roughly 3 seconds. It will contain the following code:
  128. </para>
  129. <programlisting>
  130. pam_fail_delay (pamh, 3000000 /* micro-seconds */ );
  131. pam_authenticate (pamh, 0);
  132. </programlisting>
  133. <para>
  134. if the modules do not request a delay, the failure delay will be
  135. between 1.5 and 4.5 seconds.
  136. </para>
  137. <para>
  138. However, the modules, invoked in the authentication process, may
  139. also request delays:
  140. </para>
  141. <programlisting>
  142. module #1: pam_fail_delay (pamh, 2000000);
  143. module #2: pam_fail_delay (pamh, 4000000);
  144. </programlisting>
  145. <para>
  146. in this case, it is the largest requested value that is used to
  147. compute the actual failed delay: here between 2 and 6 seconds.
  148. </para>
  149. </refsect1>
  150. <refsect1 id='pam_fail_delay-return_values'>
  151. <title>RETURN VALUES</title>
  152. <variablelist>
  153. <varlistentry>
  154. <term>PAM_SUCCESS</term>
  155. <listitem>
  156. <para>
  157. Delay was successful adjusted.
  158. </para>
  159. </listitem>
  160. </varlistentry>
  161. <varlistentry>
  162. <term>PAM_SYSTEM_ERR</term>
  163. <listitem>
  164. <para>
  165. A NULL pointer was submitted as PAM handle.
  166. </para>
  167. </listitem>
  168. </varlistentry>
  169. </variablelist>
  170. </refsect1>
  171. <refsect1 id='pam_fail_delay-see_also'>
  172. <title>SEE ALSO</title>
  173. <para>
  174. <citerefentry>
  175. <refentrytitle>pam_start</refentrytitle><manvolnum>3</manvolnum>
  176. </citerefentry>,
  177. <citerefentry>
  178. <refentrytitle>pam_get_item</refentrytitle><manvolnum>3</manvolnum>
  179. </citerefentry>,
  180. <citerefentry>
  181. <refentrytitle>pam_strerror</refentrytitle><manvolnum>3</manvolnum>
  182. </citerefentry>
  183. </para>
  184. </refsect1>
  185. <refsect1 id='pam_fail_delay-standards'>
  186. <title>STANDARDS</title>
  187. <para>
  188. The <function>pam_fail_delay</function> function is an
  189. Linux-PAM extension.
  190. </para>
  191. </refsect1>
  192. </refentry>