Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp714253pxf; Thu, 1 Apr 2021 11:34:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyx0djXlUw/VFTTDPxnSeUS3TjOy31M21BBpuqg3RGXzc9UQYjMPpzUmGRLIRG5aZMrwsb0 X-Received: by 2002:a17:906:130c:: with SMTP id w12mr10500744ejb.253.1617302087656; Thu, 01 Apr 2021 11:34:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617302087; cv=none; d=google.com; s=arc-20160816; b=fpSJMsvpva9P8TydHr2hUZei/lLxb2FdvkBOs1rlyqfrq14u8ehog2fovJoKC1LVyE ubO4r4p9Jfxp5RYvmiPHvaD5jCYro/SPTIKiG7ofK5Vew0oTrCFsrk8Qow3mIVFXOoD3 4PDEmNjMZtv9bcWRz8H7gEoooQJlXTg8R+9xgcHjT4zSrH51JACkfKu22DbO5iic4AnM lt8Ajn88FO4u79oGum6iwwveNx2pk/YiXo6nksjCVwy1rXnh1uFRMr1eS3FDi9JOi6Nl IUwH1/Om7C303exc1aQn9rMcqsov86dNxyvxLSGwncpv/tXKIZ1XqWbUXLoFIssn23uL puZw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version; bh=VyiK3ga+MjpNx3ROsvcuMTu8ZgQYqAmDYD3HeeCO9E8=; b=FvWuuGaGbmRcvtYqlW85vHUfQsL/EmFBux8K69VkkVbsf7bMHob9rhvdEC8Tqc+M+t niziuwQOE+cYvWzKO5Nw8mCXoX05Z/y10XeUW4EJwjvK2cvkkblH5HjnVYNPzbd3CkJV VEDOi/tJNwwHY3k5RO5OOFzcDqv4yRFpvREpugACTTky5OCmunkaR1JZNTcRtMJL5rs9 L9wyOO0AxbGBdya2WLfu8f/eEreqop0QtH3+YIujUxmlVQ9B+gzjFj9yr4KYwkENqlYi dsXmZwF3+R0fcpB04mTMo1EOcpHnbyYAxEA/Gm6b6hBVgsL52IldTISp+Eb4OWZ4nATV xUcg== ARC-Authentication-Results: i=1; mx.google.com; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x10si4899035ejs.610.2021.04.01.11.34.23; Thu, 01 Apr 2021 11:34:47 -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; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234563AbhDAScE (ORCPT + 99 others); Thu, 1 Apr 2021 14:32:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37958 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236481AbhDASVf (ORCPT ); Thu, 1 Apr 2021 14:21:35 -0400 Received: from mail-oi1-x232.google.com (mail-oi1-x232.google.com [IPv6:2607:f8b0:4864:20::232]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F3651C02FEAE; Thu, 1 Apr 2021 09:22:55 -0700 (PDT) Received: by mail-oi1-x232.google.com with SMTP id i81so2321000oif.6; Thu, 01 Apr 2021 09:22:55 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=VyiK3ga+MjpNx3ROsvcuMTu8ZgQYqAmDYD3HeeCO9E8=; b=uQClKYOH5szUATdP/CSDB9c3xJsfgRrcieOVUg3c3Z/1xlyidFHkgVzowu2cf/Gufy gw7GzjHFgtYkaVnjdJ7NSnKYYaGFWU1TuI2RnEdgt871nsN/JfrwQVqMlWQ6Fbian0D8 BKrdYI8TXBTXMxGR89FIAmxs/dadVUtc1JhK1QIHKNXVzTfjkiwsku5QTpUapRRmRTnQ C1oAYTIpEJ9Gq1stbqANEuYT6j6xBr1fdr6qqHV8/QuA0X0d5mh/HoaHEHZQQ70z6ZeV OSfODwliHI8cE4w4TQ0QhYZNCFS5N3YmGlWFsY1qZ+ff/5Pr9fUPww9cPZbGNkUBywEA tDLA== X-Gm-Message-State: AOAM530Wour3fi0nIHeIBEDk6cGQ0NLN/8/78WO/C+WLI3FjSQ6+lQkw wzAPBZUeipz2OiJygzWGiT8ikcAiAX/a1pZhMew= X-Received: by 2002:aca:c4c5:: with SMTP id u188mr6587947oif.71.1617294175221; Thu, 01 Apr 2021 09:22:55 -0700 (PDT) MIME-Version: 1.0 References: <20210401122458.12663-1-crecklin@redhat.com> <20210401122458.12663-2-crecklin@redhat.com> In-Reply-To: From: "Rafael J. Wysocki" Date: Thu, 1 Apr 2021 18:22:43 +0200 Message-ID: Subject: Re: [PATCH 1/1] use crc32 instead of md5 for hibernation e820 integrity check To: Chris von Recklinghausen Cc: Ard Biesheuvel , simo@redhat.com, "Rafael J. Wysocki" , Dexuan Cui , Linux PM , Linux Crypto Mailing List , Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org On Thu, Apr 1, 2021 at 3:34 PM Rafael J. Wysocki wrote: > > On Thu, Apr 1, 2021 at 2:25 PM Chris von Recklinghausen > wrote: > > > > 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 | 31 +++++++++++++++++-------------- > > 1 file changed, 17 insertions(+), 14 deletions(-) > > > > diff --git a/arch/x86/power/hibernate.c b/arch/x86/power/hibernate.c > > index cd3914fc9f3d..6a3f4e32e49c 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]; > > }; > > No. > > CRC32 was used here before and it was deemed insufficient. > > Please find a different way to address this issue. Well, I guess I'm going to change my mind on this, so we can go with this patch, but please bump up RESTORE_MAGIC too. > > -#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,7 +134,7 @@ 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 > > @@ -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 > >