Skip to contentSkip to conversation

selftests/sgx: remove checks for file execute permissions

PATCH In review Dave Hansen 5 participants 5 messages Jun 21, 2021 – Jun 24, 2021

Subsystems (3)
lore
Share & tools
lore

Dave Hansen

author reviewer
#0 lore raw

PATCH 1/1 selftests/sgx: remove checks for file execute permissions

The SGX selftests can fail for a bunch of non-obvious reasons like 'noexec' permissions on /dev (which is the default *EVERYWHERE* it seems).

A new test mistakenly also looked for +x permission on the /dev/sgx_enclave. File execute permissions really only apply to the ability of execve() to work on a file, *NOT* on the ability for an application to map the file with PROT_EXEC. SGX needs to mmap(PROT_EXEC), but doesn't need to execve() the device file.

Remove the check.

Fixes 4284f7acb78b ("selftests/sgx: Improve error detection and messages")
Cc Jarkko Sakkinen <[email protected]>
Cc Reinette Chatre <[email protected]>
Cc Dave Hansen <[email protected]>
Cc Shuah Khan <[email protected]>

---

 b/tools/testing/selftests/sgx/load.c |   16 +++-------------
 1 file changed, 3 insertions(+), 13 deletions(-)
tools/testing/selftests/sgx/load.c renamed from tools/testing/selftests/sgx/load.c~sgx-no-file-exec +3 -13
diff -puN tools/testing/selftests/sgx/load.c~sgx-no-file-exec tools/testing/selftests/sgx/load.c
@@ -150,16 +150,6 @@ bool encl_load(const char *path, struct
 		goto err;
 	}
 
-	/*
-	 * This just checks if the /dev file has these permission
-	 * bits set.  It does not check that the current user is
-	 * the owner or in the owning group.
-	 */
-	if (!(sb.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH))) {
-		fprintf(stderr, "no execute permissions on device file %s\n", device_path);
-		goto err;
-	}
-
 	ptr = mmap(NULL, PAGE_SIZE, PROT_READ, MAP_SHARED, fd, 0);
 	if (ptr == (void *)-1) {
 		perror("mmap for read");
@@ -169,13 +159,13 @@ bool encl_load(const char *path, struct
 
 #define ERR_MSG \
 "mmap() succeeded for PROT_READ, but failed for PROT_EXEC.\n" \
-" Check that current user has execute permissions on %s and \n" \
-" that /dev does not have noexec set: mount | grep \"/dev .*noexec\"\n" \
+" Check that /dev does not have noexec set:\n" \
+" \tmount | grep \"/dev .*noexec\"\n" \
 " If so, remount it executable: mount -o remount,exec /dev\n\n"
 
 	ptr = mmap(NULL, PAGE_SIZE, PROT_EXEC, MAP_SHARED, fd, 0);
 	if (ptr == (void *)-1) {
-		fprintf(stderr, ERR_MSG, device_path);
+		fprintf(stderr, ERR_MSG);
 		goto err;
 	}
 	munmap(ptr, PAGE_SIZE);

_

Tested-by on v1 1/1
#1 lore raw

Hi Dave,

Quoted 13 lines · Dave Hansen

The SGX selftests can fail for a bunch of non-obvious reasons like 'noexec' permissions on /dev (which is the default *EVERYWHERE* it seems).

A new test mistakenly also looked for +x permission on the /dev/sgx_enclave. File execute permissions really only apply to the ability of execve() to work on a file, *NOT* on the ability for an application to map the file with PROT_EXEC. SGX needs to mmap(PROT_EXEC), but doesn't need to execve() the device file.

Remove the check.

Quoted 10 lines
Fixes 4284f7acb78b ("selftests/sgx: Improve error detection and messages")
Cc Jarkko Sakkinen <[email protected]>
Cc Reinette Chatre <[email protected]>
Cc Dave Hansen <[email protected]>
Cc Shuah Khan <[email protected]>

Thank you very much for fixing this. With this applied the SGX tests are able to run again on my system.

I think it is missing a "Signed-off-by".

Reinette

#2 lore raw
Quoted 7 lines · Reinette Chatre

Thank you very much for fixing this. With this applied the SGX tests are able to run again on my system.

I think it is missing a "Signed-off-by".

Right you are. I think I've done this twice in a row for one-off patches. Sheesh.

If anyone wants a resend with this included, please let me know.

maintainer
#3 lore raw
Quoted 7 lines · Dave Hansen
Quoted 6 lines · Reinette Chatre

Thank you very much for fixing this. With this applied the SGX tests are able to run again on my system.

Quoted 9 lines
Quoted 1 line

I think it is missing a "Signed-off-by".

Right you are. I think I've done this twice in a row for one-off patches. Sheesh.

If anyone wants a resend with this included, please let me know.

Thanks to b4/patchwork - no need to resend. I have the signed-off-by in the downloaded patch.

Thank you all. Now applied to linux-kselftest next for 5.14-rc1

-- Shuah

maintainer Reviewed-by on v1 1/1
#4 lore raw
In reply to Dave Hansen
Quoted 65 lines · Dave Hansen

The SGX selftests can fail for a bunch of non-obvious reasons like 'noexec' permissions on /dev (which is the default *EVERYWHERE* it seems).

A new test mistakenly also looked for +x permission on the /dev/sgx_enclave. File execute permissions really only apply to the ability of execve() to work on a file, *NOT* on the ability for an application to map the file with PROT_EXEC. SGX needs to mmap(PROT_EXEC), but doesn't need to execve() the device file.

Remove the check.

Fixes 4284f7acb78b ("selftests/sgx: Improve error detection and messages")
Cc Jarkko Sakkinen <[email protected]>
Cc Reinette Chatre <[email protected]>
Cc Dave Hansen <[email protected]>
Cc Shuah Khan <[email protected]>

---

 b/tools/testing/selftests/sgx/load.c |   16 +++-------------
 1 file changed, 3 insertions(+), 13 deletions(-)

diff -puN tools/testing/selftests/sgx/load.c~sgx-no-file-exec tools/testing/selftests/sgx/load.c

tools/testing/selftests/sgx/load.c renamed from tools/testing/selftests/sgx/load.c~sgx-no-file-exec +3 -13
@@ -150,16 +150,6 @@ bool encl_load(const char *path, struct
 		goto err;
 	}
 
-	/*
-	 * This just checks if the /dev file has these permission
-	 * bits set.  It does not check that the current user is
-	 * the owner or in the owning group.
-	 */
-	if (!(sb.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH))) {
-		fprintf(stderr, "no execute permissions on device file %s\n", device_path);
-		goto err;
-	}
-
 	ptr = mmap(NULL, PAGE_SIZE, PROT_READ, MAP_SHARED, fd, 0);
 	if (ptr == (void *)-1) {
 		perror("mmap for read");
@@ -169,13 +159,13 @@ bool encl_load(const char *path, struct
 
 #define ERR_MSG \
 "mmap() succeeded for PROT_READ, but failed for PROT_EXEC.\n" \
-" Check that current user has execute permissions on %s and \n" \
-" that /dev does not have noexec set: mount | grep \"/dev .*noexec\"\n" \
+" Check that /dev does not have noexec set:\n" \
+" \tmount | grep \"/dev .*noexec\"\n" \
 " If so, remount it executable: mount -o remount,exec /dev\n\n"
 
 	ptr = mmap(NULL, PAGE_SIZE, PROT_EXEC, MAP_SHARED, fd, 0);
 	if (ptr == (void *)-1) {
-		fprintf(stderr, ERR_MSG, device_path);
+		fprintf(stderr, ERR_MSG);
 		goto err;
 	}
 	munmap(ptr, PAGE_SIZE);
Quoted 2 lines

_

/Jarkko