From patchwork Fri Jul 21 15:42:37 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 108489 Delivered-To: patch@linaro.org Received: by 10.140.101.44 with SMTP id t41csp943966qge; Fri, 21 Jul 2017 08:43:08 -0700 (PDT) X-Received: by 10.84.232.14 with SMTP id h14mr8555262plk.359.1500651788372; Fri, 21 Jul 2017 08:43:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1500651788; cv=none; d=google.com; s=arc-20160816; b=cc4F6DOU2j8A3AzY5Bx9MFtwiCJT3ZUmweS1PRYy/b9DfSYt2MKXJtCYv76sA5J1yi maKP0cDsipzuQ4xncH9ReaG1yW1JNMFpE6ToUo/0BUuYuv0pA5E92lVEEeRSLC2ZF44V EHMdHSMQPDTk2lKCPR9Bz16RjayeUAbIU4nsdKNXAQsXv6hKs87OYeYt20beYHG9Tv2H 3nFBgvRvfkN6eMwvHvp216btKex6DncAPrVe4dV73sT6zfbRNa7fVgj0wkpRUax/xpvt oOO4CmNAq8v3uoblJ+5ViUuvX/RW6QMfrSAP56R1ORSz0Opqm/AUxx/YLpSfZKqPzWKI lYvg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=a7JNrWpnMVlUFAGuoqLTIYgtq98pCEcXjPyUDarEqzo=; b=lLkXptxvqwAq1U1Yi/T/6V9o0RP73lnyIkneD1yxjgDi0vQHn+E17cg6awblEngqQz bXjjWObkIIN7hzAVGI7iPUADetiI6gzQ7Iz6zeV3aqYjvpUZdMe497uf/PxO+KuTYGW3 Y5hH5qOYS4cATqosCR/RrRDYmJEQcIxUEVmEJhdTe/tiZu+MmeNKjzGw+HmBjXEmflOG WBbd9rl1YiuNX6ITCOC02UJn806tXhDGgyLpxvIbGRzoLo5VCGI1khc8Dnx96Gyd2+Io XSEQmM24VharB0fM1pLSmIN6NHVUpi8NxaMPaWrTBmsjZUWf2EjtZC3cEEuZ1OsrI24Q 9ZjQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.b=Air7MSZT; spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o1si1422656pld.973.2017.07.21.08.43.08; Fri, 21 Jul 2017 08:43:08 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.b=Air7MSZT; spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753795AbdGUPnE (ORCPT + 1 other); Fri, 21 Jul 2017 11:43:04 -0400 Received: from mail-wm0-f48.google.com ([74.125.82.48]:38683 "EHLO mail-wm0-f48.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750802AbdGUPnB (ORCPT ); Fri, 21 Jul 2017 11:43:01 -0400 Received: by mail-wm0-f48.google.com with SMTP id w191so17403597wmw.1 for ; Fri, 21 Jul 2017 08:43:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=a7JNrWpnMVlUFAGuoqLTIYgtq98pCEcXjPyUDarEqzo=; b=Air7MSZTH+BC2EoUQrzpSewfpOkbBqWs5/YNVdJeQYKNcGEQ+7w2UQlxVOK2FhNL4K VXiAOyxrWaLk+dhv+YtuPBxTXLSwPVh7pGehR4eAwDJMev9huG653oenQe6clrPZLDH7 N1EFRGP5U74nu4VbFkHMP88zO1tqtTiixrQio= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=a7JNrWpnMVlUFAGuoqLTIYgtq98pCEcXjPyUDarEqzo=; b=fsfcE/a74dYl2ZGDnXwIXOqO+HXXGGlvnUaa/A+yauWVEmViiVPtz5LP7xt3eYhHFx zEg7EWE209hGw0UGarXuv9JSNfJ8bsHoMDaJYVts37rleq7zWciTBRinHgzPR2CtFB4B we53d3Uhtdr8Pr8UAQ0Eelg7EgY5pkf9VAal8zLCGE+yFXXjLmu/URv+w/SlABUCySIN jrgpeX5eAjDFqmvS2QpKI0eADxroY4pbM3JxGPiNRmJCXWRe56+r8eoVivyg2d0jBpoU V8HSumPe8pUSMMftWpTvFZdDmgtoVujC7ik7vXVtlPm01Z5oTAMETOTqM0FB5L+fAELC KVHA== X-Gm-Message-State: AIVw111Ih63Qg+P+1H+UKni0P/FTtERmHFU5uGWrxk/BD9QL0GdlPQPT h8Q50EMz1zh++IRLFC8vRg== X-Received: by 10.28.87.205 with SMTP id l196mr4975854wmb.121.1500651779957; Fri, 21 Jul 2017 08:42:59 -0700 (PDT) Received: from localhost.localdomain ([105.148.195.69]) by smtp.gmail.com with ESMTPSA id f203sm1498563wme.39.2017.07.21.08.42.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 21 Jul 2017 08:42:59 -0700 (PDT) From: Ard Biesheuvel To: linux-crypto@vger.kernel.org, herbert@gondor.apana.org.au, giovanni.cabiddu@intel.com Cc: Ard Biesheuvel Subject: [PATCH v2 2/3] crypto: scompress - free partially allocated scratch buffers on failure Date: Fri, 21 Jul 2017 16:42:37 +0100 Message-Id: <20170721154238.21697-3-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170721154238.21697-1-ard.biesheuvel@linaro.org> References: <20170721154238.21697-1-ard.biesheuvel@linaro.org> Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org When allocating the per-CPU scratch buffers, we allocate the source and destination buffers separately, but bail immediately if the second allocation fails, without freeing the first one. Fix that. Signed-off-by: Ard Biesheuvel --- crypto/scompress.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) -- 2.11.0 diff --git a/crypto/scompress.c b/crypto/scompress.c index 0b40d991d65f..2c07648305ad 100644 --- a/crypto/scompress.c +++ b/crypto/scompress.c @@ -125,8 +125,11 @@ static int crypto_scomp_alloc_all_scratches(void) if (!scomp_src_scratches) return -ENOMEM; scomp_dst_scratches = crypto_scomp_alloc_scratches(); - if (!scomp_dst_scratches) + if (!scomp_dst_scratches) { + crypto_scomp_free_scratches(scomp_src_scratches); + scomp_src_scratches = NULL; return -ENOMEM; + } } return 0; }