public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
From: Petr Vorel <pvorel@suse.cz>
To: Li Wang <liwang@redhat.com>
Cc: ltp@lists.linux.it
Subject: Re: [LTP] [PATCH] pkey01: Adding test for PKEY_DISABLE_EXECUTE
Date: Thu, 8 Aug 2024 09:44:16 +0200	[thread overview]
Message-ID: <20240808074416.GA306790@pevik> (raw)
In-Reply-To: <20240808065732.64328-1-liwang@redhat.com>

Hi Li,

> The pkey_test function now includes a code snippet to test execute
> permissions, ensuring proper handling of execution rights in memory
> protection keys.

Reviewed-by: Petr Vorel <pvorel@suse.cz>

LGTM, thanks!

Few notes + tiny fixes below (which can be done before merge).

...
> +	pkey = pkey_alloc(0, PKEY_DISABLE_EXECUTE);
> +	if (pkey == -1) {
> +		if (errno == EINVAL) {
> +			tst_res(TINFO, "PKEY_DISABLE_EXECUTE hasn't implement.");
nit: maybe "PKEY_DISABLE_EXECUTE not implemented"

> +			execute_supported = 0;
> +		} else {
> +			tst_brk(TBROK | TERRNO, "pkey_alloc failed");
> +		}
> +	}
> +	pkey_free(pkey);
...

>  static void pkey_test(struct tcase *tc, struct mmap_param *mpa)
>  {
>  	pid_t pid;
>  	char *buffer;
>  	int pkey, status;
>  	int fd = mpa->fd;
> +	size_t (*func)();
> +	size_t func_size = -1;
> +
> +	if (!execute_supported && (tc->access_rights == PKEY_DISABLE_EXECUTE))
> +		tst_brk(TCONF, "skip PKEY_DISABLE_EXECUTE test");
NOTE due to possible tst_brk() it'd be good to keep PKEY_DISABLE_EXECUTE as a
last test. Not sure if it's worth to add a comment (or replace with tst_res()
and return).

...
> +	if (mpa->prot == (PROT_READ | PROT_WRITE | PROT_EXEC)) {
> +		func_size = function_size((void (*)(void))function_size);
> +		memcpy(buffer, (void *)function_size, func_size);
> +	}
> +
>  	pkey = pkey_alloc(tc->flags, tc->access_rights);
>  	if (pkey == -1)
>  		tst_brk(TBROK | TERRNO, "pkey_alloc failed");
> @@ -169,6 +203,10 @@ static void pkey_test(struct tcase *tc, struct mmap_param *mpa)
>  			tst_res(TFAIL | TERRNO,
>  				"Write buffer success, buffer[0] = %d", *buffer);
>  		break;
> +		case PKEY_DISABLE_EXECUTE:
> +			func = (size_t (*)())buffer;;
nit: double ; (please remove the last one).
> +			tst_res(TFAIL | TERRNO, "Excute buffer result = %lu", func(func));
s/%lu/%zi/ (otherwise it introduces warnings on 32bit)
nit: s/Excute/Execute/

> +		break;
>  		}
>  		exit(0);
>  	}
> @@ -193,10 +231,16 @@ static void pkey_test(struct tcase *tc, struct mmap_param *mpa)
>  		tst_res(TPASS, "Write buffer success, buffer[0] = %d", *buffer);
>  	break;
>  	case PROT_READ | PROT_WRITE:
> -	case PROT_READ | PROT_WRITE | PROT_EXEC:
>  		*buffer = 'a';
>  		tst_res(TPASS, "Read & Write buffer success, buffer[0] = %d", *buffer);
>  	break;
> +	case PROT_READ | PROT_WRITE | PROT_EXEC:
> +		func = (size_t (*)())buffer;;
> +		if (func_size == func(func))
> +			tst_res(TPASS, "Execute buffer success, result = %lu", func_size);
s/%lu/%zi/
> +		else
> +			tst_res(TFAIL, "Execute buffer with unexpected result: %lu", func(func));
s/%lu/%zi/

Kind regards,
Petr

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

  reply	other threads:[~2024-08-08  7:44 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-08  6:57 [LTP] [PATCH] pkey01: Adding test for PKEY_DISABLE_EXECUTE Li Wang
2024-08-08  7:44 ` Petr Vorel [this message]
2024-08-08 10:20   ` Li Wang
2024-08-09  0:59     ` Li Wang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240808074416.GA306790@pevik \
    --to=pvorel@suse.cz \
    --cc=liwang@redhat.com \
    --cc=ltp@lists.linux.it \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox