From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753944Ab2A0SiW (ORCPT ); Fri, 27 Jan 2012 13:38:22 -0500 Received: from out02.mta.xmission.com ([166.70.13.232]:46417 "EHLO out02.mta.xmission.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753157Ab2A0SiV (ORCPT ); Fri, 27 Jan 2012 13:38:21 -0500 From: ebiederm@xmission.com (Eric W. Biederman) To: Cyrill Gorcunov Cc: LKML , Andrew Morton , Pavel Emelyanov , KOSAKI Motohiro , Pavel Emelyanov , Andrey Vagin , KOSAKI Motohiro , Ingo Molnar , "H. Peter Anvin" , Thomas Gleixner , Glauber Costa , Andi Kleen , Tejun Heo , Matt Helsley , Pekka Enberg , Eric Dumazet , Vasiliy Kulikov , Alexey Dobriyan , Valdis.Kletnieks@vt.edu Subject: Re: [RFC c/r 2/4] [RFC] syscalls, x86: Add __NR_kcmp syscall v7 References: <20120127175342.273260614@openvz.org> <20120127175939.795551339@openvz.org> Date: Fri, 27 Jan 2012 10:40:54 -0800 In-Reply-To: <20120127175939.795551339@openvz.org> (Cyrill Gorcunov's message of "Fri, 27 Jan 2012 21:53:44 +0400") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-XM-SPF: eid=;;;mid=;;;hst=in02.mta.xmission.com;;;ip=98.207.153.68;;;frm=ebiederm@xmission.com;;;spf=neutral X-XM-AID: U2FsdGVkX18bpz7X8HV4bne6im+yFbTOBBum2DnGB2U= X-SA-Exim-Connect-IP: 98.207.153.68 X-SA-Exim-Mail-From: ebiederm@xmission.com X-SA-Exim-Scanned: No (on in02.mta.xmission.com); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Cyrill Gorcunov 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