Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752683Ab2BOQ17 (ORCPT ); Wed, 15 Feb 2012 11:27:59 -0500 Received: from mail-bk0-f46.google.com ([209.85.214.46]:60016 "EHLO mail-bk0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752073Ab2BOQ15 (ORCPT ); Wed, 15 Feb 2012 11:27:57 -0500 Date: Wed, 15 Feb 2012 20:27:52 +0400 From: Cyrill Gorcunov To: Oleg Nesterov Cc: "Eric W. Biederman" , 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, Michal Marek , Frederic Weisbecker , Andrew Morton , linux-kernel@vger.kernel.org Subject: Re: + syscalls-x86-add-__nr_kcmp-syscall-v8.patch added to -mm tree Message-ID: <20120215162752.GF4533@moon> References: <20120215143606.GA14037@redhat.com> <20120215160652.GA17680@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20120215160652.GA17680@redhat.com> User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1727 Lines: 54 On Wed, Feb 15, 2012 at 05:06:52PM +0100, Oleg Nesterov wrote: > Not a comment, but the question. I am just curious... > > > +/* > > + * We don't expose real in-memory order of objects for security > > + * reasons, still the comparison results should be suitable for > > + * sorting. Thus, we obfuscate kernel pointers values 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]; > > +} > > OK, but why do we need this per type? Just to add more obfuscation > or there is another reason? Just to add more obfuscation. > > > +static __init int kcmp_cookies_init(void) > > +{ > > + int i; > > + > > + get_random_bytes(cookies, sizeof(cookies)); > > + > > + for (i = 0; i < KCMP_TYPES; i++) > > + cookies[i][1] |= (~(~0UL >> 1) | 1); > > I am puzzled, help ;) this is equal to > > cookies[i][1] |= -LONG_MAX; > or > cookies[i][1] |= (LONG_MIN | 1); > > for what? why do we want to set these 2 bits (MSB and LSB) ? Letme quote hpa@ here :) | This code is wrong. You will have a zero cookie, legitimately, once in | 2^32 or 2^64 attempts, depending on the bitness. | | The other thing is that for the multiplicative cookie you should OR in | the value (~(~0UL >> 1) | 1) in order to make sure that the value is (a) | large and (b) odd. Cyrill -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/