Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp958078pxb; Wed, 6 Apr 2022 05:18:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzod5fD9D3sJM0+TxrOuJqLlgAPHt7j+zd25QSiAF/ua4RlPVOfBrwFNgppJPJZd3Icbq1r X-Received: by 2002:a17:902:b40c:b0:156:b616:e257 with SMTP id x12-20020a170902b40c00b00156b616e257mr8220504plr.44.1649247525934; Wed, 06 Apr 2022 05:18:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649247525; cv=none; d=google.com; s=arc-20160816; b=Q21bcfzLon8sWwjbKVtjowZpJH87TwGW75afSO9AYs1mHdMoMB8si64BXbvKcxpkeA tKiI4YI1V0ckq4Vifk1qwbw7VSe6Y+BnXyJuZkgTqXMgI1TO9ct/Hk4vX48dILpIVn7G K29YaWYV+Y279jh/zy5fbKjPB0zOLkrznDwqsOV2NbUeDxTyzB8OOi/dg0yeNQN8IDYk Eis9ktLVDgGu9zkOFJEeVcazCs6W4SUiBkPLjE6UgQpXNHQO46N4pJhEdj7zGQlQzgHp rCM+AeCWybvSg547LIRF1cgYrZrGUdoKBANeCPMLFVO5N67aSW94LKCQEIrrpIKXG3U9 7xzQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=jRVJPtciZTy1ZLTRJkofZxFk8WJXum0VUaEsFfAIv/s=; b=QCPKC9vdPRf5bkXIjrIp+gTGIaJCT7Feyc2dVfQJCuJ/Q86zH5bklBrvdr5n5qhgy7 1bmDImWVuJKaH4ySvbkEBjeOmMlrA6Yabc8RHVDn4NYrqurUhU16MYIFBV10G8lRG0ea doQIY+iYGt494PUu/8evlYfmSoRlihjWfCj2E/YgCzrKNta91gdl6i0tfBG5c9NZFUs3 kq0zWc1b7L9JOI7bRsWMGjCiHd/cr1CU/uCi+SfzO349ojOcsDRcDVKGyNePgdHuqFMO cw/DlZw5AijEO60EWoDp8Qz+4XE4acJ2zHnyBp2A2QcTlYEBPsxXCoeoLBthgmio98hq vi5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=18qnlSS1; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id j1-20020aa78001000000b004fa852292b0si13664896pfi.308.2022.04.06.05.18.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Apr 2022 05:18:45 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=18qnlSS1; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 1FE342EC4DA; Wed, 6 Apr 2022 04:03:36 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353774AbiDEVYg (ORCPT + 99 others); Tue, 5 Apr 2022 17:24:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50648 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1356667AbiDEKYq (ORCPT ); Tue, 5 Apr 2022 06:24:46 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D14C7BF011; Tue, 5 Apr 2022 03:08:46 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 768ACB81C89; Tue, 5 Apr 2022 10:08:45 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B2E85C385A1; Tue, 5 Apr 2022 10:08:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649153324; bh=oWjfkRKzdp9mkQs+OY5JSRZxx+ONjc0DhU87xVvfLdg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=18qnlSS1hUD+jek0NA/auAu9cm1DjKV71LXCLSQ85Q40XVcIQDEZzaPnEeCSE4LW+ m9JziCcCgxeZ3utFtI0pi2+sJL2mLQk6sF4tbjHf/n6aBWF0Ch/Gtpc+y8Ka78UHzZ lEhF9ljR2D9rGv02c2Ca/iyk3StTGJsMHCSIJRXA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Filipe Manana , David Sterba , Sasha Levin Subject: [PATCH 5.10 182/599] btrfs: fix unexpected error path when reflinking an inline extent Date: Tue, 5 Apr 2022 09:27:56 +0200 Message-Id: <20220405070304.257272051@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220405070258.802373272@linuxfoundation.org> References: <20220405070258.802373272@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Filipe Manana [ Upstream commit 1f4613cdbe7739ce291554b316bff8e551383389 ] When reflinking an inline extent, we assert that its file offset is 0 and that its uncompressed length is not greater than the sector size. We then return an error if one of those conditions is not satisfied. However we use a return statement, which results in returning from btrfs_clone() without freeing the path and buffer that were allocated before, as well as not clearing the flag BTRFS_INODE_NO_DELALLOC_FLUSH for the destination inode. Fix that by jumping to the 'out' label instead, and also add a WARN_ON() for each condition so that in case assertions are disabled, we get to known which of the unexpected conditions triggered the error. Fixes: a61e1e0df9f321 ("Btrfs: simplify inline extent handling when doing reflinks") Signed-off-by: Filipe Manana Signed-off-by: David Sterba Signed-off-by: Sasha Levin --- fs/btrfs/reflink.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/fs/btrfs/reflink.c b/fs/btrfs/reflink.c index 3a3102bc15a0..4b3ae0faf548 100644 --- a/fs/btrfs/reflink.c +++ b/fs/btrfs/reflink.c @@ -503,8 +503,11 @@ static int btrfs_clone(struct inode *src, struct inode *inode, */ ASSERT(key.offset == 0); ASSERT(datal <= fs_info->sectorsize); - if (key.offset != 0 || datal > fs_info->sectorsize) - return -EUCLEAN; + if (WARN_ON(key.offset != 0) || + WARN_ON(datal > fs_info->sectorsize)) { + ret = -EUCLEAN; + goto out; + } ret = clone_copy_inline_extent(inode, path, &new_key, drop_start, datal, size, -- 2.34.1