diff --git a/Linux-PAM-1.3.1.tar.xz b/Linux-PAM-1.3.1.tar.xz
deleted file mode 100644
index 424ac57beb925a2cd9f02e79911d6d92087b4cae..0000000000000000000000000000000000000000
Binary files a/Linux-PAM-1.3.1.tar.xz and /dev/null differ
diff --git a/Linux-PAM-1.3.1.tar.xz.asc b/Linux-PAM-1.3.1.tar.xz.asc
deleted file mode 100644
index 7057c1810b583b07d156dd62769bf0d1a705bc6d..0000000000000000000000000000000000000000
--- a/Linux-PAM-1.3.1.tar.xz.asc
+++ /dev/null
@@ -1,7 +0,0 @@
------BEGIN PGP SIGNATURE-----
-Version: GnuPG v2
-
-iD8DBQBa/r62bRp/BS5ZJLsRArnKAJ9pGaJHpsEsbOVa5dBQLHYC4DhPuACeJNrg
-+DaNc8W13E4Z2ZEUSsgUGe4=
-=aSTW
------END PGP SIGNATURE-----
diff --git a/download b/download
new file mode 100644
index 0000000000000000000000000000000000000000..34109d3bab9f5823a37be78aafb0adc0c122eb8a
--- /dev/null
+++ b/download
@@ -0,0 +1,3 @@
+558ff53b0fc0563ca97f79e911822165 Linux-PAM-1.3.1.tar.xz
+6e287bee205469ecb9da47e50f1a2eda Linux-PAM-1.3.1.tar.xz.asc
+29eab110f57e8d60471081a6278a5a92 pam-redhat-0.99.11.tar.bz2
diff --git a/pam-1.3.1-pam-limits-unlimited-value.patch b/pam-1.3.1-pam-limits-unlimited-value.patch
new file mode 100644
index 0000000000000000000000000000000000000000..1cf063c232931445a5c7d680d6807e2bc9f70c2a
--- /dev/null
+++ b/pam-1.3.1-pam-limits-unlimited-value.patch
@@ -0,0 +1,78 @@
+diff -up Linux-PAM-1.3.1/modules/pam_limits/limits.conf.5.xml.pam-limits-unlimited-value Linux-PAM-1.3.1/modules/pam_limits/limits.conf.5.xml
+--- Linux-PAM-1.3.1/modules/pam_limits/limits.conf.5.xml.pam-limits-unlimited-value 2022-01-28 09:45:41.431606850 +0100
++++ Linux-PAM-1.3.1/modules/pam_limits/limits.conf.5.xml 2022-01-28 09:47:31.732430391 +0100
+@@ -275,6 +275,8 @@
+ All items support the values -1,
+ unlimited or infinity indicating no limit,
+ except for priority and nice.
++ If nofile is to be set to one of these values,
++ it will be set to the contents of /proc/sys/fs/nr_open instead (see setrlimit(3)).
+
+
+ If a hard limit or soft limit of a resource is set to a valid value,
+diff -up Linux-PAM-1.3.1/modules/pam_limits/pam_limits.c.pam-limits-unlimited-value Linux-PAM-1.3.1/modules/pam_limits/pam_limits.c
+--- Linux-PAM-1.3.1/modules/pam_limits/pam_limits.c.pam-limits-unlimited-value 2022-01-28 09:45:41.415606731 +0100
++++ Linux-PAM-1.3.1/modules/pam_limits/pam_limits.c 2022-01-28 09:45:41.431606850 +0100
+@@ -487,6 +487,41 @@ static int init_limits(pam_handle_t *pam
+ return retval;
+ }
+
++/*
++ * Read the contents of and return it in *valuep
++ * return 1 if conversion succeeds, result is in *valuep
++ * return 0 if conversion fails, *valuep is untouched.
++ */
++static int
++value_from_file(const char *pathname, rlim_t *valuep)
++{
++ char buf[128];
++ FILE *fp;
++ int retval;
++
++ retval = 0;
++
++ if ((fp = fopen(pathname, "r")) != NULL) {
++ if (fgets(buf, sizeof(buf), fp) != NULL) {
++ char *endptr;
++ unsigned long long value;
++
++ errno = 0;
++ value = strtoull(buf, &endptr, 10);
++ if (endptr != buf &&
++ (value != ULLONG_MAX || errno == 0) &&
++ (unsigned long long) (rlim_t) value == value) {
++ *valuep = (rlim_t) value;
++ retval = 1;
++ }
++ }
++
++ fclose(fp);
++ }
++
++ return retval;
++}
++
+ static void
+ process_limit (const pam_handle_t *pamh, int source, const char *lim_type,
+ const char *lim_item, const char *lim_value,
+@@ -652,6 +687,20 @@ process_limit (const pam_handle_t *pamh,
+ rlimit_value = 20 - int_value;
+ break;
+ #endif
++ case RLIMIT_NOFILE:
++ /*
++ * If nofile is to be set to "unlimited", try to set it to
++ * the value in /proc/sys/fs/nr_open instead.
++ */
++ if (rlimit_value == RLIM_INFINITY) {
++ if (!value_from_file("/proc/sys/fs/nr_open", &rlimit_value))
++ pam_syslog(pamh, LOG_WARNING,
++ "Cannot set \"nofile\" to a sensible value");
++ else if (ctrl & PAM_DEBUG_ARG)
++ pam_syslog(pamh, LOG_DEBUG, "Setting \"nofile\" limit to %llu",
++ (unsigned long long) rlimit_value);
++ }
++ break;
+ }
+
+ if ( (limit_item != LIMIT_LOGIN)
diff --git a/pam-redhat-0.99.11.tar.bz2 b/pam-redhat-0.99.11.tar.bz2
deleted file mode 100644
index 6d85e7a6f2a2d95e14e8dc3a23e5f0d1e5011450..0000000000000000000000000000000000000000
Binary files a/pam-redhat-0.99.11.tar.bz2 and /dev/null differ
diff --git a/pam.spec b/pam.spec
index 551c746a5160ed45e66c4f7b9e4ba88ebb7ba8fc..56d11043898caff312755dcea5a15ceaeee8552a 100644
--- a/pam.spec
+++ b/pam.spec
@@ -3,7 +3,7 @@
Summary: An extensible library which provides authentication for applications
Name: pam
Version: 1.3.1
-Release: 15%{?dist}
+Release: 16%{?dist}
# The library is BSD licensed with option to relicense as GPLv2+
# - this option is redundant as the BSD license allows that anyway.
# pam_timestamp, pam_loginuid, and pam_console modules are GPLv2+.
@@ -67,6 +67,8 @@ Patch48: pam-1.3.1-wheel-pam_ruser-fallback.patch
Patch49: pam-1.3.1-namespace-gdm-doc.patch
# https://github.com/linux-pam/linux-pam/commit/a7453aeeb398d6cbb7a709c4e2a1d75905220fff
Patch50: pam-1.3.1-pam-userdb-prevent-garbage-characters-from-db.patch
+# https://github.com/linux-pam/linux-pam/commit/3234488f2c52a021eec87df1990d256314c21bff
+Patch51: pam-1.3.1-pam-limits-unlimited-value.patch
%define _pamlibdir %{_libdir}
%define _moduledir %{_libdir}/security
@@ -165,6 +167,8 @@ cp %{SOURCE18} .
%patch48 -p1 -b .wheel-pam_ruser-fallback
%patch49 -p1 -b .namespace-gdm-doc
%patch50 -p1 -b .pam-userdb-prevent-garbage-characters-from-db
+%patch51 -p1 -b .pam-limits-unlimited-value
+
autoreconf -i
%build
@@ -410,6 +414,9 @@ done
%doc doc/specs/rfc86.0.txt
%changelog
+* Fri Jan 28 2022 Iker Pedrosa - 1.3.1-16
+- pam_limits: "Unlimited" is not a valid value for RLIMIT_NOFILE. Resolves: #2047655
+
* Mon May 3 2021 Iker Pedrosa 1.3.1-15
- pam_userdb: Prevent garbage characters from db (#1791965)