From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-171.mta1.migadu.com (out-171.mta1.migadu.com [95.215.58.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 107533DC4AD for ; Wed, 11 Mar 2026 15:10:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.171 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773241826; cv=none; b=akjbXpiw1i0x36NynysQcq64sXr7Dtl1Kobu7bXpD9FHJqDN9DAoNJcCEd/tZ0lpTzBlH/HkjQUV5iucC44X+XFHEkgY4w7QvvCks3mgVKfPK1rMnKKkumdIhG9nmw5IUGfLW+cpc31zGHEs51M3SjlLqQJHZK16tOmr1hHTAWQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773241826; c=relaxed/simple; bh=iG015FVCN7oPWGVVn9a39BqVhRv1LNNupCbGtz9cTtI=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=oURupwzxkZkLKwejnSQktoW/Mv4wVYWXQMf4o3J5wD96JufA/j6iIEwkw4sBwla5H7JSNfRMXItiJub+L6Jhq7mlK26myTfDMwWqD6m0MUi0N0essXmUzb/Il2mjtx24zmYf8/HbEkUFFrVs2CKU0FtXrY/iHiTGbKDdN3f6J7I= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=GK3fS4w1; arc=none smtp.client-ip=95.215.58.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="GK3fS4w1" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1773241810; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=Y050AoUlwUvE4JwnOIvUs9WWS/VlkQtCxi3b0zHeXK0=; b=GK3fS4w1p586rGFvb7W0Kx91572o8m6OQ+CSVZnCR9ApTUCQ8yrd77df/GhVoSJ/oFVAyr 3cGZFlVwYR8QJLgg66nLiMpi63XJ4jex51Kz/y3Z94JTC3moVU2HrAJ1+rMesFP3VkEbjQ dZYlcJAUool8HeK4P2fdtfVvtzxkdZU= From: Thorsten Blum To: Haren Myneni , Madhavan Srinivasan , Michael Ellerman , Nicholas Piggin , "Christophe Leroy (CS GROUP)" , Herbert Xu , "David S. Miller" , Dan Streetman , Ard Biesheuvel Cc: Thorsten Blum , stable@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] crypto: nx - fix memory leaks in nx842_crypto_{alloc,free}_ctx Date: Wed, 11 Mar 2026 16:09:24 +0100 Message-ID: <20260311150922.382941-3-thorsten.blum@linux.dev> Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1901; i=thorsten.blum@linux.dev; h=from:subject; bh=iG015FVCN7oPWGVVn9a39BqVhRv1LNNupCbGtz9cTtI=; b=owGbwMvMwCUWt7pQ4caZUj3G02pJDJkbWxe7bCtbbHHYJ3xFb6NL37Kd5yvdrmtMrL9xvfaGG 1937bHUjlIWBjEuBlkxRZYHs37M8C2tqdxkErETZg4rE8gQBi5OAZjIhRUM/5PqbKvWzPma3PaS 43L5/oz4hYF8y0z2XXKfujJOQ+fF0SeMDC8iZ21rnO+tpM+t9fBq6Z3bLW1/v/DxP+BKWFN4L0G JiwcA X-Developer-Key: i=thorsten.blum@linux.dev; a=openpgp; fpr=1D60735E8AEF3BE473B69D84733678FD8DFEEAD4 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT The bounce buffers are allocated with __get_free_pages() using BOUNCE_BUFFER_ORDER (order 2 = 4 pages), but both the allocation error path and nx842_crypto_free_ctx() release the buffers with free_page(). Use free_pages() with the matching order instead. Also, since the scomp conversion, nx842_crypto_alloc_ctx() allocates the context separately, but nx842_crypto_free_ctx() never releases it. Add the missing kfree(ctx) in nx842_crypto_free_ctx(), and reuse nx842_crypto_free_ctx() in the allocation error path. Fixes: ed70b479c2c0 ("crypto: nx - add hardware 842 crypto comp alg") Fixes: 980b5705f4e7 ("crypto: nx - Migrate to scomp API") Cc: stable@vger.kernel.org Signed-off-by: Thorsten Blum --- drivers/crypto/nx/nx-842.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/drivers/crypto/nx/nx-842.c b/drivers/crypto/nx/nx-842.c index b61f2545e165..a61208cbcd27 100644 --- a/drivers/crypto/nx/nx-842.c +++ b/drivers/crypto/nx/nx-842.c @@ -115,10 +115,7 @@ void *nx842_crypto_alloc_ctx(struct nx842_driver *driver) ctx->sbounce = (u8 *)__get_free_pages(GFP_KERNEL, BOUNCE_BUFFER_ORDER); ctx->dbounce = (u8 *)__get_free_pages(GFP_KERNEL, BOUNCE_BUFFER_ORDER); if (!ctx->wmem || !ctx->sbounce || !ctx->dbounce) { - kfree(ctx->wmem); - free_page((unsigned long)ctx->sbounce); - free_page((unsigned long)ctx->dbounce); - kfree(ctx); + nx842_crypto_free_ctx(ctx); return ERR_PTR(-ENOMEM); } @@ -131,8 +128,9 @@ void nx842_crypto_free_ctx(void *p) struct nx842_crypto_ctx *ctx = p; kfree(ctx->wmem); - free_page((unsigned long)ctx->sbounce); - free_page((unsigned long)ctx->dbounce); + free_pages((unsigned long)ctx->sbounce, BOUNCE_BUFFER_ORDER); + free_pages((unsigned long)ctx->dbounce, BOUNCE_BUFFER_ORDER); + kfree(ctx); } EXPORT_SYMBOL_GPL(nx842_crypto_free_ctx);