All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@linux-foundation.org>
To: mm-commits@vger.kernel.org,stable@vger.kernel.org,mark@fasheh.com,
	joseph.qi@linux.alibaba.com,jlbec@evilplan.org,jack@suse.cz,
	heming.zhao@suse.com,zzjas98@gmail.com,akpm@linux-foundation.org
Subject: + ocfs2-dont-free-a-null-chunk-in-ocfs2_local_quota_add_chunk.patch added to mm-nonmm-hotfixes-unstable branch
Date: Tue, 01 Dec 2026 12:20:28 -0800	[thread overview]
Message-ID: <20261201202029.3980D1F00899@smtp.kernel.org> (raw)
In-Reply-To: <20261130-kbug-l1059-ocfs2-quota-v1-1-ea88bd28639b@gmail.com>


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


  parent reply	other threads:[~2026-12-01 20:20 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-30 23:56 [PATCH] ocfs2: don't free a NULL chunk in ocfs2_local_quota_add_chunk() Zijie Zhao
2026-11-30 23:56 ` Zijie Zhao via B4 Relay
2026-12-01 10:36 ` Jan Kara
2026-12-01 11:00   ` Joseph Qi
2026-12-01 20:20 ` Andrew Morton [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261201202029.3980D1F00899@smtp.kernel.org \
    --to=akpm@linux-foundation.org \
    --cc=heming.zhao@suse.com \
    --cc=jack@suse.cz \
    --cc=jlbec@evilplan.org \
    --cc=joseph.qi@linux.alibaba.com \
    --cc=mark@fasheh.com \
    --cc=mm-commits@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=zzjas98@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.