Linux XFS filesystem development
 help / color / mirror / Atom feed
From: "user.mail" <sandeen@redhat.com>
To: linux-xfs@vger.kernel.org
Cc: "user.mail" <sandeen@redhat.com>
Subject: [PATCH 1/2] xfs_repair: do not allow cache growth to overflow
Date: Mon, 24 Aug 2026 14:58:59 -0500	[thread overview]
Message-ID: <20260824214056.400740-2-sandeen@redhat.com> (raw)
In-Reply-To: <20260824214056.400740-1-sandeen@redhat.com>

Nothing stops cache_expand() from growing c_maxcount (via *2)
repeatedly until it overflows.

Add a bounds check here and return failure if for any reason we try to
grow too much.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: user.mail <sandeen@redhat.com>
---
 libxfs/cache.c | 20 ++++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)

diff --git a/libxfs/cache.c b/libxfs/cache.c
index d5d9ba56..f8be9b89 100644
--- a/libxfs/cache.c
+++ b/libxfs/cache.c
@@ -79,16 +79,23 @@ cache_init(
 	return cache;
 }
 
-static void
+static int
 cache_expand(
 	struct cache *		cache)
 {
+	int			success = 1;
 	pthread_mutex_lock(&cache->c_mutex);
+	if (cache->c_maxcount <= UINT_MAX/2) {
 #ifdef CACHE_DEBUG
-	fprintf(stderr, "doubling cache size to %u\n", 2 * cache->c_maxcount);
+		fprintf(stderr, "doubling cache size to %u\n",
+			2 * cache->c_maxcount);
 #endif
-	cache->c_maxcount *= 2;
+		cache->c_maxcount *= 2;
+	} else
+		success = 0;
 	pthread_mutex_unlock(&cache->c_mutex);
+
+	return success;
 }
 
 void
@@ -468,7 +475,8 @@ next_object:
 		 */
 		if (priority > CACHE_MAX_PRIORITY) {
 			priority = 0;
-			cache_expand(cache);
+			if (!cache_expand(cache))
+				goto fail;
 		}
 	}
 
@@ -488,6 +496,10 @@ next_object:
 
 	*nodep = node;
 	return 1;
+
+fail:
+	*nodep = NULL;
+	return -1;
 }
 
 void
-- 
2.55.0


  reply	other threads:[~2026-08-24 21:41 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-24 19:58 [PATCH 0/2] xfs_repair: improve caching in the face of ENOMEM user.mail
2026-08-24 19:58 ` user.mail [this message]
2026-08-25  3:17   ` [PATCH 1/2] xfs_repair: do not allow cache growth to overflow Darrick J. Wong
2026-08-25 12:36     ` Eric Sandeen
2026-08-24 19:59 ` [PATCH 2/2] xfs_repair: distinguish true ENOMEM from "not found" in cache_node_get user.mail
2026-08-25  3:18   ` Darrick J. Wong
2026-08-25 15:39     ` Eric Sandeen
2026-08-25 15:49       ` Darrick J. Wong
2026-08-25 15:50         ` Eric Sandeen

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=20260824214056.400740-2-sandeen@redhat.com \
    --to=sandeen@redhat.com \
    --cc=linux-xfs@vger.kernel.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox