Re: [selinux-testsuite][PATCH] use extfs ioctls only when running on ext[234]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 01/23/2013 11:36 PM, Serge E. Hallyn wrote:
Quoting Stephen Smalley (sds@xxxxxxxxxxxxx):
Odd, I have the following diff locally.

Hi,

is there any commit message or author attribution for the diff, so I
can apply it to the testsuite?



>From 7462ad205b27cfb785a3f5ec263ff47771e9da43 Mon Sep 17 00:00:00 2001
From: Stephen Smalley <sds@xxxxxxxxxxxxx>
Date: Wed, 23 Jan 2013 13:38:53 -0500
Subject: [PATCH] Ensure that the ioctl tests do not fail on other filesystem
 types.

Some of the ioctl tests use ioctl commands that are not supported
on all filesystem types.  Make sure that we use the generic command
values in all cases, and that we ignore ENOTTY errors that result
from the commands not being supported for specific filesystems.

Signed-off-by: Stephen Smalley <sds@xxxxxxxxxxxxx>
---
 tests/ioctl/test_ioctl.c   | 22 ++++++++++------------
 tests/ioctl/test_noioctl.c | 27 +++++++++++++--------------
 2 files changed, 23 insertions(+), 26 deletions(-)

diff --git a/tests/ioctl/test_ioctl.c b/tests/ioctl/test_ioctl.c
index 0852f41..a0fe365 100644
--- a/tests/ioctl/test_ioctl.c
+++ b/tests/ioctl/test_ioctl.c
@@ -6,9 +6,7 @@
 #include <sys/stat.h>
 #include <linux/fs.h>
 #include <unistd.h>
-
-#define EXT2_IOC_GETVERSION FS_IOC_GETVERSION
-#define EXT2_IOC_SETVERSION FS_IOC_SETVERSION
+#include <errno.h>
 
 /*
  * Test the ioctl() calls on a file whose name is given as the first
@@ -30,37 +28,37 @@ int main(int argc, char **argv) {
 
   /* This one should hit the FILE__GETATTR or FILE__IOCTL test */
   rc = ioctl(fd, FIGETBSZ, &val);
-  if( rc != 0 ) {
+  if( rc < 0 ) {
     perror("test_ioctl:FIGETBSZ");
     exit(1);
   }
 
   /* This one should hit the FILE__IOCTL test */
   rc = ioctl(fd, FIOCLEX);
-  if( rc != 0 ) {
+  if( rc < 0 ) {
     perror("test_ioctl:FIOCLEX");
     exit(1);
   }
 
   /* This one should hit the FD__USE or FILE__IOCTL test */
   rc = ioctl(fd, FIONBIO, &val);
-  if( rc != 0 ) {
+  if( rc < 0 ) {
     perror("test_ioctl:FIONBIO");
     exit(1);
   }
 
   /* This one should hit the FILE__GETATTR or FILE__READ test */
-  rc = ioctl(fd, EXT2_IOC_GETVERSION, &val);
-  if( rc != 0 ) {
-    perror("test_ioctl:EXT2_IOC_GETVERSION");
+  rc = ioctl(fd, FS_IOC_GETVERSION, &val);
+  if( rc < 0 && errno != ENOTTY) {
+    perror("test_ioctl:FS_IOC_GETVERSION");
     exit(1);
   }
 
   /* This one should hit the FILE__SETATTR or FILE__WRITE test */
   val = 0;
-  rc = ioctl(fd, EXT2_IOC_SETVERSION, &val);
-  if( rc != 0 ) {
-    perror("test_ioctl:EXT2_IOC_SETVERSION");
+  rc = ioctl(fd, FS_IOC_SETVERSION, &val);
+  if( rc < 0 && errno != ENOTTY) {
+    perror("test_ioctl:FS_IOC_SETVERSION");
     exit(1);
   }
 
diff --git a/tests/ioctl/test_noioctl.c b/tests/ioctl/test_noioctl.c
index ef3fac5..f615054 100644
--- a/tests/ioctl/test_noioctl.c
+++ b/tests/ioctl/test_noioctl.c
@@ -11,9 +11,7 @@
 #include <sys/utsname.h>
 #include <unistd.h>
 #include <string.h>
-
-#define EXT2_IOC_GETVERSION FS_IOC_GETVERSION
-#define EXT2_IOC_SETVERSION FS_IOC_SETVERSION
+#include <errno.h>
 
 /*
  * Test the ioctl() calls on a file whose name is given as the first
@@ -25,7 +23,7 @@
 int main(int argc, char **argv) {
   struct utsname uts;
   int fd;
-  int rc, oldkernel = 1;
+  int rc, useaccessmode = 1;
   int val;
 
   if (uname(&uts) < 0) {
@@ -34,7 +32,7 @@ int main(int argc, char **argv) {
   }
 
   if (strverscmp(uts.release, "2.6.27") >= 0 && strverscmp(uts.release, "2.6.39") < 0)
-    oldkernel = 0;
+    useaccessmode = 0;
 
   fd = open(argv[1], O_RDONLY, 0);
  
@@ -59,11 +57,11 @@ int main(int argc, char **argv) {
 
   /*
    * This one depends on kernel version:
-   * New:  Should hit the FILE__IOCTL test and fail.
-   * Old:  Should only check FD__USE and succeed.
+   * >= 2.6.27 and < 2.6.39:  Should hit the FILE__IOCTL test and fail.
+   * < 2.6.27 or >= 2.6.39:  Should only check FD__USE and succeed.
    */
   rc = ioctl(fd, FIONBIO, &val);
-  if( !rc == !oldkernel ) {
+  if( !rc == !useaccessmode ) {
     printf("test_noioctl:FIONBIO");
     exit(1);
   }
@@ -73,17 +71,18 @@ int main(int argc, char **argv) {
    * New:  Should hit the FILE__READ test and succeed.
    * Old:  Should hit the FILE__GETATTR test and fail.
    */
-  rc = ioctl(fd, EXT2_IOC_GETVERSION, &val);
-  if( !rc != !oldkernel ) {
-    perror("test_noioctl:EXT2_IOC_GETVERSION");
+  rc = ioctl(fd, FS_IOC_GETVERSION, &val);
+  if( (useaccessmode && rc == 0) ||
+      (!useaccessmode && rc < 0 && errno != ENOTTY) ) {
+    perror("test_noioctl:FS_IOC_GETVERSION");
     exit(1);
   }
 
-  /* This one should hit the FILE__WRITE test and fail. */
+  /* This one should hit the FILE__WRITE or FILE_SETATTR test and fail. */
   val = 0;
-  rc = ioctl(fd, EXT2_IOC_SETVERSION, &val);
+  rc = ioctl(fd, FS_IOC_SETVERSION, &val);
   if( rc == 0 ) {
-    perror("test_noioctl:EXT2_IOC_SETVERSION");
+    perror("test_noioctl:FS_IOC_SETVERSION");
     exit(1);
   }
 
-- 
1.7.11.7


[Index of Archives]     [Selinux Refpolicy]     [Linux SGX]     [Fedora Users]     [Fedora Desktop]     [Yosemite Photos]     [Yosemite Camping]     [Yosemite Campsites]     [KDE Users]     [Gnome Users]

  Powered by Linux