Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 25 additions & 3 deletions tests/phone-smoke
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,16 @@ has 'of them ASoC no backend DAIs (PipeWire probe) x1, UFS dme-set 0x4021 (s2idl
pass "counted and new lines together"

# The boot and storage guard rows (--slot-from: a fake root). The boot row
# wants the slot boot-update.conf names (b when absent); the guard row
# allows userdata and the running slot's five boot images.
# wants the slot boot-update.conf names (b when absent); Pixel storage checks
# retain the userdata and active-slot allowlist for both slots.
fr=$t/fr
fakeroot() { # running suffix (or none), then the writable partitions
rm -rf "$fr"; mkdir -p "$fr/proc" "$fr/etc/omamobile"
local disk
for disk in a b c d e f; do
mkdir -p "$fr/sys/block/sd$disk"
echo 1 > "$fr/sys/block/sd$disk/ro"
done
echo '123.45 100.00' > "$fr/proc/uptime"
[[ $1 == none ]] || printf 'androidboot.slot_suffix = "%s"\n' "$1" > "$fr/proc/bootconfig"
echo 'console=ttynull' > "$fr/proc/cmdline"
Expand All @@ -150,16 +155,23 @@ fakeroot _b $B5; rows
has 'ok|1|boot|kernel ' && has ', slot b, up 123s' && has 'ok|1|storage guard|13 partitions; only userdata and slot b' \
|| fail "a development phone on slot B, no boot-update.conf: both rows pass as before"
pass "a development phone on slot B, no boot-update.conf: both rows pass as before"
mkdir -p "$fr/usr/share/omamobile"
echo 'UFS_RW="boot_b init_boot_b vendor_boot_b vendor_kernel_boot_b dtbo_b userdata"' > "$fr/usr/share/omamobile/device.conf"
echo 'AUTO_WRITE=yes' > "$fr/etc/omamobile/boot-update.conf"; rows
has 'ok|1|boot|' && has 'ok|1|storage guard|' || fail "a release on slot B whose boot-update.conf names no slot: b"
pass "a release on slot B whose boot-update.conf names no slot: b"
fakeroot _a $A5; printf 'AUTO_WRITE=yes\nSLOT=a\n' > "$fr/etc/omamobile/boot-update.conf"; rows
fakeroot _a $A5; printf 'AUTO_WRITE=yes\nSLOT=a\n' > "$fr/etc/omamobile/boot-update.conf"
mkdir -p "$fr/usr/share/omamobile"
echo 'UFS_RW="boot_b init_boot_b vendor_boot_b vendor_kernel_boot_b dtbo_b userdata"' > "$fr/usr/share/omamobile/device.conf"
rows
has 'ok|1|boot|' && has ', slot a, up' && has 'ok|1|storage guard|13 partitions; only userdata and slot a' \
|| fail "a release on slot A with SLOT=a: both rows pass"
pass "a release on slot A with SLOT=a: both rows pass"
fakeroot _a $A5; rows
has 'not ok|1|boot|' && has 'on slot a: our builds boot from slot b' || fail "slot A without SLOT=a fails the boot row"
pass "slot A without SLOT=a fails the boot row"
mkdir -p "$fr/usr/share/omamobile"
echo 'UFS_RW="boot_b init_boot_b vendor_boot_b vendor_kernel_boot_b dtbo_b userdata"' > "$fr/usr/share/omamobile/device.conf"
fakeroot _b $B5; printf 'SLOT="a"\n' > "$fr/etc/omamobile/boot-update.conf"; rows
has 'not ok|1|boot|' && has 'on slot b: boot-update.conf says SLOT=a' || fail "SLOT=a booted from slot B (a fallback) fails the boot row"
pass "SLOT=a booted from slot B (a fallback) fails the boot row"
Expand All @@ -177,6 +189,16 @@ fakeroot none $B5; rows
has 'not ok|1|storage guard|writable outside the allowlist: ' && has ' boot_b ' || fail "no slot named: a writable boot image fails the guard row"
pass "no slot named: the boot row skips and only userdata may be writable"

fakeroot _b; mkdir -p "$fr/usr/share/omamobile"
echo 'UFS_RW=""' > "$fr/usr/share/omamobile/device.conf"; rows
has 'ok|1|storage guard|6 whole disks read-only; 13 partitions; no UFS writes allowed' || fail "a RAM-only descriptor allows no UFS writes"
echo 0 > "$fr/sys/class/block/sda11/ro"; rows
has 'not ok|1|storage guard|writable UFS nodes: disks none; partitions userdata' || fail "RAM-only refuses writable userdata"
echo 1 > "$fr/sys/class/block/sda11/ro"
echo 0 > "$fr/sys/block/sda/ro"; rows
has 'not ok|1|storage guard|writable UFS nodes: disks sda; partitions none' || fail "a writable whole disk fails"
pass "RAM-only descriptor and whole-disk guard"

# From the laptop: PHONE_SSH stands in for the phone. It answers the
# compatible question and records what the smoke run was started with.
printf '%s\n' '#!/bin/bash' 'case $1 in' ' tr*) echo "$COMPAT" ;;' \
Expand Down
42 changes: 34 additions & 8 deletions tools/phone-smoke
Original file line number Diff line number Diff line change
Expand Up @@ -104,26 +104,49 @@ else case $slot in
esac; fi

# ---------------------------------------------------------------- storage
# Every UFS partition is read-only except userdata and the running slot's
# boot images (the guard maps its list to the slot the phone runs from; with
# no slot named, only userdata).
# Keep the existing Pixel policy: allow userdata and the running slot's boot images.
allowed=" userdata "
[[ -z $slot ]] || allowed+="boot$slot init_boot$slot vendor_boot$slot vendor_kernel_boot$slot dtbo$slot "
rw=() total=0
descriptor="$sr/usr/share/omamobile/device.conf"
ram_only=0
if [[ -r $descriptor ]] && grep -Fxq 'UFS_RW=""' "$descriptor"; then
ram_only=1
fi
rw=() disks=0 total=0
if ((ram_only)); then
disk_rw=()
for s in "$sr"/sys/block/sd[a-f]; do
[[ -r $s/ro ]] || continue
disks=$((disks + 1))
[[ $(<"$s/ro") == 1 ]] || disk_rw+=("${s##*/}")
done
fi
for s in "$sr"/sys/class/block/sd*; do
[[ -r $s/partition && -r $s/uevent ]] || continue
name=$(sed -n 's/^PARTNAME=//p' "$s/uevent")
[[ -n $name ]] || continue
total=$((total + 1))
[[ $(<"$s/ro") == 0 && $allowed != *" $name "* ]] && rw+=("$name")
if ((ram_only)); then
[[ $(<"$s/ro") == 0 ]] && rw+=("$name")
else
[[ $(<"$s/ro") == 0 && $allowed != *" $name "* ]] && rw+=("$name")
fi
done
if ((total == 0)); then
check skip 1 "storage guard" "no named UFS partitions"
elif ((${#rw[@]})); then
elif ((ram_only)) && ((disks == 0)); then
check "not ok" 1 "storage guard" "no named UFS whole-disk nodes"
elif ((ram_only)) && ((${#disk_rw[@]} || ${#rw[@]})); then
check "not ok" 1 "storage guard" "writable UFS nodes: disks ${disk_rw[*]:-none}; partitions ${rw[*]:-none}"
elif ((!ram_only)) && ((${#rw[@]})); then
check "not ok" 1 "storage guard" "writable outside the allowlist: ${rw[*]}"
else
imgs=""; [[ -z $slot ]] || imgs=" and slot ${slot#_}'s boot images"
check ok 1 "storage guard" "$total partitions; only userdata$imgs writable"
if ((ram_only)); then
check ok 1 "storage guard" "$disks whole disks read-only; $total partitions; no UFS writes allowed"
else
imgs=""; [[ -z $slot ]] || imgs=" and slot ${slot#_}'s boot images"
check ok 1 "storage guard" "$total partitions; only userdata$imgs writable"
fi
fi
if [[ -n $slot_from ]]; then
printf '%s\n' "${results[@]}"
Expand All @@ -132,8 +155,11 @@ fi

rootdev=$(findmnt -no SOURCE / 2>/dev/null)
rootpart=$(sed -n 's/^PARTNAME=//p' "/sys/class/block/${rootdev#/dev/}/uevent" 2>/dev/null)
rootfs=$(findmnt -no FSTYPE / 2>/dev/null)
if [[ $rootpart == userdata ]]; then
check ok 1 "root" "$(findmnt -no FSTYPE /) on userdata, $(df -h --output=avail / | tail -1 | tr -d ' ') free"
elif [[ $rootfs == nfs || $rootfs == nfs4 ]]; then
check skip 0 "root" "$rootfs test root; not persistent"
else
check "not ok" 1 "root" "root is on ${rootpart:-$rootdev}, not userdata"
fi
Expand Down