Linux kernel -stable discussions
 help / color / mirror / Atom feed
* [PATCH] ocfs2: don't free a NULL chunk in ocfs2_local_quota_add_chunk()
@ 2026-11-30 23:56 Zijie Zhao via B4 Relay
  2026-12-01 10:36 ` Jan Kara
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Zijie Zhao via B4 Relay @ 2026-11-30 23:56 UTC (permalink / raw)
  To: Mark Fasheh, Joel Becker, Joseph Qi
  Cc: Heming Zhao, Jan Kara, ocfs2-devel, stable, Zijie Zhao

From: Zijie Zhao <zzjas98@gmail.com>

ocfs2_local_quota_add_chunk() allocates the in-memory chunk only after
the local quota file has been extended. If ocfs2_extend_no_holes() or
ocfs2_simple_size_update() fails, for example with -ENOSPC on a full
filesystem, or if kmem_cache_alloc() fails, the function jumps to the
out label with chunk still NULL. The out label then calls
kmem_cache_free(ocfs2_qf_chunk_cachep, NULL).

Unlike kfree(), kmem_cache_free() does not accept NULL. It calls
virt_to_slab() on the pointer and reads the struct page derived from
address 0. This can oops, or warn about freeing an object that is not
from a slab page.

Allocate the chunk before the file is extended and return right away if
the allocation fails. Every jump to the out label then has a valid
chunk to free. A failed allocation also no longer leaves the local
quota file grown by two unused blocks.

Found by a static analysis tool.

The fix and this changelog were drafted with AI assistance (Claude Code,
with a second review by OpenAI Codex), then reviewed by the submitter.

Fixes: 9e33d69f553a ("ocfs2: Implementation of local and global quota file handling")
Cc: stable@vger.kernel.org
Signed-off-by: Zijie Zhao <zzjas98@gmail.com>
---
An alternative was to keep the allocation where it was and guard the free
with "if (chunk)". Allocating first also stops a failed allocation from
leaving the local quota file two blocks larger.

Two related issues on this error path predate the patch and are left out of
it. If ocfs2_simple_size_update() or the chunk initialisation fails, the
extended local quota file is not shrunk back. Also, ocfs2_acquire_dquot()
does not undo the dq_use_count it has already committed when
ocfs2_create_local_dquot() fails. Happy to send separate patches if wanted.

Testing:
- Compile-tested on x86_64 (allmodconfig, W=1): fs/ocfs2/quota_local.o;
  no new warnings.
- checkpatch.pl --strict: no errors or warnings.
---
 fs/ocfs2/quota_local.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/fs/ocfs2/quota_local.c b/fs/ocfs2/quota_local.c
index 8be76fa784ac..5a241d465f46 100644
--- a/fs/ocfs2/quota_local.c
+++ b/fs/ocfs2/quota_local.c
@@ -1003,6 +1003,13 @@ static struct ocfs2_quota_chunk *ocfs2_local_quota_add_chunk(
 	struct buffer_head *bh = NULL, *dbh = NULL;
 	u64 p_blkno;
 
+	chunk = kmem_cache_alloc(ocfs2_qf_chunk_cachep, GFP_NOFS);
+	if (!chunk) {
+		status = -ENOMEM;
+		mlog_errno(status);
+		return ERR_PTR(status);
+	}
+
 	/* We are protected by dqio_sem so no locking needed */
 	status = ocfs2_extend_no_holes(lqinode, NULL,
 				       i_size_read(lqinode) + 2 * sb->s_blocksize,
@@ -1018,12 +1025,6 @@ static struct ocfs2_quota_chunk *ocfs2_local_quota_add_chunk(
 		goto out;
 	}
 
-	chunk = kmem_cache_alloc(ocfs2_qf_chunk_cachep, GFP_NOFS);
-	if (!chunk) {
-		status = -ENOMEM;
-		mlog_errno(status);
-		goto out;
-	}
 	/* Local quota info and two new blocks we initialize */
 	handle = ocfs2_start_trans(OCFS2_SB(sb),
 			OCFS2_LOCAL_QINFO_WRITE_CREDITS +

---
base-commit: 19cc08c1a6a650f8e54c0461ff198be6448f425d
change-id: 20261130-kbug-l1059-ocfs2-quota-b402c6eeb200

Best regards,
--  
Zijie Zhao <zzjas98@gmail.com>



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

* Re: [PATCH] ocfs2: don't free a NULL chunk in ocfs2_local_quota_add_chunk()
  2026-11-30 23:56 [PATCH] ocfs2: don't free a NULL chunk in ocfs2_local_quota_add_chunk() Zijie Zhao via B4 Relay
@ 2026-12-01 10:36 ` Jan Kara
  2026-12-01 11:00   ` Joseph Qi
  2026-12-01 20:20 ` + ocfs2-dont-free-a-null-chunk-in-ocfs2_local_quota_add_chunk.patch added to mm-nonmm-hotfixes-unstable branch Andrew Morton
  2026-12-02  3:51 ` [merged mm-nonmm-hotfixes-stable] ocfs2-dont-free-a-null-chunk-in-ocfs2_local_quota_add_chunk.patch removed from -mm tree Andrew Morton
  2 siblings, 1 reply; 5+ messages in thread
From: Jan Kara @ 2026-12-01 10:36 UTC (permalink / raw)
  To: zzjas98
  Cc: Mark Fasheh, Joel Becker, Joseph Qi, Heming Zhao, Jan Kara,
	ocfs2-devel, stable

On Mon 30-11-26 17:56:19, Zijie Zhao via B4 Relay wrote:
> From: Zijie Zhao <zzjas98@gmail.com>
> 
> ocfs2_local_quota_add_chunk() allocates the in-memory chunk only after
> the local quota file has been extended. If ocfs2_extend_no_holes() or
> ocfs2_simple_size_update() fails, for example with -ENOSPC on a full
> filesystem, or if kmem_cache_alloc() fails, the function jumps to the
> out label with chunk still NULL. The out label then calls
> kmem_cache_free(ocfs2_qf_chunk_cachep, NULL).
> 
> Unlike kfree(), kmem_cache_free() does not accept NULL. It calls
> virt_to_slab() on the pointer and reads the struct page derived from
> address 0. This can oops, or warn about freeing an object that is not
> from a slab page.
> 
> Allocate the chunk before the file is extended and return right away if
> the allocation fails. Every jump to the out label then has a valid
> chunk to free. A failed allocation also no longer leaves the local
> quota file grown by two unused blocks.
> 
> Found by a static analysis tool.
> 
> The fix and this changelog were drafted with AI assistance (Claude Code,
> with a second review by OpenAI Codex), then reviewed by the submitter.
> 
> Fixes: 9e33d69f553a ("ocfs2: Implementation of local and global quota file handling")
> Cc: stable@vger.kernel.org
> Signed-off-by: Zijie Zhao <zzjas98@gmail.com>

Looks good. Feel free to add:

Reviewed-by: Jan Kara <jack@suse.cz>

								Honza

> ---
> An alternative was to keep the allocation where it was and guard the free
> with "if (chunk)". Allocating first also stops a failed allocation from
> leaving the local quota file two blocks larger.
> 
> Two related issues on this error path predate the patch and are left out of
> it. If ocfs2_simple_size_update() or the chunk initialisation fails, the
> extended local quota file is not shrunk back. Also, ocfs2_acquire_dquot()
> does not undo the dq_use_count it has already committed when
> ocfs2_create_local_dquot() fails. Happy to send separate patches if wanted.
> 
> Testing:
> - Compile-tested on x86_64 (allmodconfig, W=1): fs/ocfs2/quota_local.o;
>   no new warnings.
> - checkpatch.pl --strict: no errors or warnings.
> ---
>  fs/ocfs2/quota_local.c | 13 +++++++------
>  1 file changed, 7 insertions(+), 6 deletions(-)
> 
> diff --git a/fs/ocfs2/quota_local.c b/fs/ocfs2/quota_local.c
> index 8be76fa784ac..5a241d465f46 100644
> --- a/fs/ocfs2/quota_local.c
> +++ b/fs/ocfs2/quota_local.c
> @@ -1003,6 +1003,13 @@ static struct ocfs2_quota_chunk *ocfs2_local_quota_add_chunk(
>  	struct buffer_head *bh = NULL, *dbh = NULL;
>  	u64 p_blkno;
>  
> +	chunk = kmem_cache_alloc(ocfs2_qf_chunk_cachep, GFP_NOFS);
> +	if (!chunk) {
> +		status = -ENOMEM;
> +		mlog_errno(status);
> +		return ERR_PTR(status);
> +	}
> +
>  	/* We are protected by dqio_sem so no locking needed */
>  	status = ocfs2_extend_no_holes(lqinode, NULL,
>  				       i_size_read(lqinode) + 2 * sb->s_blocksize,
> @@ -1018,12 +1025,6 @@ static struct ocfs2_quota_chunk *ocfs2_local_quota_add_chunk(
>  		goto out;
>  	}
>  
> -	chunk = kmem_cache_alloc(ocfs2_qf_chunk_cachep, GFP_NOFS);
> -	if (!chunk) {
> -		status = -ENOMEM;
> -		mlog_errno(status);
> -		goto out;
> -	}
>  	/* Local quota info and two new blocks we initialize */
>  	handle = ocfs2_start_trans(OCFS2_SB(sb),
>  			OCFS2_LOCAL_QINFO_WRITE_CREDITS +
> 
> ---
> base-commit: 19cc08c1a6a650f8e54c0461ff198be6448f425d
> change-id: 20261130-kbug-l1059-ocfs2-quota-b402c6eeb200
> 
> Best regards,
> --  
> Zijie Zhao <zzjas98@gmail.com>
> 
> 
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR

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

* Re: [PATCH] ocfs2: don't free a NULL chunk in ocfs2_local_quota_add_chunk()
  2026-12-01 10:36 ` Jan Kara
@ 2026-12-01 11:00   ` Joseph Qi
  0 siblings, 0 replies; 5+ messages in thread
From: Joseph Qi @ 2026-12-01 11:00 UTC (permalink / raw)
  To: Jan Kara, zzjas98, Andrew Morton
  Cc: Mark Fasheh, Joel Becker, Heming Zhao, ocfs2-devel, stable



On 12/1/26 6:36 PM, Jan Kara wrote:
> On Mon 30-11-26 17:56:19, Zijie Zhao via B4 Relay wrote:
>> From: Zijie Zhao <zzjas98@gmail.com>
>>
>> ocfs2_local_quota_add_chunk() allocates the in-memory chunk only after
>> the local quota file has been extended. If ocfs2_extend_no_holes() or
>> ocfs2_simple_size_update() fails, for example with -ENOSPC on a full
>> filesystem, or if kmem_cache_alloc() fails, the function jumps to the
>> out label with chunk still NULL. The out label then calls
>> kmem_cache_free(ocfs2_qf_chunk_cachep, NULL).
>>
>> Unlike kfree(), kmem_cache_free() does not accept NULL. It calls
>> virt_to_slab() on the pointer and reads the struct page derived from
>> address 0. This can oops, or warn about freeing an object that is not
>> from a slab page.
>>
>> Allocate the chunk before the file is extended and return right away if
>> the allocation fails. Every jump to the out label then has a valid
>> chunk to free. A failed allocation also no longer leaves the local
>> quota file grown by two unused blocks.
>>
>> Found by a static analysis tool.
>>
>> The fix and this changelog were drafted with AI assistance (Claude Code,
>> with a second review by OpenAI Codex), then reviewed by the submitter.
>>
>> Fixes: 9e33d69f553a ("ocfs2: Implementation of local and global quota file handling")
>> Cc: stable@vger.kernel.org
>> Signed-off-by: Zijie Zhao <zzjas98@gmail.com>
> 
> Looks good. Feel free to add:
> 
> Reviewed-by: Jan Kara <jack@suse.cz>
> 

Reviewed-by: Joseph Qi <joseph.qi@linux.alibaba.com>


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

* + ocfs2-dont-free-a-null-chunk-in-ocfs2_local_quota_add_chunk.patch added to mm-nonmm-hotfixes-unstable branch
  2026-11-30 23:56 [PATCH] ocfs2: don't free a NULL chunk in ocfs2_local_quota_add_chunk() Zijie Zhao via B4 Relay
  2026-12-01 10:36 ` Jan Kara
@ 2026-12-01 20:20 ` Andrew Morton
  2026-12-02  3:51 ` [merged mm-nonmm-hotfixes-stable] ocfs2-dont-free-a-null-chunk-in-ocfs2_local_quota_add_chunk.patch removed from -mm tree Andrew Morton
  2 siblings, 0 replies; 5+ messages in thread
From: Andrew Morton @ 2026-12-01 20:20 UTC (permalink / raw)
  To: mm-commits, stable, mark, joseph.qi, jlbec, jack, heming.zhao,
	zzjas98, akpm


The patch titled
     Subject: ocfs2: don't free a NULL chunk in ocfs2_local_quota_add_chunk()
has been added to the -mm mm-nonmm-hotfixes-unstable branch.  Its filename is
     ocfs2-dont-free-a-null-chunk-in-ocfs2_local_quota_add_chunk.patch

This patch will shortly appear at
     https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/ocfs2-dont-free-a-null-chunk-in-ocfs2_local_quota_add_chunk.patch

This patch will later appear in the mm-nonmm-hotfixes-unstable branch at
    git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm

Before you just go and hit "reply", please:
   a) Consider who else should be cc'ed
   b) Prefer to cc a suitable mailing list as well
   c) Ideally: find the original patch on the mailing list and do a
      reply-to-all to that, adding suitable additional cc's

*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***

The -mm tree is included into linux-next via various
branches at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
and is updated there most days

------------------------------------------------------
From: Zijie Zhao <zzjas98@gmail.com>
Subject: ocfs2: don't free a NULL chunk in ocfs2_local_quota_add_chunk()
Date: Mon, 30 Nov 2026 17:56:19 -0600

ocfs2_local_quota_add_chunk() allocates the in-memory chunk only after the
local quota file has been extended.  If ocfs2_extend_no_holes() or
ocfs2_simple_size_update() fails, for example with -ENOSPC on a full
filesystem, or if kmem_cache_alloc() fails, the function jumps to the out
label with chunk still NULL.  The out label then calls
kmem_cache_free(ocfs2_qf_chunk_cachep, NULL).

Unlike kfree(), kmem_cache_free() does not accept NULL.  It calls
virt_to_slab() on the pointer and reads the struct page derived from
address 0.  This can oops, or warn about freeing an object that is not
from a slab page.

Allocate the chunk before the file is extended and return right away if
the allocation fails.  Every jump to the out label then has a valid chunk
to free.  A failed allocation also no longer leaves the local quota file
grown by two unused blocks.

Found by a static analysis tool.

The fix and this changelog were drafted with AI assistance (Claude Code,
with a second review by OpenAI Codex), then reviewed by the submitter.

Link: https://patch.msgid.link/20261130-kbug-l1059-ocfs2-quota-v1-1-ea88bd28639b@gmail.com
Fixes: 9e33d69f553a ("ocfs2: Implementation of local and global quota file handling")
Signed-off-by: Zijie Zhao <zzjas98@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Reviewed-by: Joseph Qi <joseph.qi@linux.alibaba.com>
Reviewed-by: Jan Kara <jack@suse.cz>
Cc: Mark Fasheh <mark@fasheh.com>
Cc: Joel Becker <jlbec@evilplan.org>
Cc: Heming Zhao <heming.zhao@suse.com>
Cc: <stable@vger.kernel.org>

 fs/ocfs2/quota_local.c |   13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

--- a/fs/ocfs2/quota_local.c~ocfs2-dont-free-a-null-chunk-in-ocfs2_local_quota_add_chunk
+++ a/fs/ocfs2/quota_local.c
@@ -1003,6 +1003,13 @@ static struct ocfs2_quota_chunk *ocfs2_l
 	struct buffer_head *bh = NULL, *dbh = NULL;
 	u64 p_blkno;
 
+	chunk = kmem_cache_alloc(ocfs2_qf_chunk_cachep, GFP_NOFS);
+	if (!chunk) {
+		status = -ENOMEM;
+		mlog_errno(status);
+		return ERR_PTR(status);
+	}
+
 	/* We are protected by dqio_sem so no locking needed */
 	status = ocfs2_extend_no_holes(lqinode, NULL,
 				       i_size_read(lqinode) + 2 * sb->s_blocksize,
@@ -1018,12 +1025,6 @@ static struct ocfs2_quota_chunk *ocfs2_l
 		goto out;
 	}
 
-	chunk = kmem_cache_alloc(ocfs2_qf_chunk_cachep, GFP_NOFS);
-	if (!chunk) {
-		status = -ENOMEM;
-		mlog_errno(status);
-		goto out;
-	}
 	/* Local quota info and two new blocks we initialize */
 	handle = ocfs2_start_trans(OCFS2_SB(sb),
 			OCFS2_LOCAL_QINFO_WRITE_CREDITS +
_

Patches currently in -mm which might be from zzjas98@gmail.com are

ocfs2-dont-free-a-null-chunk-in-ocfs2_local_quota_add_chunk.patch


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

* [merged mm-nonmm-hotfixes-stable] ocfs2-dont-free-a-null-chunk-in-ocfs2_local_quota_add_chunk.patch removed from -mm tree
  2026-11-30 23:56 [PATCH] ocfs2: don't free a NULL chunk in ocfs2_local_quota_add_chunk() Zijie Zhao via B4 Relay
  2026-12-01 10:36 ` Jan Kara
  2026-12-01 20:20 ` + ocfs2-dont-free-a-null-chunk-in-ocfs2_local_quota_add_chunk.patch added to mm-nonmm-hotfixes-unstable branch Andrew Morton
@ 2026-12-02  3:51 ` Andrew Morton
  2 siblings, 0 replies; 5+ messages in thread
From: Andrew Morton @ 2026-12-02  3:51 UTC (permalink / raw)
  To: mm-commits, stable, mark, joseph.qi, jlbec, jack, heming.zhao,
	zzjas98, akpm


The quilt patch titled
     Subject: ocfs2: don't free a NULL chunk in ocfs2_local_quota_add_chunk()
has been removed from the -mm tree.  Its filename was
     ocfs2-dont-free-a-null-chunk-in-ocfs2_local_quota_add_chunk.patch

This patch was dropped because it was merged into the mm-nonmm-hotfixes-stable branch
of git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm

------------------------------------------------------
From: Zijie Zhao <zzjas98@gmail.com>
Subject: ocfs2: don't free a NULL chunk in ocfs2_local_quota_add_chunk()
Date: Mon, 30 Nov 2026 17:56:19 -0600

ocfs2_local_quota_add_chunk() allocates the in-memory chunk only after the
local quota file has been extended.  If ocfs2_extend_no_holes() or
ocfs2_simple_size_update() fails, for example with -ENOSPC on a full
filesystem, or if kmem_cache_alloc() fails, the function jumps to the out
label with chunk still NULL.  The out label then calls
kmem_cache_free(ocfs2_qf_chunk_cachep, NULL).

Unlike kfree(), kmem_cache_free() does not accept NULL.  It calls
virt_to_slab() on the pointer and reads the struct page derived from
address 0.  This can oops, or warn about freeing an object that is not
from a slab page.

Allocate the chunk before the file is extended and return right away if
the allocation fails.  Every jump to the out label then has a valid chunk
to free.  A failed allocation also no longer leaves the local quota file
grown by two unused blocks.

Found by a static analysis tool.

The fix and this changelog were drafted with AI assistance (Claude Code,
with a second review by OpenAI Codex), then reviewed by the submitter.

Link: https://patch.msgid.link/20261130-kbug-l1059-ocfs2-quota-v1-1-ea88bd28639b@gmail.com
Fixes: 9e33d69f553a ("ocfs2: Implementation of local and global quota file handling")
Signed-off-by: Zijie Zhao <zzjas98@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Reviewed-by: Joseph Qi <joseph.qi@linux.alibaba.com>
Reviewed-by: Jan Kara <jack@suse.cz>
Cc: Mark Fasheh <mark@fasheh.com>
Cc: Joel Becker <jlbec@evilplan.org>
Cc: Heming Zhao <heming.zhao@suse.com>
Cc: <stable@vger.kernel.org>

 fs/ocfs2/quota_local.c |   13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

--- a/fs/ocfs2/quota_local.c~ocfs2-dont-free-a-null-chunk-in-ocfs2_local_quota_add_chunk
+++ a/fs/ocfs2/quota_local.c
@@ -1003,6 +1003,13 @@ static struct ocfs2_quota_chunk *ocfs2_l
 	struct buffer_head *bh = NULL, *dbh = NULL;
 	u64 p_blkno;
 
+	chunk = kmem_cache_alloc(ocfs2_qf_chunk_cachep, GFP_NOFS);
+	if (!chunk) {
+		status = -ENOMEM;
+		mlog_errno(status);
+		return ERR_PTR(status);
+	}
+
 	/* We are protected by dqio_sem so no locking needed */
 	status = ocfs2_extend_no_holes(lqinode, NULL,
 				       i_size_read(lqinode) + 2 * sb->s_blocksize,
@@ -1018,12 +1025,6 @@ static struct ocfs2_quota_chunk *ocfs2_l
 		goto out;
 	}
 
-	chunk = kmem_cache_alloc(ocfs2_qf_chunk_cachep, GFP_NOFS);
-	if (!chunk) {
-		status = -ENOMEM;
-		mlog_errno(status);
-		goto out;
-	}
 	/* Local quota info and two new blocks we initialize */
 	handle = ocfs2_start_trans(OCFS2_SB(sb),
 			OCFS2_LOCAL_QINFO_WRITE_CREDITS +
_

Patches currently in -mm which might be from zzjas98@gmail.com are



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

end of thread, other threads:[~2026-12-02  3:51 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-30 23:56 [PATCH] ocfs2: don't free a NULL chunk in ocfs2_local_quota_add_chunk() Zijie Zhao via B4 Relay
2026-12-01 10:36 ` Jan Kara
2026-12-01 11:00   ` Joseph Qi
2026-12-01 20:20 ` + ocfs2-dont-free-a-null-chunk-in-ocfs2_local_quota_add_chunk.patch added to mm-nonmm-hotfixes-unstable branch Andrew Morton
2026-12-02  3:51 ` [merged mm-nonmm-hotfixes-stable] ocfs2-dont-free-a-null-chunk-in-ocfs2_local_quota_add_chunk.patch removed from -mm tree Andrew Morton

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