Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp3996102imm; Mon, 14 May 2018 00:40:01 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqDWm9jn+W2IEQbfzP3FhEKeOo5d4qjUmtJN5t7Lg5hAsCpAZKOyZNMHkh0z98tIAmimJtc X-Received: by 2002:a17:902:264:: with SMTP id 91-v6mr8668728plc.341.1526283601170; Mon, 14 May 2018 00:40:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526283601; cv=none; d=google.com; s=arc-20160816; b=Q2ntkwB42UeA1gmIYojXR7aa1E6aKlsJEdkEo4eRaMM/A+1YdmG2S0SGd40ocoFpJU mpYWo0Qoxr0tSJyYGIDi2aqLM1IYywk3e04vtmy9yJ6jnYAhj3WO7QZk3oVl8q0a2WET VnQLkFpVgc9xEgdkS6LXo5Rsb0yl/Uj4CbxCd5B+NUSmVhEJUqOhLEQeXx5//BtReD6m 1kUrDp6vWWsaCj1b5/xpbetkQIo9e8YmwNM9KxiDDnvNdyEFzAkjwYcMezE1sW5oiKKk iW9f/r7O2hylWpi3YSKi1yHwNiVZ7a9ovWJ9JvM2D8z1otl3Tbt2GFuElIN8SHHaI7nR grkQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=0xS1G9Z+cSJqol/Pxrb1BX4IP7/gH3yGa6chOtF3IFM=; b=QhWDkhvIbgx6VDHaQQNUUOTmNpA3qyCis+yp1sgEHbroNPpvQ3NtoiX/jjsqgl9YTM pHihQ3hTa4K4OdE6S7CArAm0xGbWoG+rv7jQaCv3mr8sbe+lg8mxOabzeZfxaGdbckC9 s6AmSDw2HvN4QAICCDgkUM2UJyRaHt4rfFP1oHt/RqHVtmFjgWxrNN+/JqBQ8NMPdwyN UJXyqg0Ox395OtoY1Bz4QQOP0pU1+YMQ01lIZqDAMsqQc3jRtrPd2qzRHNDHpTb6lzB2 Z19LgVkTlox9kUcUmFc9F0EA8yU7RCvQBGT2qdKM+V6NfK7QgavXc/5nfEm+9y3fE+iL 7s0Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=rLjPoB1Q; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w2-v6si9017046pll.40.2018.05.14.00.39.47; Mon, 14 May 2018 00:40:01 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=rLjPoB1Q; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752681AbeENGwa (ORCPT + 99 others); Mon, 14 May 2018 02:52:30 -0400 Received: from mail.kernel.org ([198.145.29.99]:58922 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752606AbeENGw1 (ORCPT ); Mon, 14 May 2018 02:52:27 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 9315620834; Mon, 14 May 2018 06:52:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1526280747; bh=1bbIaYQxoreW2NjB2zW47FO0KCOId8JPznHI4cby0ok=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rLjPoB1QqnmdnuomF7BXi+DsPrtyBsvQihP410AYz1SlM3rSinUrI1R88KyvQGQdf ucyRAsxK6ccANLu2sEdrAuv2ojmbs4a488nFACvE0QysCpTvPAwlkhZqH944kGQYv/ 1NBV1Bi1gwt/5Ud4SQO85u6Y4wzymFbzADxU4njM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Wei Fang , Chao Yu , Jaegeuk Kim , Guenter Roeck Subject: [PATCH 4.4 42/56] f2fs: fix a dead loop in f2fs_fiemap() Date: Mon, 14 May 2018 08:48:47 +0200 Message-Id: <20180514064758.657859681@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180514064754.853201981@linuxfoundation.org> References: <20180514064754.853201981@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: Wei Fang commit b86e33075ed1909d8002745b56ecf73b833db143 upstream. A dead loop can be triggered in f2fs_fiemap() using the test case as below: ... fd = open(); fallocate(fd, 0, 0, 4294967296); ioctl(fd, FS_IOC_FIEMAP, fiemap_buf); ... It's caused by an overflow in __get_data_block(): ... bh->b_size = map.m_len << inode->i_blkbits; ... map.m_len is an unsigned int, and bh->b_size is a size_t which is 64 bits on 64 bits archtecture, type conversion from an unsigned int to a size_t will result in an overflow. In the above-mentioned case, bh->b_size will be zero, and f2fs_fiemap() will call get_data_block() at block 0 again an again. Fix this by adding a force conversion before left shift. Signed-off-by: Wei Fang Acked-by: Chao Yu Signed-off-by: Jaegeuk Kim Cc: Guenter Roeck Signed-off-by: Greg Kroah-Hartman --- fs/f2fs/data.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/fs/f2fs/data.c +++ b/fs/f2fs/data.c @@ -721,7 +721,7 @@ static int __get_data_block(struct inode if (!ret) { map_bh(bh, inode->i_sb, map.m_pblk); bh->b_state = (bh->b_state & ~F2FS_MAP_FLAGS) | map.m_flags; - bh->b_size = map.m_len << inode->i_blkbits; + bh->b_size = (u64)map.m_len << inode->i_blkbits; } return ret; }