linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* fs: hfs: Possible issue with increment of extent
@ 2018-08-31 13:39 Colin Ian King
  2018-08-31 13:56 ` Al Viro
  0 siblings, 1 reply; 3+ messages in thread
From: Colin Ian King @ 2018-08-31 13:39 UTC (permalink / raw)
  To: linux-fsdevel, David Howells, Al Viro; +Cc: linux-kernel

Hi,

Static analysis has picked up a potential issue with an out of bounds
read in fs/hfs/extent.c; the following for-loop in  hfs_free_fork()
increments i and also extent while also reading extent[i].count.  This
looks incorrect to me, I think the increment of extent is not needed:

        for (i = 0; i < 3; extent++, i++)
                blocks += be16_to_cpu(extent[i].count);

        res = hfs_free_extents(sb, extent, blocks, blocks);

I'm not familiar enough with the code to conclude that removing the
increment of extent is necessary a correct fix just in case I'm missing
something subtle here.

This issue was picked up by static analysis with CoverityScan:

CID 711541 (#1 of 1): Out-of-bounds read:
Overrunning array of 3 4-byte elements at element index 4 (byte offset
16) by dereferencing pointer extent + i.

Colin

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: fs: hfs: Possible issue with increment of extent
  2018-08-31 13:39 fs: hfs: Possible issue with increment of extent Colin Ian King
@ 2018-08-31 13:56 ` Al Viro
  2018-08-31 13:56   ` Colin Ian King
  0 siblings, 1 reply; 3+ messages in thread
From: Al Viro @ 2018-08-31 13:56 UTC (permalink / raw)
  To: Colin Ian King; +Cc: linux-fsdevel, David Howells, linux-kernel

On Fri, Aug 31, 2018 at 02:39:11PM +0100, Colin Ian King wrote:
> Hi,
> 
> Static analysis has picked up a potential issue with an out of bounds
> read in fs/hfs/extent.c; the following for-loop in  hfs_free_fork()
> increments i and also extent while also reading extent[i].count.  This
> looks incorrect to me, I think the increment of extent is not needed:
> 
>         for (i = 0; i < 3; extent++, i++)
>                 blocks += be16_to_cpu(extent[i].count);
> 
>         res = hfs_free_extents(sb, extent, blocks, blocks);
> 
> I'm not familiar enough with the code to conclude that removing the
> increment of extent is necessary a correct fix just in case I'm missing
> something subtle here.

Goes back to commit d1081202f1d0 (in bk-to-git historical tree)
Author: Andrew Morton <akpm@osdl.org>
Date:   Wed Feb 25 16:17:36 2004 -0800

    [PATCH] HFS rewrite
    
    From: Roman Zippel <zippel@linux-m68k.org>

and it's almost certainly a bug in there, judging by the code nearby...

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: fs: hfs: Possible issue with increment of extent
  2018-08-31 13:56 ` Al Viro
@ 2018-08-31 13:56   ` Colin Ian King
  0 siblings, 0 replies; 3+ messages in thread
From: Colin Ian King @ 2018-08-31 13:56 UTC (permalink / raw)
  To: Al Viro; +Cc: linux-fsdevel, David Howells, linux-kernel

On 31/08/18 14:56, Al Viro wrote:
> On Fri, Aug 31, 2018 at 02:39:11PM +0100, Colin Ian King wrote:
>> Hi,
>>
>> Static analysis has picked up a potential issue with an out of bounds
>> read in fs/hfs/extent.c; the following for-loop in  hfs_free_fork()
>> increments i and also extent while also reading extent[i].count.  This
>> looks incorrect to me, I think the increment of extent is not needed:
>>
>>         for (i = 0; i < 3; extent++, i++)
>>                 blocks += be16_to_cpu(extent[i].count);
>>
>>         res = hfs_free_extents(sb, extent, blocks, blocks);
>>
>> I'm not familiar enough with the code to conclude that removing the
>> increment of extent is necessary a correct fix just in case I'm missing
>> something subtle here.
> 
> Goes back to commit d1081202f1d0 (in bk-to-git historical tree)
> Author: Andrew Morton <akpm@osdl.org>
> Date:   Wed Feb 25 16:17:36 2004 -0800
> 
>     [PATCH] HFS rewrite
>     
>     From: Roman Zippel <zippel@linux-m68k.org>
> 
> and it's almost certainly a bug in there, judging by the code nearby...
> 
OK, I'll send a fix then.

Colin

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-08-31 18:04 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-08-31 13:39 fs: hfs: Possible issue with increment of extent Colin Ian King
2018-08-31 13:56 ` Al Viro
2018-08-31 13:56   ` Colin Ian King

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).