Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp1688562ybz; Thu, 16 Apr 2020 13:44:02 -0700 (PDT) X-Google-Smtp-Source: APiQypI0YXfEelK8jjLi3hrIKXLQlV7gLzU7EoAWB0Ei3YDki3tVyY0jHIonWI67itNZQH+j3lff X-Received: by 2002:a17:906:16ce:: with SMTP id t14mr4010161ejd.366.1587069842542; Thu, 16 Apr 2020 13:44:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587069842; cv=none; d=google.com; s=arc-20160816; b=0lUvJutsKnaUJ4tDGq2tpZhQ3yXICFU9cI0w1I+ptxHTq5IkCRPKCyiWtBX3edCf/N rk1sIOmIhpnvt8wtpX8eqYI7i9ZAoCMntkfU/A14rfCVRMLkqMi3Y+wgA7TC9UrVXN23 FS1cmWIhiGunGUNLIbSZoVOzVNRoDfNGzWCZngzBlgM9eZCNr3jg4nZ2WglGtU8L6iF1 K/99kE5juvafg+RVGi5LJxtimwbsoXD/s7HWc0YxuB934x3Or436BOXy1tqUZnaCcAza hrZearyDWuPAbpOGsXydrmKYqjYZUTPWWZikPxK1r2reM8qlAGBW5PPAq9w95rf/lWBC a1bw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:content-transfer-encoding :mime-version:date:subject:cc:to:from; bh=clZmHwao39UBbRd2++rfSVCBToTgso9bN6VauWcAyE4=; b=W3jaFUnnfyFiJkfzIBfZC+OMYhX95t9vQZL0hIkE86QL2vob8n4LbodS4FiGqNv/Gs +56vbzgt4bMBBMnNvS52CZh2q2SCTkeWcNqIsGn/4nY8S5r9aQ35cGWfpPC5pRiPRtfY YIksDMVix+aheYJ3iLj45JkDApYodbC8Lxfl0PfK6I2GZvZxeUtev3lDcwFTgBTDwvmJ mbwXAeHNjMpvTD26Gw1vL4MJJ3dXQQiWGKeaXhxncgWWvkqIRj4Z6HQDKBGLwwiBYbC+ zh7/uQWC18+obDpuRx9qFgrDJdf7GRAjATcDL9FuP2tYubeAmCQxyiQx2Hm+l52kOPms pwcg== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t22si12174432edy.347.2020.04.16.13.43.38; Thu, 16 Apr 2020 13:44:02 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727834AbgDPSxA (ORCPT + 99 others); Thu, 16 Apr 2020 14:53:00 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:28822 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727796AbgDPSw7 (ORCPT ); Thu, 16 Apr 2020 14:52:59 -0400 Received: from pps.filterd (m0098409.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 03GIgYM9188549 for ; Thu, 16 Apr 2020 14:52:58 -0400 Received: from e06smtp02.uk.ibm.com (e06smtp02.uk.ibm.com [195.75.94.98]) by mx0a-001b2d01.pphosted.com with ESMTP id 30evvc88kh-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 16 Apr 2020 14:52:58 -0400 Received: from localhost by e06smtp02.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 16 Apr 2020 19:52:27 +0100 Received: from b06avi18878370.portsmouth.uk.ibm.com (9.149.26.194) by e06smtp02.uk.ibm.com (192.168.101.132) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Thu, 16 Apr 2020 19:52:23 +0100 Received: from d06av21.portsmouth.uk.ibm.com (d06av21.portsmouth.uk.ibm.com [9.149.105.232]) by b06avi18878370.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 03GIqpnS35586458 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 16 Apr 2020 18:52:51 GMT Received: from d06av21.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 5AE9D5204E; Thu, 16 Apr 2020 18:52:51 +0000 (GMT) Received: from localhost.localdomain.com (unknown [9.85.81.253]) by d06av21.portsmouth.uk.ibm.com (Postfix) with ESMTP id 226B45204F; Thu, 16 Apr 2020 18:52:48 +0000 (GMT) From: Ritesh Harjani To: linux-ext4@vger.kernel.org Cc: jack@suse.cz, tytso@mit.edu, adilger@dilger.ca, darrick.wong@oracle.com, hch@infradead.org, linux-fsdevel@vger.kernel.org, syzbot+77fa5bdb65cc39711820@syzkaller.appspotmail.com, syzkaller-bugs@googlegroups.com, Ritesh Harjani Subject: [PATCHv2 1/1] ext4: Fix overflow case for map.m_len in ext4_iomap_begin_* Date: Fri, 17 Apr 2020 00:22:43 +0530 X-Mailer: git-send-email 2.21.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 x-cbid: 20041618-0008-0000-0000-00000371E911 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 20041618-0009-0000-0000-00004A93A1F8 Message-Id: <1a2dc8f198e1225ddd40833de76b60c7ee20d22d.1587024137.git.riteshh@linux.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.138,18.0.676 definitions=2020-04-16_07:2020-04-14,2020-04-16 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 spamscore=0 malwarescore=0 clxscore=1015 bulkscore=0 phishscore=0 priorityscore=1501 mlxlogscore=906 mlxscore=0 lowpriorityscore=0 suspectscore=1 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2003020000 definitions=main-2004160129 Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org 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. Fixes: d3b6f23f7167 ("ext4: move ext4_fiemap to use iomap framework") Reported-and-tested-by: syzbot+77fa5bdb65cc39711820@syzkaller.appspotmail.com Reviewed-by: Jan Kara Signed-off-by: Ritesh Harjani --- @Jan, I retained your Reviewed by, since there was no logic change, but just couple of minor change - missed semicolon and tab space issue. fs/ext4/inode.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index e416096fc081..d9feaaad8ab8 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, - EXT4_MAX_LOGICAL_BLOCK) - map.m_lblk + 1; + 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, - EXT4_MAX_LOGICAL_BLOCK) - map.m_lblk + 1; + 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