Messages in this thread |  | | | Date | Fri, 20 Jan 2012 20:29:00 +0400 | | From | Cyrill Gorcunov <> | | Subject | Re: [RFC] syscalls, x86: Add __NR_kcmp syscall |
| |
On Fri, Jan 20, 2012 at 06:51:31AM -0800, H. Peter Anvin wrote: > On 01/20/2012 01:02 AM, Cyrill Gorcunov wrote: > > On Fri, Jan 20, 2012 at 12:40:08PM +0400, Cyrill Gorcunov wrote: > > ... > >> + > >> +static __init int kcmp_cookie_init(void) > >> +{ > >> + int i, j; > >> + > >> + for (i = 0; i < KCMP_TYPES; i++) { > >> + for (j = 0; j < 2; j++) { > >> + get_random_bytes(&cookies[i][j], sizeof(cookies[i][j])); > >> + > >> + if (cookies[i][j]) > >> + continue; > >> + > >> + /* > >> + * This is impossible case but just to be sure. > >> + */ > >> + cookies_valid = false; > >> + WARN_ONCE(1, "Can't get random bytes for k-pointers\n"); > >> + } > >> + } > >> + > >> + cookies_valid = true; > > > > darn, this string of course should be on top, > > i'll update don't complain on this nit. > > > > This code is wrong. You will have a zero cookie, legitimately, once in > 2^32 or 2^64 attempts, depending on the bitness. >
We've had kind of emergency pool before which were used in such cases. These legitime cases can happen not that frequently, so I guess -- can we use it again?
if (cookies[i][j]) continue; else cookies[i][j] = some-value; One wont know which exactly values we were using.
> 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. >
I see, i'll update (at first, I occasionally translated odd as 'even' which made me really scratching the head, until I realized it's 'odd'! :)
Cyrill
|  |