Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp105389yba; Mon, 20 May 2019 05:48:32 -0700 (PDT) X-Google-Smtp-Source: APXvYqw2KwhfPE8FFKkp/fhYq6gAz5g9BIVBiuu4zy0nO4r0eWJ+weoYV2wVkLjHEtTQ9jjZmR1P X-Received: by 2002:a17:902:b601:: with SMTP id b1mr27690755pls.117.1558356512402; Mon, 20 May 2019 05:48:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558356512; cv=none; d=google.com; s=arc-20160816; b=ls8E4C22zwlMZCXpUz7LzZzsYorYB2hGQQICKeCOZpgEh0yD87XQxz9UwNC2J5SN7d SbAIya9i0L6DrlEzyyOVXMhkRzwfoxj7DgB1OLyJRJ6P+GUVHfNtTma6zWro72QdqFhM fpHrh5KtO4ccNxXjrp6md9kLS4G6ECdLqZFOoTFD6mBpsbCsegMP1zKL6w+LJU4yDTHe oEK/vuXtKzV+TlQwgi2DfnCYNMeG4NvUJkhs9a0hwjiXGzDZuVvQrc3fmUFTLAmI7dHW ru8o5mUEsnFb8attEvOfMZuhaCmpdjODS3iIX/jD1QvgykXM6DmqOVpgwG7w1dAfHonj kCag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=XMUHV5DM0wi2FUgZFgY9dUb+2V83gmdFbkD8kPjqzO4=; b=ZLt7lHJDJS1qnf64WiRpDEaP0DOKYtGqQkXgUwCm91590LTBNAVz1grHs+kdpQYV3e ZsH0nhD+w5yIbDK5GZi6Al/dyC6JQ7ooADswSDDk1w7EAlppZEw0T61CWXeMtcvUAYjq r2PpHJOCnMOhLKZbZGBs9nF9WNc2R1NqaLdK74eILnz9FernkjuLX3ennYVt9MabQmfG jIxR4BIJveD77uVySJ4KGmcZ5YBwslgiXrxZw24eXn+Qle5Nx3QR9m90tIc0f8jc8T7W zPFRtG3uRb0AqNaQQuVoliz3mrI6oaLXFnWBwLLw+zaAzIggSgwsdZ8i00nW4oLUw6sp AyOQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=HEoqgwRs; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g191si17860949pgc.197.2019.05.20.05.48.17; Mon, 20 May 2019 05:48:32 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-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=@kernel.org header.s=default header.b=HEoqgwRs; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389011AbfETMZL (ORCPT + 99 others); Mon, 20 May 2019 08:25:11 -0400 Received: from mail.kernel.org ([198.145.29.99]:40176 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389000AbfETMZK (ORCPT ); Mon, 20 May 2019 08:25:10 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id E97E020645; Mon, 20 May 2019 12:25:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1558355109; bh=g+LiIFWUKzTKBJwpmGwYkeqEN7TNVfGGtCtw2bIfbs0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HEoqgwRshE/Sw0Gtmv78FevFi5TvUO9DCkX5S0El1H+DnJQVauZm4/owBfYofQmQ1 2nDDlgF8pt4FMpqe/lBJVfjeCKSFGN01ezBHkw8ma2PNoG6nwlHu8rzQA+3EUBDQUO XXgwp2m7vVeBbNgUKuK51wlSdNumXFAcou1z5DXw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Kees Cook , Guenter Roeck Subject: [PATCH 4.19 101/105] pstore: Refactor compression initialization Date: Mon, 20 May 2019 14:14:47 +0200 Message-Id: <20190520115254.199143364@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190520115247.060821231@linuxfoundation.org> References: <20190520115247.060821231@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Kees Cook commit 95047b0519c17a28e09df5f38750f5354e3db4c4 upstream. This refactors compression initialization slightly to better handle getting potentially called twice (via early pstore_register() calls and later pstore_init()) and improves the comments and reporting to be more verbose. Signed-off-by: Kees Cook Tested-by: Guenter Roeck Signed-off-by: Greg Kroah-Hartman --- fs/pstore/platform.c | 48 +++++++++++++++++++++++++++++++++--------------- 1 file changed, 33 insertions(+), 15 deletions(-) --- a/fs/pstore/platform.c +++ b/fs/pstore/platform.c @@ -274,36 +274,56 @@ static int pstore_decompress(void *in, v static void allocate_buf_for_compression(void) { + struct crypto_comp *ctx; + int size; + char *buf; + + /* Skip if not built-in or compression backend not selected yet. */ if (!IS_ENABLED(CONFIG_PSTORE_COMPRESS) || !zbackend) return; + /* Skip if no pstore backend yet or compression init already done. */ + if (!psinfo || tfm) + return; + if (!crypto_has_comp(zbackend->name, 0, 0)) { - pr_err("No %s compression\n", zbackend->name); + pr_err("Unknown compression: %s\n", zbackend->name); return; } - big_oops_buf_sz = zbackend->zbufsize(psinfo->bufsize); - if (big_oops_buf_sz <= 0) + size = zbackend->zbufsize(psinfo->bufsize); + if (size <= 0) { + pr_err("Invalid compression size for %s: %d\n", + zbackend->name, size); return; + } - big_oops_buf = kmalloc(big_oops_buf_sz, GFP_KERNEL); - if (!big_oops_buf) { - pr_err("allocate compression buffer error!\n"); + buf = kmalloc(size, GFP_KERNEL); + if (!buf) { + pr_err("Failed %d byte compression buffer allocation for: %s\n", + size, zbackend->name); return; } - tfm = crypto_alloc_comp(zbackend->name, 0, 0); - if (IS_ERR_OR_NULL(tfm)) { - kfree(big_oops_buf); - big_oops_buf = NULL; - pr_err("crypto_alloc_comp() failed!\n"); + ctx = crypto_alloc_comp(zbackend->name, 0, 0); + if (IS_ERR_OR_NULL(ctx)) { + kfree(buf); + pr_err("crypto_alloc_comp('%s') failed: %ld\n", zbackend->name, + PTR_ERR(ctx)); return; } + + /* A non-NULL big_oops_buf indicates compression is available. */ + tfm = ctx; + big_oops_buf_sz = size; + big_oops_buf = buf; + + pr_info("Using compression: %s\n", zbackend->name); } static void free_buf_for_compression(void) { - if (IS_ENABLED(CONFIG_PSTORE_COMPRESS) && !IS_ERR_OR_NULL(tfm)) + if (IS_ENABLED(CONFIG_PSTORE_COMPRESS) && tfm) crypto_free_comp(tfm); kfree(big_oops_buf); big_oops_buf = NULL; @@ -774,7 +794,6 @@ void __init pstore_choose_compression(vo for (step = zbackends; step->name; step++) { if (!strcmp(compress, step->name)) { zbackend = step; - pr_info("using %s compression\n", zbackend->name); return; } } @@ -791,8 +810,7 @@ static int __init pstore_init(void) * initialize compression because crypto was not ready. If so, * initialize compression now. */ - if (psinfo && !tfm) - allocate_buf_for_compression(); + allocate_buf_for_compression(); ret = pstore_init_fs(); if (ret)