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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id AEEBEC10F1A for ; Thu, 9 May 2024 15:16:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 39D616B0085; Thu, 9 May 2024 11:16:44 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 34AD16B0087; Thu, 9 May 2024 11:16:44 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2389A6B008A; Thu, 9 May 2024 11:16:44 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 057566B0085 for ; Thu, 9 May 2024 11:16:43 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id A9126141624 for ; Thu, 9 May 2024 15:16:43 +0000 (UTC) X-FDA: 82099209486.20.FD481B6 Received: from out-174.mta1.migadu.com (out-174.mta1.migadu.com [95.215.58.174]) by imf16.hostedemail.com (Postfix) with ESMTP id B862F18000F for ; Thu, 9 May 2024 15:16:41 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=tKoN2z+0; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf16.hostedemail.com: domain of luis.henriques@linux.dev designates 95.215.58.174 as permitted sender) smtp.mailfrom=luis.henriques@linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1715267802; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=WuV7M9mHf7zLGoXyvtH3Is1VnuTrzUZ1N2ISvLJru+k=; b=4cI6cFag5nUd9PdxtR2Ve++rhJSEYeic7SB2dfkI33QSjCVUGDOJnuO5lxRsRtgocJxMaQ MsjrZhSYYG10Cm1NSa1uNeyPpaw5dku8QlmwbC8BRfMO3owybcuIRGINTmxhbIHV3w2XFo xwE/jef0ioR/22p/AP42rmwkVjmz8fA= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1715267802; a=rsa-sha256; cv=none; b=V24lawIh2TiKUo0i9MYespr9eCoCMUBrxeirpIV6B/7eONbmIaPQeQf2JOEvfjy+5M9Jkd QnCw00/SEISvuKn+xM6eb7gFaz0pggx1b4tnV9FEJlwuv8TcUI0aJiEdyOr4sYce12bjGA pE4/BWSxpNn7xgUixZww5tSjPpi0ETA= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=tKoN2z+0; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf16.hostedemail.com: domain of luis.henriques@linux.dev designates 95.215.58.174 as permitted sender) smtp.mailfrom=luis.henriques@linux.dev X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1715267799; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=WuV7M9mHf7zLGoXyvtH3Is1VnuTrzUZ1N2ISvLJru+k=; b=tKoN2z+02HEGPxaMBMX19ZneYgaEWjlQx1yjDRa+5EtNM+Tk4h+QyONWXsiZlzBqwIkM0v y02jbP0F9WK/J4dQxTDaCsJa9HxkYxUlN07D+ppV/DoxZeEABmqSngg/D+YBoNgF7iuP38 uWCX/WykcZyS911GVQsXeGumCrHpsR8= From: Luis Henriques To: Zhang Yi Cc: linux-ext4@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, tytso@mit.edu, adilger.kernel@dilger.ca, jack@suse.cz, ritesh.list@gmail.com, hch@infradead.org, djwong@kernel.org, willy@infradead.org, zokeefe@google.com, yi.zhang@huawei.com, chengzhihao1@huawei.com, yukuai3@huawei.com, wangkefeng.wang@huawei.com Subject: Re: [PATCH v3 03/26] ext4: correct the hole length returned by ext4_map_blocks() In-Reply-To: <20240127015825.1608160-4-yi.zhang@huaweicloud.com> (Zhang Yi's message of "Sat, 27 Jan 2024 09:58:02 +0800") References: <20240127015825.1608160-1-yi.zhang@huaweicloud.com> <20240127015825.1608160-4-yi.zhang@huaweicloud.com> Date: Thu, 09 May 2024 16:16:34 +0100 Message-ID: <87zfszuib1.fsf@brahms.olymp> MIME-Version: 1.0 Content-Type: text/plain X-Migadu-Flow: FLOW_OUT X-Rspamd-Queue-Id: B862F18000F X-Rspam-User: X-Rspamd-Server: rspam03 X-Stat-Signature: ug1y58fewxnj1iunduuzi54ta9shfekr X-HE-Tag: 1715267801-5393 X-HE-Meta: U2FsdGVkX1+nDgBa1Pi21NWdhxVNsq3fVAeKcjt6+3lfCck1sFRn+eS9nj98wVjojjr5ExlwY9YckDEPawCJDRhKFkXRGauXWB5HnhYGVET3DiL8i69wXja3fxueSc1Eox3xGbaTGI9B71OADWAnWulgLH8PRitP0g06iUjgWYEcX9HrBoH8DTsKawX7zrtMyYATH0mPGb7BFnIv8Fv0Qlg9wh1+ei1p57eJtEN37c8hTbd2DhkaQyh1B62Cp6dKwYBvJQwohlBJXfReFBGY681DpQYstL/iRvDk/KyDTAR1VZ0NiHYJIAgIzpNhB7GnqgD7Fue3cm/xoLMHfjPNJYgmieVRlWI6Arnng2ZUjoGxqm1DERns2A5/XKSuwXt9eClE9BJSnMogdf5mQOgK35VbAbzRbsDvuLQ7RB9vvgOsBZsf6gq5lZ/KMKR/+2meDIwdHk1kriDurlz2P4codZfpa0cp67KEbN9bYd2RLRqNTftEeZzhG7W80nCyPgZX4EUw4bvod3zs31eMEf03msAKgX2IKkeihV7PdYFLmdDMlIuXcfdBxM6TAGc2cXozUnFQsqVe1pHWvrt6zvJ3p2OVzDnLJFALmdcMIYe/E4T/93hGjZQlnPDX83Hu1m1lAepL8mk56X8R3krCSgxHvZB7OmMUXul9wg4Y/J9xBCLMPXpMMMB5NTop87jxtvUXPBKNthnlfVdh/HYjN/wsau7XLAbTjr4GJLc7Vi9nKtjSX/ola49MUP0oKeoN23MKCHrfhgkuMHi96yXYweYzk8eisDUPdEya4JLAVkS09+aaenaL341wX+Io8N8VBmVvksatobqGfw2mbgmPp6wwEUeZemLiIgSt34vhl1bmBEjNJs+qJdsNESLK7r94Oi3C/fypuoNnxD8pIepLf2oADQ9kJhcx3HILEmLKDm/DCKSEap9FdiXfqRORALTyGKiWSeQZGjP6DNaCkzswE80 RAgUWglr mEMqYHsokvNJ42AnCMdKvLWDMCQgnmFIdU2nPhHqVczjL6h7InIqej3mx9kkA1ebhJrkqlZxrv4q1oj0v8kTMxmoJRKSVXh16aq7mNcT86/eibjD1nMrx2Rs7SA== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Sat 27 Jan 2024 09:58:02 AM +08, Zhang Yi wrote; <...> > +static ext4_lblk_t ext4_ext_determine_insert_hole(struct inode *inode, > + struct ext4_ext_path *path, > + ext4_lblk_t lblk) > +{ > + ext4_lblk_t hole_start, len; > + struct extent_status es; > + > + hole_start = lblk; > + len = ext4_ext_find_hole(inode, path, &hole_start); > +again: > + ext4_es_find_extent_range(inode, &ext4_es_is_delayed, hole_start, > + hole_start + len - 1, &es); > + if (!es.es_len) > + goto insert_hole; > + > + /* > + * There's a delalloc extent in the hole, handle it if the delalloc > + * extent is in front of, behind and straddle the queried range. > + */ > + if (lblk >= es.es_lblk + es.es_len) { > + /* > + * The delalloc extent is in front of the queried range, > + * find again from the queried start block. > + */ > + len -= lblk - hole_start; > + hole_start = lblk; > + goto again; It's looks like it's easy to trigger an infinite loop here using fstest generic/039. If I understand it correctly (which doesn't happen as often as I'd like), this is due to an integer overflow in the 'if' condition, and should be fixed with the patch below. >From 3117af2f8dacad37a2722850421f31075ae9e88d Mon Sep 17 00:00:00 2001 From: "Luis Henriques (SUSE)" Date: Thu, 9 May 2024 15:53:01 +0100 Subject: [PATCH] ext4: fix infinite loop caused by integer overflow An integer overflow will happen if the extent_status len is set to EXT_MAX_BLOCKS (0xffffffff). This may cause an infinite loop in function ext4_ext_determine_insert_hole(), easily reproducible using fstest generic/039. Fixes: 6430dea07e85 ("ext4: correct the hole length returned by ext4_map_blocks()") Signed-off-by: Luis Henriques (SUSE) --- fs/ext4/extents.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c index e57054bdc5fd..193121b394f9 100644 --- a/fs/ext4/extents.c +++ b/fs/ext4/extents.c @@ -4064,7 +4064,7 @@ static ext4_lblk_t ext4_ext_determine_insert_hole(struct inode *inode, * There's a delalloc extent in the hole, handle it if the delalloc * extent is in front of, behind and straddle the queried range. */ - if (lblk >= es.es_lblk + es.es_len) { + if (lblk >= ((__u64) es.es_lblk) + es.es_len) { /* * The delalloc extent is in front of the queried range, * find again from the queried start block.