Generate a separate fstab file for FIPS mode

Add a file "fstab.gs201-fips" alongside the existing "fstab.gs201" in
order to specify different encryption settings in FIPS mode.

"androidboot.fstab_suffix=gs201-fips" on the kernel command line will be
used to select the FIPS fstab when needed.

As the two fstabs should be otherwise identical, generate them from a
template file so that they will stay in sync.

Note that generating the fstabs requires that they be installed as build
system modules rather than via PRODUCT_COPY_FILES, which results in the
vendor_ramdisk copy of the fstabs being installed to system/etc rather
than /.  This shouldn't cause any problem, now that Android has been
updated to look for the fstab in this location too.

(cherry-pick from device/google/gs101)
Test: Boot to home screen with/without fips mode
Bug: 202417706
Signed-off-by: Konstantin Vyshetsky <vkon@google.com>
Change-Id: I8fdc1c9a91399816fa2d4c53f282d63e988ce7d5
This commit is contained in:
Konstantin Vyshetsky 2021-10-07 14:27:38 -07:00 committed by TreeHugger Robot
parent 11475b1588
commit 067512ec32
5 changed files with 75 additions and 7 deletions

View file

@ -54,7 +54,17 @@ BOARD_USES_GENERIC_KERNEL_IMAGE := true
BOARD_MOVE_RECOVERY_RESOURCES_TO_VENDOR_BOOT := true
BOARD_MOVE_GSI_AVB_KEYS_TO_VENDOR_BOOT := true
TARGET_RECOVERY_WIPE := device/google/gs201/conf/recovery.wipe
TARGET_RECOVERY_FSTAB := device/google/gs201/conf/fstab.gs201
# This is the fstab file that will be included in the recovery image. Note that
# recovery doesn't care about the encryption settings, so it doesn't matter
# whether we use the normal or the fips fstab here.
#
# Since this is a generated file, it's necessary to use intermediates-dir-for in
# order to refer to it correctly. And since intermediates-dir-for isn't defined
# yet when this file is included, it's necessary to use a deferred variable
# assignment ( = ) rather than an immediate variable assignment ( := ).
TARGET_RECOVERY_FSTAB = $(call intermediates-dir-for,ETC,fstab.gs201)/fstab.gs201
TARGET_RECOVERY_PIXEL_FORMAT := ABGR_8888
TARGET_RECOVERY_UI_MARGIN_HEIGHT := 165
TARGET_RECOVERY_UI_LIB := \

55
conf/Android.bp Normal file
View file

@ -0,0 +1,55 @@
/*
* Copyright (C) 2021 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// By default this device uses hardware-wrapped keys for storage encryption,
// which is intended to offer increased security over the traditional method
// (software keys). However, hardware-wrapped keys aren't compatible with
// FIPS-140 certification of the encryption hardware, and hence we have to
// disable the use of them in FIPS mode. This requires having two fstab files:
// one for the default mode, and one for FIPS mode selectable via
// androidboot.fstab_suffix on the kernel command line. These fstabs should be
// identical with the exception of the encryption settings, so to keep them in
// sync the rules below generate them from a template file.
genrule {
name: "gen_fstab.gs201",
srcs: ["fstab.gs201.in"],
out: ["fstab.gs201"],
cmd: "sed -e s/@fileencryption@/::inlinecrypt_optimized+wrappedkey_v0/" +
" -e s/@metadata_encryption@/:wrappedkey_v0/ $(in) > $(out)",
}
genrule {
name: "gen_fstab.gs201-fips",
srcs: ["fstab.gs201.in"],
out: ["fstab.gs201-fips"],
cmd: "sed -e s/@fileencryption@/aes-256-xts/" +
" -e s/@metadata_encryption@/aes-256-xts/ $(in) > $(out)",
}
prebuilt_etc {
name: "fstab.gs201",
src: ":gen_fstab.gs201",
vendor: true,
vendor_ramdisk_available: true,
}
prebuilt_etc {
name: "fstab.gs201-fips",
src: ":gen_fstab.gs201-fips",
vendor: true,
vendor_ramdisk_available: true,
}

View file

@ -17,7 +17,7 @@ vendor_dlkm /vendor_dlkm
/dev/block/platform/14700000.ufs/by-name/misc /misc emmc defaults wait
/dev/block/platform/14700000.ufs/by-name/metadata /metadata f2fs noatime,nosuid,nodev,sync wait,check,formattable,first_stage_mount
#/dev/block/platform/14700000.ufs/by-name/pvmfw /pvmfw emmc defaults wait,slotselect,avb=pvmfw,first_stage_mount
/dev/block/platform/14700000.ufs/by-name/userdata /data f2fs noatime,nosuid,nodev,discard,reserve_root=32768,resgid=1065,fsync_mode=nobarrier,inlinecrypt,compress_extension=apk,compress_extension=apex,compress_extension=so,compress_extension=vdex,compress_extension=odex,atgc,checkpoint_merge latemount,wait,check,quota,formattable,sysfs_path=/dev/sys/block/bootdevice,checkpoint=fs,reservedsize=128M,fileencryption=::inlinecrypt_optimized+wrappedkey_v0,metadata_encryption=:wrappedkey_v0,keydirectory=/metadata/vold/metadata_encryption,fscompress,readahead_size_kb=128
/dev/block/platform/14700000.ufs/by-name/userdata /data f2fs noatime,nosuid,nodev,discard,reserve_root=32768,resgid=1065,fsync_mode=nobarrier,inlinecrypt,compress_extension=apk,compress_extension=apex,compress_extension=so,compress_extension=vdex,compress_extension=odex,atgc,checkpoint_merge latemount,wait,check,quota,formattable,sysfs_path=/dev/sys/block/bootdevice,checkpoint=fs,reservedsize=128M,fileencryption=@fileencryption@,metadata_encryption=@metadata_encryption@,keydirectory=/metadata/vold/metadata_encryption,fscompress,readahead_size_kb=128
/dev/block/platform/14700000.ufs/by-name/vbmeta /vbmeta emmc defaults slotselect,first_stage_mount
/dev/block/zram0 none swap defaults zramsize=2147483648,max_comp_streams=8,zram_backingdev_size=512M
/devices/platform/11210000.usb* auto vfat defaults voldmanaged=usb:auto

View file

@ -255,7 +255,7 @@ on late-fs
class_start animation
# Mount RW partitions which need run fsck
mount_all /vendor/etc/fstab.gs201 --late
mount_all --late
on post-fs-data
# Log data folder
@ -449,7 +449,7 @@ on property:persist.vendor.radio.no_modem_board=1
setprop ro.radio.noril yes
on fs
mount_all /vendor/etc/fstab.gs201 --early
mount_all --early
restorecon_recursive /mnt/vendor/efs
chown radio system /mnt/vendor/efs
restorecon_recursive /mnt/vendor/efs_backup

View file

@ -243,10 +243,13 @@ PRODUCT_COPY_FILES += \
device/google/gs201/conf/init.recovery.device.rc:$(TARGET_COPY_OUT_RECOVERY)/root/init.recovery.gs201.rc
# Fstab files
PRODUCT_PACKAGES += \
fstab.gs201 \
fstab.gs201.vendor_ramdisk \
fstab.gs201-fips \
fstab.gs201-fips.vendor_ramdisk
PRODUCT_COPY_FILES += \
device/google/gs201/conf/fstab.gs201:$(TARGET_COPY_OUT_VENDOR)/etc/fstab.gs201 \
device/google/gs201/conf/fstab.persist:$(TARGET_COPY_OUT_VENDOR)/etc/fstab.persist \
device/google/gs201/conf/fstab.gs201:$(TARGET_COPY_OUT_VENDOR_RAMDISK)/first_stage_ramdisk/fstab.gs201
device/google/gs201/conf/fstab.persist:$(TARGET_COPY_OUT_VENDOR)/etc/fstab.persist
# Shell scripts
PRODUCT_COPY_FILES += \