Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp4407687rdh; Wed, 29 Nov 2023 00:01:00 -0800 (PST) X-Google-Smtp-Source: AGHT+IFA4H/hwDFw6TlN4OgyZn9I3xR6PwEFcB9cNncX6mwW2iQPj0q7Z5qfr+FcA9R2SmRN8luP X-Received: by 2002:a17:902:d486:b0:1cf:c401:1d9d with SMTP id c6-20020a170902d48600b001cfc4011d9dmr11578801plg.19.1701244860431; Wed, 29 Nov 2023 00:01:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701244860; cv=none; d=google.com; s=arc-20160816; b=tirWiagYG/obJg911ufiXN7dUoP3iVfuJB8X6V5DnS7xZj91vWu9+3u+kfAO08PCZP fNpODz5oUzixQYrUpQP5O8NHyFzpBqDGDFVJTXeBIJLRVMjoh8MDrPGbpZ5UFpfAmWU4 BtORV20KDgNt4RWYBvv8DKAGyAs7ir1eAESFKiCda5YNTwyRbZ8/YZ6ZOVyV/W5lVR7d 7yU4qgkBQbeBosyMPL7Zqvwk01QAWICLomeezAmdfZje/lFmpxMChF2GY4Zc3jRyJ7fg 51krWhVp66vUYQjTrMosCokbKWeU2Lws+46H+vmMF6yZJ+uEDHiE94bsqpOn5yNg9eOw WjTg== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=78NIK428pGiojxSDNWuMJ5fRqtEcCx+gV7bFdG2Ovq8=; fh=AyKu18uwDNlEjoOFEACGueJdASNLajl0I2giTYqopdo=; b=MTue0so3EGrdReAU31lBVpWAUwiFKd2/7NkBXZJxlyTJFUo2O3OGT58W/aJ+T6EU/8 ao6mPHZOjpAPP175IpCGRpZdDTSR6+g79USnGhG1phAPVH5XzQSZS6MPKg6DRKilCwDv cm8tWAF/0RGGANTRLw1q8oJe9d2RuckZmv1ZkTTBUV1t1+ZDjThMVwB/pwwQHsgOl9kV Tto8x/V0wO5pWoHqkFtl/twKc2KLevLfbDvsKBW/MPbGtDhTSViKZTG5TGbU6rO414hL C3wExCptju5Lli+yar1JIzYS0ckvhyVGSTEkZIp8pFHINUGGkNqoFrAuGHnp2weuySBn oMNA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=Oz13soOz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.com Return-Path: Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id d12-20020a170902654c00b001cc2f285b1bsi14191828pln.171.2023.11.29.00.00.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Nov 2023 00:01:00 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=Oz13soOz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 1600B807BEC2; Wed, 29 Nov 2023 00:00:17 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229991AbjK2IAA (ORCPT + 99 others); Wed, 29 Nov 2023 03:00:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55108 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230017AbjK2H75 (ORCPT ); Wed, 29 Nov 2023 02:59:57 -0500 Received: from mail-pl1-x633.google.com (mail-pl1-x633.google.com [IPv6:2607:f8b0:4864:20::633]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2047D19BD for ; Tue, 28 Nov 2023 23:59:40 -0800 (PST) Received: by mail-pl1-x633.google.com with SMTP id d9443c01a7336-1cf8e569c35so43101485ad.0 for ; Tue, 28 Nov 2023 23:59:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1701244779; x=1701849579; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=78NIK428pGiojxSDNWuMJ5fRqtEcCx+gV7bFdG2Ovq8=; b=Oz13soOzsu6BHrc4+0u8Jjs6cj1lFEupiVtcNlaEuJxlneeI3NdrWvXA5QCOo5TIVp Tv46PBCTX/i+zGfYsUSfGZ547snaTTtMr3RnNSKfo6hqERJkZYW0Zgt4dFeo9qBGVeym fQha9NE/YyGLCCQnfeaD5jb6/RX6pkOKQRyXRCwSW41EFMJlbSOtw/oPNuBJbP67hAij q3WhTBERAmWxrb4Bgq8klNw+XQb3UgUnxiFyAidLqR9xLMTaZ4hmenOBMxdUIUT+3e0y /Ny11Talta+e6fQPtZZIyyYQAUyw+drRi7UgRtIzYcp46TEI5sLE7tMAH/C7AHFLdUG7 LTyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701244779; x=1701849579; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=78NIK428pGiojxSDNWuMJ5fRqtEcCx+gV7bFdG2Ovq8=; b=QcxpGih26nTlEo3IfAFx12ZEzD/yab2+IgOjU3nH4ABM/11W3naciYaEs2wjXeK27k ZuADOjneotXyx3OIB08SLLWgyfDP2cwhgf+Vh9+PsHJBL7hxTWyPIKi9KK66JXzVEmd4 VRk2sU1yFdyNOpKBcrq6G/PJu8n6IjIn0S4l1gxGBtYShgaH6UW/wAGDg5FAWxW5bBPf EbtcVscgdyUN1sQeI4Qy2hdtHCV8yEp5OgY4Lk9HClMfKOe5SaAJuUQdsHznK8uRlK9H BVkaaF5EVnYcfhaMZ0afYn0C5Qg9PfYCvjTN1DtSgIyS39chccgSbXLmRv5iSJ0O9Ei5 DkRw== X-Gm-Message-State: AOJu0YxsSz1FoKYrLl084kBYNgnwLp0olHJ9gm/sJq7UKAgrp8PlUthI 7v6yhAORyQwjcpdJkCzvyUCC+w== X-Received: by 2002:a17:903:48c:b0:1cf:b3ed:817 with SMTP id jj12-20020a170903048c00b001cfb3ed0817mr13667907plb.20.1701244779597; Tue, 28 Nov 2023 23:59:39 -0800 (PST) Received: from localhost.localdomain ([61.213.176.9]) by smtp.gmail.com with ESMTPSA id s17-20020a170902989100b001cfd0ddc5d3sm4979419plp.277.2023.11.28.23.59.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Nov 2023 23:59:39 -0800 (PST) From: Jiachen Zhang To: Chandan Babu R , "Darrick J. Wong" Cc: Dave Chinner , Allison Henderson , Zhang Tianci , Brian Foster , Ben Myers , linux-xfs@vger.kernel.org, linux-kernel@vger.kernel.org, xieyongji@bytedance.com, me@jcix.top, Jiachen Zhang , Christoph Hellwig Subject: [PATCH v2 1/2] xfs: ensure logflagsp is initialized in xfs_bmap_del_extent_real Date: Wed, 29 Nov 2023 15:58:31 +0800 Message-Id: <20231129075832.73600-2-zhangjiachen.jaycee@bytedance.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20231129075832.73600-1-zhangjiachen.jaycee@bytedance.com> References: <20231129075832.73600-1-zhangjiachen.jaycee@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Wed, 29 Nov 2023 00:00:17 -0800 (PST) In the case of returning -ENOSPC, ensure logflagsp is initialized by 0. Otherwise the caller __xfs_bunmapi will set uninitialized illegal tmp_logflags value into xfs log, which might cause unpredictable error in the log recovery procedure. Also, remove the flags variable and set the *logflagsp directly, so that the code should be more robust in the long run. Fixes: 1b24b633aafe ("xfs: move some more code into xfs_bmap_del_extent_real") Signed-off-by: Jiachen Zhang Reviewed-by: Christoph Hellwig --- fs/xfs/libxfs/xfs_bmap.c | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c index be62acffad6c..9435bd6c950b 100644 --- a/fs/xfs/libxfs/xfs_bmap.c +++ b/fs/xfs/libxfs/xfs_bmap.c @@ -5010,7 +5010,6 @@ xfs_bmap_del_extent_real( xfs_fileoff_t del_endoff; /* first offset past del */ int do_fx; /* free extent at end of routine */ int error; /* error return value */ - int flags = 0;/* inode logging flags */ struct xfs_bmbt_irec got; /* current extent entry */ xfs_fileoff_t got_endoff; /* first offset past got */ int i; /* temp state */ @@ -5023,6 +5022,8 @@ xfs_bmap_del_extent_real( uint32_t state = xfs_bmap_fork_to_state(whichfork); struct xfs_bmbt_irec old; + *logflagsp = 0; + mp = ip->i_mount; XFS_STATS_INC(mp, xs_del_exlist); @@ -5048,10 +5049,12 @@ xfs_bmap_del_extent_real( if (tp->t_blk_res == 0 && ifp->if_format == XFS_DINODE_FMT_EXTENTS && ifp->if_nextents >= XFS_IFORK_MAXEXT(ip, whichfork) && - del->br_startoff > got.br_startoff && del_endoff < got_endoff) - return -ENOSPC; + del->br_startoff > got.br_startoff && del_endoff < got_endoff) { + error = -ENOSPC; + goto done; + } - flags = XFS_ILOG_CORE; + *logflagsp = XFS_ILOG_CORE; if (whichfork == XFS_DATA_FORK && XFS_IS_REALTIME_INODE(ip)) { if (!(bflags & XFS_BMAPI_REMAP)) { error = xfs_rtfree_blocks(tp, del->br_startblock, @@ -5093,9 +5096,9 @@ xfs_bmap_del_extent_real( xfs_iext_prev(ifp, icur); ifp->if_nextents--; - flags |= XFS_ILOG_CORE; + *logflagsp |= XFS_ILOG_CORE; if (!cur) { - flags |= xfs_ilog_fext(whichfork); + *logflagsp |= xfs_ilog_fext(whichfork); break; } if ((error = xfs_btree_delete(cur, &i))) @@ -5114,7 +5117,7 @@ xfs_bmap_del_extent_real( got.br_blockcount -= del->br_blockcount; xfs_iext_update_extent(ip, state, icur, &got); if (!cur) { - flags |= xfs_ilog_fext(whichfork); + *logflagsp |= xfs_ilog_fext(whichfork); break; } error = xfs_bmbt_update(cur, &got); @@ -5128,7 +5131,7 @@ xfs_bmap_del_extent_real( got.br_blockcount -= del->br_blockcount; xfs_iext_update_extent(ip, state, icur, &got); if (!cur) { - flags |= xfs_ilog_fext(whichfork); + *logflagsp |= xfs_ilog_fext(whichfork); break; } error = xfs_bmbt_update(cur, &got); @@ -5150,7 +5153,7 @@ xfs_bmap_del_extent_real( new.br_state = got.br_state; new.br_startblock = del_endblock; - flags |= XFS_ILOG_CORE; + *logflagsp |= XFS_ILOG_CORE; if (cur) { error = xfs_bmbt_update(cur, &got); if (error) @@ -5191,7 +5194,7 @@ xfs_bmap_del_extent_real( * to the original value. */ xfs_iext_update_extent(ip, state, icur, &old); - flags = 0; + *logflagsp = 0; error = -ENOSPC; goto done; } @@ -5200,7 +5203,7 @@ xfs_bmap_del_extent_real( goto done; } } else - flags |= xfs_ilog_fext(whichfork); + *logflagsp |= xfs_ilog_fext(whichfork); ifp->if_nextents++; xfs_iext_next(ifp, icur); @@ -5240,7 +5243,6 @@ xfs_bmap_del_extent_real( xfs_trans_mod_dquot_byino(tp, ip, qfield, (long)-nblks); done: - *logflagsp = flags; return error; } -- 2.20.1