Skip to contentSkip to conversation

tests/prlimit: avoid invalid limit combinations

PATCH Applied Ondrej Mosnacek 2 participants 3 messages Jan 10, 2020 – Jan 13, 2020 SELinux security module

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tests/prlimit: avoid invalid limit combinations

There is a bug in the prlimit test that causes invalid limit combinations (soft > hard) to be created, leading to false failures.

Consider for example an old setting of X for both soft and hard limit. In such case the hard limit test tries to set the limits to X (soft) and X/2 (hard), which always fails with -EINVAL.

This patch fixes the logic to clamp the soft limit to keep it from exceeding the hard limit. In such case the soft limit will also be changed, but this can't be avoided.

Fixes 0782228ef06b ("selinux-testsuite: Add tests for prlimit(2) permission checks")
---
 tests/prlimit/parent.c | 6 ++++++
 1 file changed, 6 insertions(+)
tests/prlimit/parent.c +6 -0
index be320f0..11c0c25 100644
@@ -147,6 +147,12 @@ int main(int argc, char **argv)
 				newrlim.rlim_max = 1024;
 			else
 				newrlim.rlim_max = oldrlim.rlim_max / 2;
+			if (newrlim.rlim_cur > newrlim.rlim_max)
+				/*
+				 * This will change also soft limit, but
+				 * what else can you do in such case...
+				 */
+				newrlim.rlim_cur = newrlim.rlim_max;
 		}
 	}
 
Signature · 1 line
2.24.1
Acked-by on v1 1/1
#1 lore raw
Quoted 7 lines · Ondrej Mosnacek

There is a bug in the prlimit test that causes invalid limit combinations (soft > hard) to be created, leading to false failures.

Consider for example an old setting of X for both soft and hard limit. In such case the hard limit test tries to set the limits to X (soft) and X/2 (hard), which always fails with -EINVAL.

Quoted 7 lines

This patch fixes the logic to clamp the soft limit to keep it from exceeding the hard limit. In such case the soft limit will also be changed, but this can't be avoided.

Fixes 0782228ef06b ("selinux-testsuite: Add tests for prlimit(2) permission checks")
Quoted 22 lines
---
  tests/prlimit/parent.c | 6 ++++++
  1 file changed, 6 insertions(+)
tests/prlimit/parent.c +6 -0
index be320f0..11c0c25 100644
@@ -147,6 +147,12 @@ int main(int argc, char **argv)
  				newrlim.rlim_max = 1024;
  			else
  				newrlim.rlim_max = oldrlim.rlim_max / 2;
+			if (newrlim.rlim_cur > newrlim.rlim_max)
+				/*
+				 * This will change also soft limit, but
+				 * what else can you do in such case...
+				 */
+				newrlim.rlim_cur = newrlim.rlim_max;
  		}
  	}
 
#2 lore raw
Quoted 12 lines · Stephen Smalley
Quoted 11 lines · Ondrej Mosnacek

There is a bug in the prlimit test that causes invalid limit combinations (soft > hard) to be created, leading to false failures.

Consider for example an old setting of X for both soft and hard limit. In such case the hard limit test tries to set the limits to X (soft) and X/2 (hard), which always fails with -EINVAL.

This patch fixes the logic to clamp the soft limit to keep it from exceeding the hard limit. In such case the soft limit will also be changed, but this can't be avoided.

Quoted 5 lines
Quoted 3 lines
Fixes 0782228ef06b ("selinux-testsuite: Add tests for prlimit(2) permission checks")

Applied.

Quoted 23 lines
Quoted 22 lines

---
  tests/prlimit/parent.c | 6 ++++++

  1 file changed, 6 insertions(+)
tests/prlimit/parent.c +0 -0
index be320f0..11c0c25 100644
@@ -147,6 +147,12 @@ int main(int argc, char **argv)
                   newrlim.rlim_max = 1024;

              else
                  newrlim.rlim_max = oldrlim.rlim_max / 2; +            if (newrlim.rlim_cur > newrlim.rlim_max) +                /*
+                 * This will change also soft limit, but +                 * what else can you do in such case... +                 */
+                newrlim.rlim_cur = newrlim.rlim_max; }
      }