This uses compat_alloc_userspace to remove the various hacks to allow do_sysctl to write to throuh oldlenp. The rest of our mature compat syscall helper facitilies are used as well to ensure we have a nice clean maintainable compat syscall that can be used on all architectures. The motiviation for a generic compat sysctl (besides the obvious hack removal) is to reduce the number of compat sysctl defintions out there so I can refactor the binary sysctl implementation. ppc already used the name compat_sys_sysctl so I remove the ppcs version here.
Showing the changes to kernel/sysctl_binary.c (1 of 2 files). Show all
Unified · Split
| @@ -176,3 +176,53 @@ SYSCALL_DEFINE1(sysctl, struct __sysctl_args __user *, args) · 175 unmodified lines | ||
| 176 | 176 | |
| 177 | 177 | return error; |
| 178 | 178 | } |
| 179 | + | |
| 180 | +#ifdef CONFIG_COMPAT | |
| 181 | +#include <asm/compat.h> | |
| 182 | + | |
| 183 | +struct compat_sysctl_args { | |
| 184 | + compat_uptr_t name; | |
| 185 | + int nlen; | |
| 186 | + compat_uptr_t oldval; | |
| 187 | + compat_uptr_t oldlenp; | |
| 188 | + compat_uptr_t newval; | |
| 189 | + compat_size_t newlen; | |
| 190 | + compat_ulong_t __unused[4]; | |
| 191 | +}; | |
| 192 | + | |
| 193 | +asmlinkage long compat_sys_sysctl(struct compat_sysctl_args __user *args) | |
| 194 | +{ | |
| 195 | + struct compat_sysctl_args tmp; | |
| 196 | + compat_size_t __user *compat_oldlenp; | |
| 197 | + size_t __user *oldlenp = NULL; | |
| 198 | + size_t oldlen = 0; | |
| 199 | + ssize_t result; | |
| 200 | + | |
| 201 | + if (copy_from_user(&tmp, args, sizeof(tmp))) | |
| 202 | + return -EFAULT; | |
| 203 | + | |
| 204 | + compat_oldlenp = compat_ptr(tmp.oldlenp); | |
| 205 | + if (compat_oldlenp) { | |
| 206 | + oldlenp = compat_alloc_user_space(sizeof(*compat_oldlenp)); | |
| 207 | + | |
| 208 | + if (get_user(oldlen, compat_oldlenp) || | |
| 209 | + put_user(oldlen, oldlenp)) | |
| 210 | + return -EFAULT; | |
| 211 | + } | |
| 212 | + | |
| 213 | + lock_kernel(); | |
| 214 | + result = do_sysctl(compat_ptr(tmp.name), tmp.nlen, | |
| 215 | + compat_ptr(tmp.oldval), oldlenp, | |
| 216 | + compat_ptr(tmp.newval), tmp.newlen); | |
| 217 | + unlock_kernel(); | |
| 218 | + | |
| 219 | + if (oldlenp && !result) { | |
| 220 | + if (get_user(oldlen, oldlenp) || | |
| 221 | + put_user(oldlen, compat_oldlenp)) | |
| 222 | + return -EFAULT; | |
| 223 | + } | |
| 224 | + | |
| 225 | + return result; | |
| 226 | +} | |
| 227 | + | |
| 228 | +#endif /* CONFIG_COMPAT */ | |