Commit 4bd6a735 authored by Matthew Wilcox (Oracle)'s avatar Matthew Wilcox (Oracle) Committed by Al Viro

sysctl: Convert to iter interfaces

Using the read_iter/write_iter interfaces allows for in-kernel users
to set sysctls without using set_fs().  Also, the buffer is a string,
so give it the real type of 'char *', not void *.

[AV: Christoph's fixup folded in]
Signed-off-by: default avatarMatthew Wilcox (Oracle) <willy@infradead.org>
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
parent fd5a13f4
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include <linux/cred.h> #include <linux/cred.h>
#include <linux/namei.h> #include <linux/namei.h>
#include <linux/mm.h> #include <linux/mm.h>
#include <linux/uio.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/bpf-cgroup.h> #include <linux/bpf-cgroup.h>
#include <linux/mount.h> #include <linux/mount.h>
...@@ -540,13 +541,14 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry, ...@@ -540,13 +541,14 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
return err; return err;
} }
static ssize_t proc_sys_call_handler(struct file *filp, void __user *ubuf, static ssize_t proc_sys_call_handler(struct kiocb *iocb, struct iov_iter *iter,
size_t count, loff_t *ppos, int write) int write)
{ {
struct inode *inode = file_inode(filp); struct inode *inode = file_inode(iocb->ki_filp);
struct ctl_table_header *head = grab_header(inode); struct ctl_table_header *head = grab_header(inode);
struct ctl_table *table = PROC_I(inode)->sysctl_entry; struct ctl_table *table = PROC_I(inode)->sysctl_entry;
void *kbuf; size_t count = iov_iter_count(iter);
char *kbuf;
ssize_t error; ssize_t error;
if (IS_ERR(head)) if (IS_ERR(head))
...@@ -569,32 +571,30 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *ubuf, ...@@ -569,32 +571,30 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *ubuf,
error = -ENOMEM; error = -ENOMEM;
if (count >= KMALLOC_MAX_SIZE) if (count >= KMALLOC_MAX_SIZE)
goto out; goto out;
kbuf = kzalloc(count + 1, GFP_KERNEL);
if (write) {
kbuf = memdup_user_nul(ubuf, count);
if (IS_ERR(kbuf)) {
error = PTR_ERR(kbuf);
goto out;
}
} else {
kbuf = kzalloc(count, GFP_KERNEL);
if (!kbuf) if (!kbuf)
goto out; goto out;
if (write) {
error = -EFAULT;
if (!copy_from_iter_full(kbuf, count, iter))
goto out_free_buf;
kbuf[count] = '\0';
} }
error = BPF_CGROUP_RUN_PROG_SYSCTL(head, table, write, &kbuf, &count, error = BPF_CGROUP_RUN_PROG_SYSCTL(head, table, write, &kbuf, &count,
ppos); &iocb->ki_pos);
if (error) if (error)
goto out_free_buf; goto out_free_buf;
/* careful: calling conventions are nasty here */ /* careful: calling conventions are nasty here */
error = table->proc_handler(table, write, kbuf, &count, ppos); error = table->proc_handler(table, write, kbuf, &count, &iocb->ki_pos);
if (error) if (error)
goto out_free_buf; goto out_free_buf;
if (!write) { if (!write) {
error = -EFAULT; error = -EFAULT;
if (copy_to_user(ubuf, kbuf, count)) if (copy_to_iter(kbuf, count, iter) < count)
goto out_free_buf; goto out_free_buf;
} }
...@@ -607,16 +607,14 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *ubuf, ...@@ -607,16 +607,14 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *ubuf,
return error; return error;
} }
static ssize_t proc_sys_read(struct file *filp, char __user *buf, static ssize_t proc_sys_read(struct kiocb *iocb, struct iov_iter *iter)
size_t count, loff_t *ppos)
{ {
return proc_sys_call_handler(filp, (void __user *)buf, count, ppos, 0); return proc_sys_call_handler(iocb, iter, 0);
} }
static ssize_t proc_sys_write(struct file *filp, const char __user *buf, static ssize_t proc_sys_write(struct kiocb *iocb, struct iov_iter *iter)
size_t count, loff_t *ppos)
{ {
return proc_sys_call_handler(filp, (void __user *)buf, count, ppos, 1); return proc_sys_call_handler(iocb, iter, 1);
} }
static int proc_sys_open(struct inode *inode, struct file *filp) static int proc_sys_open(struct inode *inode, struct file *filp)
...@@ -853,8 +851,10 @@ static int proc_sys_getattr(const struct path *path, struct kstat *stat, ...@@ -853,8 +851,10 @@ static int proc_sys_getattr(const struct path *path, struct kstat *stat,
static const struct file_operations proc_sys_file_operations = { static const struct file_operations proc_sys_file_operations = {
.open = proc_sys_open, .open = proc_sys_open,
.poll = proc_sys_poll, .poll = proc_sys_poll,
.read = proc_sys_read, .read_iter = proc_sys_read,
.write = proc_sys_write, .write_iter = proc_sys_write,
.splice_read = generic_file_splice_read,
.splice_write = iter_file_splice_write,
.llseek = default_llseek, .llseek = default_llseek,
}; };
......
...@@ -136,7 +136,7 @@ int __cgroup_bpf_check_dev_permission(short dev_type, u32 major, u32 minor, ...@@ -136,7 +136,7 @@ int __cgroup_bpf_check_dev_permission(short dev_type, u32 major, u32 minor,
int __cgroup_bpf_run_filter_sysctl(struct ctl_table_header *head, int __cgroup_bpf_run_filter_sysctl(struct ctl_table_header *head,
struct ctl_table *table, int write, struct ctl_table *table, int write,
void **buf, size_t *pcount, loff_t *ppos, char **buf, size_t *pcount, loff_t *ppos,
enum bpf_attach_type type); enum bpf_attach_type type);
int __cgroup_bpf_run_filter_setsockopt(struct sock *sock, int *level, int __cgroup_bpf_run_filter_setsockopt(struct sock *sock, int *level,
......
...@@ -1226,7 +1226,7 @@ const struct bpf_verifier_ops cg_dev_verifier_ops = { ...@@ -1226,7 +1226,7 @@ const struct bpf_verifier_ops cg_dev_verifier_ops = {
*/ */
int __cgroup_bpf_run_filter_sysctl(struct ctl_table_header *head, int __cgroup_bpf_run_filter_sysctl(struct ctl_table_header *head,
struct ctl_table *table, int write, struct ctl_table *table, int write,
void **buf, size_t *pcount, loff_t *ppos, char **buf, size_t *pcount, loff_t *ppos,
enum bpf_attach_type type) enum bpf_attach_type type)
{ {
struct bpf_sysctl_kern ctx = { struct bpf_sysctl_kern ctx = {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment