From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796381900; b=ktSRWiJZpAFeB75Xb8T20Xcp8r+oC06U81qQTtYrrllxq+AJwNRcB8fI5yXTtENTGF6J GztJNqN88sUwb5m91IA0pqMobSYNXNexCqW9UmRT5oCKZDNiO/hrhR+OKGLXbSYS9eXOz gMgW28klN9pBRKfMKkwGwpdqPfDi7dYmJU4oAVk19TuwVk9FG8sE/tq3b37GRdIJZsWE+ wXLH+C6NxSZP7JU1RavUNGXoC/z+OBFbRoYhlI3zQ/pVDCKuvusXCFuDRCEIIs3GNj3Qj 6oGnpZQ3T8g8nA+9qHIFf1u55wNzfTJsgnG+vGkIwXU2OaNlAaY6qHkW+fs4O6pcyIQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796381900; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=nSdG/KUlkCvSl126nWt7Wo16fC960tZchXY3anaDvBk=; b=wHoU9K1BjLarqXsChe84QtXy7CBUqvCNrwyv/vLEAHhpdC3wXhyigffd7rJzXrmOjJnP rG1aPY08HLHNSjfXZborwSIgyU6BcJ1vh1+869KNV1UGj216b5/fgQ/utsDE6ahJYwp1Z IhkEq6b7tP8To8vFUNHU6zVbOVKBkxQO5f40+s4VdSWnRYKbRtyZJq3Snd07bdIGwttXG FcfqZL0NPCfrijz4iCOsG313cPFmRf0/5xWE1Yif5dryafPO+iyq4zhVDmzv0abQYKs2g mT8lCGBoAtnaniEOhYYcI3PEgnToLRjEQE2u63JqM1oJ2P3Vaa4zJjVjCgzDzIHCeXw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=gme22th4; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C412D606A68B; Fri, 4 Dec 2026 10:58:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=gme22th4 Received: by smtp.kernel.org (Postfix) with ESMTPSA id E20021F0093B; Fri, 4 Dec 2026 10:58:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796381900; bh=nSdG/KUlkCvSl126nWt7Wo16fC960tZchXY3anaDvBk=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=gme22th4l4TRsnDkk1/XuuEcmaDyaCcUdgmtBD1XlHaMu3zzfl+NyBYDu1Bkjo3j8 eKDJHXK0DF7AUTRUAfcmOscV0SZ2udHH1T7dtGMaKiWtvmb+hpbvlHH7K7xD/KDYzS HcsdRtruQYp0o+ze6z+E/QSV2rRlsDZ/OD8OczAs= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Yevgeny Kliteynik , Alex Vesker , Tariq Toukan , Jakub Kicinski , Sasha Levin Subject: [PATCH 6.18 221/703] net/mlx5: DR, Fix out-of-bounds write when sync to HW fails Date: Fri, 4 Dec 2026 19:02:00 +0900 Message-ID: <20261204100633.712992654@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100627.522266145@linuxfoundation.org> References: <20261204100627.522266145@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Yevgeny Kliteynik [ Upstream commit 0e56ff4441eea333bfbfeff86ef39038f6e8c378 ] mlx5dr_icm_free_chunk() moves a freed chunk to the "hot" chunks array by writing it to hot_chunks_arr and, once the accumulated hot memory crosses a threshold, triggers a sync to HW that flushes the array. The array is large enough to hold the chunks of a single accumulation cycle, and relies on the sync path to flush it. However, if sync to HW fails, hot chunks array is not cleared, and every subsequent mlx5dr_icm_free_chunk will write past the end of hot_chunks_arr, resulting in an out-of-bounds write and kernel heap corruption. A failed sync to HW also means it is no longer safe to recycle ICM: a chunk's memory may only be returned to the buddy allocator (and thus be reused) after a sync has confirmed that HW no longer references it. The issue was discovered by a fuzzer that repeatedly triggered sync failure, at which point the out-of-bounds write was reported by KASAN: KASAN log excerpt: BUG: slab-out-of-bounds in mlx5dr_icm_free_chunk+0x4cd at call 2 (hot_chunks_num=3 > cap=2). Fix this by putting the pool into an error state on the first failed sync to HW, reporting the failure once. The sync is not retried, and while the pool is in this state: - mlx5dr_icm_free_chunk() doesn't queue freed chunks; the segment is left reserved and is reclaimed when the pool is destroyed. - mlx5dr_icm_alloc_chunk() doesn't serve new chunks. Fixes: 4519fc45beeb ("net/mlx5: DR, Keep track of hot ICM chunks in an array instead of list") Signed-off-by: Yevgeny Kliteynik Reviewed-by: Alex Vesker Signed-off-by: Tariq Toukan Link: https://patch.msgid.link/20261118173227.1957670-3-tariqt@nvidia.com Signed-off-by: Jakub Kicinski Signed-off-by: Sasha Levin --- .../mlx5/core/steering/sws/dr_icm_pool.c | 32 +++++++++++++++++-- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/steering/sws/dr_icm_pool.c b/drivers/net/ethernet/mellanox/mlx5/core/steering/sws/dr_icm_pool.c index 0b5af9f3f605b..c0beedffba60f 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/steering/sws/dr_icm_pool.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/steering/sws/dr_icm_pool.c @@ -33,6 +33,11 @@ struct mlx5dr_icm_pool { u64 hot_memory_size; /* hot memory size threshold for triggering sync */ u64 th; + /* Set when a sync to HW fails - no new chunks are served, freed + * chunks are no longer queued, and their ICM is not returned to + * the buddy allocator. + */ + bool error_state; }; struct mlx5dr_icm_dm { @@ -369,7 +374,15 @@ static int dr_icm_pool_sync_all_buddy_pools(struct mlx5dr_icm_pool *pool) err = mlx5dr_cmd_sync_steering(pool->dmn->mdev); if (err) { - mlx5dr_err(pool->dmn, "Failed to sync to HW (err: %d)\n", err); + /* The hot chunks could not be flushed. Put the pool in an + * error state so that no further chunks are queued (which + * would overflow hot_chunks_arr), and no new chunks are + * served. The sync is not retried. + */ + mlx5dr_err(pool->dmn, + "Failed to sync to HW (err: %d), disabling ICM pool\n", + err); + pool->error_state = true; return err; } @@ -444,6 +457,10 @@ mlx5dr_icm_alloc_chunk(struct mlx5dr_icm_pool *pool, return NULL; mutex_lock(&pool->mutex); + + if (pool->error_state) + goto out; + /* find mem, get back the relevant buddy pool and seg in that mem */ ret = dr_icm_handle_buddies_get_mem(pool, chunk_size, &buddy, &seg); if (ret) @@ -476,6 +493,14 @@ void mlx5dr_icm_free_chunk(struct mlx5dr_icm_chunk *chunk) /* move the chunk to the waiting chunks array, AKA "hot" memory */ mutex_lock(&pool->mutex); + /* If the pool is in an error state, the chunk must not be queued. + * ICM memory is not returned to the buddy allocator - it is + * reclaimed only when the pool is destroyed. + * Just free the chunk's bookkeeping struct. + */ + if (pool->error_state) + goto out; + pool->hot_memory_size += mlx5dr_icm_pool_get_chunk_byte_size(chunk); hot_chunk = &pool->hot_chunks_arr[pool->hot_chunks_num++]; @@ -483,12 +508,13 @@ void mlx5dr_icm_free_chunk(struct mlx5dr_icm_chunk *chunk) hot_chunk->seg = chunk->seg; hot_chunk->size = chunk->size; - kmem_cache_free(chunks_cache, chunk); - /* Check if we have chunks that are waiting for sync-ste */ if (dr_icm_pool_is_sync_required(pool)) dr_icm_pool_sync_all_buddy_pools(pool); +out: + kmem_cache_free(chunks_cache, chunk); + mutex_unlock(&pool->mutex); } -- 2.53.0