Gitweb:
http://git.fedorahosted.org/git/?p=gfs2-utils.git;a=commitdiff;h=a4117132...
Commit: a411713232097d1fe73d94d3bb2c5ae52f62074e
Parent: b4333e4109d082e666ec74f534ef4d55df6557dd
Author: Andrew Price <anprice(a)redhat.com>
AuthorDate: Wed Nov 9 18:27:12 2016 +0000
Committer: Andrew Price <anprice(a)redhat.com>
CommitterDate: Thu Jan 12 16:20:33 2017 +0000
gfs2_edit: Fix unaligned access in restore_init()
Scanning this buffer byte-by-byte using casts results in a quick bus
error on sparc64. Avoid this by using a memcpy. This function only runs
once at the beginning of a restoremeta and in most cases the loop will
only execute once so this adds very little overhead.
Reported-By: Valentin Vidic <Valentin.Vidic(a)CARNet.hr>
Signed-off-by: Andrew Price <anprice(a)redhat.com>
---
gfs2/edit/savemeta.c | 16 ++++++++--------
1 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/gfs2/edit/savemeta.c b/gfs2/edit/savemeta.c
index c9b51e9..ac2dd9f 100644
--- a/gfs2/edit/savemeta.c
+++ b/gfs2/edit/savemeta.c
@@ -924,8 +924,7 @@ static off_t restore_init(gzFile gzfd, struct savemeta_header *smh)
size_t rs;
char buf[256];
off_t startpos = 0;
- struct saved_metablock *svb;
- struct gfs2_meta_header *sbmh;
+ struct gfs2_meta_header sbmh;
err = read_header(gzfd, smh);
if (err < 0) {
@@ -943,14 +942,15 @@ static off_t restore_init(gzFile gzfd, struct savemeta_header *smh)
exit(1);
}
/* Scan for the beginning of the file body. Required to support old formats(?). */
- for (i = 0; i < (256 - sizeof(*svb) - sizeof(*sbmh)); i++) {
- svb = (struct saved_metablock *)&buf[i];
- sbmh = (struct gfs2_meta_header *)svb->buf;
- if (sbmh->mh_magic == cpu_to_be32(GFS2_MAGIC) &&
- sbmh->mh_type == cpu_to_be32(GFS2_METATYPE_SB))
+ for (i = 0; i < (256 - sizeof(struct saved_metablock) - sizeof(sbmh)); i++) {
+ off_t off = i + sizeof(struct saved_metablock);
+
+ memcpy(&sbmh, &buf[off], sizeof(sbmh));
+ if (sbmh.mh_magic == cpu_to_be32(GFS2_MAGIC) &&
+ sbmh.mh_type == cpu_to_be32(GFS2_METATYPE_SB))
break;
}
- if (i == (sizeof(buf) - sizeof(*svb) - sizeof(*sbmh)))
+ if (i == (sizeof(buf) - sizeof(struct saved_metablock) - sizeof(sbmh)))
i = 0;
return startpos + i; /* File offset of saved sb */
}