Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp687712pxf; Thu, 1 Apr 2021 10:56:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyCjkCGHRVyIdvex1kbtD+g9Rc5/vNUnkfDwV8E8m1TAG9ONd8wq5c6cfmmeZidos7VCX16 X-Received: by 2002:aa7:cd54:: with SMTP id v20mr11405438edw.80.1617299794733; Thu, 01 Apr 2021 10:56:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617299794; cv=none; d=google.com; s=arc-20160816; b=SVnBOaGV/F7Yjdnl778tVXekfqx/Ok1j4+mjaCoGxG0Q60gD1KqwjuITMwD7eJ5T+y dZiCXXml+eSbyhRzJ1ntd6Dd3GkOWhA2JHTIF10hdoW8jx3Zo7buGkd8d0QEeUziLN6b IgwL8IZVxnRt/XJ7N23IAfxKaAjW2G+AgL/aq5O5xRLBQba59cAhajZih3BK3JuQy+gd DBhbH6XxMkrNaPTVI7EQsIC5AB1O4BnXFsLxU86TqAmrNCNotFKbYhSA46fQnj/5Jx48 gh23ef3TqQkxLy9pphb1synJsvbIwt14JUJPMs8b/DN/h6qjLjyvPdGwhu6a/LjOXJsw obgQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :to:from:dkim-signature; bh=L6weqK0EgOdnKM6eI+LLl6Quz9MwIP8tW17Rjuf/Yjc=; b=UksKgri/CYQ7LtceIEMZ6HnWaLy6Q1nP4sx9+CWDJUjOIo5wMQQ8RAXu7e59h13mKT jgUI4uUDfydpy3RxKj+X9XeujuOb08fL0Q6fdwFFRx5VlrF0D1mO5S3NzRwKHhKFi4FY v2skdUjJvsZTfdqawgm02oat/xn1z/vFLL2B0R/k4eYg8FeyjXo6RsmPKrJpRP87eyQF /fBvo6ahAseLD8HLgBa+dcLbELU3gt2xbLM0ng8nfKQFOrr0DBgt1gbfOHdK28JbNLAh mYc6GxdXwtiwTyTI+lbyJUgOJhod9I5enCbZizB8shy1A3S8gCg55LKH0AKUkpqc+k4s qPUw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=djhcnNCR; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k3si5407886edh.184.2021.04.01.10.56.10; Thu, 01 Apr 2021 10:56:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=djhcnNCR; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234184AbhDARw5 (ORCPT + 99 others); Thu, 1 Apr 2021 13:52:57 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:53467 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234982AbhDARoH (ORCPT ); Thu, 1 Apr 2021 13:44:07 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1617299047; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:in-reply-to:in-reply-to:references:references; bh=L6weqK0EgOdnKM6eI+LLl6Quz9MwIP8tW17Rjuf/Yjc=; b=djhcnNCRoIJZMjERQMcJ+22XLqlSl3qSMKYjxUpj9kewUrvJOS1y+xaXg+PGvB6TMQ8XII e5Zweh5zdXkSb9522W/YUi9ZutOysQQ+I48ffygK1ohN3BGRimksIEP7drT/Njpgz+yyDX pN7klPqal+biICN1TX9ufMxjv4GMHG4= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-220-pPFPgX6bPdCeTjGQaFVDyw-1; Thu, 01 Apr 2021 12:43:17 -0400 X-MC-Unique: pPFPgX6bPdCeTjGQaFVDyw-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 093FF8015B6; Thu, 1 Apr 2021 16:42:52 +0000 (UTC) Received: from crecklin.bos.com (unknown [10.22.8.39]) by smtp.corp.redhat.com (Postfix) with ESMTP id AC1C35D9DE; Thu, 1 Apr 2021 16:42:49 +0000 (UTC) From: Chris von Recklinghausen To: ardb@kernel.org, simo@redhat.com, rafael@kernel.org, decui@microsoft.com, linux-pm@vger.kernel.org, linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 1/1] use crc32 instead of md5 for hibernation e820 integrity check Date: Thu, 1 Apr 2021 12:41:45 -0400 Message-Id: <20210401164145.8051-2-crecklin@redhat.com> In-Reply-To: <20210401164145.8051-1-crecklin@redhat.com> References: <20210401164145.8051-1-crecklin@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Suspend fails on a system in fips mode because md5 is used for the e820 integrity check and is not available. Use crc32 instead. Fixes: 62a03defeabd ("PM / hibernate: Verify the consistent of e820 memory map by md5 digest") Signed-off-by: Chris von Recklinghausen --- arch/x86/power/hibernate.c | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/arch/x86/power/hibernate.c b/arch/x86/power/hibernate.c index cd3914fc9f3d..b56172553275 100644 --- a/arch/x86/power/hibernate.c +++ b/arch/x86/power/hibernate.c @@ -55,31 +55,31 @@ int pfn_is_nosave(unsigned long pfn) } -#define MD5_DIGEST_SIZE 16 +#define CRC32_DIGEST_SIZE 16 struct restore_data_record { unsigned long jump_address; unsigned long jump_address_phys; unsigned long cr3; unsigned long magic; - u8 e820_digest[MD5_DIGEST_SIZE]; + u8 e820_digest[CRC32_DIGEST_SIZE]; }; -#if IS_BUILTIN(CONFIG_CRYPTO_MD5) +#if IS_BUILTIN(CONFIG_CRYPTO_CRC32) /** - * get_e820_md5 - calculate md5 according to given e820 table + * get_e820_crc32 - calculate crc32 according to given e820 table * * @table: the e820 table to be calculated - * @buf: the md5 result to be stored to + * @buf: the crc32 result to be stored to */ -static int get_e820_md5(struct e820_table *table, void *buf) +static int get_e820_crc32(struct e820_table *table, void *buf) { struct crypto_shash *tfm; struct shash_desc *desc; int size; int ret = 0; - tfm = crypto_alloc_shash("md5", 0, 0); + tfm = crypto_alloc_shash("crc32", 0, 0); if (IS_ERR(tfm)) return -ENOMEM; @@ -107,24 +107,24 @@ static int get_e820_md5(struct e820_table *table, void *buf) static int hibernation_e820_save(void *buf) { - return get_e820_md5(e820_table_firmware, buf); + return get_e820_crc32(e820_table_firmware, buf); } static bool hibernation_e820_mismatch(void *buf) { int ret; - u8 result[MD5_DIGEST_SIZE]; + u8 result[CRC32_DIGEST_SIZE]; - memset(result, 0, MD5_DIGEST_SIZE); + memset(result, 0, CRC32_DIGEST_SIZE); /* If there is no digest in suspend kernel, let it go. */ - if (!memcmp(result, buf, MD5_DIGEST_SIZE)) + if (!memcmp(result, buf, CRC32_DIGEST_SIZE)) return false; - ret = get_e820_md5(e820_table_firmware, result); + ret = get_e820_crc32(e820_table_firmware, result); if (ret) return true; - return memcmp(result, buf, MD5_DIGEST_SIZE) ? true : false; + return memcmp(result, buf, CRC32_DIGEST_SIZE) ? true : false; } #else static int hibernation_e820_save(void *buf) @@ -134,15 +134,15 @@ static int hibernation_e820_save(void *buf) static bool hibernation_e820_mismatch(void *buf) { - /* If md5 is not builtin for restore kernel, let it go. */ + /* If crc32 is not builtin for restore kernel, let it go. */ return false; } #endif #ifdef CONFIG_X86_64 -#define RESTORE_MAGIC 0x23456789ABCDEF01UL +#define RESTORE_MAGIC 0x23456789ABCDEF02UL #else -#define RESTORE_MAGIC 0x12345678UL +#define RESTORE_MAGIC 0x12345679UL #endif /** @@ -160,6 +160,9 @@ int arch_hibernation_header_save(void *addr, unsigned int max_size) rdr->jump_address = (unsigned long)restore_registers; rdr->jump_address_phys = __pa_symbol(restore_registers); + /* crc32 digest size is 4 but digest buffer size is 16 so zero it all */ + memset(rdr->e820_digest, 0, CRC32_DIGEST_SIZE); + /* * The restore code fixes up CR3 and CR4 in the following sequence: * -- 2.18.1