From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.2 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BBF77C2BB85 for ; Tue, 14 Apr 2020 15:50:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A3B90206D5 for ; Tue, 14 Apr 2020 15:50:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2440953AbgDNPuj (ORCPT ); Tue, 14 Apr 2020 11:50:39 -0400 Received: from mx2.suse.de ([195.135.220.15]:37980 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2440940AbgDNPuU (ORCPT ); Tue, 14 Apr 2020 11:50:20 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 15767ACBA; Tue, 14 Apr 2020 15:50:14 +0000 (UTC) Received: by quack2.suse.cz (Postfix, from userid 1000) id 983311E125F; Tue, 14 Apr 2020 17:50:13 +0200 (CEST) Date: Tue, 14 Apr 2020 17:50:13 +0200 From: Jan Kara To: Ritesh Harjani Cc: jack@suse.cz, tytso@mit.edu, linux-ext4@vger.kernel.org, adilger@dilger.ca, darrick.wong@oracle.com, hch@infradead.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-xfs@vger.kernel.org, willy@infradead.org, linux-unionfs@vger.kernel.org, syzbot+77fa5bdb65cc39711820@syzkaller.appspotmail.com Subject: Re: [RFC 1/1] ext4: Fix overflow case for map.m_len in ext4_iomap_begin_* Message-ID: <20200414155013.GF28226@quack2.suse.cz> References: <00000000000048518b05a2fef23a@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun 12-04-20 14:54:35, Ritesh Harjani wrote: > EXT4_MAX_LOGICAL_BLOCK - map.m_lblk + 1 in case when > map.m_lblk (offset) is 0 could overflow an unsigned int > and become 0. > > Fix this. > > Signed-off-by: Ritesh Harjani > Reported-by: syzbot+77fa5bdb65cc39711820@syzkaller.appspotmail.com > Fixes: d3b6f23f7167 ("ext4: move ext4_fiemap to use iomap framework") The patch looks good to me. You can add: Reviewed-by: Jan Kara Honza > --- > fs/ext4/inode.c | 12 ++++++++++-- > 1 file changed, 10 insertions(+), 2 deletions(-) > > diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c > index e416096fc081..d630ec7a9c8e 100644 > --- a/fs/ext4/inode.c > +++ b/fs/ext4/inode.c > @@ -3424,6 +3424,7 @@ static int ext4_iomap_begin(struct inode *inode, loff_t offset, loff_t length, > int ret; > struct ext4_map_blocks map; > u8 blkbits = inode->i_blkbits; > + loff_t len; > > if ((offset >> blkbits) > EXT4_MAX_LOGICAL_BLOCK) > return -EINVAL; > @@ -3435,8 +3436,11 @@ static int ext4_iomap_begin(struct inode *inode, loff_t offset, loff_t length, > * Calculate the first and last logical blocks respectively. > */ > map.m_lblk = offset >> blkbits; > - map.m_len = min_t(loff_t, (offset + length - 1) >> blkbits, > + len = min_t(loff_t, (offset + length - 1) >> blkbits, > EXT4_MAX_LOGICAL_BLOCK) - map.m_lblk + 1; > + if (len > EXT4_MAX_LOGICAL_BLOCK) > + len = EXT4_MAX_LOGICAL_BLOCK; > + map.m_len = len; > > if (flags & IOMAP_WRITE) > ret = ext4_iomap_alloc(inode, &map, flags); > @@ -3524,6 +3528,7 @@ static int ext4_iomap_begin_report(struct inode *inode, loff_t offset, > bool delalloc = false; > struct ext4_map_blocks map; > u8 blkbits = inode->i_blkbits; > + loff_t len > > if ((offset >> blkbits) > EXT4_MAX_LOGICAL_BLOCK) > return -EINVAL; > @@ -3541,8 +3546,11 @@ static int ext4_iomap_begin_report(struct inode *inode, loff_t offset, > * Calculate the first and last logical block respectively. > */ > map.m_lblk = offset >> blkbits; > - map.m_len = min_t(loff_t, (offset + length - 1) >> blkbits, > + len = min_t(loff_t, (offset + length - 1) >> blkbits, > EXT4_MAX_LOGICAL_BLOCK) - map.m_lblk + 1; > + if (len > EXT4_MAX_LOGICAL_BLOCK) > + len = EXT4_MAX_LOGICAL_BLOCK; > + map.m_len = len; > > /* > * Fiemap callers may call for offset beyond s_bitmap_maxbytes. > -- > 2.21.0 > -- Jan Kara SUSE Labs, CR