mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-08-27 03:10:12 +00:00
![Linus Torvalds](/assets/img/avatar_default.png)
- Switch pmsg_lock to an rt_mutex to avoid priority inversion (John Stultz) - Correctly assign mem_type property (Luca Stefani) -----BEGIN PGP SIGNATURE----- iQJKBAABCgA0FiEEpcP2jyKd1g9yPm4TiXL039xtwCYFAmOl9XkWHGtlZXNjb29r QGNocm9taXVtLm9yZwAKCRCJcvTf3G3AJgkUD/9QoUAxaCQY6NHjbnujyF6e2gOx A7IHxy6h3Z7ZAYvxDrtNqB/pJEVQR81rdz+NGJ/Hsu3k3N/1NeXioD6rM5tsW3tp 7/KdMbX3eUmGmgq2kvENS8yD6HqW4IMTdZJJeO7GaM1+LuIOvLsR6rprwoS//BfW 5Asugk5BDsucFVmHxjC7m9eb4wuSPhRCtlFHw0HCeGIeClHY5oU6N6/LpEkjjIBo Hy0v8qU6xS3c7HjENw7REVdeiIb9goa4EDYt1EqjCoQ/mQXSOuuVKxT8GV0CNRWX pwkWF916xYOmIlWqLXjMXYSoJdt3BmpqB/KnkeKRPkUdIh8YgnSWHRMT74ib6DM1 FEwA0j/JCOZYOmrQ0jWnLfaWKIiXKfyu56EIXKC9eRf4J2NdrfUflwhqhG56JgkW Yz1XoS2IviNNjEISCfwS2c22f+U2vr4PrIarHeJWJZRhO1dnP8JvHdqjl8Ps1cEn LePbrHIUZdLZldVE1wix5Lfv6nhR08ttgy8sp4SkTZdNUtW5DmqGV40wY9olHjqq JfcS0EvZXidm+aB4N2oVBTNjCcwL38EYinXF7jS+LePkJayUVSf83liS05QwNFTj xlQ9rr7kB49S0T5+HWV0IAOB0i5tIu1vWy5ziEyZ1pPcP1hzqqLT+gTbRvYTWxW5 OFnZtKLTzzTteLl4Nw== =wpaN -----END PGP SIGNATURE----- Merge tag 'pstore-v6.2-rc1-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux Pull pstore fixes from Kees Cook: - Switch pmsg_lock to an rt_mutex to avoid priority inversion (John Stultz) - Correctly assign mem_type property (Luca Stefani) * tag 'pstore-v6.2-rc1-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux: pstore: Properly assign mem_type property pstore: Make sure CONFIG_PSTORE_PMSG selects CONFIG_RT_MUTEXES pstore: Switch pmsg_lock to an rt_mutex to avoid priority inversion
95 lines
2 KiB
C
95 lines
2 KiB
C
// SPDX-License-Identifier: GPL-2.0-only
|
|
/*
|
|
* Copyright 2014 Google, Inc.
|
|
*/
|
|
|
|
#include <linux/cdev.h>
|
|
#include <linux/device.h>
|
|
#include <linux/fs.h>
|
|
#include <linux/uaccess.h>
|
|
#include <linux/rtmutex.h>
|
|
#include "internal.h"
|
|
|
|
static DEFINE_RT_MUTEX(pmsg_lock);
|
|
|
|
static ssize_t write_pmsg(struct file *file, const char __user *buf,
|
|
size_t count, loff_t *ppos)
|
|
{
|
|
struct pstore_record record;
|
|
int ret;
|
|
|
|
if (!count)
|
|
return 0;
|
|
|
|
pstore_record_init(&record, psinfo);
|
|
record.type = PSTORE_TYPE_PMSG;
|
|
record.size = count;
|
|
|
|
/* check outside lock, page in any data. write_user also checks */
|
|
if (!access_ok(buf, count))
|
|
return -EFAULT;
|
|
|
|
rt_mutex_lock(&pmsg_lock);
|
|
ret = psinfo->write_user(&record, buf);
|
|
rt_mutex_unlock(&pmsg_lock);
|
|
return ret ? ret : count;
|
|
}
|
|
|
|
static const struct file_operations pmsg_fops = {
|
|
.owner = THIS_MODULE,
|
|
.llseek = noop_llseek,
|
|
.write = write_pmsg,
|
|
};
|
|
|
|
static struct class *pmsg_class;
|
|
static int pmsg_major;
|
|
#define PMSG_NAME "pmsg"
|
|
#undef pr_fmt
|
|
#define pr_fmt(fmt) PMSG_NAME ": " fmt
|
|
|
|
static char *pmsg_devnode(const struct device *dev, umode_t *mode)
|
|
{
|
|
if (mode)
|
|
*mode = 0220;
|
|
return NULL;
|
|
}
|
|
|
|
void pstore_register_pmsg(void)
|
|
{
|
|
struct device *pmsg_device;
|
|
|
|
pmsg_major = register_chrdev(0, PMSG_NAME, &pmsg_fops);
|
|
if (pmsg_major < 0) {
|
|
pr_err("register_chrdev failed\n");
|
|
goto err;
|
|
}
|
|
|
|
pmsg_class = class_create(THIS_MODULE, PMSG_NAME);
|
|
if (IS_ERR(pmsg_class)) {
|
|
pr_err("device class file already in use\n");
|
|
goto err_class;
|
|
}
|
|
pmsg_class->devnode = pmsg_devnode;
|
|
|
|
pmsg_device = device_create(pmsg_class, NULL, MKDEV(pmsg_major, 0),
|
|
NULL, "%s%d", PMSG_NAME, 0);
|
|
if (IS_ERR(pmsg_device)) {
|
|
pr_err("failed to create device\n");
|
|
goto err_device;
|
|
}
|
|
return;
|
|
|
|
err_device:
|
|
class_destroy(pmsg_class);
|
|
err_class:
|
|
unregister_chrdev(pmsg_major, PMSG_NAME);
|
|
err:
|
|
return;
|
|
}
|
|
|
|
void pstore_unregister_pmsg(void)
|
|
{
|
|
device_destroy(pmsg_class, MKDEV(pmsg_major, 0));
|
|
class_destroy(pmsg_class);
|
|
unregister_chrdev(pmsg_major, PMSG_NAME);
|
|
}
|