lkml.org 
[lkml]   [2012]   [Jan]   [27]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [RFC c/r 2/4] [RFC] syscalls, x86: Add __NR_kcmp syscall v7
On 01/27/2012 09:53 AM, Cyrill Gorcunov wrote:
> +
> +/*
> + * 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)
> +{
> + long ret;
> +
> + ret = kptr_obfuscate(v1, type) - kptr_obfuscate(v2, type);
> +
> + return (ret < 0) | ((ret > 0) << 1);
> +}
> +

I just want to point out that we could do hard cryptography, too --
using DES or AES and compare the result since symmetric cryptography is
an isomorphism. One would have to compare the whole result, obviously,
not a truncated one, so using memcmp() or the similar.

I'll leave it up to the security guys to worry about if that is needed,
but since it is something that can be slotted in without changing the
API it seems reasonably safe.

-hpa


\
 
 \ /
  Last update: 2012-01-27 19:09    [W:0.276 / U:0.068 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site