From: Tom Rini Date: Mon, 7 Aug 2017 09:55:22 -0400 Subject: [U-Boot] [U-Boot, v2, 10/10] gpt: harden set_gpt_info() against non NULL-terminated strings In-Reply-To: <20170704181946.11343-1-alison@peloton-tech.com> References: <20170704181946.11343-1-alison@peloton-tech.com> Message-ID: <20170807135522.GO29197@bill-the-cat> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="windows-1252" Content-Transfer-Encoding: quoted-printable To: u-boot@lists.denx.de On Tue, Jul 04, 2017 at 11:19:46AM -0700, Alison Chaiken wrote: > From: Alison Chaiken >=20 > Strings read from devices may sometimes fail to be > NULL-terminated. The functions in lib/string.c are subject to > failure in this case. Protect against observed failures in > set_gpt_info() by switching to length-checking variants with a length > limit of the maximum possible partition table length. At the same > time, add a few checks for NULL string pointers. >=20 > Here is an example as observed in sandbox under GDB: >=20 > =3D> gpt verify host 0 $partitions > Program received signal SIGSEGV, Segmentation fault. > 0x0000000000477747 in strlen (s=3D0x0) at lib/string.c:267 > 267 for (sc =3D s; *sc !=3D '\0'; ++sc) > (gdb) bt > #0 0x0000000000477747 in strlen (s=3D0x0) at lib/string.c:267 > #1 0x00000000004140b2 in set_gpt_info (str_part=3D, > str_disk_guid=3Dstr_disk_guid at entry=3D0x7fffffffdbe8, partitions= =3Dpartitions at entry=3D0x7fffffffdbd8, > parts_count=3Dparts_count at entry=3D0x7fffffffdbcf "", dev_desc=3D) at cmd/gpt.c:415 > #2 0x00000000004145b9 in gpt_verify (str_part=3D, blk= _dev_desc=3D0x7fffef09a9d0) at cmd/gpt.c:580 > #3 do_gpt (cmdtp=3D, flag=3D, argc=3D<= optimized out>, argv=3D0x7fffef09a8f0) > at cmd/gpt.c:783 > #4 0x00000000004295b0 in cmd_call (argv=3D0x7fffef09a8f0, argc=3D0x5= , flag=3D, > cmdtp=3D0x714e20 <_u_boot_list_2_cmd_2_gpt>) at common/command.c:500 > #5 cmd_process (flag=3D, argc=3D0x5, argv=3D0x7fffef0= 9a8f0, > repeatable=3Drepeatable at entry=3D0x726c04 , ticks=3Dti= cks at entry=3D0x0) at common/command.c:539 >=20 > Suggested-by: Lothar Wa=C3=9Fmann > Signed-off-by: Alison Chaiken Applied to u-boot/master, thanks! --=20 Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: Digital signature URL: