Debian Codegraph @

debian/patches/pam_limits_fallback_defaults

raw
1 From: Sam Hartman <[email protected]>
2 Date: Thu, 16 Jan 2025 15:40:56 -0700
3 Subject: pam_limits: Defaults if kernel limits unavailable
4
5 When set_all is set in pam_limits control, if we are not on linux, or
6 if parsing kernel limits fails, set explicit defaults that are similar
7 to linux defaults.
8
9 This patch is not particularly important to Debian on linux now that
10 set_all is no longer the default; kept mainly for non-linux ports.
11
12 based on patch by Peter Paluch <[email protected]>
13 ---
14 modules/pam_limits/pam_limits.c | 73 +++++++++++++++++++++++++++++++++++++++--
15 1 file changed, 70 insertions(+), 3 deletions(-)
16
17 diff --git a/modules/pam_limits/pam_limits.c b/modules/pam_limits/pam_limits.c
18 index 7eb93c0..ca3bb18 100644
19 --- a/modules/pam_limits/pam_limits.c
20 +++ b/modules/pam_limits/pam_limits.c
21 @@ -58,6 +58,14 @@
22 # define PR_SET_NO_NEW_PRIVS 38 /* from <linux/prctl.h> */
23 #endif
24
25 +#ifndef MLOCK_LIMIT
26 +#ifdef __FreeBSD_kernel__
27 +#define MLOCK_LIMIT RLIM_INFINITY
28 +#else
29 +#define MLOCK_LIMIT (64*1024)
30 +#endif
31 +#endif
32 +
33 /* Module defines */
34 #define LIMITS_DEF_USER 0 /* limit was set by a user entry */
35 #define LIMITS_DEF_GROUP 1 /* limit was set by a group entry */
36 @@ -537,11 +545,18 @@ static int init_limits(pam_handle_t *pamh, struct pam_limit_s *pl, int ctrl)
37 {
38 int i;
39 int retval = PAM_SUCCESS;
40 + static int mlock_limit = 0;
41
42 D(("called."));
43
44 pl->root = 0;
45
46 + if (mlock_limit == 0) {
47 + mlock_limit = sysconf(_SC_PAGESIZE);
48 + if (mlock_limit < MLOCK_LIMIT)
49 + mlock_limit = MLOCK_LIMIT;
50 + }
51 +
52 for(i = 0; i < RLIM_NLIMITS; i++) {
53 int r = getrlimit(i, &pl->limits[i].limit);
54 if (r == -1) {
55 @@ -556,19 +571,71 @@ static int init_limits(pam_handle_t *pamh, struct pam_limit_s *pl, int ctrl)
56 }
57 }
58
59 -#ifdef __linux__
60 if (ctrl & PAM_SET_ALL) {
61 +#ifdef __linux__
62 parse_kernel_limits(pamh, pl, ctrl);
63 +#endif
64
65 for(i = 0; i < RLIM_NLIMITS; i++) {
66 if (pl->limits[i].supported &&
67 (pl->limits[i].src_soft == LIMITS_DEF_NONE ||
68 pl->limits[i].src_hard == LIMITS_DEF_NONE)) {
69 - pam_syslog(pamh, LOG_WARNING, "Did not find kernel RLIMIT for %s, using PAM default", rlimit2str(i));
70 +#ifdef __linux__
71 + pam_syslog(pamh, LOG_WARNING, "Did not find kernel RLIMIT for %s, using default", rlimit2str(i));
72 +#endif
73 + pl->limits[i].src_soft = LIMITS_DEF_DEFAULT;
74 + pl->limits[i].src_hard = LIMITS_DEF_DEFAULT;
75 + switch(i) {
76 + case RLIMIT_CPU:
77 + case RLIMIT_FSIZE:
78 + case RLIMIT_DATA:
79 + case RLIMIT_RSS:
80 + case RLIMIT_NPROC:
81 +#ifdef RLIMIT_AS
82 + case RLIMIT_AS:
83 +#endif
84 +#ifdef RLIMIT_LOCKS
85 + case RLIMIT_LOCKS:
86 +#endif
87 + pl->limits[i].limit.rlim_cur = RLIM_INFINITY;
88 + pl->limits[i].limit.rlim_max = RLIM_INFINITY;
89 + break;
90 + case RLIMIT_MEMLOCK:
91 + pl->limits[i].limit.rlim_cur = mlock_limit;
92 + pl->limits[i].limit.rlim_max = mlock_limit;
93 + break;
94 +#ifdef RLIMIT_SIGPENDING
95 + case RLIMIT_SIGPENDING:
96 + pl->limits[i].limit.rlim_cur = 16382;
97 + pl->limits[i].limit.rlim_max = 16382;
98 + break;
99 +#endif
100 +#ifdef RLIMIT_MSGQUEUE
101 + case RLIMIT_MSGQUEUE:
102 + pl->limits[i].limit.rlim_cur = 819200;
103 + pl->limits[i].limit.rlim_max = 819200;
104 + break;
105 +#endif
106 + case RLIMIT_CORE:
107 + pl->limits[i].limit.rlim_cur = 0;
108 + pl->limits[i].limit.rlim_max = RLIM_INFINITY;
109 + break;
110 + case RLIMIT_STACK:
111 + pl->limits[i].limit.rlim_cur = 8192*1024;
112 + pl->limits[i].limit.rlim_max = RLIM_INFINITY;
113 + break;
114 + case RLIMIT_NOFILE:
115 + pl->limits[i].limit.rlim_cur = 1024;
116 + pl->limits[i].limit.rlim_max = 1024;
117 + break;
118 + default:
119 + pl->limits[i].src_soft = LIMITS_DEF_NONE;
120 + pl->limits[i].src_hard = LIMITS_DEF_NONE;
121 + break;
122 + }
123 }
124 }
125 }
126 -#endif
127
128 errno = 0;
129 pl->priority = getpriority (PRIO_PROCESS, 0);