XU3/XU4 sd_fusing.sh unsafe argument checking

This forum is for topics dealing with problems with software specifically in the ARMv7h repo.

XU3/XU4 sd_fusing.sh unsafe argument checking

Postby karog » Tue Oct 03, 2017 5:20 pm

sd_fusing.sh for XU3/XU4 does not check arguments sufficiently for safety. Via some quirk, when I tried to fuse a new 5.1 eMMC card, I was accidentally running with an older u-boot that did not recognize the newer revision of the 5.1 eMMC card so that /dev/mmcblk0 existed but /dev/mmcblk0boot0 did not. As a consequence, it attempted to fuse /dev/mmcblk0 as if it were a /dev/sdX device and reported success.

I propose changing the following code in sd_fusing.sh
Code: Select all
if [ -z $1 ]
then
    echo "usage: ./sd_fusing.sh <SD Reader's device file>"
    exit 0
fi

if [ -b $1 ]
then
    echo "$1 reader is identified."
else
    echo "$1 is NOT identified."
    exit 0
fi

if [ -d /sys/block/${1##*/}boot0 ]; then
    echo "$1 is an eMMC card, disabling ${1##*/}boot0 ro"
    if ! echo 0 > /sys/block/${1##*/}boot0/force_ro; then
   echo "Enabling r/w for $1boot0 failed"
   exit 1
    fi
    emmc=1
fi


to

Code: Select all
shopt -s extglob

case "$1" in
  /dev/mmcblk0)
    echo "Attempting to fuse eMMC $1"
    BOOT0="/sys/block/${1##*/}boot0"
    if [ ! -d $BOOT0 ]; then
      echo "Not found: $1boot0"
      exit 1
    fi
    echo "Enabling $1boot0 r/w"
    if ! echo 0 > $BOOT0/force_ro; then
      echo "Enabling $1boot0 r/w failed"
      exit 1
    fi
    emmc=1
    ;;
  /dev/sd+([a-z]))
     echo "Attempting to fuse SD $1"
     if [ ! -b $1 ]; then
       echo "Not found: $1"
       exit 1
     fi
     ;;
  *)
    echo "Usage: ./sd_fusing.sh (/dev/sdX | /dev/mmcblk0)"
    exit 1
    ;;
esac
karog
 
Posts: 183
Joined: Thu Jan 05, 2012 7:55 pm

Return to ARMv7h

Who is online

Users browsing this forum: Bing [Bot] and 1 guest