Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp632830pxk; Sun, 30 Aug 2020 17:25:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw3GhhRKzS0FMXlZC+iiuO7jCahy6yr4RBmTyvHBHA1PEbImG8DOnyatvLdhHg23JO+yOBy X-Received: by 2002:aa7:d688:: with SMTP id d8mr9366431edr.168.1598833516038; Sun, 30 Aug 2020 17:25:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598833516; cv=none; d=google.com; s=arc-20160816; b=NMPVejK/IUnK6+aw+RA7uh3phxGTkHSZVWAD6woM3XZG88+2Dv7rdPyWpARLHYB5ur 5DsKXIjkhmAAWN6d16k2wKTPZGMcZYhHwzqiP31QQekGmyhWdpSntCIia4wRlBsMbD0j BqhjwiuJ9o0Klo0KYr6xuI3NBebsmIpLbYTUDd+cgvwAg8gr0GoY46sEfjQZQJn14/1X X8R/DbQ8tIf+RfrUuKley8jW0WkyPSTvmpNTErVYOO5rYzT2vXhNil3T3Egrm+uakPek 8VfNLDU6iCKUQkjsg7TYiP3a+Tw/SytFEXePA2tO1LQ8QcLLDm3cFW8tEuA3Jnc+ZoTs EbvQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=ZnfXYUbCB2BbWKqT6zdvNTUKiLkNrjoRnmWZrCX/fz8=; b=MENJEaW8R6WZJty8Plc6l5e3AzAsGcGp+kdv3GVQyKbv86sihdqEPB5ubBGGPdUAZb knn6WhMet+a1k3rdGfDIq/vkyIxqtoA4UuMc7uQxtKVTTzZy/wqWk2iIR1c36fut0n2r EyuTy9hJt6tI4qLr6cBhWesx3xPATDGIy5e/kjhBAVc6DBFuYhp4mjEQV1SIAx3bHNgM 53a/pfdm9k9Z2r7/YC/1b9dAUfPaV491Xy9CadvD0QOdrI9GMEXlSU+JIBau/cuihZ2Q WZwVdNDhwi7nKXBuBAHjjAZ/Bsz20B8SKgbcIaL+PEpzTj7h8omlnhkPPnBjumlSZknB ITng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=nftfqZ8D; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b23si4262311ejb.465.2020.08.30.17.24.53; Sun, 30 Aug 2020 17:25:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=nftfqZ8D; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726465AbgHaAYM (ORCPT + 99 others); Sun, 30 Aug 2020 20:24:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55612 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726179AbgHaAYL (ORCPT ); Sun, 30 Aug 2020 20:24:11 -0400 Received: from mail-pj1-x1041.google.com (mail-pj1-x1041.google.com [IPv6:2607:f8b0:4864:20::1041]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CEE7EC061573 for ; Sun, 30 Aug 2020 17:24:10 -0700 (PDT) Received: by mail-pj1-x1041.google.com with SMTP id 2so2215893pjx.5 for ; Sun, 30 Aug 2020 17:24:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=ZnfXYUbCB2BbWKqT6zdvNTUKiLkNrjoRnmWZrCX/fz8=; b=nftfqZ8DnVy4hFsXpIRjiH68UiYa/itmOgKxyJ8MtRpETwtiFJSTo0RhIvPObdIiY9 nDlO0/B9dtHyjgyLPWLM+2wCwsrBlZqGDjDp7PK1wIL/Npo5eUmrWKrMa/haOcTSEAVV 9F7DjOt8O93v4r+x69+HXwwjF2A9xW2S8RfWZadS3vBFgW5J2MkdvDrjyTVIFPaToAVp daKOR28aP1Xrh0JonpUVoTEPh6ZzEhyty1DB8lwKEgQ7uH0vjBMDORM6K5i/wvPOLQkA UNQcpiys4UE5avtviwdPsmiuXK/GpfQgFpB4CyNoBTRCF4zHkucKJHbfx5PnuODnzFBU Dj3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=ZnfXYUbCB2BbWKqT6zdvNTUKiLkNrjoRnmWZrCX/fz8=; b=Q2vSKk3XSwOsgqvQPFTOiyDu6+AhfanCjXDbvfip3iMIM/R54QoLFNeVV0JXEOYUua FCxk8UcRoGDKEmMNtQsIxw6Xt4t75BS/q/d64KkUJ5ZF7ysMFFGYU1n/tXph2ZA579zo YEmmOUN8kGdqXb7hxQCCNzD7oSRG1sNwghXCIOBai7E9CgMOx1fUSgm8Os3aXh8yF2Vt 2louyDxKc8QrluSuKeDo4+L4Xgcchpmb5Y6Pv50aTN5+GvQCmz6mAoo1xjP454a9LMFs lKbnbo6QwAPnGHWlsxf354zh55o0yzce0TGfzDeY3isBu5hyofPsaYTXDMUYICsdOUEF MVXQ== X-Gm-Message-State: AOAM530XKnuBRvH/qTPfjEeUM0IuItMBAhH9Ila0IZB6fcDRog7QACQ8 0BfTZ8+lFXpEFK9nx67ytJg/3Ci1IeI= X-Received: by 2002:a17:90a:eb17:: with SMTP id j23mr8148264pjz.151.1598833449671; Sun, 30 Aug 2020 17:24:09 -0700 (PDT) Received: from daehojeong1.seo.corp.google.com ([2401:fa00:d:1:a6ae:11ff:fe18:6ce2]) by smtp.gmail.com with ESMTPSA id r33sm5244826pgm.75.2020.08.30.17.24.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 30 Aug 2020 17:24:08 -0700 (PDT) From: Daeho Jeong To: linux-kernel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, kernel-team@android.com Cc: Daeho Jeong Subject: [PATCH] f2fs: add block address limit check to compressed file Date: Mon, 31 Aug 2020 09:24:01 +0900 Message-Id: <20200831002401.3159134-1-daeho43@gmail.com> X-Mailer: git-send-email 2.28.0.402.g5ffc5be6b7-goog MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Daeho Jeong Need to add block address range check to compressed file case and avoid calling get_data_block_bmap() for compressed file. Signed-off-by: Daeho Jeong --- fs/f2fs/data.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c index c1b676be67b9..48cab85205e2 100644 --- a/fs/f2fs/data.c +++ b/fs/f2fs/data.c @@ -1755,10 +1755,6 @@ static int get_data_block_dio(struct inode *inode, sector_t iblock, static int get_data_block_bmap(struct inode *inode, sector_t iblock, struct buffer_head *bh_result, int create) { - /* Block number less than F2FS MAX BLOCKS */ - if (unlikely(iblock >= F2FS_I_SB(inode)->max_file_blocks)) - return -EFBIG; - return __get_data_block(inode, iblock, bh_result, create, F2FS_GET_BLOCK_BMAP, NULL, NO_CHECK_TYPE, create); @@ -3753,11 +3749,16 @@ static sector_t f2fs_bmap(struct address_space *mapping, sector_t block) if (mapping_tagged(mapping, PAGECACHE_TAG_DIRTY)) filemap_write_and_wait(mapping); - if (f2fs_compressed_file(inode)) - blknr = f2fs_bmap_compress(inode, block); + /* Block number less than F2FS MAX BLOCKS */ + if (unlikely(block >= F2FS_I_SB(inode)->max_file_blocks)) + goto out; - if (!get_data_block_bmap(inode, block, &tmp, 0)) - blknr = tmp.b_blocknr; + if (f2fs_compressed_file(inode)) { + blknr = f2fs_bmap_compress(inode, block); + } else { + if (!get_data_block_bmap(inode, block, &tmp, 0)) + blknr = tmp.b_blocknr; + } out: trace_f2fs_bmap(inode, block, blknr); return blknr; -- 2.28.0.402.g5ffc5be6b7-goog