mirror of
https://github.com/hardkernel/linux.git
synced 2026-06-05 18:41:58 +09:00
Merge tag 'pstore-v5.20-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux
Pull pstore updates from Kees Cook: - Migrate to modern acomp crypto interface (Ard Biesheuvel) - Use better return type for "rcnt" (Dan Carpenter) * tag 'pstore-v5.20-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux: pstore/zone: cleanup "rcnt" type pstore: migrate to crypto acomp interface
This commit is contained in:
@@ -28,11 +28,14 @@
|
|||||||
#include <linux/crypto.h>
|
#include <linux/crypto.h>
|
||||||
#include <linux/string.h>
|
#include <linux/string.h>
|
||||||
#include <linux/timer.h>
|
#include <linux/timer.h>
|
||||||
|
#include <linux/scatterlist.h>
|
||||||
#include <linux/slab.h>
|
#include <linux/slab.h>
|
||||||
#include <linux/uaccess.h>
|
#include <linux/uaccess.h>
|
||||||
#include <linux/jiffies.h>
|
#include <linux/jiffies.h>
|
||||||
#include <linux/workqueue.h>
|
#include <linux/workqueue.h>
|
||||||
|
|
||||||
|
#include <crypto/acompress.h>
|
||||||
|
|
||||||
#include "internal.h"
|
#include "internal.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -90,7 +93,8 @@ module_param(compress, charp, 0444);
|
|||||||
MODULE_PARM_DESC(compress, "compression to use");
|
MODULE_PARM_DESC(compress, "compression to use");
|
||||||
|
|
||||||
/* Compression parameters */
|
/* Compression parameters */
|
||||||
static struct crypto_comp *tfm;
|
static struct crypto_acomp *tfm;
|
||||||
|
static struct acomp_req *creq;
|
||||||
|
|
||||||
struct pstore_zbackend {
|
struct pstore_zbackend {
|
||||||
int (*zbufsize)(size_t size);
|
int (*zbufsize)(size_t size);
|
||||||
@@ -268,12 +272,21 @@ static const struct pstore_zbackend zbackends[] = {
|
|||||||
static int pstore_compress(const void *in, void *out,
|
static int pstore_compress(const void *in, void *out,
|
||||||
unsigned int inlen, unsigned int outlen)
|
unsigned int inlen, unsigned int outlen)
|
||||||
{
|
{
|
||||||
|
struct scatterlist src, dst;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
if (!IS_ENABLED(CONFIG_PSTORE_COMPRESS))
|
if (!IS_ENABLED(CONFIG_PSTORE_COMPRESS))
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
ret = crypto_comp_compress(tfm, in, inlen, out, &outlen);
|
sg_init_table(&src, 1);
|
||||||
|
sg_set_buf(&src, in, inlen);
|
||||||
|
|
||||||
|
sg_init_table(&dst, 1);
|
||||||
|
sg_set_buf(&dst, out, outlen);
|
||||||
|
|
||||||
|
acomp_request_set_params(creq, &src, &dst, inlen, outlen);
|
||||||
|
|
||||||
|
ret = crypto_acomp_compress(creq);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
pr_err("crypto_comp_compress failed, ret = %d!\n", ret);
|
pr_err("crypto_comp_compress failed, ret = %d!\n", ret);
|
||||||
return ret;
|
return ret;
|
||||||
@@ -284,7 +297,7 @@ static int pstore_compress(const void *in, void *out,
|
|||||||
|
|
||||||
static void allocate_buf_for_compression(void)
|
static void allocate_buf_for_compression(void)
|
||||||
{
|
{
|
||||||
struct crypto_comp *ctx;
|
struct crypto_acomp *acomp;
|
||||||
int size;
|
int size;
|
||||||
char *buf;
|
char *buf;
|
||||||
|
|
||||||
@@ -296,7 +309,7 @@ static void allocate_buf_for_compression(void)
|
|||||||
if (!psinfo || tfm)
|
if (!psinfo || tfm)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!crypto_has_comp(zbackend->name, 0, 0)) {
|
if (!crypto_has_acomp(zbackend->name, 0, CRYPTO_ALG_ASYNC)) {
|
||||||
pr_err("Unknown compression: %s\n", zbackend->name);
|
pr_err("Unknown compression: %s\n", zbackend->name);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -315,16 +328,24 @@ static void allocate_buf_for_compression(void)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx = crypto_alloc_comp(zbackend->name, 0, 0);
|
acomp = crypto_alloc_acomp(zbackend->name, 0, CRYPTO_ALG_ASYNC);
|
||||||
if (IS_ERR_OR_NULL(ctx)) {
|
if (IS_ERR_OR_NULL(acomp)) {
|
||||||
kfree(buf);
|
kfree(buf);
|
||||||
pr_err("crypto_alloc_comp('%s') failed: %ld\n", zbackend->name,
|
pr_err("crypto_alloc_comp('%s') failed: %ld\n", zbackend->name,
|
||||||
PTR_ERR(ctx));
|
PTR_ERR(acomp));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
creq = acomp_request_alloc(acomp);
|
||||||
|
if (!creq) {
|
||||||
|
crypto_free_acomp(acomp);
|
||||||
|
kfree(buf);
|
||||||
|
pr_err("acomp_request_alloc('%s') failed\n", zbackend->name);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* A non-NULL big_oops_buf indicates compression is available. */
|
/* A non-NULL big_oops_buf indicates compression is available. */
|
||||||
tfm = ctx;
|
tfm = acomp;
|
||||||
big_oops_buf_sz = size;
|
big_oops_buf_sz = size;
|
||||||
big_oops_buf = buf;
|
big_oops_buf = buf;
|
||||||
|
|
||||||
@@ -334,7 +355,8 @@ static void allocate_buf_for_compression(void)
|
|||||||
static void free_buf_for_compression(void)
|
static void free_buf_for_compression(void)
|
||||||
{
|
{
|
||||||
if (IS_ENABLED(CONFIG_PSTORE_COMPRESS) && tfm) {
|
if (IS_ENABLED(CONFIG_PSTORE_COMPRESS) && tfm) {
|
||||||
crypto_free_comp(tfm);
|
acomp_request_free(creq);
|
||||||
|
crypto_free_acomp(tfm);
|
||||||
tfm = NULL;
|
tfm = NULL;
|
||||||
}
|
}
|
||||||
kfree(big_oops_buf);
|
kfree(big_oops_buf);
|
||||||
@@ -671,6 +693,8 @@ static void decompress_record(struct pstore_record *record)
|
|||||||
int ret;
|
int ret;
|
||||||
int unzipped_len;
|
int unzipped_len;
|
||||||
char *unzipped, *workspace;
|
char *unzipped, *workspace;
|
||||||
|
struct acomp_req *dreq;
|
||||||
|
struct scatterlist src, dst;
|
||||||
|
|
||||||
if (!IS_ENABLED(CONFIG_PSTORE_COMPRESS) || !record->compressed)
|
if (!IS_ENABLED(CONFIG_PSTORE_COMPRESS) || !record->compressed)
|
||||||
return;
|
return;
|
||||||
@@ -694,16 +718,30 @@ static void decompress_record(struct pstore_record *record)
|
|||||||
if (!workspace)
|
if (!workspace)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
dreq = acomp_request_alloc(tfm);
|
||||||
|
if (!dreq) {
|
||||||
|
kfree(workspace);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
sg_init_table(&src, 1);
|
||||||
|
sg_set_buf(&src, record->buf, record->size);
|
||||||
|
|
||||||
|
sg_init_table(&dst, 1);
|
||||||
|
sg_set_buf(&dst, workspace, unzipped_len);
|
||||||
|
|
||||||
|
acomp_request_set_params(dreq, &src, &dst, record->size, unzipped_len);
|
||||||
|
|
||||||
/* After decompression "unzipped_len" is almost certainly smaller. */
|
/* After decompression "unzipped_len" is almost certainly smaller. */
|
||||||
ret = crypto_comp_decompress(tfm, record->buf, record->size,
|
ret = crypto_acomp_decompress(dreq);
|
||||||
workspace, &unzipped_len);
|
|
||||||
if (ret) {
|
if (ret) {
|
||||||
pr_err("crypto_comp_decompress failed, ret = %d!\n", ret);
|
pr_err("crypto_acomp_decompress failed, ret = %d!\n", ret);
|
||||||
kfree(workspace);
|
kfree(workspace);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Append ECC notice to decompressed buffer. */
|
/* Append ECC notice to decompressed buffer. */
|
||||||
|
unzipped_len = dreq->dlen;
|
||||||
memcpy(workspace + unzipped_len, record->buf + record->size,
|
memcpy(workspace + unzipped_len, record->buf + record->size,
|
||||||
record->ecc_notice_size);
|
record->ecc_notice_size);
|
||||||
|
|
||||||
@@ -711,6 +749,7 @@ static void decompress_record(struct pstore_record *record)
|
|||||||
unzipped = kmemdup(workspace, unzipped_len + record->ecc_notice_size,
|
unzipped = kmemdup(workspace, unzipped_len + record->ecc_notice_size,
|
||||||
GFP_KERNEL);
|
GFP_KERNEL);
|
||||||
kfree(workspace);
|
kfree(workspace);
|
||||||
|
acomp_request_free(dreq);
|
||||||
if (!unzipped)
|
if (!unzipped)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|||||||
@@ -363,7 +363,7 @@ static int psz_kmsg_recover_data(struct psz_context *cxt)
|
|||||||
rcnt = info->read((char *)buf, zone->buffer_size + sizeof(*buf),
|
rcnt = info->read((char *)buf, zone->buffer_size + sizeof(*buf),
|
||||||
zone->off);
|
zone->off);
|
||||||
if (rcnt != zone->buffer_size + sizeof(*buf))
|
if (rcnt != zone->buffer_size + sizeof(*buf))
|
||||||
return (int)rcnt < 0 ? (int)rcnt : -EIO;
|
return rcnt < 0 ? rcnt : -EIO;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -372,7 +372,7 @@ static int psz_kmsg_recover_meta(struct psz_context *cxt)
|
|||||||
{
|
{
|
||||||
struct pstore_zone_info *info = cxt->pstore_zone_info;
|
struct pstore_zone_info *info = cxt->pstore_zone_info;
|
||||||
struct pstore_zone *zone;
|
struct pstore_zone *zone;
|
||||||
size_t rcnt, len;
|
ssize_t rcnt, len;
|
||||||
struct psz_buffer *buf;
|
struct psz_buffer *buf;
|
||||||
struct psz_kmsg_header *hdr;
|
struct psz_kmsg_header *hdr;
|
||||||
struct timespec64 time = { };
|
struct timespec64 time = { };
|
||||||
@@ -400,7 +400,7 @@ static int psz_kmsg_recover_meta(struct psz_context *cxt)
|
|||||||
continue;
|
continue;
|
||||||
} else if (rcnt != len) {
|
} else if (rcnt != len) {
|
||||||
pr_err("read %s with id %lu failed\n", zone->name, i);
|
pr_err("read %s with id %lu failed\n", zone->name, i);
|
||||||
return (int)rcnt < 0 ? (int)rcnt : -EIO;
|
return rcnt < 0 ? rcnt : -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (buf->sig != zone->buffer->sig) {
|
if (buf->sig != zone->buffer->sig) {
|
||||||
@@ -502,7 +502,7 @@ static int psz_recover_zone(struct psz_context *cxt, struct pstore_zone *zone)
|
|||||||
rcnt = info->read((char *)&tmpbuf, len, zone->off);
|
rcnt = info->read((char *)&tmpbuf, len, zone->off);
|
||||||
if (rcnt != len) {
|
if (rcnt != len) {
|
||||||
pr_debug("read zone %s failed\n", zone->name);
|
pr_debug("read zone %s failed\n", zone->name);
|
||||||
return (int)rcnt < 0 ? (int)rcnt : -EIO;
|
return rcnt < 0 ? rcnt : -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tmpbuf.sig != zone->buffer->sig) {
|
if (tmpbuf.sig != zone->buffer->sig) {
|
||||||
@@ -544,7 +544,7 @@ static int psz_recover_zone(struct psz_context *cxt, struct pstore_zone *zone)
|
|||||||
rcnt = info->read(buf, len - start, off + start);
|
rcnt = info->read(buf, len - start, off + start);
|
||||||
if (rcnt != len - start) {
|
if (rcnt != len - start) {
|
||||||
pr_err("read zone %s failed\n", zone->name);
|
pr_err("read zone %s failed\n", zone->name);
|
||||||
ret = (int)rcnt < 0 ? (int)rcnt : -EIO;
|
ret = rcnt < 0 ? rcnt : -EIO;
|
||||||
goto free_oldbuf;
|
goto free_oldbuf;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -552,7 +552,7 @@ static int psz_recover_zone(struct psz_context *cxt, struct pstore_zone *zone)
|
|||||||
rcnt = info->read(buf + len - start, start, off);
|
rcnt = info->read(buf + len - start, start, off);
|
||||||
if (rcnt != start) {
|
if (rcnt != start) {
|
||||||
pr_err("read zone %s failed\n", zone->name);
|
pr_err("read zone %s failed\n", zone->name);
|
||||||
ret = (int)rcnt < 0 ? (int)rcnt : -EIO;
|
ret = rcnt < 0 ? rcnt : -EIO;
|
||||||
goto free_oldbuf;
|
goto free_oldbuf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user