Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp197572imj; Thu, 14 Feb 2019 18:29:14 -0800 (PST) X-Google-Smtp-Source: AHgI3IZSifhu3OW6wkiQxokof7/w2+fTN6urHIOwy6QRd2G1agGDL9evmw+Nph0Ip279hij4MGR2 X-Received: by 2002:a62:60c5:: with SMTP id u188mr7435516pfb.4.1550197754896; Thu, 14 Feb 2019 18:29:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550197754; cv=none; d=google.com; s=arc-20160816; b=D8nrxsPNFpeTKs1dv2UsxaiyJYNms2JuHy/lyATY8hs2wgN9bHPsAJdYactUSPdw3T 5EVM2iSKdqp3/ugzc3JzG1AYNYsLWUf83//ULGp7gJC1WVV2GyziHI6pv8WsgsyrGHpp CM7i7mG1iMVR9iUPosKpj1YWjz6QgXOjCxxeo+lK0ZBF7CZF86cXpcDO8zCB0QBzgyzp 1+3Te1LdiUCJCkFVMPXqhPRVuIckYI9Kk6B4FFEzTSvydZxUdf/LdORmYBjKrwmUVu4r ONHtBCt/DvGUhuOClkvhB40WdN6kntLdvuIR/sbwV4x8SnIifEgqkBseCZeZbJamExiR bt9Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=+XLEjjzdjCgAwtwHQ676zKJroqVtqk/+91UBG0D75wQ=; b=Qw2jQh7rrX0G0DxZNVD+BmJwOleOEGg+ugCNTaQX2rI8DSS2XJp6UHc6eaVgPoZIcg fCWeAN9eEbEuCyOHfCgtOG5t8+XSD0YW/gcLK/o8bvSBN/756F1UEF77JCS09Nys16et 5IIm4O4kaNst5bbWrkIBv+nxg5+DP136TIyxstR66EzcSvh1bsHx5fJXCCrC3PJeu9HN ze85kEK9hDQP9A5WMQxt/hTXQHV2NQLL1YmtKxugE1v+HZjn/jdYxZY+SmPuZjzTd5QC lsYpYMqpL8i5nbulVt1OdsiNxRMZBPpD/ckfYTU1FGL1ALkPe5AZ3JKrGv0ec3sj9CiQ 56jg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=KYrEcvIP; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p14si3995530pfi.12.2019.02.14.18.28.59; Thu, 14 Feb 2019 18:29:14 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=KYrEcvIP; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388464AbfBOCJh (ORCPT + 99 others); Thu, 14 Feb 2019 21:09:37 -0500 Received: from mail.kernel.org ([198.145.29.99]:49724 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388137AbfBOCJf (ORCPT ); Thu, 14 Feb 2019 21:09:35 -0500 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 3BBDE2229F; Fri, 15 Feb 2019 02:09:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1550196574; bh=4er9CuufuaZ0Cmw1TnMlo0juDv8NNMxB2L8h3uXmaDs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KYrEcvIP3yuZkfj53Gjw+ImLmJpBgvKzVeHK3LH7I/pvFMTg9W/+9nppA19lXIofD 64fgUII9NUQXYRHb2Qkm870vCjh2DWuTRj76YLPra6dohOiuX49kCebKjnqyTRc8u8 oOo9FmekzofDRfC/iptIfEfTUy1O1dBGAztXPCUk= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Peng Hao , Thomas Gleixner , "Kirill A . Shutemov" , Tom Lendacky , dave.hansen@linux.intel.com, peterz@infradead.org, luto@kernel.org, Sasha Levin Subject: [PATCH AUTOSEL 4.20 21/77] x86/mm/mem_encrypt: Fix erroneous sizeof() Date: Thu, 14 Feb 2019 21:07:59 -0500 Message-Id: <20190215020855.176727-21-sashal@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190215020855.176727-1-sashal@kernel.org> References: <20190215020855.176727-1-sashal@kernel.org> MIME-Version: 1.0 X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Peng Hao [ Upstream commit bf7d28c53453ea904584960de55e33e03b9d93b1 ] Using sizeof(pointer) for determining the size of a memset() only works when the size of the pointer and the size of type to which it points are the same. For pte_t this is only true for 64bit and 32bit-NONPAE. On 32bit PAE systems this is wrong as the pointer size is 4 byte but the PTE entry is 8 bytes. It's actually not a real world issue as this code depends on 64bit, but it's wrong nevertheless. Use sizeof(*p) for correctness sake. Fixes: aad983913d77 ("x86/mm/encrypt: Simplify sme_populate_pgd() and sme_populate_pgd_large()") Signed-off-by: Peng Hao Signed-off-by: Thomas Gleixner Cc: Kirill A. Shutemov Cc: Tom Lendacky Cc: dave.hansen@linux.intel.com Cc: peterz@infradead.org Cc: luto@kernel.org Link: https://lkml.kernel.org/r/1546065252-97996-1-git-send-email-peng.hao2@zte.com.cn Signed-off-by: Sasha Levin --- arch/x86/mm/mem_encrypt_identity.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/x86/mm/mem_encrypt_identity.c b/arch/x86/mm/mem_encrypt_identity.c index a19ef1a416ff..4aa9b1480866 100644 --- a/arch/x86/mm/mem_encrypt_identity.c +++ b/arch/x86/mm/mem_encrypt_identity.c @@ -158,8 +158,8 @@ static void __init sme_populate_pgd(struct sme_populate_pgd_data *ppd) pmd = pmd_offset(pud, ppd->vaddr); if (pmd_none(*pmd)) { pte = ppd->pgtable_area; - memset(pte, 0, sizeof(pte) * PTRS_PER_PTE); - ppd->pgtable_area += sizeof(pte) * PTRS_PER_PTE; + memset(pte, 0, sizeof(*pte) * PTRS_PER_PTE); + ppd->pgtable_area += sizeof(*pte) * PTRS_PER_PTE; set_pmd(pmd, __pmd(PMD_FLAGS | __pa(pte))); } -- 2.19.1