Skip to contentSkip to conversation

prot_hsymlinks: Fix failure on read-only machine

PATCH New [email protected] 2 participants 5 messages Mar 10, 2017 – Apr 9, 2017

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 prot_hsymlinks: Fix failure on read-only machine

From: Hoang Nguyen <[email protected]>

Return 32 if /etc/passwd is read-only.
Also move tst_tmpdir before useradd in setup, to avoid "TESTDIR was NULL" in tst_rmdir in cleanup.

Fixes #88

---
 testcases/kernel/security/prot_hsymlinks/prot_hsymlinks.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)
testcases/kernel/security/prot_hsymlinks/prot_hsymlinks.c +10 -4
index b23064a..31ddefa 100644
@@ -206,6 +206,8 @@ static void setup(int argc, char *argv[])
 
 	tst_sig(FORK, DEF_HANDLER, cleanup);
 
+	tst_tmpdir();
+
 	test_user_cmd("useradd");
 	/*
 	 * enable hardlinks and symlinks restrictions,
@@ -220,8 +222,6 @@ static void setup(int argc, char *argv[])
 		disable_protected_slinks = 1;
 	}
 
-	tst_tmpdir();
-
 	init_base_dirs();
 
 	init_files_dirs();
@@ -273,7 +273,8 @@ static void cleanup(void)
 	if (skip_cleanup)
 		return;
 
-	test_user_cmd("userdel -r");
+	if (!eaccess("/etc/passwd", W_OK))
+		test_user_cmd("userdel -r");
 
 	if (disable_protected_hlinks) {
 		tst_resm(TINFO, "Disable protected hardlinks mode back");
@@ -316,8 +317,13 @@ static void test_user_cmd(const char *user_cmd)
 	char cmd[MAX_CMD_LEN];
 	snprintf(cmd, MAX_CMD_LEN, "%s %s", user_cmd, users[TEST_USER].name);
 	if (system(cmd) != 0) {
-		tst_brkm(TBROK, cleanup, "Failed to run cmd: %s %s",
+		if (eaccess("/etc/passwd", W_OK)) {
+			tst_brkm(TCONF, cleanup,
+			"/etc/passwd is not accessible");
+		} else {
+			tst_brkm(TBROK, cleanup, "Failed to run cmd: %s %s",
 			user_cmd, users[TEST_USER].name);
+		}
 	}
 }
 
Signature · 1 line
2.7.4
#1 lore raw

PATCH 1/1 prot_hsymlinks: Fix failure on read-only machine

Hi,
Could you help to check, so that we can close the Issue ? Thanks and regards
Hoang

Sent from Yahoo Mail on Android

On Fri, Mar 10, 2017 at 7:55, [email protected]<[email protected]> wrote: From: Hoang Nguyen <[email protected]>

Return 32 if /etc/passwd is read-only.
Also move tst_tmpdir before useradd in setup, to avoid "TESTDIR was NULL" in tst_rmdir in cleanup.

Fixes #88

---
 testcases/kernel/security/prot_hsymlinks/prot_hsymlinks.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)
testcases/kernel/security/prot_hsymlinks/prot_hsymlinks.c +10 -4
index b23064a..31ddefa 100644
@@ -206,6 +206,8 @@ static void setup(int argc, char *argv[])
 
     tst_sig(FORK, DEF_HANDLER, cleanup);
 
+    tst_tmpdir();
+
     test_user_cmd("useradd");
     /*
     * enable hardlinks and symlinks restrictions,
@@ -220,8 +222,6 @@ static void setup(int argc, char *argv[])
         disable_protected_slinks = 1;
     }
 
-    tst_tmpdir();
-
     init_base_dirs();
 
     init_files_dirs();
@@ -273,7 +273,8 @@ static void cleanup(void)
     if (skip_cleanup)
         return;
 
-    test_user_cmd("userdel -r");
+    if (!eaccess("/etc/passwd", W_OK))
+        test_user_cmd("userdel -r");
 
     if (disable_protected_hlinks) {
         tst_resm(TINFO, "Disable protected hardlinks mode back");
@@ -316,8 +317,13 @@ static void test_user_cmd(const char *user_cmd)
     char cmd[MAX_CMD_LEN];
     snprintf(cmd, MAX_CMD_LEN, "%s %s", user_cmd, users[TEST_USER].name);
     if (system(cmd) != 0) {
-        tst_brkm(TBROK, cleanup, "Failed to run cmd: %s %s",
+        if (eaccess("/etc/passwd", W_OK)) {
+            tst_brkm(TCONF, cleanup,
+            "/etc/passwd is not accessible");
+        } else {
+            tst_brkm(TBROK, cleanup, "Failed to run cmd: %s %s",
             user_cmd, users[TEST_USER].name);
+        }
     }
 }
 
Signature · 6 lines
2.7.4

  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20170322/668fd6c7/attachment-0001.html>
#2 lore raw

PATCH 1/1 prot_hsymlinks: Fix failure on read-only machine

Hello,
Could you help to check if the patch is ok or not ? Thanks and regards.
Hoang

From: Hoang Nguyen <[email protected]>
To: "[email protected]" <[email protected]>; "[email protected]" <[email protected]>
Sent: Wednesday, 22 March 2017, 10:06
Subject: Re: [LTP] [PATCH] prot_hsymlinks: Fix failure on read-only machine

Hi,
Could you help to check, so that we can close the Issue ? Thanks and regards
Hoang

Sent from Yahoo Mail on Android

On Fri, Mar 10, 2017 at 7:55, [email protected]<[email protected]> wrote: From: Hoang Nguyen <[email protected]>

Return 32 if /etc/passwd is read-only.
Also move tst_tmpdir before useradd in setup, to avoid "TESTDIR was NULL" in tst_rmdir in cleanup.

Fixes #88

---
 testcases/kernel/security/prot_hsymlinks/prot_hsymlinks.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)
testcases/kernel/security/prot_hsymlinks/prot_hsymlinks.c +10 -4
index b23064a..31ddefa 100644
@@ -206,6 +206,8 @@ static void setup(int argc, char *argv[])
 
     tst_sig(FORK, DEF_HANDLER, cleanup);
 
+    tst_tmpdir();
+
     test_user_cmd("useradd");
     /*
     * enable hardlinks and symlinks restrictions,
@@ -220,8 +222,6 @@ static void setup(int argc, char *argv[])
         disable_protected_slinks = 1;
     }
 
-    tst_tmpdir();
-
     init_base_dirs();
 
     init_files_dirs();
@@ -273,7 +273,8 @@ static void cleanup(void)
     if (skip_cleanup)
         return;
 
-    test_user_cmd("userdel -r");
+    if (!eaccess("/etc/passwd", W_OK))
+        test_user_cmd("userdel -r");
 
     if (disable_protected_hlinks) {
         tst_resm(TINFO, "Disable protected hardlinks mode back");
@@ -316,8 +317,13 @@ static void test_user_cmd(const char *user_cmd)
     char cmd[MAX_CMD_LEN];
     snprintf(cmd, MAX_CMD_LEN, "%s %s", user_cmd, users[TEST_USER].name);
     if (system(cmd) != 0) {
-        tst_brkm(TBROK, cleanup, "Failed to run cmd: %s %s",
+        if (eaccess("/etc/passwd", W_OK)) {
+            tst_brkm(TCONF, cleanup,
+            "/etc/passwd is not accessible");
+        } else {
+            tst_brkm(TBROK, cleanup, "Failed to run cmd: %s %s",
             user_cmd, users[TEST_USER].name);
+        }
     }
 }
 
Signature · 9 lines
2.7.4

  


   
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20170405/1007f06e/attachment.html>
#3 lore raw

PATCH 1/1 prot_hsymlinks: Fix failure on read-only machine

In reply to [email protected]

Hi,

testcases/kernel/security/prot_hsymlinks/prot_hsymlinks.c static void test_user_cmd(const char *user_cmd) · line 322

Quoted 11 lines · On 10.03.2017 3:54, [email protected] wrote:

...

testcases/kernel/security/prot_hsymlinks/prot_hsymlinks.c +3 -1
 	if (disable_protected_hlinks) {
 		tst_resm(TINFO, "Disable protected hardlinks mode back");
@@ -316,8 +317,13 @@ static void test_user_cmd(const char *user_cmd)
 	char cmd[MAX_CMD_LEN];
 	snprintf(cmd, MAX_CMD_LEN, "%s %s", user_cmd, users[TEST_USER].name);
 	if (system(cmd) != 0) {
-		tst_brkm(TBROK, cleanup, "Failed to run cmd: %s %s",
+		if (eaccess("/etc/passwd", W_OK)) {
+			tst_brkm(TCONF, cleanup,
+			"/etc/passwd is not accessible");

It would be better to add this check to the top of setup(), right after tst_kvercmp(), and exit without doing cleanup.

Thanks,
Alexey

#4 lore raw

PATCH 1/1 prot_hsymlinks: Fix failure on read-only machine

Hi,
Thanks Alexey, this would be much simpler. I'll send new patch. (also setpriority01 fails on my read-only system, I'll update it similiarly)

Thanks a lot for your help,
Best regards,
Hoang

From: Alexey Kodanev <[email protected]>
To: [email protected]; [email protected]
Sent: Thursday, 6 April 2017, 0:25
Subject: Re: [LTP] [PATCH] prot_hsymlinks: Fix failure on read-only machine

Hi,

testcases/kernel/security/prot_hsymlinks/prot_hsymlinks.c static void test_user_cmd(const char *user_cmd) · line 322

Quoted 11 lines · On 10.03.2017 3:54, [email protected] wrote:

...
      if (disable_protected_hlinks) {
          tst_resm(TINFO, "Disable protected hardlinks mode back");

testcases/kernel/security/prot_hsymlinks/prot_hsymlinks.c +3 -1
@@ -316,8 +317,13 @@ static void test_user_cmd(const char *user_cmd)
       char cmd[MAX_CMD_LEN];
       snprintf(cmd, MAX_CMD_LEN, "%s %s", user_cmd, users[TEST_USER].name);
       if (system(cmd) != 0) {
-        tst_brkm(TBROK, cleanup, "Failed to run cmd: %s %s",
+        if (eaccess("/etc/passwd", W_OK)) {
+            tst_brkm(TCONF, cleanup,
+            "/etc/passwd is not accessible");

It would be better to add this check to the top of setup(), right after tst_kvercmp(), and exit without doing cleanup.

Thanks,
Alexey

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20170409/d764cf7c/attachment-0001.html>