From nobody Sat Feb 7 09:58:36 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (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 05A7D329C6B for ; Wed, 24 Dec 2025 18:21:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766600472; cv=none; b=GSRZJOqz4tfUXtDqVIAGppHZrIEuG0blDmZSaRFL19scSQ4EgDVZPfXGMtuVIIsJ+xed3098ClG2IQLLf24Ub0RceZNhEBs3Q3Ir/35FSQ2jSfFjCHNtllQIiN2FVeZfiij7XpzG4Aa3HobAxmwDWrPMlziCmsOXFnXGYiPLQhk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766600472; c=relaxed/simple; bh=kUEtGZexwuxWvBBaH3Bt8qhV0BzOV87ZgQoNucqqOoo=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=s7EtzGLrSCHpMocpfvtoQNnR6T34Q0SyZmSHMjQXAiFZdgx1t4u9rJ1y1x0Ngd/N4DxDChafqVZKXvnOj8xuYf5F6KrEjmWTfo8EFVAhjWaz/Law38hCdoCZlr8wJfiuWsBWSMkGqGCCy7CRBa8zXVdjGvRL5kscHsFvbbanFR0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=h1Oo0bU9; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="h1Oo0bU9" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1766600469; 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=FMDaQlrjaLe9XjxVldJhVnRL6bKjLFnfMBk3tnqVZUo=; b=h1Oo0bU9B+TLp5TPA/zGNcb7YGvNlhXHonFTMd5CLA02DoYY9NUK9xd3V296uDdbH7BIfj uFb5sE0lI8PL+pVONv8VWL1Qgcz9pp7b4bdmSTGBU7GABxhwxnGCUEVzXzlT8XncsD8JaN /PKbVyvxnr4UucOlQyrnAl9YnlY1K8M= Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-655-iF84iMlRNH6skcQMwTbYoQ-1; Wed, 24 Dec 2025 13:21:04 -0500 X-MC-Unique: iF84iMlRNH6skcQMwTbYoQ-1 X-Mimecast-MFC-AGG-ID: iF84iMlRNH6skcQMwTbYoQ_1766600463 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 345ED1955F3F; Wed, 24 Dec 2025 18:21:03 +0000 (UTC) Received: from mrout-thinkpadp16vgen1.punetw6.csb (unknown [10.74.64.11]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id B78A519560A7; Wed, 24 Dec 2025 18:20:59 +0000 (UTC) From: Malaya Kumar Rout To: linux-kernel@vger.kernel.org Cc: mrout@redhat.com, malayarout91@gmail.com, "Rafael J. Wysocki" , Len Brown , Pavel Machek , linux-pm@vger.kernel.org Subject: [PATCH] PM: hibernate: Fix crash when freeing invalid crypto compressor Date: Wed, 24 Dec 2025 23:50:54 +0530 Message-ID: <20251224182055.124020-1-mrout@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 Content-Type: text/plain; charset="utf-8" When crypto_alloc_acomp() fails, it returns an ERR_PTR value, not NULL. The cleanup code in save_compressed_image() and load_compressed_image() unconditionally calls crypto_free_acomp() without checking for ERR_PTR, which causes crypto_acomp_tfm() to dereference an invalid pointer and crash the kernel. This can be triggered when the compression algorithm is unavailable (e.g., CONFIG_CRYPTO_LZO not enabled). Fix by adding IS_ERR_OR_NULL() checks before calling crypto_free_acomp() and acomp_request_free(), similar to the existing kthread_stop() check. Signed-off-by: Malaya Kumar Rout --- kernel/power/swap.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/kernel/power/swap.c b/kernel/power/swap.c index 33a186373bef..8ee2fa995580 100644 --- a/kernel/power/swap.c +++ b/kernel/power/swap.c @@ -902,8 +902,10 @@ static int save_compressed_image(struct swap_map_handl= e *handle, for (thr =3D 0; thr < nr_threads; thr++) { if (data[thr].thr) kthread_stop(data[thr].thr); - acomp_request_free(data[thr].cr); - crypto_free_acomp(data[thr].cc); + if (data[thr].cr) + acomp_request_free(data[thr].cr); + if (!IS_ERR_OR_NULL(data[thr].cc)) + crypto_free_acomp(data[thr].cc); } vfree(data); } @@ -1499,8 +1501,10 @@ static int load_compressed_image(struct swap_map_han= dle *handle, for (thr =3D 0; thr < nr_threads; thr++) { if (data[thr].thr) kthread_stop(data[thr].thr); - acomp_request_free(data[thr].cr); - crypto_free_acomp(data[thr].cc); + if (data[thr].cr) + acomp_request_free(data[thr].cr); + if (!IS_ERR_OR_NULL(data[thr].cc)) + crypto_free_acomp(data[thr].cc); } vfree(data); } --=20 2.51.0