Messages in this thread | | | From | (Eric W. Biederman) | Subject | Re: [RFC c/r 2/4] [RFC] syscalls, x86: Add __NR_kcmp syscall v7 | Date | Fri, 27 Jan 2012 10:40:54 -0800 |
| |
Cyrill Gorcunov <gorcunov@openvz.org> writes:
> +/* > + * We don't expose real in-memory order of objects for security > + * reasons, still the comparision results should be suitable for > + * sorting. Thus, we obfuscate kernel pointers values (using random > + * cookies obtaned at early boot stage) and compare the production > + * instead. > + */ > +static unsigned long cookies[KCMP_TYPES][2] __read_mostly; > + > +static long kptr_obfuscate(long v, int type) > +{ > + return (v ^ cookies[type][0]) * cookies[type][1]; > +} > + > +/* > + * 0 - equal > + * 1 - less than > + * 2 - greater than > + * 3 - not equal but ordering unavailable (reserved for future) > + */ > +static int kcmp_ptr(long v1, long v2, enum kcmp_type type) > +{
Can you make the prototype: static int kcmp_ptr(void *v1, void *v2, enum kcmp_type type)
So the caller does not need to have casts?
> + long ret; > + > + ret = kptr_obfuscate(v1, type) - kptr_obfuscate(v2, type); > + > + return (ret < 0) | ((ret > 0) << 1); > +} > + > +/* The caller must have pinned the task */ > +static struct file * > +get_file_raw_ptr(struct task_struct *task, unsigned int idx) > +{ > + struct fdtable *fdt; > + struct file *file; > + > + spin_lock(&task->files->file_lock); > + fdt = files_fdtable(task->files); > + if (idx < fdt->max_fds) > + file = fdt->fd[idx]; > + else > + file = NULL; > + spin_unlock(&task->files->file_lock);
I believe I commented on this earlier but it looks like it got lost in the noise.
file == NULL != file == NULL.
When you can't lookup the file kcmp should return -EBADF.
Eric
| |