2019-05-29 22:17:56 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2015-01-17 08:01:10 +08:00
|
|
|
/*
|
|
|
|
* Copyright 2014 Google, Inc.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/cdev.h>
|
|
|
|
#include <linux/device.h>
|
|
|
|
#include <linux/fs.h>
|
|
|
|
#include <linux/uaccess.h>
|
|
|
|
#include "internal.h"
|
|
|
|
|
|
|
|
static DEFINE_MUTEX(pmsg_lock);
|
|
|
|
|
|
|
|
static ssize_t write_pmsg(struct file *file, const char __user *buf,
|
|
|
|
size_t count, loff_t *ppos)
|
|
|
|
{
|
2017-05-20 06:10:31 +08:00
|
|
|
struct pstore_record record;
|
2016-09-01 23:13:46 +08:00
|
|
|
int ret;
|
2015-01-17 08:01:10 +08:00
|
|
|
|
|
|
|
if (!count)
|
|
|
|
return 0;
|
|
|
|
|
2017-05-20 06:10:31 +08:00
|
|
|
pstore_record_init(&record, psinfo);
|
|
|
|
record.type = PSTORE_TYPE_PMSG;
|
|
|
|
record.size = count;
|
|
|
|
|
2017-03-06 14:41:10 +08:00
|
|
|
/* check outside lock, page in any data. write_user also checks */
|
Remove 'type' argument from access_ok() function
Nobody has actually used the type (VERIFY_READ vs VERIFY_WRITE) argument
of the user address range verification function since we got rid of the
old racy i386-only code to walk page tables by hand.
It existed because the original 80386 would not honor the write protect
bit when in kernel mode, so you had to do COW by hand before doing any
user access. But we haven't supported that in a long time, and these
days the 'type' argument is a purely historical artifact.
A discussion about extending 'user_access_begin()' to do the range
checking resulted this patch, because there is no way we're going to
move the old VERIFY_xyz interface to that model. And it's best done at
the end of the merge window when I've done most of my merges, so let's
just get this done once and for all.
This patch was mostly done with a sed-script, with manual fix-ups for
the cases that weren't of the trivial 'access_ok(VERIFY_xyz' form.
There were a couple of notable cases:
- csky still had the old "verify_area()" name as an alias.
- the iter_iov code had magical hardcoded knowledge of the actual
values of VERIFY_{READ,WRITE} (not that they mattered, since nothing
really used it)
- microblaze used the type argument for a debug printout
but other than those oddities this should be a total no-op patch.
I tried to fix up all architectures, did fairly extensive grepping for
access_ok() uses, and the changes are trivial, but I may have missed
something. Any missed conversion should be trivially fixable, though.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2019-01-04 10:57:57 +08:00
|
|
|
if (!access_ok(buf, count))
|
2015-01-17 08:01:10 +08:00
|
|
|
return -EFAULT;
|
|
|
|
|
|
|
|
mutex_lock(&pmsg_lock);
|
2017-03-06 14:41:10 +08:00
|
|
|
ret = psinfo->write_user(&record, buf);
|
2015-01-17 08:01:10 +08:00
|
|
|
mutex_unlock(&pmsg_lock);
|
2016-09-01 23:13:46 +08:00
|
|
|
return ret ? ret : count;
|
2015-01-17 08:01:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
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(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;
|
|
|
|
}
|
2015-10-20 15:39:03 +08:00
|
|
|
|
|
|
|
void pstore_unregister_pmsg(void)
|
|
|
|
{
|
|
|
|
device_destroy(pmsg_class, MKDEV(pmsg_major, 0));
|
|
|
|
class_destroy(pmsg_class);
|
|
|
|
unregister_chrdev(pmsg_major, PMSG_NAME);
|
|
|
|
}
|