]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs_repair: fix unaligned accesses
authorEric Sandeen <sandeen@sandeen.net>
Wed, 14 Oct 2015 00:01:23 +0000 (11:01 +1100)
committerDave Chinner <david@fromorbit.com>
Wed, 14 Oct 2015 00:01:23 +0000 (11:01 +1100)
This fixes some unaligned accesses spotted by libubsan in repair.

See Documentation/unaligned-memory-access.txt in the kernel
tree for why these can be a problem.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Signed-off-by: Dave Chinner <david@fromorbit.com>
include/libxfs.h
repair/dinode.c
repair/prefetch.c

index f733c36d97bd7fcdd3439e14cf3d554fd8e00cd8..04c6f9c74e7b4a5ad0e250a85b1029b1c6b0b33a 100644 (file)
@@ -211,8 +211,8 @@ libxfs_bmbt_disk_get_all(
 {
        struct xfs_bmbt_rec_host hrec;
 
-       hrec.l0 = be64_to_cpu(rp->l0);
-       hrec.l1 = be64_to_cpu(rp->l1);
+       hrec.l0 = get_unaligned_be64(&rp->l0);
+       hrec.l1 = get_unaligned_be64(&rp->l1);
        libxfs_bmbt_get_all(&hrec, irec);
 }
 
index f78f907883473d1bc5200b8473811293322445e1..43142d6ae447753e642a7af1d5f9611a89b4ec09 100644 (file)
@@ -960,15 +960,17 @@ _("bad numrecs 0 in inode %" PRIu64 " bmap btree root block\n"),
                 * btree, we'd do it right here.  For now, if there's a
                 * problem, we'll bail out and presumably clear the inode.
                 */
-               if (!verify_dfsbno(mp, be64_to_cpu(pp[i])))  {
-                       do_warn(_("bad bmap btree ptr 0x%llx in ino %" PRIu64 "\n"),
-                              (unsigned long long) be64_to_cpu(pp[i]), lino);
+               if (!verify_dfsbno(mp, get_unaligned_be64(&pp[i])))  {
+                       do_warn(
+_("bad bmap btree ptr 0x%" PRIx64 " in ino %" PRIu64 "\n"),
+                               get_unaligned_be64(&pp[i]), lino);
                        return(1);
                }
 
-               if (scan_lbtree(be64_to_cpu(pp[i]), level, scan_bmapbt, type,
-                               whichfork, lino, tot, nex, blkmapp, &cursor,
-                               1, check_dups, magic, &xfs_bmbt_buf_ops))
+               if (scan_lbtree(get_unaligned_be64(&pp[i]), level, scan_bmapbt,
+                               type, whichfork, lino, tot, nex, blkmapp,
+                               &cursor, 1, check_dups, magic,
+                               &xfs_bmbt_buf_ops))
                        return(1);
                /*
                 * fix key (offset) mismatches between the keys in root
@@ -977,28 +979,27 @@ _("bad numrecs 0 in inode %" PRIu64 " bmap btree root block\n"),
                 * blocks but the parent hasn't been updated
                 */
                if (!check_dups && cursor.level[level-1].first_key !=
-                                       be64_to_cpu(pkey[i].br_startoff))  {
+                                  get_unaligned_be64(&pkey[i].br_startoff)) {
                        if (!no_modify)  {
                                do_warn(
-       _("correcting key in bmbt root (was %llu, now %" PRIu64") in inode "
-         "%" PRIu64" %s fork\n"),
-                                      (unsigned long long)
-                                              be64_to_cpu(pkey[i].br_startoff),
-                                       cursor.level[level-1].first_key,
-                                       XFS_AGINO_TO_INO(mp, agno, ino),
-                                       forkname);
+_("correcting key in bmbt root (was %" PRIu64 ", now %" PRIu64") in inode "
+  "%" PRIu64" %s fork\n"),
+                                      get_unaligned_be64(&pkey[i].br_startoff),
+                                      cursor.level[level-1].first_key,
+                                      XFS_AGINO_TO_INO(mp, agno, ino),
+                                      forkname);
                                *dirty = 1;
-                               pkey[i].br_startoff = cpu_to_be64(
-                                       cursor.level[level-1].first_key);
+                               put_unaligned_be64(
+                                       cursor.level[level-1].first_key,
+                                       &pkey[i].br_startoff);
                        } else  {
                                do_warn(
-       _("bad key in bmbt root (is %llu, would reset to %" PRIu64 ") in inode "
-         "%" PRIu64 " %s fork\n"),
-                                      (unsigned long long)
-                                              be64_to_cpu(pkey[i].br_startoff),
-                                       cursor.level[level-1].first_key,
-                                       XFS_AGINO_TO_INO(mp, agno, ino),
-                                       forkname);
+_("bad key in bmbt root (is %" PRIu64 ", would reset to %" PRIu64 ") in inode "
+  "%" PRIu64 " %s fork\n"),
+                                      get_unaligned_be64(&pkey[i].br_startoff),
+                                      cursor.level[level-1].first_key,
+                                      XFS_AGINO_TO_INO(mp, agno, ino),
+                                      forkname);
                        }
                }
                /*
index 32ec55ebdea9ea5ca11fe2df7cf0a88594eb765c..52238ca3314547a6c8ae814a5f16415c7d037547 100644 (file)
@@ -330,7 +330,7 @@ pf_scanfunc_bmap(
        pp = XFS_BMBT_PTR_ADDR(mp, block, 1, mp->m_bmap_dmxr[1]);
 
        for (i = 0; i < numrecs; i++) {
-               dbno = be64_to_cpu(pp[i]);
+               dbno = get_unaligned_be64(&pp[i]);
                if (!verify_dfsbno(mp, dbno))
                        return 0;
                if (!pf_scan_lbtree(dbno, level, isadir, args, pf_scanfunc_bmap))
@@ -372,7 +372,7 @@ pf_read_btinode(
        pp = XFS_BMDR_PTR_ADDR(dib, 1, xfs_bmdr_maxrecs(dsize, 0));
 
        for (i = 0; i < numrecs; i++) {
-               dbno = be64_to_cpu(pp[i]);
+               dbno = get_unaligned_be64(&pp[i]);
                if (!verify_dfsbno(mp, dbno))
                        break;
                if (!pf_scan_lbtree(dbno, level, isadir, args, pf_scanfunc_bmap))