All of lore.kernel.org
 help / color / mirror / Atom feed
From: Borys <borysp@invisiblethingslab.com>
To: Reinette Chatre <reinette.chatre@intel.com>,
	jarkko@kernel.org, dave.hansen@linux.intel.com,
	linux-sgx@vger.kernel.org
Cc: mkow@invisiblethingslab.com
Subject: Re: sgx_validate_offset_length bug
Date: Tue, 4 Oct 2022 15:22:05 +0200	[thread overview]
Message-ID: <703f49cb-7edd-9ac5-4202-0e799e1a98a4@invisiblethingslab.com> (raw)
In-Reply-To: <5b3bc4ce-bdfa-285e-79e0-77a85616e637@intel.com>

Hi,

On 10/3/22 19:58, Reinette Chatre wrote:
> Hi Borys,
>
> On 10/3/2022 10:33 AM, Reinette Chatre wrote:
>> On 10/3/2022 10:19 AM, Borys wrote:
>>> I've stumbled upon "sgx_validate_offset_length" function in
>>> "arch/x86/kernel/cpu/sgx/ioctl.c" (all of this is based on 6.0-rc7
>>> version), which does not entirely do what it claims. "offset" and
>>> "length" parameters are provided by userspace and as such their
>>> addition can overflow, which may result in this function approving
>>> malicious values. Fortunately this does not result in any exploitable
>>> bugs at the moment (or at least I couldn't find any), but this might
>>> change if "sgx_validate_offset_length" is used in a new context or
>>> current usages are changed, so it might be worth fixing anyway.
>>> Simple overflow check `offset + length < offset` should be enough.>
>> Could you please elaborate where you see a possibility for overflow?
>>
>> Together the provided values, offset and length, are already ensured to
>> not exceed the total size of the enclave in the following check:
>>
>> sgx_validate_offset_length() {
>> 	...
>> 	if (offset + length - PAGE_SIZE >= encl->size)
>> 		return -EINVAL;
>> 	...
>> }
> I think I see what you mean now ... if offset and length are
> sufficiently large the above check can still pass but loops
> that have the following pattern may have issues:
>
> for (c = 0 ; c < length; c += PAGE_SIZE) {
>
> 	...
> 	/* do something at <offset> */
>
> }
>
> Are you planning to submit a patch for the check you propose?
>
> Reinette

Sure, I'll try to submit a patch later today.

Borys


  reply	other threads:[~2022-10-04 13:22 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-03 17:19 sgx_validate_offset_length bug Borys
2022-10-03 17:33 ` Reinette Chatre
2022-10-03 17:58   ` Reinette Chatre
2022-10-04 13:22     ` Borys [this message]
2022-10-04 15:21       ` Reinette Chatre
2022-10-04 21:50 ` Jarkko Sakkinen
2022-10-04 23:02   ` Borys
2022-10-04 23:13     ` 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=703f49cb-7edd-9ac5-4202-0e799e1a98a4@invisiblethingslab.com \
    --to=borysp@invisiblethingslab.com \
    --cc=dave.hansen@linux.intel.com \
    --cc=jarkko@kernel.org \
    --cc=linux-sgx@vger.kernel.org \
    --cc=mkow@invisiblethingslab.com \
    --cc=reinette.chatre@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.