Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp680877pxf; Thu, 1 Apr 2021 10:46:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxeEOxYl5VBTLm3rcMX1oQRmvVel9aMygU9MEQJ3XIYpSgMVCu/0H3pbBxk0B1PTPXsKqro X-Received: by 2002:aa7:d7da:: with SMTP id e26mr11316561eds.269.1617299186026; Thu, 01 Apr 2021 10:46:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617299186; cv=none; d=google.com; s=arc-20160816; b=KT6uUps81ZfS0sYB8wEV8k5z+LSXxR4G1ZDEgdkAo/c3DViewygCJ9bn6fwlf5mODI 7tWMy3uLsAH9uh8uWDIkZhOWsVSNqqbYeS1UpZr25c8pVPS3JZAGkdLkIQsB9uVMfDMc tzmN0ncHgFPDon+76geKWkPYOV/AqdGjnKiJ1UBJIhgRfe0vND6UvkwS7Fr1tTD6QWbP Gr7kK3IFBIM6IYL+GjSYlVBqbdbNcqQCDywPUHZkoMo8psT36V5019jB9EgZQyxvza0k piI14Em733ksLQnFv9+1zunakQCtZGbEVyi/QUtJSFsV79nAHOjoIrCD9o7aUJRhF+43 hJQw== 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:dkim-signature; bh=KAchGenRRvJse0HSPDEqkYgJbaInrhnLlWHg66eQJOM=; b=fwGJY4rUv8e/aYHGqR2vwD2qABox4bifnxNA/w+/SKqloxA070XXkhJ78yFwDPgS06 uTc9ofdNDeFo9Bpe/9u8hAg4LOA/xST/LGYTW+VJtm5aMbj5NSvQir+ScH0FOx6r9ymX 4C/2G4YmB9QYopJTEb3si1dvCkwTQhLtgop3iuQDNLJ6TjzXouTONAry8CVT4jez+BmK FaqBlRtLM4MbIvdLiiDRPCMTNCAbPVa1ug4B3nxaua+737pn5i4rarDXjBb1AfhMzvJb AP7Kh1HzBjNkT99Ca4l4iduaaMHKQ8DjObMquXAmEsyupKS9xtR6ZEhPmPmu/ArF8a0I ok/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=kkynDdy5; 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 a19si4455526ejt.403.2021.04.01.10.46.01; Thu, 01 Apr 2021 10:46:26 -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=@kernel.org header.s=k20201202 header.b=kkynDdy5; 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 S234547AbhDARmN (ORCPT + 99 others); Thu, 1 Apr 2021 13:42:13 -0400 Received: from mail.kernel.org ([198.145.29.99]:40712 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234604AbhDARiY (ORCPT ); Thu, 1 Apr 2021 13:38:24 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 3884361165; Thu, 1 Apr 2021 13:59:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1617285558; bh=47oSCm6wz3F6fLZ1XMnrJFATTDJ7ZR3krNCKwoLXG90=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=kkynDdy5gPI90SI9CBruiqdlhvmOeggzosyGIgvY7cFTy+Jl7z3KYBxBGAl16CKuA QCiHmd+K369thuxMKTMzgFj3JDW3sWv75nYehUqJrDiTs1nEUQCd1TeYnpJFy7w69r dn4rllk1YzShI8aDlArZAlaisImgsvAB8KGO4t+Y5rJ6xAX72AZHyX0qAggqVWMQFM Ecj1letEH580OkN8tuaGcxBh7wPpks5UJJmOS24SpgumOfQMGLi9v3H4U8Op1v1wSw npXwGS3KJWoVECSJMx6DCQLVlGX1zxJpeOnT1qxH5vxUTKEkudUkXkrWfQVnn60ZCL HueKhXxmTX3ug== Received: by mail-ot1-f48.google.com with SMTP id v24-20020a9d69d80000b02901b9aec33371so2217957oto.2; Thu, 01 Apr 2021 06:59:18 -0700 (PDT) X-Gm-Message-State: AOAM532Mhqikat5ngfBSPmpeVHV0wiyNh8dMz3DBc52c+X5IHfP5DrUr chIojgWRo4dJYcrTmbiYLosOU2OXm0yusZZfwew= X-Received: by 2002:a9d:12cb:: with SMTP id g69mr6823869otg.77.1617285557578; Thu, 01 Apr 2021 06:59:17 -0700 (PDT) MIME-Version: 1.0 References: <20210401122458.12663-1-crecklin@redhat.com> <20210401122458.12663-2-crecklin@redhat.com> In-Reply-To: From: Ard Biesheuvel Date: Thu, 1 Apr 2021 15:59:05 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 1/1] use crc32 instead of md5 for hibernation e820 integrity check To: "Rafael J. Wysocki" Cc: Chris von Recklinghausen , Simo Sorce , 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, 1 Apr 2021 at 15:34, 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. > Why? The git commit log does not have an explanation of this. > Please find a different way to address this issue. > > > -#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 > >