diff options
author | Toomas Soome <tsoome@FreeBSD.org> | 2020-03-19 17:27:08 +0000 |
---|---|---|
committer | Kyle Evans <kevans@FreeBSD.org> | 2021-10-08 01:15:59 +0000 |
commit | 51ddd2851e4a36e28cf78dfe06125723f7d2b113 (patch) | |
tree | be351d4c2ebd959a9328bb1279d765d5777eedd8 | |
parent | 90603ee8e051807c5469e51b547d9dc856d9b6c8 (diff) | |
download | src-51ddd2851e4a36e28cf78dfe06125723f7d2b113.tar.gz src-51ddd2851e4a36e28cf78dfe06125723f7d2b113.zip |
loader: misaligned access of dos_partition structure
armv7 crash due to misligned access of dos_partition dp_start field.
Allocate and make copy of dos_partition array to make sure the data
is aligned.
(cherry picked from commit 87d8d5ea3dd0a8ad2c0468660805017d6d45d937)
-rw-r--r-- | stand/common/part.c | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/stand/common/part.c b/stand/common/part.c index b84678efd3cc..69df57abb175 100644 --- a/stand/common/part.c +++ b/stand/common/part.c @@ -662,6 +662,7 @@ ptable_open(void *dev, uint64_t sectors, uint16_t sectorsize, int has_ext; #endif table = NULL; + dp = NULL; buf = malloc(sectorsize); if (buf == NULL) return (NULL); @@ -716,7 +717,11 @@ ptable_open(void *dev, uint64_t sectors, uint16_t sectorsize, goto out; } /* Check that we have PMBR. Also do some validation. */ - dp = (struct dos_partition *)(buf + DOSPARTOFF); + dp = malloc(NDOSPART * sizeof(struct dos_partition)); + if (dp == NULL) + goto out; + bcopy(buf + DOSPARTOFF, dp, NDOSPART * sizeof(struct dos_partition)); + /* * In mac we can have PMBR partition in hybrid MBR; * that is, MBR partition which has DOSPTYP_PMBR entry defined as @@ -778,6 +783,7 @@ ptable_open(void *dev, uint64_t sectors, uint16_t sectorsize, #endif /* LOADER_MBR_SUPPORT */ #endif /* LOADER_MBR_SUPPORT || LOADER_GPT_SUPPORT */ out: + free(dp); free(buf); return (table); } |