Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1147149pxb; Thu, 4 Mar 2021 04:42:40 -0800 (PST) X-Google-Smtp-Source: ABdhPJwbHJ4MaHQbxUadGXN/ijlF4nf6ALB9xJjxZeqrI6t41I4nWFfbZ8XGdNPU+46UMRyn3nxV X-Received: by 2002:aa7:d511:: with SMTP id y17mr4069987edq.275.1614861759824; Thu, 04 Mar 2021 04:42:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614861759; cv=none; d=google.com; s=arc-20160816; b=PG6gWEHNY/flIoQjHjWb2masOzRqH7FEErSbM72fDnCuazGizWiVGsFXyP4FysENC9 hgAhf4CbF1J0KGhyA6GkGoBtU/sLqWFmBC2iFawIv40wrTumlCO6tFxWVwef2+Tm6zVw 9+7TeITtZoSJl0FjG7Tts+xlo+GUqnHgC+z46w/EMJFw20QjWDfV2vpJ1gEgEuuJ2a1s VRGkPXNN2DZnjUFfoSmpywtJINL+gGEI38Lj+zvdl9LeBn0uk0mldhdAnRlalO3zOhmU QwbKtJbXscWtXfmhD9bhOJg9ikZmhEG35scjDE3114RPHuLbR/tr9txvdi2RLao8VDAX 3BCA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=71DyLj2mo/SPRrenwGHRYb5z7tKhIfuc1ypDgqFmxHQ=; b=SKLy9BdiUB41FyhQBBAKK+BQH1+6K1j5ib6QippBQmhUWXKbDLarXqA90QIgwUtATY dbSdPSGcRZK4YaVvU90OWi1S8lGKvWEBsPb+buGLEzWlRx5vssooTBoTqc0PkTM1G+69 NJz2WaFpCuPKd//x04EfGFeFfPG2EJiCtcTtJ0s8OuOgNE8m4OZ2s6qrIjw5WPpOM1yH bUvBhw8q8Ox2tEY1Dqj2mqfwi6vbE7jrN013wsVUa9GNq158l3wyZ4Kn+pT2H2Pfh7UM c3IE1FjaoQz9JB6JbiaP+cbXyRUJch81xL2v0v+Ht78gyMaLHHixPozK0bnLO7GJ4ull gA+w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=hmRt+HYG; 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=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k26si16727601eds.534.2021.03.04.04.42.16; Thu, 04 Mar 2021 04:42:39 -0800 (PST) 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=@kernel.org header.s=k20201202 header.b=hmRt+HYG; 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=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236820AbhCCX74 (ORCPT + 99 others); Wed, 3 Mar 2021 18:59:56 -0500 Received: from mail.kernel.org ([198.145.29.99]:35240 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377027AbhCCTpG (ORCPT ); Wed, 3 Mar 2021 14:45:06 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id BA10D64EEC; Wed, 3 Mar 2021 19:44:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1614800664; bh=XzLN1itD6PL+bIg6U9jSAC+UFTtsG2NbdA80bYP7AMo=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=hmRt+HYGG544Fi2+h6mba4JSEU1BiziNRB2SVNBHJm0IDg2n5KjrEFNh+EulXG0Oa Xxh5to+8zCMYv+1NEO/IlAfC3b3aYf59esKN2VtD5X/FHbewG8X4bFzeeIA54xTCpi dJgIh4rWZ38s/zF7khf0XPyGTdfrf9HRti5P6ALJfLjQtWOZaMEf/RwbTMFCzpq6Jw TA3hKCEYf4ahb/8YxPB6HEnRUy/b++MBAInHSeA1UesBc3i9EiKwMOhAfoEjba7eTI YNymMrP8mB2wRzTrkrfxY92VbUhj3Wlo/GS3NsvlpQGxvPwlUfjy5TgmUmIvlSWfkg VAx+fxC0o8Bbg== Date: Wed, 3 Mar 2021 11:44:22 -0800 From: Jaegeuk Kim To: Colin Ian King Cc: Changman Lee , Chao Yu , linux-f2fs-devel@lists.sourceforge.net, "linux-kernel@vger.kernel.org" Subject: Re: f2fs_convert_inline_inode causing rebalance based on random uninitialized value in dn.node_changed Message-ID: References: <9fcca081-9a60-8ae3-5cac-d8aa38c38ff2@canonical.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <9fcca081-9a60-8ae3-5cac-d8aa38c38ff2@canonical.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 03/02, Colin Ian King wrote: > Hi, > > Static analysis on linux-next detected a potential uninitialized > variable dn.node_changed that does not get set when a call to > f2fs_get_node_page() fails. This uninitialized value gets used in the > call to f2fs_balance_fs() that may or not may not balances dirty node > and dentry pages depending on the uninitialized state of the variable. > > I believe the issue was introduced by commit: > > commit 2a3407607028f7c780f1c20faa4e922bf631d340 > Author: Jaegeuk Kim > Date: Tue Dec 22 13:23:35 2015 -0800 > > f2fs: call f2fs_balance_fs only when node was changed > > > The analysis is a follows: > > 184 int f2fs_convert_inline_inode(struct inode *inode) > 185 { > 186 struct f2fs_sb_info *sbi = F2FS_I_SB(inode); > > 1. var_decl: Declaring variable dn without initializer. > > 187 struct dnode_of_data dn; > > NOTE dn is not initialized here. > > 188 struct page *ipage, *page; > 189 int err = 0; > 190 > > 2. Condition !f2fs_has_inline_data(inode), taking false branch. > 3. Condition f2fs_hw_is_readonly(sbi), taking false branch. > 4. Condition f2fs_readonly(sbi->sb), taking false branch. > > 191 if (!f2fs_has_inline_data(inode) || > 192 f2fs_hw_is_readonly(sbi) || > f2fs_readonly(sbi->sb)) > 193 return 0; > 194 > 195 err = dquot_initialize(inode); > > 5. Condition err, taking false branch. > > 196 if (err) > 197 return err; > 198 > 199 page = f2fs_grab_cache_page(inode->i_mapping, 0, false); > > 6. Condition !page, taking false branch. > > 200 if (!page) > 201 return -ENOMEM; > 202 > 203 f2fs_lock_op(sbi); > 204 > 205 ipage = f2fs_get_node_page(sbi, inode->i_ino); > > 7. Condition IS_ERR(ipage), taking true branch. > > 206 if (IS_ERR(ipage)) { > 207 err = PTR_ERR(ipage); > > 8. Jumping to label out. > > 208 goto out; > 209 } > 210 > > NOTE: set_new_dnode memset's dn so sets the flag to false, but we > don't get to this memset if IS_ERR(ipage) above is true. > > 211 set_new_dnode(&dn, inode, ipage, ipage, 0); > 212 > 213 if (f2fs_has_inline_data(inode)) > 214 err = f2fs_convert_inline_page(&dn, page); > 215 > 216 f2fs_put_dnode(&dn); > 217 out: > 218 f2fs_unlock_op(sbi); > 219 > 220 f2fs_put_page(page, 1); > 221 > > Uninitialized scalar variable: > > 9. uninit_use_in_call: Using uninitialized value dn.node_changed when > calling f2fs_balance_fs. > > 222 f2fs_balance_fs(sbi, dn.node_changed); > 223 > 224 return err; > 225 } > > I think a suitable fix will be to set dn.node_changed to false on in > line 207-208 but I'm concerned if I'm missing something subtle to the > rebalancing if I do this. > > Comments? Thank you for the report. Yes, it seems that's a right call and we need to check the error to decide calling f2fs_balance_fs() in line 222, since set_new_dnode() is used to set all the fields in dnode_of_data. So, if you don't mind, could you please post a patch? Thanks, > > Colin >