From: Greg KH <gregkh@linuxfoundation.org>
To: Dave Hansen <dave.hansen@linux.intel.com>
Cc: linux-kernel@vger.kernel.org, patches@lists.linux.dev,
nathan@kernel.org, jarkko@kernel.org, linux-sgx@vger.kernel.org,
x86@kernel.org
Subject: Re: [PATCH] [v3] x86/sgx: Fix NULL pointer dereference on non-SGX systems
Date: Wed, 5 Jan 2022 11:40:12 +0100 [thread overview]
Message-ID: <YdV1jFHkkLHEOcS5@kroah.com> (raw)
In-Reply-To: <20220104171527.5E8416A8@davehans-spike.ostc.intel.com>
On Tue, Jan 04, 2022 at 09:15:27AM -0800, Dave Hansen wrote:
>
> From: Dave Hansen <dave.hansen@linux.intel.com>
>
> == Problem ==
>
> Nathan Chancellor reported an oops when aceessing the
> 'sgx_total_bytes' sysfs file:
>
> https://lore.kernel.org/all/YbzhBrimHGGpddDM@archlinux-ax161/
>
> The sysfs output code accesses the sgx_numa_nodes[] array
> unconditionally. However, this array is allocated during SGX
> initialization, which only occurs on systems where SGX is
> supported.
>
> If the sysfs file is accessed on systems without SGX support,
> sgx_numa_nodes[] is NULL and an oops occurs.
>
> == Solution ==
>
> To fix this, hide the entire nodeX/x86/ attribute group on
> systems without SGX support using the ->is_visible attribute
> group callback.
>
> Unfortunately, SGX is initialized via a device_initcall() which
> occurs _after_ the ->is_visible() callback. Instead of moving
> SGX initialization earlier, call sysfs_update_group() during
> SGX initialization to update the group visiblility.
>
> This update requires moving the SGX sysfs code earlier in
> sgx/main.c. There are no code changes other than the addition of
> arch_update_sysfs_visibility() and a minor whitespace fixup to
> arch_node_attr_is_visible() which checkpatch caught.
>
> Fixes: 50468e431335 ("x86/sgx: Add an attribute for the amount of SGX memory in a NUMA node")
> Reported-by: Nathan Chancellor <nathan@kernel.org>
> Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com>
> CC: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Cc: Jarkko Sakkinen <jarkko@kernel.org>
> Cc: linux-sgx@vger.kernel.org
> Cc: x86@kernel.org
> ---
>
> b/arch/x86/kernel/cpu/sgx/main.c | 65 ++++++++++++++++++++++++++++-----------
> 1 file changed, 47 insertions(+), 18 deletions(-)
Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
next prev parent reply other threads:[~2022-01-05 10:40 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-04 17:15 [PATCH] [v3] x86/sgx: Fix NULL pointer dereference on non-SGX systems Dave Hansen
2022-01-04 17:15 ` Dave Hansen
2022-01-04 19:19 ` Nathan Chancellor
2022-01-05 10:40 ` Greg KH [this message]
2022-01-07 11:47 ` Jarkko Sakkinen
2022-01-07 11:53 ` Jarkko Sakkinen
2022-01-07 16:48 ` [tip: x86/sgx] " tip-bot2 for Dave Hansen
2022-01-07 16:55 ` tip-bot2 for Dave Hansen
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=YdV1jFHkkLHEOcS5@kroah.com \
--to=gregkh@linuxfoundation.org \
--cc=dave.hansen@linux.intel.com \
--cc=jarkko@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-sgx@vger.kernel.org \
--cc=nathan@kernel.org \
--cc=patches@lists.linux.dev \
--cc=x86@kernel.org \
/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.