Stricter stat when checking for blockdevices

When checking for entries use both lstat and stat to make
sure that both link and target can be read.
Fail if only link can be read.

This makes sure that bootctl can update all ab block device
entries. Without this change, missing selinux rule would
cause partition to be silently ignored.

Bootcontrol checks if a partition exists by checking the
entries in /dev/block/by-name.
The entries in this directory are in normal case symlinks,
all with selinux label u:object_r:block_device:s0.
The target of the links might have different labels.

Performing both lstat and then stat will ensure that the error case
where bootctl don't have the correct selinux permission for accessing
block device is handled as error.

Bug: 234349374
Test: Manual. Remount the device and push bootcontrol related files
   to vendor partition (bootctrl.msmnile.so, android.hardware.boot@*.so)
   Change selinux label on ab block device to other label, example for
   modem_b on pixel4:
   chcon u:object_r:media_rw_data_file:s0 /dev/block/sda9
   Run test:
   bootctl mark-boot-successful
   Confirm result:
   Error marking as having booted successfully: Operation not permitted
   Confirm message in logcat: Unable to stat block device
Change-Id: I1cdbd74e1b0f1a105e36c02dd03519621600e57d
1 file changed
tree: 41008e258952c3300b1f34521a750fb80c6cd2ff
  1. Android.bp
  2. boot_control.cpp
  3. METADATA
  4. NOTICE