Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp592461ybz; Wed, 15 Apr 2020 14:44:04 -0700 (PDT) X-Google-Smtp-Source: APiQypI/u+8YQUtLxZD1ClOeKsSVqDkHidWjc7RBfwh5v10tEl43iw+UEBMbd9oi4Nlhg7wul4z5 X-Received: by 2002:a05:6402:17aa:: with SMTP id j10mr25960449edy.146.1586987044720; Wed, 15 Apr 2020 14:44:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586987044; cv=none; d=google.com; s=arc-20160816; b=iiMlxezVzzCS2vL3D6TIKbHbm9kGJ8QwxU+vqk0b22BQvKp9zOgpooLVywWs/ReGsh tER1jcBufUR5qyew1Ts3DbCMWV+J40/Y0wycsbJDfkLM8V2mrEkbiTG7BAI4hNoLxHXW dOmQ1HAUvJdxBd0WGUELMkNwVgXLSA4khF3CiegbXPGA1Xkz48mila31HGVuemBzzKuF WuKAkKPBf1kKQ1PBPeHX723/6T3rkrwSQBcm676NcoXmWThJkeA4E9Pg3n+ktLDdrA5e VxwuezEw2eSyuOua7k0XpBar7DQW2/pdVp6REDjVm7Mdjt/1LaLG5XpvHbw4R9w88Hf3 745Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=wXMNEREi40WKOohcQaH/EzFHiUJOiFBfHxmz6nIme5U=; b=oyPo37oWw4PIXa+ZNw5o9nBdCW7pUdAXZ9ER+p5urc1KlJP6OBhU2G91t3ByBO/zjp Yxx0flIJH9QP88TMzsWTe7TCq7Pm63DDCiFaAjcUCOtizhdAYSSVCvrkWc2SSEqAfqzb l3ZzygQ8oW0h9M/w09I7OBJ8XvGsUWxPvBu20Y5q1o3TzRhTaWmpEeJmNlRQGjhzYFl8 L5udgSR1/QUth8Mu8S2596AV1UrKwF3RZCobt3jnP/2yMTm7aU9PhCrgGyThkvyPGpVk EUNMVuT70snpwM0pkt2ozJtKdrqxQ4ilFYbEPKeXbTbbSyUkwRrJiS1sPPGQYN2JGH7Q YMhg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bi10si12748635edb.465.2020.04.15.14.43.41; Wed, 15 Apr 2020 14:44:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732022AbgDNPu0 (ORCPT + 99 others); Tue, 14 Apr 2020 11:50:26 -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-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@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