From patchwork Mon Aug 19 15:25:43 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jarkko Sakkinen X-Patchwork-Id: 11101287 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6A3E513A0 for ; Mon, 19 Aug 2019 15:26:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5AA0628727 for ; Mon, 19 Aug 2019 15:26:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4F00628862; Mon, 19 Aug 2019 15:26:05 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D25B628727 for ; Mon, 19 Aug 2019 15:26:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726628AbfHSP0E (ORCPT ); Mon, 19 Aug 2019 11:26:04 -0400 Received: from mga14.intel.com ([192.55.52.115]:9895 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726211AbfHSP0E (ORCPT ); Mon, 19 Aug 2019 11:26:04 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 19 Aug 2019 08:26:04 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,405,1559545200"; d="scan'208";a="180393057" Received: from jsakkine-mobl1.tm.intel.com (HELO localhost) ([10.237.50.125]) by orsmga003.jf.intel.com with ESMTP; 19 Aug 2019 08:26:02 -0700 From: Jarkko Sakkinen To: linux-sgx@vger.kernel.org Cc: Jarkko Sakkinen Subject: [PATCH 4/5] x86/sgx: Validate TCS permssions in sgx_validate_secinfo() Date: Mon, 19 Aug 2019 18:25:43 +0300 Message-Id: <20190819152544.7296-5-jarkko.sakkinen@linux.intel.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190819152544.7296-1-jarkko.sakkinen@linux.intel.com> References: <20190819152544.7296-1-jarkko.sakkinen@linux.intel.com> MIME-Version: 1.0 Sender: linux-sgx-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sgx@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The validation of TCS permissions was missing from sgx_validate_secinfo(). This patch adds the validation. Signed-off-by: Jarkko Sakkinen --- arch/x86/kernel/cpu/sgx/driver/ioctl.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/arch/x86/kernel/cpu/sgx/driver/ioctl.c b/arch/x86/kernel/cpu/sgx/driver/ioctl.c index 99b1b9776c3a..2415dcb20a6e 100644 --- a/arch/x86/kernel/cpu/sgx/driver/ioctl.c +++ b/arch/x86/kernel/cpu/sgx/driver/ioctl.c @@ -423,6 +423,12 @@ static int sgx_validate_secinfo(struct sgx_secinfo *secinfo) if ((perm & SGX_SECINFO_W) && !(perm & SGX_SECINFO_R)) return -EINVAL; + /* CPU will silently overwrite the permissions as zero, which means + * that we need to validate it ourselves. + */ + if (page_type == SGX_SECINFO_TCS && perm) + return -EINVAL; + if (secinfo->flags & SGX_SECINFO_RESERVED_MASK) return -EINVAL;