Debian Codegraph @

debian/patches/pam_limits_explicit_root

raw
1 From: Peter Paluch <[email protected]>
2 Date: Mon, 11 Sep 2023 14:00:42 -0600
3 Subject: Root limits must be explicit
4
5 Bug-Debian: http://bugs.debian.org/63230
6 Don't apply wildcard limits to the root account; only apply limits to
7 root that reference root by name.
8 ===================================================================
9 ---
10 modules/pam_limits/limits.conf | 4 ++++
11 modules/pam_limits/limits.conf.5.xml | 6 ++++++
12 modules/pam_limits/pam_limits.c | 11 ++++++++---
13 3 files changed, 18 insertions(+), 3 deletions(-)
14
15 diff --git a/modules/pam_limits/limits.conf b/modules/pam_limits/limits.conf
16 index e8a746c..c6b058a 100644
17 --- a/modules/pam_limits/limits.conf
18 +++ b/modules/pam_limits/limits.conf
19 @@ -22,6 +22,9 @@
20 # - the wildcard *, for default entry
21 # - the wildcard %, can be also used with %group syntax,
22 # for maxlogin limit
23 +# - NOTE: group and wildcard limits are not applied to root.
24 +# To apply a limit to the root user, <domain> must be
25 +# the literal username root.
26 #
27 #<type> can have the two values:
28 # - "soft" for enforcing the soft limits
29 @@ -51,6 +54,7 @@
30 #
31
32 #* soft core 0
33 +#root hard core 100000
34 #* hard rss 10000
35 #@student hard nproc 20
36 #@faculty soft nproc 20
37 diff --git a/modules/pam_limits/limits.conf.5.xml b/modules/pam_limits/limits.conf.5.xml
38 index dd8d68b..803cb4e 100644
39 --- a/modules/pam_limits/limits.conf.5.xml
40 +++ b/modules/pam_limits/limits.conf.5.xml
41 @@ -89,6 +89,11 @@
42 </para>
43 </listitem>
44 </itemizedlist>
45 + <para>
46 + <emphasis remap='B'>NOTE:</emphasis> group and wildcard limits are not
47 + applied to the root user. To set a limit for the root user, this field
48 + must contain the literal username <emphasis remap='B'>root</emphasis>.
49 + </para>
50 </listitem>
51 </varlistentry>
52
53 @@ -320,6 +325,7 @@
54 </para>
55 <programlisting>
56 * soft core 0
57 +root hard core 100000
58 * hard nofile 512
59 @student hard nproc 20
60 @faculty soft nproc 20
61 diff --git a/modules/pam_limits/pam_limits.c b/modules/pam_limits/pam_limits.c
62 index 1e4dfa3..7eb93c0 100644
63 --- a/modules/pam_limits/pam_limits.c
64 +++ b/modules/pam_limits/pam_limits.c
65 @@ -93,6 +93,7 @@ struct user_limits_struct {
66
67 /* internal data */
68 struct pam_limit_s {
69 + int root; /* running as root? */
70 int login_limit; /* the max logins limit */
71 int login_limit_def; /* which entry set the login limit */
72 int flag_numsyslogins; /* whether to limit logins only for a
73 @@ -539,6 +540,8 @@ static int init_limits(pam_handle_t *pamh, struct pam_limit_s *pl, int ctrl)
74
75 D(("called."));
76
77 + pl->root = 0;
78 +
79 for(i = 0; i < RLIM_NLIMITS; i++) {
80 int r = getrlimit(i, &pl->limits[i].limit);
81 if (r == -1) {
82 @@ -1020,7 +1023,7 @@ parse_config_file(pam_handle_t *pamh, const char *uname, uid_t uid, gid_t gid,
83
84 if (strcmp(uname, domain) == 0) /* this user has a limit */
85 process_limit(pamh, LIMITS_DEF_USER, ltype, item, value, ctrl, pl);
86 - else if (domain[0]=='@') {
87 + else if (domain[0]=='@' && !pl->root) {
88 if (ctrl & PAM_DEBUG_ARG) {
89 pam_syslog(pamh, LOG_DEBUG,
90 "checking if %s is in group %s",
91 @@ -1046,7 +1049,7 @@ parse_config_file(pam_handle_t *pamh, const char *uname, uid_t uid, gid_t gid,
92 process_limit(pamh, LIMITS_DEF_GROUP, ltype, item, value, ctrl,
93 pl);
94 }
95 - } else if (domain[0]=='%') {
96 + } else if (domain[0]=='%' && !pl->root) {
97 if (ctrl & PAM_DEBUG_ARG) {
98 pam_syslog(pamh, LOG_DEBUG,
99 "checking if %s is in group %s",
100 @@ -1081,7 +1084,7 @@ parse_config_file(pam_handle_t *pamh, const char *uname, uid_t uid, gid_t gid,
101 } else {
102 switch(rngtype) {
103 case LIMIT_RANGE_NONE:
104 - if (strcmp(domain, "*") == 0)
105 + if (strcmp(domain, "*") == 0 && !pl->root)
106 process_limit(pamh, LIMITS_DEF_DEFAULT, ltype, item, value, ctrl,
107 pl);
108 break;
109 @@ -1372,6 +1375,8 @@ pam_sm_open_session (pam_handle_t *pamh, int flags UNUSED,
110 return PAM_ABORT;
111 }
112
113 + if (pwd->pw_uid == 0)
114 + pl->root = 1;
115 retval = parse_config_file(pamh, pwd->pw_name, pwd->pw_uid, pwd->pw_gid,
116 ctrl, pl, conf_file_set_by_user);
117 if (retval == PAM_IGNORE) {