Skip to contentSkip to conversation

SELinux testsuite compilation fixes

PATCH Superseded Paul Moore 3 participants 9 messages Jun 4, 2015 SELinux security module

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Paul Moore

author
#0 lore raw

v2 cover SELinux testsuite compilation fixes

A collection of compilation fixes.

---

Paul Moore (6):
selinux-testsuite: add _GNU_SOURCE to tests/Makefile
selinux-testsuite: add some default CFLAGS
selinux-testsuite: fix some compile warnings in tests/nnp
selinux-testsuite: fix compile warnings in tests/setnice
selinux-testsuite: fix compile problems in tests/shm
selinux-testsuite: fix compile problems in tests/capable_file

 tests/Makefile                  |    3 +++
 tests/capable_file/test_lease.c |    9 +++++----
 tests/msg/msgrcv.c              |    5 -----
 tests/msg/msgsnd.c              |    5 -----
 tests/nnp/execnnp.c             |    2 ++
 tests/setnice/parent.c          |    2 ++
 tests/shm/shmat.c               |    6 +-----
 tests/shm/shmctl.c              |    6 +-----
 tests/shm/shmget.c              |    6 +-----
 9 files changed, 15 insertions(+), 29 deletions(-)
author
#1 lore raw

PATCH v2 1/6 selinux-testsuite: add _GNU_SOURCE to tests/Makefile

As suggested by Stephen Smalley. A couple of msgbuf struct definitions had to be removed as they were conflicting with system definitions.

---
 tests/Makefile     |    3 +++
 tests/msg/msgrcv.c |    5 -----
 tests/msg/msgsnd.c |    5 -----
 3 files changed, 3 insertions(+), 10 deletions(-)
tests/Makefile +3 -0
index e9d4646..8100b8f 100644
@@ -1,3 +1,6 @@
+
+export CFLAGS+=-D_GNU_SOURCE
+
 DISTRO=$(shell ./os_detect)
 
 SUBDIRS_COMMON:=domain_trans entrypoint execshare exectrace execute_no_trans fdreceive inherit link mkdir msg open ptrace readlink relabel rename rxdir sem setattr setnice shm sigkill stat sysctl task_create task_setnice task_setscheduler task_getscheduler task_getsid task_getpgid task_setpgid wait file ioctl capable_file capable_net capable_sys
tests/msg/msgrcv.c +0 -5
index b23c801..285dcad 100644
@@ -6,11 +6,6 @@
 
 #define MSGMAX 1024
 
-struct msgbuf {
-  long mtype;     /* message type, must be > 0 */
-  char mtext[1024];  /* message data */
-};
-
 int main(int argc, char **argv)
 {
 	int ch;
tests/msg/msgsnd.c +0 -5
index e200aef..7204ab6 100644
@@ -7,11 +7,6 @@
 
 #define MSGMAX 1024
 
-struct msgbuf {
-  long mtype;     /* message type, must be > 0 */
-  char mtext[1024];  /* message data */
-};
-
 int main(int argc, char **argv)
 {
 	int ch;
author
#4 lore raw

PATCH v2 2/6 selinux-testsuite: add some default CFLAGS

In reply to Paul Moore
---
 tests/Makefile |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tests/Makefile +1 -1
index 8100b8f..b679137 100644
@@ -1,5 +1,5 @@
 
-export CFLAGS+=-D_GNU_SOURCE
+export CFLAGS+=-g -O0 -Wall -D_GNU_SOURCE
 
 DISTRO=$(shell ./os_detect)
 
author
#5 lore raw

PATCH v2 3/6 selinux-testsuite: fix some compile warnings in tests/nnp

In reply to Paul Moore

Correct the following:

make[2]: Entering directory '/root/sources/selinux-testsuite/tests/nnp'
cc execnnp.c -lselinux -o execnnp
execnnp.c: In function 'main':
execnnp.c:27:9: warning: implicit declaration of function 'strverscmp'

        (strverscmp(uts.release, "3.18") < 0));
         ^

execnnp.c:47:8: warning: implicit declaration of function 'wait'
pid = wait(&status);

---
 tests/nnp/execnnp.c |    2 ++
 1 file changed, 2 insertions(+)
tests/nnp/execnnp.c +2 -0
index a5a80cf..756c2d0 100644
@@ -5,6 +5,8 @@
 #include <unistd.h>
 #include <sys/utsname.h>
 #include <sys/prctl.h>
+#include <sys/types.h>
+#include <sys/wait.h>
 
 int main(int argc, char **argv)
 {
author
#6 lore raw

PATCH v2 4/6 selinux-testsuite: fix compile warnings in tests/setnice

In reply to Paul Moore

Correct the following:

make[2]: Entering directory '/root/sources/selinux-testsuite/tests/setnice'
cc parent.c -lselinux -o parent
parent.c: In function 'main':
parent.c:92:9: warning: implicit declaration of function 'setpriority'

   rc =  setpriority(0,pid,10);
         ^
---
 tests/setnice/parent.c |    2 ++
 1 file changed, 2 insertions(+)
tests/setnice/parent.c +2 -0
index d5a2533..6d3c855 100644
@@ -3,6 +3,8 @@
 #include <unistd.h>
 #include <sys/types.h>
 #include <sys/wait.h>
+#include <sys/time.h>
+#include <sys/resource.h>
 #include <signal.h>
 #include <selinux/selinux.h>
 #include <selinux/context.h>
author
#7 lore raw

PATCH v2 5/6 selinux-testsuite: fix compile problems in tests/shm

In reply to Paul Moore

Resolve the following problems:

make[2]: Entering directory '/home/pmoore/sources/selinux-testsuite/selinux_testsuite-upstream/tests/shm'
cc -g -O0 -Wall -D_GNU_SOURCE shmctl.c -o shmctl
shmctl.c: In function 'main':
shmctl.c:11:6: warning: variable 'num' set but not used

  int num = 1;
      ^
cc -g -O0 -Wall -D_GNU_SOURCE    shmat.c   -o shmat
shmat.c: In function 'main':
shmat.c:11:6: warning: variable 'num' set but not used
  int num = 1;
      ^
cc -g -O0 -Wall -D_GNU_SOURCE    shmget.c   -o shmget
shmget.c: In function 'main':
shmget.c:11:6: warning: variable 'num' set but not used
  int num = 1;
      ^
---
 tests/shm/shmat.c  |    6 +-----
 tests/shm/shmctl.c |    6 +-----
 tests/shm/shmget.c |    6 +-----
 3 files changed, 3 insertions(+), 15 deletions(-)
tests/shm/shmat.c +1 -5
index 89ac299..704d676 100644
@@ -8,20 +8,16 @@
 int main(int argc, char **argv)
 {
 	int ch;
-	int num = 1;
 	int key = 0x8888;
 	int id;
 	int error;
 	char *buf;
 
-	while ((ch = getopt(argc, argv, "k:-n:")) != -1) {
+	while ((ch = getopt(argc, argv, "k:")) != -1) {
 		switch (ch) {
 		case 'k':
 			key = atoi(optarg);
 			break;
-		case 'n':
-			num = atoi(optarg);
-			break;
 		}
 	}
 
tests/shm/shmctl.c +1 -5
index 78397b6..d17a804 100644
@@ -8,20 +8,16 @@
 int main(int argc, char **argv)
 {
 	int ch;
-	int num = 1;
 	int key = 0x8888;
 	int id;
 	int error;
 	struct shmid_ds buf;
 
-	while ((ch = getopt(argc, argv, "k:-n:")) != -1) {
+	while ((ch = getopt(argc, argv, "k:")) != -1) {
 		switch (ch) {
 		case 'k':
 			key = atoi(optarg);
 			break;
-		case 'n':
-			num = atoi(optarg);
-			break;
 		}
 	}
 
tests/shm/shmget.c +1 -5
index a04da25..42d6394 100644
@@ -8,18 +8,14 @@
 int main(int argc, char **argv)
 {
 	int ch;
-	int num = 1;
 	int key = 0x8888;
 	int id;
 
-	while ((ch = getopt(argc, argv, "k:-n:")) != -1) {
+	while ((ch = getopt(argc, argv, "k:")) != -1) {
 		switch (ch) {
 		case 'k':
 			key = atoi(optarg);
 			break;
-		case 'n':
-			num = atoi(optarg);
-			break;
 		}
 	}
 
author
#8 lore raw

PATCH v2 6/6 selinux-testsuite: fix compile problems in tests/capable_file

In reply to Paul Moore

Fix the following warnings:

make[2]: Entering directory '/home/pmoore/sources/selinux-testsuite/selinux_testsuite-upstream/tests/capable_file'
cc -g -O0 -Wall -D_GNU_SOURCE test_lease.c -o test_lease
test_lease.c: In function 'main':
test_lease.c:22:3: warning: implicit declaration of function 'open'
fd = open(argv[1], O_RDONLY, 0);
^
test_lease.c:29:3: warning: implicit declaration of function 'fcntl'
rc = fcntl(fd, F_SETLEASE, 0);
^

---
 tests/capable_file/test_lease.c |    9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
tests/capable_file/test_lease.c +5 -4
index 606d75c..e8f29eb 100644
@@ -1,9 +1,10 @@
-#include<stdio.h>
-#include<stdlib.h>
-#include<sys/types.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <sys/stat.h>
 #include <linux/posix_types.h>
-#include<linux/fcntl.h>
 #include <unistd.h>
+#include <fcntl.h>
 
 /*
  * Test the fcntl F_SETLEASE operation on a file whose name is given as 
#2 lore raw

Re: [PATCH 1/6] selinux-testsuite: add _GNU_SOURCE to tests/Makefile

In reply to Paul Moore
Quoted 27 lines · Paul Moore

As suggested by Stephen Smalley. A couple of msgbuf struct definitions had to be removed as they were conflicting with system definitions.

---
 tests/Makefile     |    3 +++
 tests/msg/msgrcv.c |    5 -----
 tests/msg/msgsnd.c |    5 -----
 3 files changed, 3 insertions(+), 10 deletions(-)
tests/Makefile +3 -0
index e9d4646..8100b8f 100644
@@ -1,3 +1,6 @@
+
+export CFLAGS+=-D_GNU_SOURCE
+
 DISTRO=$(shell ./os_detect)
 
 SUBDIRS_COMMON:=domain_trans entrypoint execshare exectrace execute_no_trans fdreceive inherit link mkdir msg open ptrace readlink relabel rename rxdir sem setattr setnice shm sigkill stat sysctl task_create task_setnice task_setscheduler task_getscheduler task_getsid task_getpgid task_setpgid wait file ioctl capable_file capable_net capable_sys
tests/msg/msgrcv.c +0 -0
index b23c801..285dcad 100644

tests/msg/msgrcv.c line 13

Quoted 8 lines
tests/msg/msgrcv.c +0 -5
@@ -6,11 +6,6 @@
 
 #define MSGMAX 1024
 
-struct msgbuf {
-  long mtype;     /* message type, must be > 0 */
-  char mtext[1024];  /* message data */
-};
-

This doesn't seem right. I see that the _GNU_SOURCE definition triggers inclusion of a struct msgbuf definition from sys/msg.h, but that definition doesn't allocate any space for the mtext buffer. So then when we try to msgsnd() or msgrcv() with MSGMAX, we'll be reading/writing memory past the end of the structure?

Maybe you were right the first time, sorry.

Quoted 26 lines
tests/msg/msgrcv.c +0 -0
 int main(int argc, char **argv)
 {
 	int ch;
tests/msg/msgsnd.c +0 -5
index e200aef..7204ab6 100644
@@ -7,11 +7,6 @@
 
 #define MSGMAX 1024
 
-struct msgbuf {
-  long mtype;     /* message type, must be > 0 */
-  char mtext[1024];  /* message data */
-};
-
 int main(int argc, char **argv)
 {
 	int ch;

_______________________________________________
Selinux mailing list
[email protected]
To unsubscribe, send email to [email protected].
To get help, send an email containing "help" to [email protected].

maintainer
#3 lore raw

Re: [PATCH 1/6] selinux-testsuite: add _GNU_SOURCE to tests/Makefile

Quoted 21 lines · Stephen Smalley

tests/msg/msgrcv.c line 13

Quoted 13 lines · Paul Moore
tests/msg/msgrcv.c +0 -5
index b23c801..285dcad 100644
@@ -6,11 +6,6 @@
 
 #define MSGMAX 1024
 
-struct msgbuf {
-  long mtype;     /* message type, must be > 0 */
-  char mtext[1024];  /* message data */
-};
-

This doesn't seem right. I see that the _GNU_SOURCE definition triggers inclusion of a struct msgbuf definition from sys/msg.h, but that definition doesn't allocate any space for the mtext buffer. So then when we try to msgsnd() or msgrcv() with MSGMAX, we'll be reading/writing memory past the end of the structure?

Quoted 1 line

Maybe you were right the first time, sorry.

My mistake, I should have looked closer then I saw the conflict; I was rushing to get some other things sorted and did something stupid, thanks for the sanity check.

I like your idea of defining _GNU_SOURCE at a higher level, I think the right solution here is to just rename our local definition of the msgbuf struct. A new patchset due shortly ...

Signature · 2 lines
paul moore
www.paul-moore.com