From: Eric Sandeen <sandeen@redhat.com>
To: Andreas Dilger <adilger@sun.com>
Cc: ext4 development <linux-ext4@vger.kernel.org>
Subject: Re: [PATCH, RFC V2] ext4: limit block allocations for indirect-block files to < 2^32
Date: Sat, 05 Sep 2009 13:16:38 -0500 [thread overview]
Message-ID: <4AA2AB06.6040809@redhat.com> (raw)
In-Reply-To: <20090905164535.GL4197@webber.adilger.int>
Andreas Dilger wrote:
> On Sep 04, 2009 22:21 -0500, Eric Sandeen wrote:
>> Today, the ext4 allocator will happily allocate blocks past
>> 232 for indirect-block files, which results in the block
>> numbers getting truncated, and corruption ensues.
>>
>> This patch limits such allocations to < 2^32, and adds
>> WARN_ONs (maybe should be BUG_ONs) if we do get blocks
>> larger than that.
>
> Eric, thanks for making the patch.
>
>> This should address RH Bug 519471, ext4 bitmap allocator must limit
>> blocks to < 2^32
>>
>> * ext4_find_goal() is modified to choose a goal < UINT_MAX,
>> so that our starting point is in an acceptable range.
>>
>> * ext4_xattr_block_set() is modified such that the goal block
>> is < UINT_MAX, as above.
>
> Using UINT_MAX probably isn't wholly safe, as I know of systems
> that have e.g. 64-bit ints (though I guess none that have Linux
> kernel ports). It should use (u32)~0 or ((1 << 32) - 1) directly.
>
>> Perhaps an ext4-specific #define would be better than UINT_MAX?
>
> I think yes, since we know the maximum value is tied specifically
> to the u32 indirect block pointers, and not necessarily to an "int".
yep, I had considered that, I should have just done it :) (esp
considering the patch I sent a while back to get rid of similar things) :)
>> static ext4_fsblk_t ext4_find_goal(struct inode *inode, ext4_lblk_t block,
>> Indirect *partial)
>> {
>> + goal = ext4_find_near(inode, partial);
>> + goal = goal % UINT_MAX;
>> + return goal;
>
> Using "% UINT_MAX" here will result in a 64-bit division on 32-bit
> platforms, since ext4_fsblk_t is declared as an unsigned long long.
> This should instead be "(u32)" or "& 0xffffffff".
whoops good point. I wasn't thinking of 32-bit boxes, thinking they
can't go past 16T but for smaller blocks we still could go past 2^32
blocks... and it is a 64-bit modulo regardless.
>> @@ -1943,6 +1943,11 @@ ext4_mb_regular_allocator(struct ext4_allocation_context *ac)
>> + /* non-extent files are limited to low blocks/groups */
>> + if (!(EXT4_I(ac->ac_inode)->i_flags & EXT4_EXTENTS_FL))
>> + ngroups = min_t(unsigned long, ngroups,
>> + (UINT_MAX / EXT4_BLOCKS_PER_GROUP(sb)));
>
> Since EXT4_BLOCKS_PER_GROUP() is a run-time variable, but is constant
> for the life of the filesystem, this could be computed once and stored
> in the superblock?
ok.
>> +++ b/fs/ext4/xattr.c
>> @@ -810,12 +810,22 @@ inserted:
>> + if (!(EXT4_I(inode)->i_flags & EXT4_EXTENTS_FL))
>> + goal = goal % UINT_MAX;
>
> As above.
Thanks for the review, will fix those up.
-Eric
> Cheers, Andreas
> --
> Andreas Dilger
> Sr. Staff Engineer, Lustre Group
> Sun Microsystems of Canada, Inc.
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
next prev parent reply other threads:[~2009-09-05 18:16 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-09-04 22:17 [PATCH, RFC] ext4: limit block allocations for indirect-block files to < 2^32 Eric Sandeen
2009-09-05 3:21 ` [PATCH, RFC V2] " Eric Sandeen
2009-09-05 16:45 ` Andreas Dilger
2009-09-05 18:16 ` Eric Sandeen [this message]
2009-09-10 16:02 ` [PATCH, RFC V3] " Eric Sandeen
2009-09-10 16:53 ` Theodore Tso
2009-09-10 16:56 ` Eric Sandeen
2009-09-10 21:10 ` Andreas Dilger
2009-09-10 21:16 ` Eric Sandeen
2009-09-10 21:33 ` Theodore Tso
2009-09-10 21:42 ` Eric Sandeen
2009-09-10 21:51 ` Andreas Dilger
2009-09-10 21:57 ` Eric Sandeen
2009-09-10 23:19 ` Theodore Tso
2009-09-11 14:15 ` Eric Sandeen
2009-09-10 22:01 ` Andreas Dilger
2009-09-14 20:03 ` [PATCH, RFC V4] " Eric Sandeen
2009-09-16 18:54 ` Theodore Tso
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=4AA2AB06.6040809@redhat.com \
--to=sandeen@redhat.com \
--cc=adilger@sun.com \
--cc=linux-ext4@vger.kernel.org \
/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;
as well as URLs for NNTP newsgroup(s).