Re: [tip: x86/sgx] selftests/sgx: Improve error detection and messages

From: Jarkko Sakkinen
Date: Fri Mar 19 2021 - 11:21:09 EST


On Fri, Mar 19, 2021 at 03:58:07PM +0100, Borislav Petkov wrote:
> On Fri, Mar 19, 2021 at 11:38:44AM -0000, tip-bot2 for Dave Hansen wrote:
> > tools/testing/selftests/sgx/load.c | 66 ++++++++++++++++++++++-------
> > tools/testing/selftests/sgx/main.c | 2 +-
> > 2 files changed, 53 insertions(+), 15 deletions(-)
>
> Anything against some more tweaks ontop?

Nope :-)

> ---
> diff --git a/tools/testing/selftests/sgx/load.c b/tools/testing/selftests/sgx/load.c
> index 4c149f46d798..f441ac34b4d4 100644
> --- a/tools/testing/selftests/sgx/load.c
> +++ b/tools/testing/selftests/sgx/load.c
> @@ -156,7 +156,7 @@ bool encl_load(const char *path, struct encl *encl)
> * 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\n");
> + fprintf(stderr, "no execute permissions on device file %s\n", device_path);
> goto err;
> }
>
> @@ -167,12 +167,15 @@ bool encl_load(const char *path, struct encl *encl)
> }
> munmap(ptr, PAGE_SIZE);
>
> +#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" \
> +" 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) {
> - perror("ERROR: mmap for exec");
> - fprintf(stderr, "mmap() succeeded for PROT_READ, but failed for PROT_EXEC\n");
> - fprintf(stderr, "check that user has execute permissions on %s and\n", device_path);
> - fprintf(stderr, "that /dev does not have noexec set: 'mount | grep \"/dev .*noexec\"'\n");
> + fprintf(stderr, ERR_MSG, device_path);
> goto err;
> }
> munmap(ptr, PAGE_SIZE);
>
>
> --
> Regards/Gruss,
> Boris.
>
> https://people.kernel.org/tglx/notes-about-netiquette
>

Printing device path is a good sanity thing to have, thanks.

/Jarkko