1 .\" Title: pam_fail_delay
3 .\" Generator: DocBook XSL Stylesheets v1.70.1 <http://docbook.sf.net/>
5 .\" Manual: Linux\-PAM Manual
6 .\" Source: Linux\-PAM Manual
8 .TH "PAM_FAIL_DELAY" "3" "08/01/2006" "Linux\-PAM Manual" "Linux\-PAM Manual"
9 .\" disable hyphenation
11 .\" disable justification (adjust text to left margin only)
14 pam_fail_delay \- request a delay on failure
19 #include <security/pam_appl.h>
23 .BI "int pam_fail_delay(pam_handle_t\ *" "pamh" ", unsigned\ int\ " "usec" ");"
28 function provides a mechanism by which an application or module can suggest a minimum delay of
30 micro\-seconds. The function keeps a record of the longest time requested with this function. Should
31 \fBpam_authenticate\fR(3)
32 fail, the failing return to the application is delayed by an amount of time randomly distributed (by up to 25%) about this longest value.
34 Independent of success, the delay time is reset to its zero default value when the PAM service module returns control to the application. The delay occurs
36 all authentication modules have been called, but
38 control is returned to the service application.
40 When using this function the programmer should check if it is available with:
44 #ifdef HAVE_PAM_FAIL_DELAY
46 #endif /* HAVE_PAM_FAIL_DELAY */
51 For applications written with a single thread that are event driven in nature, generating this delay may be undesirable. Instead, the application may want to register the delay in some other way. For example, in a single threaded server that serves multiple authentication requests from a single event loop, the application might want to simply mark a given connection as blocked until an application timer expires. For this reason the delay function can be changed with the
53 item. It can be queried and set with
56 \fBpam_set_item \fR(3)
57 respectively. The value used to set it should be a function pointer of the following prototype:
61 void (*delay_fn)(int retval, unsigned usec_delay, void *appdata_ptr);
66 The arguments being the
68 return code of the module stack, the
70 micro\-second delay that libpam is requesting and the
72 that the application has associated with the current
73 \fIpamh\fR. This last value was set by the application when it called
76 \fBpam_set_item\fR(3). Note, if PAM_FAIL_DELAY item is unset (or set to NULL), then no delay will be performed.
79 It is often possible to attack an authentication scheme by exploiting the time it takes the scheme to deny access to an applicant user. In cases of
81 timeouts, it may prove possible to attempt a
83 dictionary attack \-\- with an automated process, the attacker tries all possible passwords to gain access to the system. In other cases, where individual failures can take measurable amounts of time (indicating the nature of the failure), an attacker can obtain useful information about the authentication process. These latter attacks make use of procedural delays that constitute a
85 of useful information.
87 To minimize the effectiveness of such attacks, it is desirable to introduce a random delay in a failed authentication process. Preferable this value should be set by the application or a special PAM module. Standard PAM modules should not modify the delay unconditional.
90 For example, a login application may require a failure delay of roughly 3 seconds. It will contain the following code:
94 pam_fail_delay (pamh, 3000000 /* micro\-seconds */ );
95 pam_authenticate (pamh, 0);
100 if the modules do not request a delay, the failure delay will be between 2.25 and 3.75 seconds.
102 However, the modules, invoked in the authentication process, may also request delays:
106 module #1: pam_fail_delay (pamh, 2000000);
107 module #2: pam_fail_delay (pamh, 4000000);
112 in this case, it is the largest requested value that is used to compute the actual failed delay: here between 3 and 5 seconds.
116 Delay was successful adjusted.
119 A NULL pointer was submitted as PAM handle.
124 \fBpam_get_item\fR(3),
125 \fBpam_strerror\fR(3)
130 function is an Linux\-PAM extension.