[FFE] FIPS compatibility patches

Bug #2056593 reported by Tobias Heider
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
openssl (Ubuntu)
Fix Released
Undecided
Unassigned

Bug Description

We have an open MR with a handful of FIPS compatibilty changes we wore hoping
to get into 24.04. The main purpose of the changes is to detect whether the
kernel is running in FIPS mode and adjust the behavior of the library
accordingly by loading the correct provider backend and using defaults that
are FIPS compliant (no md5, DES etc) instead trying to use non-compliant code
paths and crashing.

The proposed patches were taken from the OpenSSL version shipped in the FIPS
archive at esm.ubuntu.com for 22.04. Having them in the regular archive will
reduce the maintenance work significantly. None of the changes should have any
impact on running OpenSSL in regular (non-fips) mode.

Below is a detailed list of the changes:

- d/p/fips/crypto-Add-kernel-FIPS-mode-detection.patch:
  This adds a new internal API to determine whether the kernel has been booted
  in FIPS mode. This can be overridden with the OPENSSL_FORCE_FIPS_MODE
  environment variable. OPENSSL_FIPS_MODE_SWITCH_PATH can be used to specify an
  alternative path for the fips_enabled file and is used in tests.
  The FIPS_MODULE switch can be used to enable build of the the FIPS provider
  module specific parts which are not needed in the OpenSSL library itself.

- d/p/fips/crypto-Automatically-use-the-FIPS-provider-when-the-kerne.patch:
  This automatically configures all library contexts to use the FIPS provider when
  the kernel is booted in FIPS mode by:
  - Setting "fips=yes" as the default property for algorithm fetches
  - Loading and activating the FIPS provider as the fallback provider.

  If applications load providers via a configuration either because the default
  configuration is modified or they override the default configuration, this
  disables loading of the fallback providers. In this case, the configuration
  must load the FIPS provider when FIPS mode is enabled, else algorithm fetches
  will fail

  Applications can choose to use non-FIPS approved algorithms by specifying the
  "-fips" or "fips=no" property for algorithm fetches and loading the default
  provider.

- d/p/fips/apps-speed-Omit-unavailable-algorithms-in-FIPS-mode.patch:
  Omit unavailable algorithms in FIPS mode

- d/p/fips/apps-pass-propquery-arg-to-the-libctx-DRBG-fetches.patch
  The -propquery argument might be used to define a preference for which provider
  an algorithm is fetched from. Set the query properties for the library context
  DRBG fetches as well so that they are fetched with the same properties.

- d/p/fips/test-Ensure-encoding-runs-with-the-correct-context-during.patch:
  This test uses 2 library contexts - one context for creating initial test keys,
  and then another context (or the default context) for running tests. There is an
  issue that during the encoding tests, the OSSL_ENCODER_CTX is created from the
  created EVP_PKEYs, which are associated with the library context used to create
  the keys. This means that encoding tests run with the wrong library context,
  which always uses the default provider.

These changes are now included in a larger MR with other changes in the same package version: https://code.launchpad.net/~adrien-n/ubuntu/+source/openssl/+git/openssl/+merge/462486

The now-superseded MR is at https://code.launchpad.net/~tobhe/ubuntu/+source/openssl/+git/openssl/+merge/460953

Since OpenSSL just received another big update to 3.0.13 we had to rebase our changes
and will have to rerun our install/upgrade tests.

A test build is also available at https://launchpad.net/~tobhe/+archive/ubuntu/openssl-test/

Revision history for this message
Tobias Heider (tobhe) wrote :
Revision history for this message
Tobias Heider (tobhe) wrote :

As promised, here are some more details on how I tested:
- been running autopkgtest locally and made sure they pass (log attached)
- installed it on my local development machine to see if anything breaks
- tested the upgrade in a lxd container, made sure openssl speed works and does the right thing
- built and installer a FIPS provider for 24.04 and made sure everything still works when forcing FIPS mode

Revision history for this message
Tobias Heider (tobhe) wrote :

Adding a few more details as requested by Adrien.
I used lxd to run the autopkgtest, in particular:

  # Build lxd image
  /usr/bin/autopkgtest-build-lxd ubuntu-daily:noble

  # Run
  autopkgtest -s --apt-pocket=proposed ./openssl_3.0.13-1ubuntu2.dsc -- lxd autopkgtest/ubuntu/noble/amd64

It is quite easy to verify OpenSSL doesn't accidentally enable FIPS mode on non fips_enabled machines.

1. openssl speed will skip non-compliant alorithms in FIPS mode, if it starts with md5 OpenSSL is not in FIPS mode.

2. Using OPENSSL_FORCE_FIPS_MODE=1 FIPS mode can be enforced resulting in an error if the FIPS provider is not installed. Similarly OPENSSL_FORCE_FIPS_MODE=0 can be used to force disable FIPS mode on a fips_enabled kernel

Revision history for this message
Adrien Nader (adrien) wrote :

I did some additional tests too in a noble container.

With/without the env var to set the file location, including with the file missing, with/without the env var to force FIPS mode, and using values 0, 1, 42, -42, a.

By the way, note that access to these environment variables uses secure_getenv().

Adrien Nader (adrien)
description: updated
Changed in openssl (Ubuntu):
milestone: none → ubuntu-24.03
milestone: ubuntu-24.03 → ubuntu-24.04
Revision history for this message
Graham Inggs (ginggs) wrote :

FFe granted.

Changed in openssl (Ubuntu):
status: New → Triaged
Adrien Nader (adrien)
Changed in openssl (Ubuntu):
status: Triaged → Fix Committed
Revision history for this message
Launchpad Janitor (janitor) wrote :

This bug was fixed in the package openssl - 3.0.13-0ubuntu2

---------------
openssl (3.0.13-0ubuntu2) noble; urgency=medium

  [ Tobias Heider ]
  * Add fips-mode detection and adjust defaults when running in fips mode
    (LP: #2056593):
    - d/p/fips/crypto-Add-kernel-FIPS-mode-detection.patch:
      Detect if kernel fips mode is enabled
    - d/p/fips/crypto-Automatically-use-the-FIPS-provider-when-the-kerne.patch:
      Load FIPS provider if running in FIPS mode
    - d/p/fips/apps-speed-Omit-unavailable-algorithms-in-FIPS-mode.patch:
      Limit openssl-speed to FIPS compliant algorithms when running in FIPS mode
    - d/p/fips/apps-pass-propquery-arg-to-the-libctx-DRBG-fetches.patch
      Make sure DRBG respects query properties
    - d/p/fips/test-Ensure-encoding-runs-with-the-correct-context-during.patch:
      Make sure encoding runs with correct library context and provider

  [ Adrien Nader ]
  * Re-enable intel/0002-AES-GCM-enabled-with-AVX512-vAES-and-vPCLMULQDQ.patch
    (LP: #2030784)
    Thanks Bun K Tan and Dan Zimmerman
  * Disable LTO with which the codebase is generally incompatible (LP: #2058017)

 -- Adrien Nader <email address hidden> Fri, 15 Mar 2024 09:46:33 +0100

Changed in openssl (Ubuntu):
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.