Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp4683785pxb; Thu, 14 Oct 2021 09:54:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwOsJhjuCMFhSCIDr6aSODQ3XX9eet0xjX5ohpXHWCqCQ1V3y3ry1MwVZ3MeEqqZX/psHHa X-Received: by 2002:a05:6a00:1481:b0:43d:275b:7ba4 with SMTP id v1-20020a056a00148100b0043d275b7ba4mr6518573pfu.63.1634230491130; Thu, 14 Oct 2021 09:54:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634230491; cv=none; d=google.com; s=arc-20160816; b=JzlFIqcpV8lxBC4JOXTP0BKGi1C8xuF4W+nsqEe/TqCCp3DxAOUXDwOT4EC5piHWoK 74d19XZGsk5suvfBO0W2HCPBuPoaGoe1C6DSRB5BuWrS1+61ZoeZitZq48gBGhKW6Qyd w9ooW5gr5wREBo8iKHZgZmVT8aNZvscoi0si2LW/9wvzvX0yyQ+8k0jCdoaCYVn/wZVQ UU99vAYENQqnviJk2PvnrqI1SYDNmBlMYTYz/qJCQevYT3VKmC6T7I3WRDa64KsZyIcO 3Tt88TrOBR+jR7IqKgZGEVeMABp02rB0SqY6DGbleb/8XRo6rz6cEsm6oaqkx1L8n31+ H+1g== 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=ngKuyf1qcXvRkkcdsHozP5Lmi39TEWTlgrecYcwaK5Y=; b=HBeuS0OLL2Gy7uTFF0FejNx+/CD4487TAPr+tFDdexb6JR/5chMcRxGvceWqhNR4wE nbpIxTkVoRtDa69dno08HceHUEAZeUM14DE++9lQARIshqyS7a7dmBbrVYtfNHAJnkJN 3tkuZTfgTc2eDCtHi0pnghKl99fuD92X1znpwUiN9U+WNZHD10NM0eKySLc0C9NifH0R O9iwvgLXw8h1iFP9nnJFu1jsR+Pq65erIQVL/GlhlDh2JBoEuT6HQNrhV12khLcJWfHd m73aQjdAMh8fPqgMVrJqGmGFHEHap4AAP0yY6ehZH+jVI2wS4FtnOhO+J4v1yXpKWLzg UKUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=F3lbYtaD; 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=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id kb12si5012375pjb.104.2021.10.14.09.54.38; Thu, 14 Oct 2021 09:54:51 -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=@linuxfoundation.org header.s=korg header.b=F3lbYtaD; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232426AbhJNPC6 (ORCPT + 99 others); Thu, 14 Oct 2021 11:02:58 -0400 Received: from mail.kernel.org ([198.145.29.99]:43300 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232647AbhJNPBe (ORCPT ); Thu, 14 Oct 2021 11:01:34 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id F0D4B611C1; Thu, 14 Oct 2021 14:58:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1634223531; bh=0rpzARYStUc3f5Pq0EGNWSdaIM3XhFhgwF2xLmELz9A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=F3lbYtaDywabnxgtdQp1RYVS4+z6YThWSGA8MTCM87pDIkviLBAKCiwWgI+5Y1k9v K2+ck4ShT9S9zTyKMSkMLm6ipFuDeUvUy51BKmiEmMiAYdCgVvWDQ9kAxSuF/IxwUk AVKO41N0X2NgVTp8SvL8ex0r3AmgXJSY+9uQczV8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Zhang Yi , Jan Kara , Theodore Tso , Sasha Levin Subject: [PATCH 5.4 02/16] ext4: correct the error path of ext4_write_inline_data_end() Date: Thu, 14 Oct 2021 16:54:05 +0200 Message-Id: <20211014145207.391232156@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211014145207.314256898@linuxfoundation.org> References: <20211014145207.314256898@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Zhang Yi [ Upstream commit 55ce2f649b9e88111270333a8127e23f4f8f42d7 ] Current error path of ext4_write_inline_data_end() is not correct. Firstly, it should pass out the error value if ext4_get_inode_loc() return fail, or else it could trigger infinite loop if we inject error here. And then it's better to add inode to orphan list if it return fail in ext4_journal_stop(), otherwise we could not restore inline xattr entry after power failure. Finally, we need to reset the 'ret' value if ext4_write_inline_data_end() return success in ext4_write_end() and ext4_journalled_write_end(), otherwise we could not get the error return value of ext4_journal_stop(). Signed-off-by: Zhang Yi Reviewed-by: Jan Kara Signed-off-by: Theodore Ts'o Link: https://lore.kernel.org/r/20210716122024.1105856-3-yi.zhang@huawei.com Signed-off-by: Sasha Levin --- fs/ext4/inline.c | 15 +++++---------- fs/ext4/inode.c | 7 +++++-- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/fs/ext4/inline.c b/fs/ext4/inline.c index 46151bda6236..cdb10e9fded6 100644 --- a/fs/ext4/inline.c +++ b/fs/ext4/inline.c @@ -733,18 +733,13 @@ int ext4_write_inline_data_end(struct inode *inode, loff_t pos, unsigned len, void *kaddr; struct ext4_iloc iloc; - if (unlikely(copied < len)) { - if (!PageUptodate(page)) { - copied = 0; - goto out; - } - } + if (unlikely(copied < len) && !PageUptodate(page)) + return 0; ret = ext4_get_inode_loc(inode, &iloc); if (ret) { ext4_std_error(inode->i_sb, ret); - copied = 0; - goto out; + return ret; } ext4_write_lock_xattr(inode, &no_expand); @@ -757,7 +752,7 @@ int ext4_write_inline_data_end(struct inode *inode, loff_t pos, unsigned len, (void) ext4_find_inline_data_nolock(inode); kaddr = kmap_atomic(page); - ext4_write_inline_data(inode, &iloc, kaddr, pos, len); + ext4_write_inline_data(inode, &iloc, kaddr, pos, copied); kunmap_atomic(kaddr); SetPageUptodate(page); /* clear page dirty so that writepages wouldn't work for us. */ @@ -766,7 +761,7 @@ int ext4_write_inline_data_end(struct inode *inode, loff_t pos, unsigned len, ext4_write_unlock_xattr(inode, &no_expand); brelse(iloc.bh); mark_inode_dirty(inode); -out: + return copied; } diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 48b467353f6f..dcbd8ac8d471 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -1439,6 +1439,7 @@ static int ext4_write_end(struct file *file, goto errout; } copied = ret; + ret = 0; } else copied = block_write_end(file, mapping, pos, len, copied, page, fsdata); @@ -1465,13 +1466,14 @@ static int ext4_write_end(struct file *file, if (i_size_changed || inline_data) ext4_mark_inode_dirty(handle, inode); +errout: if (pos + len > inode->i_size && !verity && ext4_can_truncate(inode)) /* if we have allocated more blocks and copied * less. We will have blocks allocated outside * inode->i_size. So truncate them */ ext4_orphan_add(handle, inode); -errout: + ret2 = ext4_journal_stop(handle); if (!ret) ret = ret2; @@ -1554,6 +1556,7 @@ static int ext4_journalled_write_end(struct file *file, goto errout; } copied = ret; + ret = 0; } else if (unlikely(copied < len) && !PageUptodate(page)) { copied = 0; ext4_journalled_zero_new_buffers(handle, page, from, to); @@ -1583,6 +1586,7 @@ static int ext4_journalled_write_end(struct file *file, ret = ret2; } +errout: if (pos + len > inode->i_size && !verity && ext4_can_truncate(inode)) /* if we have allocated more blocks and copied * less. We will have blocks allocated outside @@ -1590,7 +1594,6 @@ static int ext4_journalled_write_end(struct file *file, */ ext4_orphan_add(handle, inode); -errout: ret2 = ext4_journal_stop(handle); if (!ret) ret = ret2; -- 2.33.0