linux-sgx.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Matthew Wilcox <willy@infradead.org>
To: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Cc: linux-sgx@vger.kernel.org,
	Haitao Huang <haitao.huang@linux.intel.com>,
	Sean Christopherson <sean.j.christopherson@intel.com>,
	Jethro Beekman <jethro@fortanix.com>,
	Dave Hansen <dave.hansen@linux.intel.com>
Subject: Re: [PATCH v2] Fix the issue further discussed in:
Date: Mon, 5 Oct 2020 12:11:39 +0100	[thread overview]
Message-ID: <20201005111139.GK20115@casper.infradead.org> (raw)
In-Reply-To: <20201005031759.143544-1-jarkko.sakkinen@linux.intel.com>

On Mon, Oct 05, 2020 at 06:17:59AM +0300, Jarkko Sakkinen wrote:
> @@ -317,10 +318,31 @@ int sgx_encl_may_map(struct sgx_encl *encl, unsigned long start,
>  	if (current->personality & READ_IMPLIES_EXEC)
>  		return -EACCES;
>  
> -	xas_for_each(&xas, page, idx_end)
> +	/*
> +	 * No need to hold encl->lock:
> +	 * 1. None of the page->* get written.
> +	 * 2. page->vm_max_prot_bits is set in sgx_encl_page_alloc(). This
> +	 *    is before calling xa_insert(). After that it is never modified.
> +	 */
> +	xas_lock(&xas);
> +	xas_for_each(&xas, page, idx_end) {
> +		if (++count % XA_CHECK_SCHED)
> +			continue;

This really doesn't do what you think it does.

	int ret = 0;
	int count = 0;

	xas_lock(&xas);
	while (xas.index < idx_end) {
		struct sgx_page *page = xas_next(&xas);

		if (!page || (~page->vm_max_prot_bits & vm_prot_bits)) {
			ret = -EACCESS;
			break;
		}

		if (++count % XA_CHECK_SCHED)
			continue;
		xas_pause(&xas);
		xas_unlock(&xas);
		cond_resched();
		xas_lock(&xas);
	}
	xas_unlock(&xas);

	return ret;

  reply	other threads:[~2020-10-05 11:11 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-05  3:17 [PATCH v2] Fix the issue further discussed in: Jarkko Sakkinen
2020-10-05 11:11 ` Matthew Wilcox [this message]
2020-10-05 11:48   ` Jarkko Sakkinen
2020-10-05 11:48     ` Jarkko Sakkinen

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=20201005111139.GK20115@casper.infradead.org \
    --to=willy@infradead.org \
    --cc=dave.hansen@linux.intel.com \
    --cc=haitao.huang@linux.intel.com \
    --cc=jarkko.sakkinen@linux.intel.com \
    --cc=jethro@fortanix.com \
    --cc=linux-sgx@vger.kernel.org \
    --cc=sean.j.christopherson@intel.com \
    /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;
as well as URLs for NNTP newsgroup(s).