Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/2] quota: Verify special quota formats match sb type
@ 2026-09-03  9:05 Jan Kara
  2026-09-03  9:05 ` [PATCH v2 1/2] ocfs2: Refuse to enable ocfs2 format for another filesystem Jan Kara
  2026-09-03  9:05 ` [PATCH v2 2/2] shmem: Refuse to enable tmpfs " Jan Kara
  0 siblings, 2 replies; 5+ messages in thread
From: Jan Kara @ 2026-09-03  9:05 UTC (permalink / raw)
  To: linux-fsdevel
  Cc: linux-mm, ocfs2-devel, Joseph Qi, Hugh Dickins, Baolin Wang,
	Farhad Alemi, Jan Kara

Hello,

here is v2 of the patches for fix quota crashes when quota format doesn't match
filesystem type. I'm now using s_magic instead of s_type for superblock type
checking as Hugh pointed out (thus I also didn't pick up OCFS2 guys' R-b tags
because the patch is different now). Once reviewed, I can merge these patches
through my tree as they are only quota related and very unlikely to clash with
anything.

Changes since v1:
* Use s_magic instead of s_type for superblock type checking

Original cover letter:

There are certain quota formats that are created only for particular
filesystems - ocfs2 and tmpfs quota formats in particular. Make sure these
formats are indeed being enabled only for filesystem of appropriate type.
Otherwise quota format operations can easily crash as was spotted by fuzz
testing. 


								Honza

Previous versions:
Link: http://lore.kernel.org/r/20260902132458.23590-1-jack@suse.cz # v1


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

* [PATCH v2 1/2] ocfs2: Refuse to enable ocfs2 format for another filesystem
  2026-09-03  9:05 [PATCH v2 0/2] quota: Verify special quota formats match sb type Jan Kara
@ 2026-09-03  9:05 ` Jan Kara
  2026-09-03 10:15   ` Joseph Qi
  2026-09-03  9:05 ` [PATCH v2 2/2] shmem: Refuse to enable tmpfs " Jan Kara
  1 sibling, 1 reply; 5+ messages in thread
From: Jan Kara @ 2026-09-03  9:05 UTC (permalink / raw)
  To: linux-fsdevel
  Cc: linux-mm, ocfs2-devel, Joseph Qi, Hugh Dickins, Baolin Wang,
	Farhad Alemi, Jan Kara

It is possible to issue Q_QUOTAON quotactl(2) e.g. for ext4 filesystem
requesting to enable quota using ocfs2 quota format. With suitable
passed arguments this can get upto ocfs2_local_check_quota_file() where
the passed superblock is from the ext4 filesystem and that can cause all
sorts of interesting things, most likely crashes. As ocfs2 quotas are
specific to ocfs2 filesystem, verify we are indeed enabling quotas
there.

Signed-off-by: Jan Kara <jack@suse.cz>
---
 fs/ocfs2/quota_local.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/fs/ocfs2/quota_local.c b/fs/ocfs2/quota_local.c
index f55810c59b1b..a2b276bcd0a8 100644
--- a/fs/ocfs2/quota_local.c
+++ b/fs/ocfs2/quota_local.c
@@ -171,6 +171,10 @@ static int ocfs2_local_check_quota_file(struct super_block *sb, int type)
 	struct ocfs2_disk_dqheader *dqhead;
 	int status, ret = 0;
 
+	/* OCFS2 quota format is supported only for OCFS2 filesystems */
+	if (sb->s_magic != OCFS2_SUPER_MAGIC)
+		goto out_err;
+
 	/* First check whether we understand local quota file */
 	status = ocfs2_read_quota_block(linode, 0, &bh);
 	if (status) {
-- 
2.51.0



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

* [PATCH v2 2/2] shmem: Refuse to enable tmpfs format for another filesystem
  2026-09-03  9:05 [PATCH v2 0/2] quota: Verify special quota formats match sb type Jan Kara
  2026-09-03  9:05 ` [PATCH v2 1/2] ocfs2: Refuse to enable ocfs2 format for another filesystem Jan Kara
@ 2026-09-03  9:05 ` Jan Kara
  2026-09-03 15:15   ` Hugh Dickins
  1 sibling, 1 reply; 5+ messages in thread
From: Jan Kara @ 2026-09-03  9:05 UTC (permalink / raw)
  To: linux-fsdevel
  Cc: linux-mm, ocfs2-devel, Joseph Qi, Hugh Dickins, Baolin Wang,
	Farhad Alemi, Jan Kara

It is possible to issue Q_QUOTAON quotactl(2) e.g. for ext4 filesystem
requesting to enable quota using tmpfs quota format. With suitable
passed arguments this can actually succeed in enabling tmpfs quota
format on top of ext4 filesystem which leads to crashes later in
dquot_acquire().  As tmpfs quota format is intended for tmpfs
filesystems only, verify we are indeed enabling quotas there.

Reported-by: Farhad Alemi <farhad.alemi@berkeley.edu>
Signed-off-by: Jan Kara <jack@suse.cz>
---
 mm/shmem_quota.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/mm/shmem_quota.c b/mm/shmem_quota.c
index d0b92d6da50f..a3fa4bd93e75 100644
--- a/mm/shmem_quota.c
+++ b/mm/shmem_quota.c
@@ -30,6 +30,7 @@
 #include <linux/slab.h>
 #include <linux/rbtree.h>
 #include <linux/shmem_fs.h>
+#include <linux/magic.h>
 
 #include <linux/quotaops.h>
 #include <linux/quota.h>
@@ -54,6 +55,10 @@ struct quota_id {
 
 static int shmem_check_quota_file(struct super_block *sb, int type)
 {
+	/* Verify enabling happens on tmpfs superblock */
+	if (sb->s_magic != TMPFS_MAGIC)
+		return 0;
+
 	/* There is no real quota file, nothing to do */
 	return 1;
 }
-- 
2.51.0



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

* Re: [PATCH v2 1/2] ocfs2: Refuse to enable ocfs2 format for another filesystem
  2026-09-03  9:05 ` [PATCH v2 1/2] ocfs2: Refuse to enable ocfs2 format for another filesystem Jan Kara
@ 2026-09-03 10:15   ` Joseph Qi
  0 siblings, 0 replies; 5+ messages in thread
From: Joseph Qi @ 2026-09-03 10:15 UTC (permalink / raw)
  To: Jan Kara, linux-fsdevel
  Cc: linux-mm, ocfs2-devel, Hugh Dickins, Baolin Wang, Farhad Alemi,
	Andrew Morton



On 9/3/26 5:05 PM, Jan Kara wrote:
> It is possible to issue Q_QUOTAON quotactl(2) e.g. for ext4 filesystem
> requesting to enable quota using ocfs2 quota format. With suitable
> passed arguments this can get upto ocfs2_local_check_quota_file() where
> the passed superblock is from the ext4 filesystem and that can cause all
> sorts of interesting things, most likely crashes. As ocfs2 quotas are
> specific to ocfs2 filesystem, verify we are indeed enabling quotas
> there.
> 
> Signed-off-by: Jan Kara <jack@suse.cz>

Reviewed-by: Joseph Qi <joseph.qi@linux.alibaba.com>
> ---
>  fs/ocfs2/quota_local.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/fs/ocfs2/quota_local.c b/fs/ocfs2/quota_local.c
> index f55810c59b1b..a2b276bcd0a8 100644
> --- a/fs/ocfs2/quota_local.c
> +++ b/fs/ocfs2/quota_local.c
> @@ -171,6 +171,10 @@ static int ocfs2_local_check_quota_file(struct super_block *sb, int type)
>  	struct ocfs2_disk_dqheader *dqhead;
>  	int status, ret = 0;
>  
> +	/* OCFS2 quota format is supported only for OCFS2 filesystems */
> +	if (sb->s_magic != OCFS2_SUPER_MAGIC)
> +		goto out_err;
> +
>  	/* First check whether we understand local quota file */
>  	status = ocfs2_read_quota_block(linode, 0, &bh);
>  	if (status) {



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

* Re: [PATCH v2 2/2] shmem: Refuse to enable tmpfs format for another filesystem
  2026-09-03  9:05 ` [PATCH v2 2/2] shmem: Refuse to enable tmpfs " Jan Kara
@ 2026-09-03 15:15   ` Hugh Dickins
  0 siblings, 0 replies; 5+ messages in thread
From: Hugh Dickins @ 2026-09-03 15:15 UTC (permalink / raw)
  To: Jan Kara
  Cc: linux-fsdevel, linux-mm, ocfs2-devel, Joseph Qi, Hugh Dickins,
	Baolin Wang, Farhad Alemi

On Thu, 3 Sep 2026, Jan Kara wrote:

> It is possible to issue Q_QUOTAON quotactl(2) e.g. for ext4 filesystem
> requesting to enable quota using tmpfs quota format. With suitable
> passed arguments this can actually succeed in enabling tmpfs quota
> format on top of ext4 filesystem which leads to crashes later in
> dquot_acquire().  As tmpfs quota format is intended for tmpfs
> filesystems only, verify we are indeed enabling quotas there.
> 
> Reported-by: Farhad Alemi <farhad.alemi@berkeley.edu>
> Signed-off-by: Jan Kara <jack@suse.cz>

Acked-by: Hugh Dickins <hughd@google.com>

Thanks: yes, please do route it through your tree.

> ---
>  mm/shmem_quota.c | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/mm/shmem_quota.c b/mm/shmem_quota.c
> index d0b92d6da50f..a3fa4bd93e75 100644
> --- a/mm/shmem_quota.c
> +++ b/mm/shmem_quota.c
> @@ -30,6 +30,7 @@
>  #include <linux/slab.h>
>  #include <linux/rbtree.h>
>  #include <linux/shmem_fs.h>
> +#include <linux/magic.h>
>  
>  #include <linux/quotaops.h>
>  #include <linux/quota.h>
> @@ -54,6 +55,10 @@ struct quota_id {
>  
>  static int shmem_check_quota_file(struct super_block *sb, int type)
>  {
> +	/* Verify enabling happens on tmpfs superblock */
> +	if (sb->s_magic != TMPFS_MAGIC)
> +		return 0;
> +
>  	/* There is no real quota file, nothing to do */
>  	return 1;
>  }
> -- 
> 2.51.0


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

end of thread, other threads:[~2026-09-03 15:15 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-03  9:05 [PATCH v2 0/2] quota: Verify special quota formats match sb type Jan Kara
2026-09-03  9:05 ` [PATCH v2 1/2] ocfs2: Refuse to enable ocfs2 format for another filesystem Jan Kara
2026-09-03 10:15   ` Joseph Qi
2026-09-03  9:05 ` [PATCH v2 2/2] shmem: Refuse to enable tmpfs " Jan Kara
2026-09-03 15:15   ` Hugh Dickins

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox