hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/net/sunrpc/sysctl.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * linux/net/sunrpc/sysctl.c
34 *
....@@ -59,25 +60,32 @@
5960 }
6061
6162 static int proc_do_xprt(struct ctl_table *table, int write,
62
- void __user *buffer, size_t *lenp, loff_t *ppos)
63
+ void *buffer, size_t *lenp, loff_t *ppos)
6364 {
6465 char tmpbuf[256];
65
- size_t len;
66
+ ssize_t len;
6667
67
- if ((*ppos && !write) || !*lenp) {
68
+ if (write || *ppos) {
6869 *lenp = 0;
6970 return 0;
7071 }
7172 len = svc_print_xprts(tmpbuf, sizeof(tmpbuf));
72
- return simple_read_from_buffer(buffer, *lenp, ppos, tmpbuf, len);
73
+ len = memory_read_from_buffer(buffer, *lenp, ppos, tmpbuf, len);
74
+
75
+ if (len < 0) {
76
+ *lenp = 0;
77
+ return -EINVAL;
78
+ }
79
+ *lenp = len;
80
+ return 0;
7381 }
7482
7583 static int
76
-proc_dodebug(struct ctl_table *table, int write,
77
- void __user *buffer, size_t *lenp, loff_t *ppos)
84
+proc_dodebug(struct ctl_table *table, int write, void *buffer, size_t *lenp,
85
+ loff_t *ppos)
7886 {
79
- char tmpbuf[20], c, *s = NULL;
80
- char __user *p;
87
+ char tmpbuf[20], *s = NULL;
88
+ char *p;
8189 unsigned int value;
8290 size_t left, len;
8391
....@@ -89,18 +97,17 @@
8997 left = *lenp;
9098
9199 if (write) {
92
- if (!access_ok(VERIFY_READ, buffer, left))
93
- return -EFAULT;
94100 p = buffer;
95
- while (left && __get_user(c, p) >= 0 && isspace(c))
96
- left--, p++;
101
+ while (left && isspace(*p)) {
102
+ left--;
103
+ p++;
104
+ }
97105 if (!left)
98106 goto done;
99107
100108 if (left > sizeof(tmpbuf) - 1)
101109 return -EINVAL;
102
- if (copy_from_user(tmpbuf, p, left))
103
- return -EFAULT;
110
+ memcpy(tmpbuf, p, left);
104111 tmpbuf[left] = '\0';
105112
106113 value = simple_strtol(tmpbuf, &s, 0);
....@@ -108,8 +115,10 @@
108115 left -= (s - tmpbuf);
109116 if (left && !isspace(*s))
110117 return -EINVAL;
111
- while (left && isspace(*s))
112
- left--, s++;
118
+ while (left && isspace(*s)) {
119
+ left--;
120
+ s++;
121
+ }
113122 } else
114123 left = 0;
115124 *(unsigned int *) table->data = value;
....@@ -120,11 +129,9 @@
120129 len = sprintf(tmpbuf, "0x%04x", *(unsigned int *) table->data);
121130 if (len > left)
122131 len = left;
123
- if (copy_to_user(buffer, tmpbuf, len))
124
- return -EFAULT;
132
+ memcpy(buffer, tmpbuf, len);
125133 if ((left -= len) > 0) {
126
- if (put_user('\n', (char __user *)buffer + len))
127
- return -EFAULT;
134
+ *((char *)buffer + len) = '\n';
128135 left--;
129136 }
130137 }