pam_fail_delay.3 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. '\" t
  2. .\" Title: pam_fail_delay
  3. .\" Author: [FIXME: author] [see http://docbook.sf.net/el/author]
  4. .\" Generator: DocBook XSL Stylesheets v1.79.1 <http://docbook.sf.net/>
  5. .\" Date: 09/03/2021
  6. .\" Manual: Linux-PAM Manual
  7. .\" Source: Linux-PAM Manual
  8. .\" Language: English
  9. .\"
  10. .TH "PAM_FAIL_DELAY" "3" "09/03/2021" "Linux-PAM Manual" "Linux-PAM Manual"
  11. .\" -----------------------------------------------------------------
  12. .\" * Define some portability stuff
  13. .\" -----------------------------------------------------------------
  14. .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  15. .\" http://bugs.debian.org/507673
  16. .\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
  17. .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  18. .ie \n(.g .ds Aq \(aq
  19. .el .ds Aq '
  20. .\" -----------------------------------------------------------------
  21. .\" * set default formatting
  22. .\" -----------------------------------------------------------------
  23. .\" disable hyphenation
  24. .nh
  25. .\" disable justification (adjust text to left margin only)
  26. .ad l
  27. .\" -----------------------------------------------------------------
  28. .\" * MAIN CONTENT STARTS HERE *
  29. .\" -----------------------------------------------------------------
  30. .SH "NAME"
  31. pam_fail_delay \- request a delay on failure
  32. .SH "SYNOPSIS"
  33. .sp
  34. .ft B
  35. .nf
  36. #include <security/pam_appl\&.h>
  37. .fi
  38. .ft
  39. .HP \w'int\ pam_fail_delay('u
  40. .BI "int pam_fail_delay(pam_handle_t\ *" "pamh" ", unsigned\ int\ " "usec" ");"
  41. .SH "DESCRIPTION"
  42. .PP
  43. The
  44. \fBpam_fail_delay\fR
  45. function provides a mechanism by which an application or module can suggest a minimum delay of
  46. \fIusec\fR
  47. micro\-seconds\&. The function keeps a record of the longest time requested with this function\&. Should
  48. \fBpam_authenticate\fR(3)
  49. fail, the failing return to the application is delayed by an amount of time randomly distributed (by up to 50%) about this longest value\&.
  50. .PP
  51. 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
  52. \fIafter\fR
  53. all authentication modules have been called, but
  54. \fIbefore\fR
  55. control is returned to the service application\&.
  56. .PP
  57. When using this function the programmer should check if it is available with:
  58. .sp
  59. .if n \{\
  60. .RS 4
  61. .\}
  62. .nf
  63. #ifdef HAVE_PAM_FAIL_DELAY
  64. \&.\&.\&.\&.
  65. #endif /* HAVE_PAM_FAIL_DELAY */
  66. .fi
  67. .if n \{\
  68. .RE
  69. .\}
  70. .PP
  71. 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
  72. \fIPAM_FAIL_DELAY\fR
  73. item\&. It can be queried and set with
  74. \fBpam_get_item\fR(3)
  75. and
  76. \fBpam_set_item\fR(3)
  77. respectively\&. The value used to set it should be a function pointer of the following prototype:
  78. .sp
  79. .if n \{\
  80. .RS 4
  81. .\}
  82. .nf
  83. void (*delay_fn)(int retval, unsigned usec_delay, void *appdata_ptr);
  84. .fi
  85. .if n \{\
  86. .RE
  87. .\}
  88. .sp
  89. The arguments being the
  90. \fIretval\fR
  91. return code of the module stack, the
  92. \fIusec_delay\fR
  93. micro\-second delay that libpam is requesting and the
  94. \fIappdata_ptr\fR
  95. that the application has associated with the current
  96. \fIpamh\fR\&. This last value was set by the application when it called
  97. \fBpam_start\fR(3)
  98. or explicitly with
  99. \fBpam_set_item\fR(3)\&.
  100. .PP
  101. Note that the PAM_FAIL_DELAY item is set to NULL by default\&. This indicates that PAM should perform a random delay as described above when authentication fails and a delay has been suggested\&. If an application does not want the PAM library to perform any delay on authentication failure, then the application must define a custom delay function that executes no statements and set the PAM_FAIL_DELAY item to point to this function\&.
  102. .SH "RATIONALE"
  103. .PP
  104. 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
  105. \fIshort\fR
  106. timeouts, it may prove possible to attempt a
  107. \fIbrute force\fR
  108. 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
  109. \fIcovert channel\fR
  110. of useful information\&.
  111. .PP
  112. 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\&.
  113. .SH "EXAMPLE"
  114. .PP
  115. For example, a login application may require a failure delay of roughly 3 seconds\&. It will contain the following code:
  116. .sp
  117. .if n \{\
  118. .RS 4
  119. .\}
  120. .nf
  121. pam_fail_delay (pamh, 3000000 /* micro\-seconds */ );
  122. pam_authenticate (pamh, 0);
  123. .fi
  124. .if n \{\
  125. .RE
  126. .\}
  127. .PP
  128. if the modules do not request a delay, the failure delay will be between 1\&.5 and 4\&.5 seconds\&.
  129. .PP
  130. However, the modules, invoked in the authentication process, may also request delays:
  131. .sp
  132. .if n \{\
  133. .RS 4
  134. .\}
  135. .nf
  136. module #1: pam_fail_delay (pamh, 2000000);
  137. module #2: pam_fail_delay (pamh, 4000000);
  138. .fi
  139. .if n \{\
  140. .RE
  141. .\}
  142. .PP
  143. in this case, it is the largest requested value that is used to compute the actual failed delay: here between 2 and 6 seconds\&.
  144. .SH "RETURN VALUES"
  145. .PP
  146. PAM_SUCCESS
  147. .RS 4
  148. Delay was successful adjusted\&.
  149. .RE
  150. .PP
  151. PAM_SYSTEM_ERR
  152. .RS 4
  153. A NULL pointer was submitted as PAM handle\&.
  154. .RE
  155. .SH "SEE ALSO"
  156. .PP
  157. \fBpam_start\fR(3),
  158. \fBpam_get_item\fR(3),
  159. \fBpam_strerror\fR(3)
  160. .SH "STANDARDS"
  161. .PP
  162. The
  163. \fBpam_fail_delay\fR
  164. function is an Linux\-PAM extension\&.