Commit 32927393 authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Al Viro
Browse files

sysctl: pass kernel pointers to ->proc_handler



Instead of having all the sysctl handlers deal with user pointers, which
is rather hairy in terms of the BPF interaction, copy the input to and
from  userspace in common code.  This also means that the strings are
always NUL-terminated by the common code, making the API a little bit
safer.

As most handler just pass through the data to one of the common handlers
a lot of the changes are mechnical.

Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Acked-by: default avatarAndrey Ignatov <rdna@fb.com>
Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
parent f461d2dc
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -203,7 +203,7 @@ static void __init register_insn_emulation(struct insn_emulation_ops *ops)
}

static int emulation_proc_handler(struct ctl_table *table, int write,
				  void __user *buffer, size_t *lenp,
				  void *buffer, size_t *lenp,
				  loff_t *ppos)
{
	int ret = 0;
+1 −2
Original line number Diff line number Diff line
@@ -341,8 +341,7 @@ static unsigned int find_supported_vector_length(unsigned int vl)
#ifdef CONFIG_SYSCTL

static int sve_proc_do_default_vl(struct ctl_table *table, int write,
				  void __user *buffer, size_t *lenp,
				  loff_t *ppos)
				  void *buffer, size_t *lenp, loff_t *ppos)
{
	int ret;
	int vl = sve_default_vl;
+5 −8
Original line number Diff line number Diff line
@@ -95,16 +95,15 @@ int proc_lasat_ip(struct ctl_table *table, int write,
		len = 0;
		p = buffer;
		while (len < *lenp) {
			if (get_user(c, p++))
				return -EFAULT;
			c = *p;
			p++;
			if (c == 0 || c == '\n')
				break;
			len++;
		}
		if (len >= sizeof(ipbuf)-1)
			len = sizeof(ipbuf) - 1;
		if (copy_from_user(ipbuf, buffer, len))
			return -EFAULT;
		memcpy(ipbuf, buffer, len);
		ipbuf[len] = 0;
		*ppos += *lenp;
		/* Now see if we can convert it to a valid IP */
@@ -122,11 +121,9 @@ int proc_lasat_ip(struct ctl_table *table, int write,
		if (len > *lenp)
			len = *lenp;
		if (len)
			if (copy_to_user(buffer, ipbuf, len))
				return -EFAULT;
			memcpy(buffer, ipbuf, len);
		if (len < *lenp) {
			if (put_user('\n', ((char *) buffer) + len))
				return -EFAULT;
			*((char *)buffer + len) = '\n';
			len++;
		}
		*lenp = len;
+5 −6
Original line number Diff line number Diff line
@@ -51,10 +51,9 @@ static struct platform_device *appldata_pdev;
 */
static const char appldata_proc_name[APPLDATA_PROC_NAME_LENGTH] = "appldata";
static int appldata_timer_handler(struct ctl_table *ctl, int write,
				  void __user *buffer, size_t *lenp, loff_t *ppos);
				  void *buffer, size_t *lenp, loff_t *ppos);
static int appldata_interval_handler(struct ctl_table *ctl, int write,
					 void __user *buffer,
					 size_t *lenp, loff_t *ppos);
				     void *buffer, size_t *lenp, loff_t *ppos);

static struct ctl_table_header *appldata_sysctl_header;
static struct ctl_table appldata_table[] = {
@@ -217,7 +216,7 @@ static void __appldata_vtimer_setup(int cmd)
 */
static int
appldata_timer_handler(struct ctl_table *ctl, int write,
			   void __user *buffer, size_t *lenp, loff_t *ppos)
			   void *buffer, size_t *lenp, loff_t *ppos)
{
	int timer_active = appldata_timer_active;
	int rc;
@@ -250,7 +249,7 @@ appldata_timer_handler(struct ctl_table *ctl, int write,
 */
static int
appldata_interval_handler(struct ctl_table *ctl, int write,
			   void __user *buffer, size_t *lenp, loff_t *ppos)
			   void *buffer, size_t *lenp, loff_t *ppos)
{
	int interval = appldata_interval;
	int rc;
@@ -280,7 +279,7 @@ appldata_interval_handler(struct ctl_table *ctl, int write,
 */
static int
appldata_generic_handler(struct ctl_table *ctl, int write,
			   void __user *buffer, size_t *lenp, loff_t *ppos)
			   void *buffer, size_t *lenp, loff_t *ppos)
{
	struct appldata_ops *ops = NULL, *tmp_ops;
	struct list_head *lh;
+1 −1
Original line number Diff line number Diff line
@@ -867,7 +867,7 @@ static int debug_active = 1;
 * if debug_active is already off
 */
static int s390dbf_procactive(struct ctl_table *table, int write,
			      void __user *buffer, size_t *lenp, loff_t *ppos)
			      void *buffer, size_t *lenp, loff_t *ppos)
{
	if (!write || debug_stoppable || !debug_active)
		return proc_dointvec(table, write, buffer, lenp, ppos);
Loading