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