From: Christoph Hellwig <hch@infradead.org>
To: Lukas Czerner <lczerner@redhat.com>
Cc: Christoph Hellwig <hch@infradead.org>, xfs@oss.sgi.com
Subject: Re: [PATCH v2] xfs: fix possible overflow in xfs_ioc_trim()
Date: Tue, 20 Sep 2011 13:12:20 -0400 [thread overview]
Message-ID: <20110920171220.GA17204@infradead.org> (raw)
In-Reply-To: <alpine.LFD.2.00.1109071333110.4579@dhcp-27-109.brq.redhat.com>
On Wed, Sep 07, 2011 at 02:26:54PM +0200, Lukas Czerner wrote:
> I do not think that start + len can overflow since we are doing
> XFS_B_TO_FSBT() on it first. Am I missing something ?
They don't have to overflow, but they can easily be outside
the range of valid AGs.
> > Care to update the test case to cover these cases as well?
> >
>
> I am not sure what do you mean ? There already is a check when both
> start and len are huge numbers. I am not sure if we can do more without
> significantly complicating the test to cover various start, or len
> numbers where can the fsblock->group_number overflow for various file
> systems.
Add a testcase where start is a relatively small number (smaller than an
AG/BG), but start + len is outside the fs.
> @@ -145,7 +145,7 @@ xfs_ioc_trim(
> struct request_queue *q = mp->m_ddev_targp->bt_bdev->bd_disk->queue;
> unsigned int granularity = q->limits.discard_granularity;
> struct fstrim_range range;
> + xfs_fsblock_t start, end, minlen;
> xfs_agnumber_t start_agno, end_agno, agno;
> __uint64_t blocks_trimmed = 0;
> int error, last_error = 0;
> @@ -165,19 +165,21 @@ xfs_ioc_trim(
> * matter as trimming blocks is an advisory interface.
> */
> start = XFS_B_TO_FSBT(mp, range.start);
> + end = start + XFS_B_TO_FSBT(mp, range.len) - 1;
> minlen = XFS_B_TO_FSB(mp, max_t(u64, granularity, range.minlen));
>
> + if (start >= mp->m_sb.sb_dblocks)
> return -XFS_ERROR(EINVAL);
> + start_agno = XFS_FSB_TO_AGNO(mp, start);
>
> + if (end >= mp->m_sb.sb_dblocks) {
> + end = mp->m_sb.sb_dblocks - 1;
> end_agno = mp->m_sb.sb_agcount - 1;
> + } else
> + end_agno = XFS_FSB_TO_AGNO(mp, end);
I'd rather do something like:
if (start >= mp->m_sb.sb_dblocks)
return -XFS_ERROR(EINVAL);
if (end > mp->m_sb.sb_dblocks - 1)
end = mp->m_sb.sb_dblocks - 1;
start_agno = XFS_FSB_TO_AGNO(mp, start);
end_agno = XFS_FSB_TO_AGNO(mp, end)
here.
Otherwise the patch looks fine.
_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs
next prev parent reply other threads:[~2011-09-20 17:12 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-09-06 15:29 [PATCH v2] xfs: fix possible overflow in xfs_ioc_trim() Lukas Czerner
2011-09-06 15:33 ` Christoph Hellwig
2011-09-07 10:05 ` Lukas Czerner
2011-09-07 11:21 ` Christoph Hellwig
2011-09-07 12:26 ` Lukas Czerner
2011-09-20 13:36 ` Lukas Czerner
2011-09-20 17:12 ` Christoph Hellwig [this message]
2011-09-21 7:46 ` Lukas Czerner
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=20110920171220.GA17204@infradead.org \
--to=hch@infradead.org \
--cc=lczerner@redhat.com \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.