1PAM_FAIL_DELAY(3) Linux-PAM Manual PAM_FAIL_DELAY(3)
2
3
4
6 pam_fail_delay - request a delay on failure
7
9 #include <security/pam_appl.h>
10
11 int pam_fail_delay(pam_handle_t *pamh, unsigned int usec);
12
14 The pam_fail_delay function provides a mechanism by which an
15 application or module can suggest a minimum delay of usec
16 micro-seconds. The function keeps a record of the longest time
17 requested with this function. Should pam_authenticate(3) fail, the
18 failing return to the application is delayed by an amount of time
19 randomly distributed (by up to 50%) about this longest value.
20
21 Independent of success, the delay time is reset to its zero default
22 value when the PAM service module returns control to the application.
23 The delay occurs after all authentication modules have been called, but
24 before control is returned to the service application.
25
26 When using this function the programmer should check if it is available
27 with:
28
29 #ifdef HAVE_PAM_FAIL_DELAY
30 ....
31 #endif /* HAVE_PAM_FAIL_DELAY */
32
33
34 For applications written with a single thread that are event driven in
35 nature, generating this delay may be undesirable. Instead, the
36 application may want to register the delay in some other way. For
37 example, in a single threaded server that serves multiple
38 authentication requests from a single event loop, the application might
39 want to simply mark a given connection as blocked until an application
40 timer expires. For this reason the delay function can be changed with
41 the PAM_FAIL_DELAY item. It can be queried and set with pam_get_item(3)
42 and pam_set_item(3) respectively. The value used to set it should be a
43 function pointer of the following prototype:
44
45 void (*delay_fn)(int retval, unsigned usec_delay, void *appdata_ptr);
46
47
48 The arguments being the retval return code of the module stack, the
49 usec_delay micro-second delay that libpam is requesting and the
50 appdata_ptr that the application has associated with the current pamh.
51 This last value was set by the application when it called pam_start(3)
52 or explicitly with pam_set_item(3).
53
54 Note that the PAM_FAIL_DELAY item is set to NULL by default. This
55 indicates that PAM should perform a random delay as described above
56 when authentication fails and a delay has been suggested. If an
57 application does not want the PAM library to perform any delay on
58 authentication failure, then the application must define a custom delay
59 function that executes no statements and set the PAM_FAIL_DELAY item to
60 point to this function.
61
63 It is often possible to attack an authentication scheme by exploiting
64 the time it takes the scheme to deny access to an applicant user. In
65 cases of short timeouts, it may prove possible to attempt a brute force
66 dictionary attack -- with an automated process, the attacker tries all
67 possible passwords to gain access to the system. In other cases, where
68 individual failures can take measurable amounts of time (indicating the
69 nature of the failure), an attacker can obtain useful information about
70 the authentication process. These latter attacks make use of procedural
71 delays that constitute a covert channel of useful information.
72
73 To minimize the effectiveness of such attacks, it is desirable to
74 introduce a random delay in a failed authentication process. Preferable
75 this value should be set by the application or a special PAM module.
76 Standard PAM modules should not modify the delay unconditional.
77
79 For example, a login application may require a failure delay of roughly
80 3 seconds. It will contain the following code:
81
82 pam_fail_delay (pamh, 3000000 /* micro-seconds */ );
83 pam_authenticate (pamh, 0);
84
85
86 if the modules do not request a delay, the failure delay will be
87 between 1.5 and 4.5 seconds.
88
89 However, the modules, invoked in the authentication process, may also
90 request delays:
91
92 module #1: pam_fail_delay (pamh, 2000000);
93 module #2: pam_fail_delay (pamh, 4000000);
94
95
96 in this case, it is the largest requested value that is used to compute
97 the actual failed delay: here between 2 and 6 seconds.
98
100 PAM_SUCCESS
101 Delay was successful adjusted.
102
103 PAM_SYSTEM_ERR
104 A NULL pointer was submitted as PAM handle.
105
107 pam_start(3), pam_get_item(3), pam_strerror(3)
108
110 The pam_fail_delay function is an Linux-PAM extension.
111
112
113
114Linux-PAM 05/07/2023 PAM_FAIL_DELAY(3)