From fbccd13c3fa10a35d73ce58f77b42c1e810af91d Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Sun, 23 Jan 2022 18:19:32 +0100 Subject: [PATCH] 4.19-stable patches added patches: ext4-make-sure-quota-gets-properly-shutdown-on-error.patch ext4-make-sure-to-reset-inode-lockdep-class-when-quota-enabling-fails.patch --- ...uota-gets-properly-shutdown-on-error.patch | 51 +++++++++++++++++++ ...kdep-class-when-quota-enabling-fails.patch | 49 ++++++++++++++++++ queue-4.19/series | 2 + 3 files changed, 102 insertions(+) create mode 100644 queue-4.19/ext4-make-sure-quota-gets-properly-shutdown-on-error.patch create mode 100644 queue-4.19/ext4-make-sure-to-reset-inode-lockdep-class-when-quota-enabling-fails.patch diff --git a/queue-4.19/ext4-make-sure-quota-gets-properly-shutdown-on-error.patch b/queue-4.19/ext4-make-sure-quota-gets-properly-shutdown-on-error.patch new file mode 100644 index 00000000000..346b66dab12 --- /dev/null +++ b/queue-4.19/ext4-make-sure-quota-gets-properly-shutdown-on-error.patch @@ -0,0 +1,51 @@ +From 15fc69bbbbbc8c72e5f6cc4e1be0f51283c5448e Mon Sep 17 00:00:00 2001 +From: Jan Kara +Date: Thu, 7 Oct 2021 17:53:35 +0200 +Subject: ext4: make sure quota gets properly shutdown on error + +From: Jan Kara + +commit 15fc69bbbbbc8c72e5f6cc4e1be0f51283c5448e upstream. + +When we hit an error when enabling quotas and setting inode flags, we do +not properly shutdown quota subsystem despite returning error from +Q_QUOTAON quotactl. This can lead to some odd situations like kernel +using quota file while it is still writeable for userspace. Make sure we +properly cleanup the quota subsystem in case of error. + +Signed-off-by: Jan Kara +Cc: stable@kernel.org +Link: https://lore.kernel.org/r/20211007155336.12493-2-jack@suse.cz +Signed-off-by: Theodore Ts'o +Signed-off-by: Greg Kroah-Hartman +--- + fs/ext4/super.c | 10 ++++++---- + 1 file changed, 6 insertions(+), 4 deletions(-) + +--- a/fs/ext4/super.c ++++ b/fs/ext4/super.c +@@ -5797,10 +5797,7 @@ static int ext4_quota_on(struct super_bl + + lockdep_set_quota_inode(path->dentry->d_inode, I_DATA_SEM_QUOTA); + err = dquot_quota_on(sb, type, format_id, path); +- if (err) { +- lockdep_set_quota_inode(path->dentry->d_inode, +- I_DATA_SEM_NORMAL); +- } else { ++ if (!err) { + struct inode *inode = d_inode(path->dentry); + handle_t *handle; + +@@ -5820,7 +5817,12 @@ static int ext4_quota_on(struct super_bl + ext4_journal_stop(handle); + unlock_inode: + inode_unlock(inode); ++ if (err) ++ dquot_quota_off(sb, type); + } ++ if (err) ++ lockdep_set_quota_inode(path->dentry->d_inode, ++ I_DATA_SEM_NORMAL); + return err; + } + diff --git a/queue-4.19/ext4-make-sure-to-reset-inode-lockdep-class-when-quota-enabling-fails.patch b/queue-4.19/ext4-make-sure-to-reset-inode-lockdep-class-when-quota-enabling-fails.patch new file mode 100644 index 00000000000..b20c0c96810 --- /dev/null +++ b/queue-4.19/ext4-make-sure-to-reset-inode-lockdep-class-when-quota-enabling-fails.patch @@ -0,0 +1,49 @@ +From 4013d47a5307fdb5c13370b5392498b00fedd274 Mon Sep 17 00:00:00 2001 +From: Jan Kara +Date: Thu, 7 Oct 2021 17:53:36 +0200 +Subject: ext4: make sure to reset inode lockdep class when quota enabling fails + +From: Jan Kara + +commit 4013d47a5307fdb5c13370b5392498b00fedd274 upstream. + +When we succeed in enabling some quota type but fail to enable another +one with quota feature, we correctly disable all enabled quota types. +However we forget to reset i_data_sem lockdep class. When the inode gets +freed and reused, it will inherit this lockdep class (i_data_sem is +initialized only when a slab is created) and thus eventually lockdep +barfs about possible deadlocks. + +Reported-and-tested-by: syzbot+3b6f9218b1301ddda3e2@syzkaller.appspotmail.com +Signed-off-by: Jan Kara +Cc: stable@kernel.org +Link: https://lore.kernel.org/r/20211007155336.12493-3-jack@suse.cz +Signed-off-by: Theodore Ts'o +Signed-off-by: Greg Kroah-Hartman +--- + fs/ext4/super.c | 13 ++++++++++++- + 1 file changed, 12 insertions(+), 1 deletion(-) + +--- a/fs/ext4/super.c ++++ b/fs/ext4/super.c +@@ -5883,8 +5883,19 @@ static int ext4_enable_quotas(struct sup + "Failed to enable quota tracking " + "(type=%d, err=%d). Please run " + "e2fsck to fix.", type, err); +- for (type--; type >= 0; type--) ++ for (type--; type >= 0; type--) { ++ struct inode *inode; ++ ++ inode = sb_dqopt(sb)->files[type]; ++ if (inode) ++ inode = igrab(inode); + dquot_quota_off(sb, type); ++ if (inode) { ++ lockdep_set_quota_inode(inode, ++ I_DATA_SEM_NORMAL); ++ iput(inode); ++ } ++ } + + return err; + } diff --git a/queue-4.19/series b/queue-4.19/series index 9d1eeec7ce0..c61893125ab 100644 --- a/queue-4.19/series +++ b/queue-4.19/series @@ -199,3 +199,5 @@ cputime-cpuacct-include-guest-time-in-user-time-in-cpuacct.stat.patch iwlwifi-mvm-increase-the-scan-timeout-guard-to-30-seconds.patch s390-mm-fix-2kb-pgtable-release-race.patch drm-etnaviv-limit-submit-sizes.patch +ext4-make-sure-to-reset-inode-lockdep-class-when-quota-enabling-fails.patch +ext4-make-sure-quota-gets-properly-shutdown-on-error.patch -- 2.47.3