Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755800AbXLQRse (ORCPT ); Mon, 17 Dec 2007 12:48:34 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1758723AbXLQRsV (ORCPT ); Mon, 17 Dec 2007 12:48:21 -0500 Received: from zeniv.linux.org.uk ([195.92.253.2]:33958 "EHLO ZenIV.linux.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757205AbXLQRsU (ORCPT ); Mon, 17 Dec 2007 12:48:20 -0500 Date: Mon, 17 Dec 2007 17:48:06 +0000 From: Al Viro To: Linus Torvalds Cc: Herbert Xu , John Reiser , Andrew Morton , security@kernel.org, tytso@mit.edu, Linux Kernel Mailing List , mpm@selenic.com, linux-sparse@vger.kernel.org Subject: Re: Signed divides vs shifts (Re: [Security] /dev/urandom uses uninit bytes, leaks user data) Message-ID: <20071217174806.GC8181@ftp.linux.org.uk> References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.4.1i Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1013 Lines: 30 On Mon, Dec 17, 2007 at 09:28:57AM -0800, Linus Torvalds wrote: > > > On Sat, 15 Dec 2007, Herbert Xu wrote: > > > > There ought to be a warning about this sort of thing. > > We could add it to sparse. The appended (untested) patch seems to say > there's a lot of those signed divides-by-power-of-twos. I'm not sure that you are warning about the right things. If you want a real nightmare scenario in that area, consider this: int x[20]; int *p = x + n; int *q = x + m; p - q ((char *)p - (char *)q)/4 ((char *)p - (char *)q)/sizeof(int) The first two are equivalent on all targets we care about. However, an attempt to make the second one "more portable" silently creates the code that'll do something entirely different as soon as we get m > n... -- 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/