linux-f2fs-devel.lists.sourceforge.net archive mirror
 help / color / mirror / Atom feed
* [PATCH] f2fs: fix potential overflow in build_sit_info
@ 2017-08-09 10:09 Chao Yu
  2017-08-09 10:23 ` Chao Yu
  0 siblings, 1 reply; 2+ messages in thread
From: Chao Yu @ 2017-08-09 10:09 UTC (permalink / raw)
  To: jaegeuk; +Cc: linux-f2fs-devel, linux-kernel, chao, Chao Yu

On a 32-bit system, below calculation may overflow the 32-bit unsigned
integer, allocating a buffer size that smaller than needed. A write on
the buffer will then trigger an out of boundary write.
1. MAIN_SEGS(sbi) * sizeof(struct seg_entry)
2. MAIN_SECS(sbi) * sizeof(struct sec_entry)

Fixes this by doing type cast before calculating.

This patch fixes CVE-2017-10662.

Signed-off-by: Chao Yu <yuchao0@huawei.com>
---
 fs/f2fs/segment.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c
index 682ae68b9ef7..947674b5f466 100644
--- a/fs/f2fs/segment.c
+++ b/fs/f2fs/segment.c
@@ -2997,8 +2997,9 @@ static int build_sit_info(struct f2fs_sb_info *sbi)
 
 	SM_I(sbi)->sit_info = sit_i;
 
-	sit_i->sentries = kvzalloc(MAIN_SEGS(sbi) *
-					sizeof(struct seg_entry), GFP_KERNEL);
+	sit_i->sentries = kvzalloc((unsigned long long)MAIN_SEGS(sbi) *
+				(unsigned long long)sizeof(struct seg_entry),
+				GFP_KERNEL);
 	if (!sit_i->sentries)
 		return -ENOMEM;
 
@@ -3036,8 +3037,10 @@ static int build_sit_info(struct f2fs_sb_info *sbi)
 		return -ENOMEM;
 
 	if (sbi->segs_per_sec > 1) {
-		sit_i->sec_entries = kvzalloc(MAIN_SECS(sbi) *
-					sizeof(struct sec_entry), GFP_KERNEL);
+		sit_i->sec_entries = kvzalloc(
+				(unsigned long long)MAIN_SECS(sbi) *
+				(unsigned long long)sizeof(struct sec_entry),
+				GFP_KERNEL);
 		if (!sit_i->sec_entries)
 			return -ENOMEM;
 	}
-- 
2.13.1.388.g69e6b9b4f4a9

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

* Re: [PATCH] f2fs: fix potential overflow in build_sit_info
  2017-08-09 10:09 [PATCH] f2fs: fix potential overflow in build_sit_info Chao Yu
@ 2017-08-09 10:23 ` Chao Yu
  0 siblings, 0 replies; 2+ messages in thread
From: Chao Yu @ 2017-08-09 10:23 UTC (permalink / raw)
  To: jaegeuk; +Cc: linux-f2fs-devel, linux-kernel, chao

Sorry, please ignore this patch. :(

Thanks,

On 2017/8/9 18:09, Chao Yu wrote:
> On a 32-bit system, below calculation may overflow the 32-bit unsigned
> integer, allocating a buffer size that smaller than needed. A write on
> the buffer will then trigger an out of boundary write.
> 1. MAIN_SEGS(sbi) * sizeof(struct seg_entry)
> 2. MAIN_SECS(sbi) * sizeof(struct sec_entry)
> 
> Fixes this by doing type cast before calculating.
> 
> This patch fixes CVE-2017-10662.
> 
> Signed-off-by: Chao Yu <yuchao0@huawei.com>
> ---
>  fs/f2fs/segment.c | 11 +++++++----
>  1 file changed, 7 insertions(+), 4 deletions(-)
> 
> diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c
> index 682ae68b9ef7..947674b5f466 100644
> --- a/fs/f2fs/segment.c
> +++ b/fs/f2fs/segment.c
> @@ -2997,8 +2997,9 @@ static int build_sit_info(struct f2fs_sb_info *sbi)
>  
>  	SM_I(sbi)->sit_info = sit_i;
>  
> -	sit_i->sentries = kvzalloc(MAIN_SEGS(sbi) *
> -					sizeof(struct seg_entry), GFP_KERNEL);
> +	sit_i->sentries = kvzalloc((unsigned long long)MAIN_SEGS(sbi) *
> +				(unsigned long long)sizeof(struct seg_entry),
> +				GFP_KERNEL);
>  	if (!sit_i->sentries)
>  		return -ENOMEM;
>  
> @@ -3036,8 +3037,10 @@ static int build_sit_info(struct f2fs_sb_info *sbi)
>  		return -ENOMEM;
>  
>  	if (sbi->segs_per_sec > 1) {
> -		sit_i->sec_entries = kvzalloc(MAIN_SECS(sbi) *
> -					sizeof(struct sec_entry), GFP_KERNEL);
> +		sit_i->sec_entries = kvzalloc(
> +				(unsigned long long)MAIN_SECS(sbi) *
> +				(unsigned long long)sizeof(struct sec_entry),
> +				GFP_KERNEL);
>  		if (!sit_i->sec_entries)
>  			return -ENOMEM;
>  	}
> 

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

end of thread, other threads:[~2017-08-09 10:23 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-08-09 10:09 [PATCH] f2fs: fix potential overflow in build_sit_info Chao Yu
2017-08-09 10:23 ` Chao Yu

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