public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
From: Junchi Chen <junchi.chen@intel.com>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH ltp] syscalls/munlockall02: fix the outdated TCONF message
Date: Tue, 28 Aug 2018 23:52:53 +0800	[thread overview]
Message-ID: <20180828155253.30621-1-junchi.chen@intel.com> (raw)

ISSUE:
  This TCONF message: "Some distros... support
   non-superuser munlockall calls."
   has unnecessarily shown for years.

REASON:
  EPERM is the error expected, which, by man page, is occurring due
   to the lack of privilege (CAP_IPC_LOCK).
   The intersection of munlockall syscall and CAP_IPC_LOCK macro is only
   in /mm/mlock.c file.

  From v2.6, in /mm/mlock.c, there are no privilege check when using
   munlockall syscall.
   - For older version, the execution of do_mlockall()
   with flag 0 is done right after the request for the semlock.
   By comparison, mlockall syscall checked via capable(CAP_IPC_LOCK)
   before do_mlockall() with flags.
   - For newer version, apply_mlockall_flags()
   substituted do_mlockall(), but nothing changed regarding privilege check.

ACTION:
  Add tst_kvercmp() to test kernel version.

Signed-off-by: Junchi Chen <junchi.chen@intel.com>
---
 .../kernel/syscalls/munlockall/munlockall02.c | 30 ++++++++++++++-----
 1 file changed, 23 insertions(+), 7 deletions(-)

diff --git a/testcases/kernel/syscalls/munlockall/munlockall02.c b/testcases/kernel/syscalls/munlockall/munlockall02.c
index f97905473..2e2695c52 100644
--- a/testcases/kernel/syscalls/munlockall/munlockall02.c
+++ b/testcases/kernel/syscalls/munlockall/munlockall02.c
@@ -48,6 +48,8 @@
  *	 otherwise,
  *	  Issue sys call fails with unexpected errno.
  *
+ *	 Since V2.6.11, the mainline kernel support none-superuser
+ *	  munlockall calls. So the test pass with a success.
  *
  * 	Cleanup:
  *      change effective user id to root
@@ -69,6 +71,7 @@
 #include <errno.h>
 #include <pwd.h>
 #include <sys/mman.h>
+#include "tst_kvercmp.h"
 #include "test.h"
 #include "safe_macros.h"
 
@@ -98,14 +101,27 @@ int main(int ac, char **av)
 
 		TEST(munlockall());
 		/* check return code */
-		if ((TEST_RETURN == -1) && (TEST_ERRNO == EPERM)) {
-			tst_resm(TPASS, "munlockall() failed"
-				 " as expected for non-superuser" ":GOT EPERM");
+		if (tst_kvercmp(2, 6, 11) < 0) {
+			if ((TEST_RETURN == -1) && (TEST_ERRNO == EPERM)) {
+				tst_resm(TPASS, "munlockall() failed"
+						" as expected for non-superuser"
+						":GOT EPERM");
+			} else {
+				tst_resm(TCONF, "munlockall() failed to produce "
+						"expected errno :%d Got : %d, %s. ***Some distros, "
+						"such as Red Hat Enterprise Linux, support "
+						"non-superuser munlockall calls.***",
+						EPERM, TEST_ERRNO, strerror(TEST_ERRNO));
+			}
 		} else {
-			tst_resm(TCONF, "munlockall() failed to produce "
-				 "expected errno :%d Got : %d, %s. ***Some distros, such as Red Hat Enterprise Linux, support non-superuser munlockall calls.***",
-				 EPERM, TEST_ERRNO, strerror(TEST_ERRNO));
-
+			if (TEST_RETURN == 0) {
+				tst_resm(TPASS, "munlockall() succeeded"
+						" as expected for non-superuser");
+			} else {
+				tst_resm(TFAIL, "munlockall() failed to run"
+						" as non-superuser, Got : %d, %s.",
+						TEST_ERRNO, strerror(TEST_ERRNO));
+			}
 		}
 	}
 
-- 
2.17.1


             reply	other threads:[~2018-08-28 15:52 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-08-28 15:52 Junchi Chen [this message]
2018-08-28 13:35 ` [LTP] [PATCH ltp] syscalls/munlockall02: fix the outdated TCONF message Cyril Hrubis

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180828155253.30621-1-junchi.chen@intel.com \
    --to=junchi.chen@intel.com \
    --cc=ltp@lists.linux.it \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox