Linux-ext4 Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH] ext4: Detect already used quota file early
@ 2020-10-13 13:22 Jan Kara
  2020-10-15  7:33 ` Andreas Dilger
  2020-10-15 14:52 ` Theodore Y. Ts'o
  0 siblings, 2 replies; 4+ messages in thread
From: Jan Kara @ 2020-10-13 13:22 UTC (permalink / raw)
  To: Ted Tso; +Cc: linux-ext4, Ritesh Harjani, Jan Kara

When we try to use file already used as a quota file again (for the same
or different quota type), strange things can happen. At the very least
lockdep annotations may be wrong but also inode flags may be wrongly set
/ reset. When the file is used for two quota types at once we can even
corrupt the file and likely crash the kernel. Catch all these cases by
checking whether passed file is already used as quota file and bail
early in that case.

This fixes occasional generic/219 failure due to lockdep complaint.

Reported-by: Ritesh Harjani <riteshh@linux.ibm.com>
Signed-off-by: Jan Kara <jack@suse.cz>
---
 fs/ext4/super.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/fs/ext4/super.c b/fs/ext4/super.c
index ea425b49b345..49b2e6be35c4 100644
--- a/fs/ext4/super.c
+++ b/fs/ext4/super.c
@@ -6042,6 +6042,11 @@ static int ext4_quota_on(struct super_block *sb, int type, int format_id,
 	/* Quotafile not on the same filesystem? */
 	if (path->dentry->d_sb != sb)
 		return -EXDEV;
+
+	/* Quota already enabled for this file? */
+	if (path->dentry->d_inode->i_flags & S_NOQUOTA)
+		return -EBUSY;
+
 	/* Journaling quota? */
 	if (EXT4_SB(sb)->s_qf_names[type]) {
 		/* Quotafile not in fs root? */
-- 
2.16.4


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] ext4: Detect already used quota file early
  2020-10-13 13:22 [PATCH] ext4: Detect already used quota file early Jan Kara
@ 2020-10-15  7:33 ` Andreas Dilger
  2020-10-15  9:51   ` Jan Kara
  2020-10-15 14:52 ` Theodore Y. Ts'o
  1 sibling, 1 reply; 4+ messages in thread
From: Andreas Dilger @ 2020-10-15  7:33 UTC (permalink / raw)
  To: Jan Kara; +Cc: Ted Tso, linux-ext4, Ritesh Harjani


[-- Attachment #1: Type: text/plain, Size: 1500 bytes --]

On Oct 13, 2020, at 7:22 AM, Jan Kara <jack@suse.cz> wrote:
> 
> When we try to use file already used as a quota file again (for the same
> or different quota type), strange things can happen. At the very least
> lockdep annotations may be wrong but also inode flags may be wrongly set
> / reset. When the file is used for two quota types at once we can even
> corrupt the file and likely crash the kernel. Catch all these cases by
> checking whether passed file is already used as quota file and bail
> early in that case.
> 
> This fixes occasional generic/219 failure due to lockdep complaint.
> 
> Reported-by: Ritesh Harjani <riteshh@linux.ibm.com>
> Signed-off-by: Jan Kara <jack@suse.cz>

Patch looks OK, but a minor question/suggestion below...

Reviewed-by: Andreas Dilger <adilger@dilger.ca>

> diff --git a/fs/ext4/super.c b/fs/ext4/super.c
> index ea425b49b345..49b2e6be35c4 100644
> --- a/fs/ext4/super.c
> +++ b/fs/ext4/super.c
> @@ -6042,6 +6042,11 @@ static int ext4_quota_on(struct super_block *sb, int type, int format_id,
> 	/* Quotafile not on the same filesystem? */
> 	if (path->dentry->d_sb != sb)
> 		return -EXDEV;
> +
> +	/* Quota already enabled for this file? */
> +	if (path->dentry->d_inode->i_flags & S_NOQUOTA)
> +		return -EBUSY;

Any reason not to use IS_NOQUOTA(path->dentry->d_inode) here?  I was trying
to see where S_NOQUOTA is set, and it seems that all of the quota code is
using IS_NOQUOTA().


Cheers, Andreas






[-- Attachment #2: Message signed with OpenPGP --]
[-- Type: application/pgp-signature, Size: 873 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] ext4: Detect already used quota file early
  2020-10-15  7:33 ` Andreas Dilger
@ 2020-10-15  9:51   ` Jan Kara
  0 siblings, 0 replies; 4+ messages in thread
From: Jan Kara @ 2020-10-15  9:51 UTC (permalink / raw)
  To: Andreas Dilger; +Cc: Jan Kara, Ted Tso, linux-ext4, Ritesh Harjani

On Thu 15-10-20 01:33:24, Andreas Dilger wrote:
> On Oct 13, 2020, at 7:22 AM, Jan Kara <jack@suse.cz> wrote:
> > 
> > When we try to use file already used as a quota file again (for the same
> > or different quota type), strange things can happen. At the very least
> > lockdep annotations may be wrong but also inode flags may be wrongly set
> > / reset. When the file is used for two quota types at once we can even
> > corrupt the file and likely crash the kernel. Catch all these cases by
> > checking whether passed file is already used as quota file and bail
> > early in that case.
> > 
> > This fixes occasional generic/219 failure due to lockdep complaint.
> > 
> > Reported-by: Ritesh Harjani <riteshh@linux.ibm.com>
> > Signed-off-by: Jan Kara <jack@suse.cz>
> 
> Patch looks OK, but a minor question/suggestion below...
> 
> Reviewed-by: Andreas Dilger <adilger@dilger.ca>
> 
> > diff --git a/fs/ext4/super.c b/fs/ext4/super.c
> > index ea425b49b345..49b2e6be35c4 100644
> > --- a/fs/ext4/super.c
> > +++ b/fs/ext4/super.c
> > @@ -6042,6 +6042,11 @@ static int ext4_quota_on(struct super_block *sb, int type, int format_id,
> > 	/* Quotafile not on the same filesystem? */
> > 	if (path->dentry->d_sb != sb)
> > 		return -EXDEV;
> > +
> > +	/* Quota already enabled for this file? */
> > +	if (path->dentry->d_inode->i_flags & S_NOQUOTA)
> > +		return -EBUSY;
> 
> Any reason not to use IS_NOQUOTA(path->dentry->d_inode) here?  I was trying
> to see where S_NOQUOTA is set, and it seems that all of the quota code is
> using IS_NOQUOTA().

OK, right. I'll change that. Thanks for review.

								Honza
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] ext4: Detect already used quota file early
  2020-10-13 13:22 [PATCH] ext4: Detect already used quota file early Jan Kara
  2020-10-15  7:33 ` Andreas Dilger
@ 2020-10-15 14:52 ` Theodore Y. Ts'o
  1 sibling, 0 replies; 4+ messages in thread
From: Theodore Y. Ts'o @ 2020-10-15 14:52 UTC (permalink / raw)
  To: Jan Kara; +Cc: linux-ext4, Ritesh Harjani

On Tue, Oct 13, 2020 at 03:22:21PM +0200, Jan Kara wrote:
> When we try to use file already used as a quota file again (for the same
> or different quota type), strange things can happen. At the very least
> lockdep annotations may be wrong but also inode flags may be wrongly set
> / reset. When the file is used for two quota types at once we can even
> corrupt the file and likely crash the kernel. Catch all these cases by
> checking whether passed file is already used as quota file and bail
> early in that case.
> 
> This fixes occasional generic/219 failure due to lockdep complaint.
> 
> Reported-by: Ritesh Harjani <riteshh@linux.ibm.com>
> Signed-off-by: Jan Kara <jack@suse.cz>

Thanks, applied.

					- Ted

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, back to index

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-13 13:22 [PATCH] ext4: Detect already used quota file early Jan Kara
2020-10-15  7:33 ` Andreas Dilger
2020-10-15  9:51   ` Jan Kara
2020-10-15 14:52 ` Theodore Y. Ts'o

Linux-ext4 Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-ext4/0 linux-ext4/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-ext4 linux-ext4/ https://lore.kernel.org/linux-ext4 \
		linux-ext4@vger.kernel.org
	public-inbox-index linux-ext4

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-ext4


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git