]> git.ipfire.org Git - people/ms/linux.git/blame - drivers/xen/xenfs/xenstored.c
Importing "grsecurity-3.1-3.19.2-201503201903.patch"
[people/ms/linux.git] / drivers / xen / xenfs / xenstored.c
CommitLineData
655d406a
IC
1#include <linux/slab.h>
2#include <linux/types.h>
3#include <linux/mm.h>
4#include <linux/fs.h>
5
6#include <xen/page.h>
7
8#include "xenfs.h"
9#include "../xenbus/xenbus_comms.h"
10
11static ssize_t xsd_read(struct file *file, char __user *buf,
12 size_t size, loff_t *off)
13{
14 const char *str = (const char *)file->private_data;
15 return simple_read_from_buffer(buf, size, off, str, strlen(str));
16}
17
18static int xsd_release(struct inode *inode, struct file *file)
19{
20 kfree(file->private_data);
21 return 0;
22}
23
24static int xsd_kva_open(struct inode *inode, struct file *file)
25{
26 file->private_data = (void *)kasprintf(GFP_KERNEL, "0x%p",
63d9c273
MT
27#ifdef CONFIG_GRKERNSEC_HIDESYM
28 NULL);
29#else
655d406a 30 xen_store_interface);
63d9c273
MT
31#endif
32
655d406a
IC
33 if (!file->private_data)
34 return -ENOMEM;
35 return 0;
36}
37
38static int xsd_kva_mmap(struct file *file, struct vm_area_struct *vma)
39{
40 size_t size = vma->vm_end - vma->vm_start;
41
42 if ((size > PAGE_SIZE) || (vma->vm_pgoff != 0))
43 return -EINVAL;
44
45 if (remap_pfn_range(vma, vma->vm_start,
46 virt_to_pfn(xen_store_interface),
47 size, vma->vm_page_prot))
48 return -EAGAIN;
49
50 return 0;
51}
52
53const struct file_operations xsd_kva_file_ops = {
54 .open = xsd_kva_open,
55 .mmap = xsd_kva_mmap,
56 .read = xsd_read,
57 .release = xsd_release,
58};
59
60static int xsd_port_open(struct inode *inode, struct file *file)
61{
62 file->private_data = (void *)kasprintf(GFP_KERNEL, "%d",
63 xen_store_evtchn);
64 if (!file->private_data)
65 return -ENOMEM;
66 return 0;
67}
68
69const struct file_operations xsd_port_file_ops = {
70 .open = xsd_port_open,
71 .read = xsd_read,
72 .release = xsd_release,
73};