From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f43.google.com (mail-wm1-f43.google.com [209.85.128.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D423F1885A5 for ; Fri, 2 Jan 2026 06:51:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.43 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767336671; cv=none; b=bnbJvJxvcAAcL79DKyD3CS+YWqgO2zQ1mMFd/rGBaBTZJsUYKtQDAi8SChuUr7SC56WS0UVqxM4pGAEH1u2cEOgW37vIiBz2wmtAxuRMnZ9mpRQ0fm3nIxOH2xXzCyBhO/kYh57nqGLnN7WPiuVKScsr2GaVMuwcSlRbvboih20= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767336671; c=relaxed/simple; bh=KtLHmMA0KgTnst4mIIuazHvvVQTrydXBMkF8NN05Wj8=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=K+LxnIM5JizdFApQBUVMmvLXScIWfA20BwVzqtNzU0DEGH5ntKIGLRxG0eOhWdeYBEdCTKsgL2kGR6eT9C3nobTNMqBP+Eevwx+lPq8t/IEAsferE4FITUcovJkU/dJSqgFdQeZ0jCHJsKQZeXbZKtn4VI3/2LNb9273kPiR/9M= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=cloudlinux.com; spf=pass smtp.mailfrom=cloudlinux.com; dkim=pass (2048-bit key) header.d=cloudlinux.com header.i=@cloudlinux.com header.b=alXudCz4; arc=none smtp.client-ip=209.85.128.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=cloudlinux.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=cloudlinux.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=cloudlinux.com header.i=@cloudlinux.com header.b="alXudCz4" Received: by mail-wm1-f43.google.com with SMTP id 5b1f17b1804b1-47d1d8a49f5so57174295e9.3 for ; Thu, 01 Jan 2026 22:51:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloudlinux.com; s=google; t=1767336665; x=1767941465; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=3hpQrTNwm3YyszShrc7DZ0drIuaJ2peMWnPJuSAGlVo=; b=alXudCz47fRKdb85D5jkymE/dHy67E13rS/Fx0jKyaHjP4iClRcSF2+Lhiff0fhaSp QqxSICsxOOW12jOyXbziyfvrJt+JCwjpPcjVsqcAokcxR+s92jVxKc6SQm+iWK1aAImp S1akj7CCNqqGo0vAsheuwRoroTVvp/U5qdMtsQiwEkFtrd3aNV6mdM0pjf8wK+pT1oha iZfdOpUYzuC5vRlsBK2tq3Kx3Olg9Le9iVtno7Eqa0ZjywhpTNCxDOq+xHVt/1Lxlsy/ zwX2BdzqzN8yf5EyBJ3PVsObiQA5MDNYY3l9Spcos9KB4Iy14tA5L7EeM3VJWeAhmtE/ H0Tw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767336665; x=1767941465; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=3hpQrTNwm3YyszShrc7DZ0drIuaJ2peMWnPJuSAGlVo=; b=wre8gmEWDXw9qky1eB9kTMTh1oDW9n4Jo5Kq4caUVE37zdZFO+kAWFqzQXRaibvxjN 3aVGqi892k1sgEXbZWe1qWgMpRjt7hi6N2KinSjBKc0sCprpi31JP952+htUQRoT7GAX 3WZE7hnsDsvsWrL5oAqe/U6diBIPG+C1qNPv3AfK3v1qtxprb9C/D7UwzW7OkiBbd+E3 O4yJANM5krJd+l3mLZVtDIw+sieZPD/IW3ZMcnnjwANpPGNmy6TWn1GRBmHwnjvh//oH kRP2nh0odiDwKfyweTfTGw2KSWOhyIOLZBR275ZBu6ZD36amjzUj1gIcXUcWauCiu63X Wbnw== X-Forwarded-Encrypted: i=1; AJvYcCUOl0pXKFnXHQhbJmwfDLnqISvdhOLsdnHwHLk/r6+1IT1bpsIj8GocXY5HjBr2E9UftQtNu/R6w4t3q4w=@vger.kernel.org X-Gm-Message-State: AOJu0YyAGoMBcoiqqI5IdVl0xLrGoZFjb/EopjaT0kvOFqeFig9Vclvz j+F7VMuZMIaHZl00/cTBkbvgE7CdUF52W1ZKcTbkoPskP5zuDbuPTTPTUZTBtdIuIW0= X-Gm-Gg: AY/fxX5Gc1U/e+msa8vzZu68WbwJWstXfkUJPSEgV6pyM9QrgOQmTnaOJ63uAXbvpzt issOVgtZD/FMAv7wL/YEn1bITmsYJz8zL9tJDU8QwqyA3h1TO4Ny+zZqCv5uXUmzkmgvCpS0V/D YLSOpD7z2eGMo/nildO+GXfFARkm8MpJ5XxPe2infReblGLIkbnZlcntUR0QwQdyDrBcE4ZREWe qoAg5DJ/GvH6s9cP9Gp5hIHRSALDb+Qqp/KiZ2hGdG5xsf4Ar1jMmqxhNjyfkl0OA9DPFIR5jEL JTdRGstosa1qqAlqLpBtGsVjid2CT5XYrYZKTrSSOvhOHiYZn+luJKBg7BwX86o573DXPtHtnyl VwLGhAs3D1mo3GUdBKuIwCj9fSsB0SK/8g8uliNkLsbl+UQFRE7tZD1ipTcdf7ZGGr1CzrVL0DF la9+VIP8L2SetLM5+BwEcobA== X-Google-Smtp-Source: AGHT+IF68v7S6jIe8LbFTO5ivrVeh6lbPhFlQxBojLvMugVBqe3kYYVhpxZgzhYV2iodtfZEG+eZjg== X-Received: by 2002:a05:600c:4e90:b0:46e:4e6d:79f4 with SMTP id 5b1f17b1804b1-47d19557183mr554474715e9.15.1767336664968; Thu, 01 Jan 2026 22:51:04 -0800 (PST) Received: from [192.168.1.92] ([94.204.137.252]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4324eaa4749sm84134006f8f.37.2026.01.01.22.51.02 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 01 Jan 2026 22:51:04 -0800 (PST) Message-ID: Date: Fri, 2 Jan 2026 10:51:01 +0400 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] mm/zswap: fix error pointer free in zswap_cpu_comp_prepare() To: SeongJae Park Cc: hannes@cmpxchg.org, yosry.ahmed@linux.dev, nphamcs@gmail.com, chengming.zhou@linux.dev, akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org References: <20260101003227.84507-1-sj@kernel.org> Content-Language: en-US From: Pavel Butsykin In-Reply-To: <20260101003227.84507-1-sj@kernel.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 1/1/26 04:32, SeongJae Park wrote: > On Wed, 31 Dec 2025 11:46:38 +0400 Pavel Butsykin wrote: > >> crypto_alloc_acomp_node() may return ERR_PTR(), but the fail path checks >> only for NULL and can pass an error pointer to crypto_free_acomp(). >> Use IS_ERR_OR_NULL() to only free valid acomp instances. >> >> Fixes: 779b9955f643 ("mm: zswap: move allocations during CPU init outside the lock") >> Cc: stable@vger.kernel.org >> Signed-off-by: Pavel Butsykin >> --- >> mm/zswap.c | 2 +- >> 1 file changed, 1 insertion(+), 1 deletion(-) >> >> diff --git a/mm/zswap.c b/mm/zswap.c >> index 5d0f8b13a958..ac9b7a60736b 100644 >> --- a/mm/zswap.c >> +++ b/mm/zswap.c >> @@ -787,7 +787,7 @@ static int zswap_cpu_comp_prepare(unsigned int cpu, struct hlist_node *node) >> return 0; >> >> fail: >> - if (acomp) >> + if (!IS_ERR_OR_NULL(acomp)) >> crypto_free_acomp(acomp); >> kfree(buffer); >> return ret; > > I understand you are keeping NULL case to keep the old behavior. But, seems > the case cannot happen to me for following reasons. > > First of all, the old NULL check was only for crypto_alloc_acomp_node() > failure. But crypto_alloc_acomp_node() seems not returning NULL, to by breif > look of the code. And the failure check of crypto_alloc_acomp_node() is > actually doing only IS_ERR() check. > > So, it seems IS_ERR() here is enough. Or, if I missed a case that > crypto_alloc_acomp_node() returns NULL, the above crypto_alloc_acomp_node() > failure check should be updated to use IS_ERR_OR_NULL()? > We have 'goto fail;' right before crypto_alloc_acomp_node() for the case where kmalloc_node fails to allocate memory. In that case, 'acomp' will still be initialized to NULL.