diff mbox

iomap: fix integer truncation issues in the zeroing and dirtying helpers

Message ID 20170811151805.22896-1-hch@lst.de (mailing list archive)
State Superseded
Headers show

Commit Message

Christoph Hellwig Aug. 11, 2017, 3:18 p.m. UTC
Fix the min_t calls in the zeroing and dirtying helpers to perform the
comparisms on 64-bit types, which prevents them from incorrectly
being truncated, and larger zeroing operations being stuck in a never
ending loop.

Special thanks to Markus Stockhausen for spotting the bug.

Reported-by: Paul Menzel <pmenzel@molgen.mpg.de>
Tested-by: Paul Menzel <pmenzel@molgen.mpg.de>
---
 fs/iomap.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Darrick J. Wong Aug. 11, 2017, 4:04 p.m. UTC | #1
On Fri, Aug 11, 2017 at 05:18:05PM +0200, Christoph Hellwig wrote:
> Fix the min_t calls in the zeroing and dirtying helpers to perform the
> comparisms on 64-bit types, which prevents them from incorrectly
> being truncated, and larger zeroing operations being stuck in a never
> ending loop.
> 
> Special thanks to Markus Stockhausen for spotting the bug.
> 
> Reported-by: Paul Menzel <pmenzel@molgen.mpg.de>
> Tested-by: Paul Menzel <pmenzel@molgen.mpg.de>

Looks fine to me,
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>

(Are you going to push this to Al yourself, or do you want me to drag it
through the xfs tree?)

> ---
>  fs/iomap.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/fs/iomap.c b/fs/iomap.c
> index 039266128b7f..59cc98ad7577 100644
> --- a/fs/iomap.c
> +++ b/fs/iomap.c
> @@ -278,7 +278,7 @@ iomap_dirty_actor(struct inode *inode, loff_t pos, loff_t length, void *data,
>  		unsigned long bytes;	/* Bytes to write to page */
>  
>  		offset = (pos & (PAGE_SIZE - 1));
> -		bytes = min_t(unsigned long, PAGE_SIZE - offset, length);
> +		bytes = min_t(loff_t, PAGE_SIZE - offset, length);
>  
>  		rpage = __iomap_read_page(inode, pos);
>  		if (IS_ERR(rpage))
> @@ -373,7 +373,7 @@ iomap_zero_range_actor(struct inode *inode, loff_t pos, loff_t count,
>  		unsigned offset, bytes;
>  
>  		offset = pos & (PAGE_SIZE - 1); /* Within page */
> -		bytes = min_t(unsigned, PAGE_SIZE - offset, count);
> +		bytes = min_t(loff_t, PAGE_SIZE - offset, count);
>  
>  		if (IS_DAX(inode))
>  			status = iomap_dax_zero(pos, offset, bytes, iomap);
> -- 
> 2.11.0
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-xfs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
--
To unsubscribe from this list: send the line "unsubscribe linux-xfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Christoph Hellwig Aug. 11, 2017, 4:06 p.m. UTC | #2
On Fri, Aug 11, 2017 at 09:04:43AM -0700, Darrick J. Wong wrote:
> Looks fine to me,
> Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
> 
> (Are you going to push this to Al yourself, or do you want me to drag it
> through the xfs tree?)

In general we've maintained iomap.c through the XFS tree so far.
I think it's easiest to stick to that.
--
To unsubscribe from this list: send the line "unsubscribe linux-xfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Paul Menzel Aug. 12, 2017, 9 a.m. UTC | #3
Dear Christoph,


On 2017-08-11 17:18, Christoph Hellwig wrote:
> Fix the min_t calls in the zeroing and dirtying helpers to perform the
> comparisms on 64-bit types, which prevents them from incorrectly
> being truncated, and larger zeroing operations being stuck in a never
> ending loop.
> 
> Special thanks to Markus Stockhausen for spotting the bug.
> 
> Reported-by: Paul Menzel <pmenzel@molgen.mpg.de>
> Tested-by: Paul Menzel <pmenzel@molgen.mpg.de>

Thank you very much for providing the fix that quickly.

Please don’t forget to tag it for the stable series (4.8+).

Cc: stable@vger.kernel.org


Kind regards,

Paul
--
To unsubscribe from this list: send the line "unsubscribe linux-xfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Christoph Hellwig Aug. 13, 2017, 9:08 a.m. UTC | #4
Hi Paul,

I'm overdue doing another XFS stable backport batch, and I will
include this patch.
--
To unsubscribe from this list: send the line "unsubscribe linux-xfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Darrick J. Wong Aug. 16, 2017, 9:52 p.m. UTC | #5
On Fri, Aug 11, 2017 at 06:06:58PM +0200, Christoph Hellwig wrote:
> On Fri, Aug 11, 2017 at 09:04:43AM -0700, Darrick J. Wong wrote:
> > Looks fine to me,
> > Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
> > 
> > (Are you going to push this to Al yourself, or do you want me to drag it
> > through the xfs tree?)
> 
> In general we've maintained iomap.c through the XFS tree so far.
> I think it's easiest to stick to that.

Needs signed-off-by. :(

--D

> --
> To unsubscribe from this list: send the line "unsubscribe linux-xfs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
--
To unsubscribe from this list: send the line "unsubscribe linux-xfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Christoph Hellwig Aug. 17, 2017, 7:05 a.m. UTC | #6
On Wed, Aug 16, 2017 at 02:52:55PM -0700, Darrick J. Wong wrote:
> On Fri, Aug 11, 2017 at 06:06:58PM +0200, Christoph Hellwig wrote:
> > On Fri, Aug 11, 2017 at 09:04:43AM -0700, Darrick J. Wong wrote:
> > > Looks fine to me,
> > > Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
> > > 
> > > (Are you going to push this to Al yourself, or do you want me to drag it
> > > through the xfs tree?)
> > 
> > In general we've maintained iomap.c through the XFS tree so far.
> > I think it's easiest to stick to that.
> 
> Needs signed-off-by. :(

Feel free to add it:

Reviewed-by: Christoph Hellwig <hch@lst.de>
--
To unsubscribe from this list: send the line "unsubscribe linux-xfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Paul Menzel Sept. 11, 2017, 2:50 p.m. UTC | #7
Dear Christoph,


On 08/13/17 11:08, Christoph Hellwig wrote:

> I'm overdue doing another XFS stable backport batch, and I will
> include this patch.

If I am not mistaken, this has not been picked up yet for the stable series.

```
$ git tag --contains e28ae8e428fefe2facd72cea9f29906ecb9c861d
v4.13
v4.13-rc6
v4.13-rc7
v4.13.1
$ git log --grep e28ae8e428fefe2facd72cea9f29906ecb9c861d v4.9.48
$
```

Do you want me to submit it for inclusion?


Kind regards,

Paul
--
To unsubscribe from this list: send the line "unsubscribe linux-xfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/fs/iomap.c b/fs/iomap.c
index 039266128b7f..59cc98ad7577 100644
--- a/fs/iomap.c
+++ b/fs/iomap.c
@@ -278,7 +278,7 @@  iomap_dirty_actor(struct inode *inode, loff_t pos, loff_t length, void *data,
 		unsigned long bytes;	/* Bytes to write to page */
 
 		offset = (pos & (PAGE_SIZE - 1));
-		bytes = min_t(unsigned long, PAGE_SIZE - offset, length);
+		bytes = min_t(loff_t, PAGE_SIZE - offset, length);
 
 		rpage = __iomap_read_page(inode, pos);
 		if (IS_ERR(rpage))
@@ -373,7 +373,7 @@  iomap_zero_range_actor(struct inode *inode, loff_t pos, loff_t count,
 		unsigned offset, bytes;
 
 		offset = pos & (PAGE_SIZE - 1); /* Within page */
-		bytes = min_t(unsigned, PAGE_SIZE - offset, count);
+		bytes = min_t(loff_t, PAGE_SIZE - offset, count);
 
 		if (IS_DAX(inode))
 			status = iomap_dax_zero(pos, offset, bytes, iomap);