From: Eric Sandeen <sandeen@sandeen.net>
To: xfs@oss.sgi.com
Subject: Re: [PATCH 2/4] xfs_repair: fix unaligned accesses
Date: Mon, 12 Oct 2015 16:31:32 -0500 [thread overview]
Message-ID: <561C26B4.3080008@sandeen.net> (raw)
In-Reply-To: <20151011222618.GX27164@dastard>
On 10/11/15 5:26 PM, Dave Chinner wrote:
> On Thu, Oct 08, 2015 at 07:25:24PM -0500, Eric Sandeen wrote:
>> This fixes some unaligned accesses spotted by libubsan in repair.
>>
>> Signed-off-by: Eric Sandeen <sandeen@redhat.com>
>> ---
>> repair/dinode.c | 19 +++++++++----------
>> repair/prefetch.c | 4 ++--
>> 2 files changed, 11 insertions(+), 12 deletions(-)
>>
>> diff --git a/repair/dinode.c b/repair/dinode.c
>> index f78f907..44bbb8f 100644
>> --- a/repair/dinode.c
>> +++ b/repair/dinode.c
>> @@ -960,13 +960,13 @@ _("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]))) {
>> + if (!verify_dfsbno(mp, get_unaligned_be64(&pp[i]))) {
>
> I don't understand - when are pointers in the BMBT not 64 bit
> aligned? The buffers are allocated by memalign to be 64 bit aligned,
> and all the internal BMBT structures are 64 bit aligned, too. i.e
> the BMBT block header is 24/72 bytes in length (depending on CRCs),
> the pointers are 64 bit, and the records are 128 bit.
>
> So where's the unaligned access coming from?
Ok, so on a recheck, I'm not crazy w.r.t. what gcc said, anyway:
dinode.c:964:26: runtime error: load of misaligned address 0x7fc4f800ef54 for type 'xfs_bmbt_ptr_t', which requires 8 byte alignment
0x7fc4f800ef54: note: pointer points here
00 00 00 00 00 00 00 00 00 20 38 5e 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
^
with some added printfs, it came from:
pp = XFS_BMDR_PTR_ADDR(dib, 1,
xfs_bmdr_maxrecs(XFS_DFORK_SIZE(dip, mp, whichfork), 0));
printf("dib at %p pp at %p\n", dib, pp);
dib at 0x7fc4f800eeb0 pp at 0x7fc4f800ef54
so pp is at not an 8-multiple away from dib ...now how'd that happen?
#define XFS_BMDR_PTR_ADDR(block, index, maxrecs) \
((xfs_bmdr_ptr_t *) \
((char *)(block) + \
sizeof(struct xfs_bmdr_block) + \
(maxrecs) * sizeof(xfs_bmdr_key_t) + \
((index) - 1) * sizeof(xfs_bmdr_ptr_t)))
xfs_bmdr_block is 32 bits, not 64.
But everything in my patch is BMDR not BMBT, right? I don't think I
ran into any problems in BMBT land, and
#define XFS_BMBT_PTR_ADDR(mp, block, index, maxrecs) \
((xfs_bmbt_ptr_t *) \
((char *)(block) + \
XFS_BMBT_BLOCK_LEN(mp) + \
(maxrecs) * sizeof(xfs_bmbt_key_t) + \
((index) - 1) * sizeof(xfs_bmbt_ptr_t)))
all those offsets seem fine.
-Eric
_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs
next prev parent reply other threads:[~2015-10-12 21:31 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-10-09 0:23 [PATCH 0/4] fix (mostly) minor nits spotted by gcc sanitization Eric Sandeen
2015-10-09 0:24 ` [PATCH 1/4] libxfs: avoid negative (and full-width) shifts in radix-tree.c Eric Sandeen
2015-10-09 13:23 ` Brian Foster
2015-10-09 0:25 ` [PATCH 2/4] xfs_repair: fix unaligned accesses Eric Sandeen
2015-10-09 13:24 ` Brian Foster
2015-10-09 14:03 ` Eric Sandeen
2015-10-11 22:26 ` Dave Chinner
2015-10-12 1:33 ` Eric Sandeen
2015-10-12 21:31 ` Eric Sandeen [this message]
2015-10-12 21:45 ` Dave Chinner
2015-10-13 0:32 ` Dave Chinner
2015-10-09 0:25 ` [PATCH 3/4] xfs_logprint: fix some " Eric Sandeen
2015-10-09 13:24 ` Brian Foster
2015-10-09 13:48 ` Eric Sandeen
2015-10-09 0:27 ` [PATCH 4/4] xfs_repair: fix left-shift overflows Eric Sandeen
2015-10-09 13:24 ` Brian Foster
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=561C26B4.3080008@sandeen.net \
--to=sandeen@sandeen.net \
--cc=xfs@oss.sgi.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox