| 1 |
From: Robie Basak <[email protected]> |
| 2 |
Date: Mon, 11 Sep 2023 14:00:42 -0600 |
| 3 |
Subject: pam_limits: cap the default soft nofile limit read from pid 1 to |
| 4 |
FD_SETSIZE |
| 5 |
|
| 6 |
Cap the default soft nofile limit read from pid 1 to FD_SETSIZE since |
| 7 |
larger values can cause problems with fd_set overflow and systemd sets |
| 8 |
itself higher. |
| 9 |
|
| 10 |
See: |
| 11 |
https://lists.ubuntu.com/archives/ubuntu-devel/2010-September/031446.html |
| 12 |
http://www.outflux.net/blog/archives/2014/06/13/5-year-old-glibc-select-weakness-fixed/ |
| 13 |
https://sourceware.org/bugzilla/show_bug.cgi?id=10352 |
| 14 |
https://github.com/systemd/systemd/commit/4096d6f5879aef73e20dd7b62a01f447629945b0 |
| 15 |
|
| 16 |
pam_limits reads the default limits from /proc/1/limits. Previously, |
| 17 |
using upstart, this resulted in a 1024 nofile soft limit on Ubuntu |
| 18 |
systems by default. Using systemd, this results in a limit of 65536 |
| 19 |
instead. This is not the intention of systemd upstream. See systemd |
| 20 |
commit 4096d6f for an explanation of systemd's behaviour. |
| 21 |
|
| 22 |
If we want to make such a change to the default distribution soft limit |
| 23 |
in PAM, we should do it deliberately and carefully, not accidentally. A |
| 24 |
change should consider what uses select(2) and might inadvertently (and |
| 25 |
incorrectly) assume that file descriptors will always fit into an |
| 26 |
fd_set, what vulnerabilities or crashes the change could consequently |
| 27 |
create, and whether the protection now present with FORTIFY_SOURCE is |
| 28 |
suitably enabled in all relevant builds. |
| 29 |
|
| 30 |
So this keeps the soft limit at 1024 for now. The hard limit will rise |
| 31 |
to 65536 along with systemd. Anything that knows that it will not be |
| 32 |
buggy with respect to fd_set and FD_SETSIZE, such as by using poll(2) or |
| 33 |
epoll(7) instead of select(2), can always raise the soft limit itself |
| 34 |
without issue. |
| 35 |
|
| 36 |
20:54 <rbasak> slangasek: [...] I'm also not sure how to go about |
| 37 |
upstreaming this as pam_limits seems to be heavily patched already. |
| 38 |
|
| 39 |
Forwarded: no |
| 40 |
Reviewed-by: Adam Conrad <[email protected]> |
| 41 |
Reviewed-by: Martin Pitt <[email protected]> |
| 42 |
Last-Update: 2015-04-22 |
| 43 |
--- |
| 44 |
modules/pam_limits/pam_limits.c | 8 ++++++++ |
| 45 |
1 file changed, 8 insertions(+) |
| 46 |
|
| 47 |
diff --git a/modules/pam_limits/pam_limits.c b/modules/pam_limits/pam_limits.c |
| 48 |
index ca3bb18..5ec30ca 100644 |
| 49 |
--- a/modules/pam_limits/pam_limits.c |
| 50 |
+++ b/modules/pam_limits/pam_limits.c |
| 51 |
@@ -538,6 +538,14 @@ static void parse_kernel_limits(pam_handle_t *pamh, struct pam_limit_s *pl, int |
| 52 |
} |
| 53 |
free(line); |
| 54 |
fclose(limitsfile); |
| 55 |
+ |
| 56 |
+ /* Cap the default soft nofile limit read from pid 1 to FD_SETSIZE |
| 57 |
+ * since larger values can cause problems with fd_set overflow and |
| 58 |
+ * systemd sets itself higher. */ |
| 59 |
+ if (pl->limits[RLIMIT_NOFILE].src_soft == LIMITS_DEF_KERNEL && |
| 60 |
+ pl->limits[RLIMIT_NOFILE].limit.rlim_cur > FD_SETSIZE) { |
| 61 |
+ pl->limits[RLIMIT_NOFILE].limit.rlim_cur = FD_SETSIZE; |
| 62 |
+ } |
| 63 |
} |
| 64 |
#endif |
| 65 |
|