[PATCH openbmc v6 12/18] initfs: update: add check for image size vs mtd size
Andrew Jeffery
andrew at aj.id.au
Thu Jun 23 15:41:29 AEST 2016
On Wed, 2016-06-22 at 19:30 -0500, OpenBMC Patches wrote:
> From: "Milton D. Miller II" <miltonm at us.ibm.com>
>
> The flashcp command will check the file size vs the partition size,
> so add a check when looking at images.
>
> Use stat -L -c "%s" to get the file size, and compare it to the mtd
> size from the sysfs size attribute.
>
> If this check is suppressed the enforcement is left to flashcp.
>
> Signed-off-by: Milton Miller <miltonm at us.ibm.com>
> ---
> .../obmc-phosphor-initfs/files/obmc-update.sh | 17 +++++++++++++++++
> 1 file changed, 17 insertions(+)
>
> diff --git a/meta-phosphor/common/recipes-phosphor/obmc-phosphor-initfs/files/obmc-update.sh b/meta-phosphor/common/recipes-phosphor/obmc-phosphor-initfs/files/obmc-update.sh
> index 22c9dcc..06e0e74 100755
> --- a/meta-phosphor/common/recipes-phosphor/obmc-phosphor-initfs/files/obmc-update.sh
> +++ b/meta-phosphor/common/recipes-phosphor/obmc-phosphor-initfs/files/obmc-update.sh
> @@ -48,6 +48,14 @@ childmtds() {
> done
> }
>
> +toobig() {
> + if test $(stat -L -c "%s" "$1") -gt $(cat /sys/class/mtd/"$2"/size)
> + then
> + return 0
> + fi
> + return 1
> +}
> +
> findmtd() {
> m=$(grep -xl "$1" /sys/class/mtd/*/name)
> m=${m%/name}
> @@ -85,6 +93,7 @@ doclean=
> dosave=y
> dorestore=y
> toram=
> +checksize=y
> checkmount=y
>
> whitelist=/run/initramfs/whitelist
> @@ -115,6 +124,9 @@ do
> --no-flash)
> doflash=
> shift ;;
> + --ignore-size)
> + checksize=
> + shift ;;
> --ignore-mount)
> checkmount=
> doflash=
> @@ -162,6 +174,11 @@ do
> echo 1>&2 "$E Unable to find mtd partiton for ${f##*/}."
> exit 1
> fi
> + if test -n "$checksize" && toobig "$f" "$m"
> + then
> + echo 1>&2 "$E Image ${f##*/} too big for $m."
> + exit 1
> + fi
> for s in $m $(childmtds $m)
> do
> if test -n "$checkmount" && mtdismounted $s
Reviewed-by: Andrew Jeffery <andrew at aj.id.au>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: This is a digitally signed message part
URL: <http://lists.ozlabs.org/pipermail/openbmc/attachments/20160623/772153d4/attachment-0001.sig>
More information about the openbmc
mailing list