get rid of legacy 'get_ds()' function
Every in-kernel use of this function defined it to KERNEL_DS (either as an actual define, or as an inline function). It's an entirely historical artifact, and long long long ago used to actually read the segment selector valueof '%ds' on x86. Which in the kernel is always KERNEL_DS. Inspired by a patch from Jann Horn that just did this for a very small subset of users (the ones in fs/), along with Al who suggested a script. I then just took it to the logical extreme and removed all the remaining gunk. Roughly scripted with git grep -l '(get_ds())' -- :^tools/ | xargs sed -i 's/(get_ds())/(KERNEL_DS)/' git grep -lw 'get_ds' -- :^tools/ | xargs sed -i '/^#define get_ds()/d' plus manual fixups to remove a few unusual usage patterns, the couple of inline function cases and to fix up a comment that had become stale. The 'get_ds()' function remains in an x86 kvm selftest, since in user space it actually does something relevant. Inspired-by: Jann Horn <jannh@google.com> Inspired-by: Al Viro <viro@zeniv.linux.org.uk> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
parent
84c4e1f89f
commit
736706bee3
|
@ -18,7 +18,6 @@
|
|||
#define USER_DS ((mm_segment_t) { -0x40000000000UL })
|
||||
|
||||
#define get_fs() (current_thread_info()->addr_limit)
|
||||
#define get_ds() (KERNEL_DS)
|
||||
#define set_fs(x) (current_thread_info()->addr_limit = (x))
|
||||
|
||||
#define segment_eq(a, b) ((a).seg == (b).seg)
|
||||
|
|
|
@ -59,7 +59,6 @@ extern int __put_user_bad(void);
|
|||
* Note that this is actually 0x1,0000,0000
|
||||
*/
|
||||
#define KERNEL_DS 0x00000000
|
||||
#define get_ds() (KERNEL_DS)
|
||||
|
||||
#ifdef CONFIG_MMU
|
||||
|
||||
|
|
|
@ -150,7 +150,7 @@ void __show_regs(struct pt_regs *regs)
|
|||
if ((domain & domain_mask(DOMAIN_USER)) ==
|
||||
domain_val(DOMAIN_USER, DOMAIN_NOACCESS))
|
||||
segment = "none";
|
||||
else if (fs == get_ds())
|
||||
else if (fs == KERNEL_DS)
|
||||
segment = "kernel";
|
||||
else
|
||||
segment = "user";
|
||||
|
|
|
@ -113,8 +113,7 @@ ENTRY(privcmd_call)
|
|||
|
||||
/*
|
||||
* Disable userspace access from kernel. This is fine to do it
|
||||
* unconditionally as no set_fs(KERNEL_DS)/set_fs(get_ds()) is
|
||||
* called before.
|
||||
* unconditionally as no set_fs(KERNEL_DS) is called before.
|
||||
*/
|
||||
uaccess_disable r4
|
||||
|
||||
|
|
|
@ -34,7 +34,6 @@
|
|||
#include <asm/memory.h>
|
||||
#include <asm/extable.h>
|
||||
|
||||
#define get_ds() (KERNEL_DS)
|
||||
#define get_fs() (current_thread_info()->addr_limit)
|
||||
|
||||
static inline void set_fs(mm_segment_t fs)
|
||||
|
|
|
@ -9,7 +9,6 @@ typedef struct {
|
|||
} mm_segment_t;
|
||||
|
||||
#define KERNEL_DS ((mm_segment_t) { 0xFFFFFFFF })
|
||||
#define get_ds() KERNEL_DS
|
||||
|
||||
#define USER_DS ((mm_segment_t) { 0x80000000UL })
|
||||
#define get_fs() (current_thread_info()->addr_limit)
|
||||
|
|
|
@ -33,12 +33,6 @@ static inline mm_segment_t get_fs(void)
|
|||
return USER_DS;
|
||||
}
|
||||
|
||||
static inline mm_segment_t get_ds(void)
|
||||
{
|
||||
/* return the supervisor data space code */
|
||||
return KERNEL_DS;
|
||||
}
|
||||
|
||||
#define segment_eq(a, b) ((a).seg == (b).seg)
|
||||
|
||||
#endif /* __ASSEMBLY__ */
|
||||
|
|
|
@ -48,7 +48,6 @@
|
|||
#define KERNEL_DS ((mm_segment_t) { ~0UL }) /* cf. access_ok() */
|
||||
#define USER_DS ((mm_segment_t) { TASK_SIZE-1 }) /* cf. access_ok() */
|
||||
|
||||
#define get_ds() (KERNEL_DS)
|
||||
#define get_fs() (current_thread_info()->addr_limit)
|
||||
#define set_fs(x) (current_thread_info()->addr_limit = (x))
|
||||
|
||||
|
|
|
@ -45,16 +45,9 @@ static inline void set_fs(mm_segment_t val)
|
|||
: /* no outputs */ : "r" (val.seg) : "memory");
|
||||
}
|
||||
|
||||
static inline mm_segment_t get_ds(void)
|
||||
{
|
||||
/* return the supervisor data space code */
|
||||
return KERNEL_DS;
|
||||
}
|
||||
|
||||
#else
|
||||
#define USER_DS MAKE_MM_SEG(TASK_SIZE)
|
||||
#define KERNEL_DS MAKE_MM_SEG(0xFFFFFFFF)
|
||||
#define get_ds() (KERNEL_DS)
|
||||
#define get_fs() (current_thread_info()->addr_limit)
|
||||
#define set_fs(x) (current_thread_info()->addr_limit = (x))
|
||||
#endif
|
||||
|
|
|
@ -42,7 +42,6 @@
|
|||
# define USER_DS MAKE_MM_SEG(TASK_SIZE - 1)
|
||||
# endif
|
||||
|
||||
# define get_ds() (KERNEL_DS)
|
||||
# define get_fs() (current_thread_info()->addr_limit)
|
||||
# define set_fs(val) (current_thread_info()->addr_limit = (val))
|
||||
|
||||
|
|
|
@ -69,7 +69,6 @@ extern u64 __ua_limit;
|
|||
#define USER_DS ((mm_segment_t) { __UA_LIMIT })
|
||||
#endif
|
||||
|
||||
#define get_ds() (KERNEL_DS)
|
||||
#define get_fs() (current_thread_info()->addr_limit)
|
||||
#define set_fs(x) (current_thread_info()->addr_limit = (x))
|
||||
|
||||
|
|
|
@ -86,7 +86,7 @@ static int ftrace_modify_code(unsigned long ip, unsigned int new_code)
|
|||
return -EFAULT;
|
||||
|
||||
old_fs = get_fs();
|
||||
set_fs(get_ds());
|
||||
set_fs(KERNEL_DS);
|
||||
flush_icache_range(ip, ip + 8);
|
||||
set_fs(old_fs);
|
||||
|
||||
|
@ -111,7 +111,7 @@ static int ftrace_modify_code_2(unsigned long ip, unsigned int new_code1,
|
|||
|
||||
ip -= 4;
|
||||
old_fs = get_fs();
|
||||
set_fs(get_ds());
|
||||
set_fs(KERNEL_DS);
|
||||
flush_icache_range(ip, ip + 8);
|
||||
set_fs(old_fs);
|
||||
|
||||
|
@ -135,7 +135,7 @@ static int ftrace_modify_code_2r(unsigned long ip, unsigned int new_code1,
|
|||
return -EFAULT;
|
||||
|
||||
old_fs = get_fs();
|
||||
set_fs(get_ds());
|
||||
set_fs(KERNEL_DS);
|
||||
flush_icache_range(ip, ip + 8);
|
||||
set_fs(old_fs);
|
||||
|
||||
|
|
|
@ -212,7 +212,7 @@ void kgdb_call_nmi_hook(void *ignored)
|
|||
mm_segment_t old_fs;
|
||||
|
||||
old_fs = get_fs();
|
||||
set_fs(get_ds());
|
||||
set_fs(KERNEL_DS);
|
||||
|
||||
kgdb_nmicallback(raw_smp_processor_id(), NULL);
|
||||
|
||||
|
@ -318,7 +318,7 @@ static int kgdb_mips_notify(struct notifier_block *self, unsigned long cmd,
|
|||
|
||||
/* Kernel mode. Set correct address limit */
|
||||
old_fs = get_fs();
|
||||
set_fs(get_ds());
|
||||
set_fs(KERNEL_DS);
|
||||
|
||||
if (atomic_read(&kgdb_active) != -1)
|
||||
kgdb_nmicallback(smp_processor_id(), regs);
|
||||
|
|
|
@ -1077,7 +1077,7 @@ asmlinkage void do_tr(struct pt_regs *regs)
|
|||
|
||||
seg = get_fs();
|
||||
if (!user_mode(regs))
|
||||
set_fs(get_ds());
|
||||
set_fs(KERNEL_DS);
|
||||
|
||||
prev_state = exception_enter();
|
||||
current->thread.trap_nr = (regs->cp0_cause >> 2) & 0x1f;
|
||||
|
|
|
@ -37,7 +37,6 @@ extern int fixup_exception(struct pt_regs *regs);
|
|||
#define KERNEL_DS ((mm_segment_t) { ~0UL })
|
||||
#define USER_DS ((mm_segment_t) {TASK_SIZE - 1})
|
||||
|
||||
#define get_ds() (KERNEL_DS)
|
||||
#define get_fs() (current_thread_info()->addr_limit)
|
||||
#define user_addr_max get_fs
|
||||
|
||||
|
|
|
@ -121,7 +121,7 @@ void show_regs(struct pt_regs *regs)
|
|||
regs->uregs[3], regs->uregs[2], regs->uregs[1], regs->uregs[0]);
|
||||
pr_info(" IRQs o%s Segment %s\n",
|
||||
interrupts_enabled(regs) ? "n" : "ff",
|
||||
segment_eq(get_fs(), get_ds())? "kernel" : "user");
|
||||
segment_eq(get_fs(), KERNEL_DS)? "kernel" : "user");
|
||||
}
|
||||
|
||||
EXPORT_SYMBOL(show_regs);
|
||||
|
|
|
@ -26,7 +26,6 @@
|
|||
#define USER_DS MAKE_MM_SEG(0x80000000UL)
|
||||
#define KERNEL_DS MAKE_MM_SEG(0)
|
||||
|
||||
#define get_ds() (KERNEL_DS)
|
||||
|
||||
#define get_fs() (current_thread_info()->addr_limit)
|
||||
#define set_fs(seg) (current_thread_info()->addr_limit = (seg))
|
||||
|
|
|
@ -42,7 +42,6 @@
|
|||
*/
|
||||
|
||||
#define KERNEL_DS (~0UL)
|
||||
#define get_ds() (KERNEL_DS)
|
||||
|
||||
#define USER_DS (TASK_SIZE)
|
||||
#define get_fs() (current_thread_info()->addr_limit)
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
|
||||
#define segment_eq(a, b) ((a).seg == (b).seg)
|
||||
|
||||
#define get_ds() (KERNEL_DS)
|
||||
#define get_fs() (current_thread_info()->addr_limit)
|
||||
#define set_fs(x) (current_thread_info()->addr_limit = (x))
|
||||
|
||||
|
|
|
@ -28,7 +28,6 @@
|
|||
#define USER_DS MAKE_MM_SEG(TASK_SIZE - 1)
|
||||
#endif
|
||||
|
||||
#define get_ds() (KERNEL_DS)
|
||||
#define get_fs() (current->thread.addr_limit)
|
||||
|
||||
static inline void set_fs(mm_segment_t fs)
|
||||
|
|
|
@ -41,7 +41,6 @@
|
|||
#define KERNEL_DS (~0UL)
|
||||
#define USER_DS (TASK_SIZE)
|
||||
|
||||
#define get_ds() (KERNEL_DS)
|
||||
#define get_fs() (current_thread_info()->addr_limit)
|
||||
|
||||
static inline void set_fs(mm_segment_t fs)
|
||||
|
|
|
@ -31,7 +31,6 @@
|
|||
#define USER_DS (2)
|
||||
#define USER_DS_SACF (3)
|
||||
|
||||
#define get_ds() (KERNEL_DS)
|
||||
#define get_fs() (current->thread.mm_segment)
|
||||
#define segment_eq(a,b) (((a) & 2) == ((b) & 2))
|
||||
|
||||
|
|
|
@ -26,7 +26,6 @@ typedef struct {
|
|||
|
||||
#define segment_eq(a, b) ((a).seg == (b).seg)
|
||||
|
||||
#define get_ds() (KERNEL_DS)
|
||||
|
||||
#define get_fs() (current_thread_info()->addr_limit)
|
||||
#define set_fs(x) (current_thread_info()->addr_limit = (x))
|
||||
|
|
|
@ -25,7 +25,6 @@
|
|||
#define KERNEL_DS ((mm_segment_t) { 0 })
|
||||
#define USER_DS ((mm_segment_t) { -1 })
|
||||
|
||||
#define get_ds() (KERNEL_DS)
|
||||
#define get_fs() (current->thread.current_ds)
|
||||
#define set_fs(val) ((current->thread.current_ds) = (val))
|
||||
|
||||
|
|
|
@ -31,7 +31,6 @@
|
|||
#define USER_DS ((mm_segment_t) { ASI_AIUS }) /* har har har */
|
||||
|
||||
#define get_fs() ((mm_segment_t){(current_thread_info()->current_ds)})
|
||||
#define get_ds() (KERNEL_DS)
|
||||
|
||||
#define segment_eq(a, b) ((a).seg == (b).seg)
|
||||
|
||||
|
|
|
@ -25,7 +25,6 @@
|
|||
#define KERNEL_DS MAKE_MM_SEG(-1UL)
|
||||
#define USER_DS MAKE_MM_SEG(TASK_SIZE_MAX)
|
||||
|
||||
#define get_ds() (KERNEL_DS)
|
||||
#define get_fs() (current->thread.addr_limit)
|
||||
static inline void set_fs(mm_segment_t fs)
|
||||
{
|
||||
|
|
|
@ -32,8 +32,6 @@
|
|||
#define KERNEL_DS 0
|
||||
#define USER_DS 1
|
||||
|
||||
#define get_ds (KERNEL_DS)
|
||||
|
||||
/*
|
||||
* get_fs reads current->thread.current_ds into a register.
|
||||
* On Entry:
|
||||
|
|
|
@ -32,7 +32,6 @@
|
|||
#define KERNEL_DS ((mm_segment_t) { 0 })
|
||||
#define USER_DS ((mm_segment_t) { 1 })
|
||||
|
||||
#define get_ds() (KERNEL_DS)
|
||||
#define get_fs() (current->thread.current_ds)
|
||||
#define set_fs(val) (current->thread.current_ds = (val))
|
||||
|
||||
|
|
|
@ -137,7 +137,7 @@ static int isFileReadable(char *path)
|
|||
ret = PTR_ERR(fp);
|
||||
}
|
||||
else {
|
||||
oldfs = get_fs(); set_fs(get_ds());
|
||||
oldfs = get_fs(); set_fs(KERNEL_DS);
|
||||
|
||||
if (1!=readFile(fp, &buf, 1))
|
||||
ret = -EINVAL;
|
||||
|
@ -165,7 +165,7 @@ static int retriveFromFile(char *path, u8 *buf, u32 sz)
|
|||
if (0 == (ret =openFile(&fp, path, O_RDONLY, 0))) {
|
||||
DBG_871X("%s openFile path:%s fp =%p\n", __func__, path , fp);
|
||||
|
||||
oldfs = get_fs(); set_fs(get_ds());
|
||||
oldfs = get_fs(); set_fs(KERNEL_DS);
|
||||
ret =readFile(fp, buf, sz);
|
||||
set_fs(oldfs);
|
||||
closeFile(fp);
|
||||
|
|
|
@ -426,7 +426,7 @@ ssize_t kernel_read(struct file *file, void *buf, size_t count, loff_t *pos)
|
|||
ssize_t result;
|
||||
|
||||
old_fs = get_fs();
|
||||
set_fs(get_ds());
|
||||
set_fs(KERNEL_DS);
|
||||
/* The cast to a user pointer is valid due to the set_fs() */
|
||||
result = vfs_read(file, (void __user *)buf, count, pos);
|
||||
set_fs(old_fs);
|
||||
|
@ -499,7 +499,7 @@ ssize_t __kernel_write(struct file *file, const void *buf, size_t count, loff_t
|
|||
return -EINVAL;
|
||||
|
||||
old_fs = get_fs();
|
||||
set_fs(get_ds());
|
||||
set_fs(KERNEL_DS);
|
||||
p = (__force const char __user *)buf;
|
||||
if (count > MAX_RW_COUNT)
|
||||
count = MAX_RW_COUNT;
|
||||
|
@ -521,7 +521,7 @@ ssize_t kernel_write(struct file *file, const void *buf, size_t count,
|
|||
ssize_t res;
|
||||
|
||||
old_fs = get_fs();
|
||||
set_fs(get_ds());
|
||||
set_fs(KERNEL_DS);
|
||||
/* The cast to a user pointer is valid due to the set_fs() */
|
||||
res = vfs_write(file, (__force const char __user *)buf, count, pos);
|
||||
set_fs(old_fs);
|
||||
|
|
|
@ -357,7 +357,7 @@ static ssize_t kernel_readv(struct file *file, const struct kvec *vec,
|
|||
ssize_t res;
|
||||
|
||||
old_fs = get_fs();
|
||||
set_fs(get_ds());
|
||||
set_fs(KERNEL_DS);
|
||||
/* The cast to a user pointer is valid due to the set_fs() */
|
||||
res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos, 0);
|
||||
set_fs(old_fs);
|
||||
|
|
|
@ -22,7 +22,6 @@
|
|||
#endif
|
||||
|
||||
#ifndef get_fs
|
||||
#define get_ds() (KERNEL_DS)
|
||||
#define get_fs() (current_thread_info()->addr_limit)
|
||||
|
||||
static inline void set_fs(mm_segment_t fs)
|
||||
|
|
|
@ -200,7 +200,7 @@ int integrity_kernel_read(struct file *file, loff_t offset,
|
|||
return -EBADF;
|
||||
|
||||
old_fs = get_fs();
|
||||
set_fs(get_ds());
|
||||
set_fs(KERNEL_DS);
|
||||
ret = __vfs_read(file, buf, count, &offset);
|
||||
set_fs(old_fs);
|
||||
|
||||
|
|
Loading…
Reference in New Issue