From owner-freebsd-arch@FreeBSD.ORG Tue Nov 26 01:20:34 2013 Return-Path: Delivered-To: freebsd-arch@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 802052E0 for ; Tue, 26 Nov 2013 01:20:34 +0000 (UTC) Received: from mail-vc0-x233.google.com (mail-vc0-x233.google.com [IPv6:2607:f8b0:400c:c03::233]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 3D5772759 for ; Tue, 26 Nov 2013 01:20:34 +0000 (UTC) Received: by mail-vc0-f179.google.com with SMTP id ie18so3286353vcb.38 for ; Mon, 25 Nov 2013 17:20:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wemm.org; s=google; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=N3dB+SN39jTjEIE5b8rcSx/mS1sVZkM0WHfzE7Mz8Tk=; b=A4X16bCGDde8ghVjUZDHFodEw7BN8LuIeGkiK1sQthWakoTR+uqvyF6mXcYwW5IFYQ yCpXPlkP89CBW/8JaPhK3Jk6whw7SDVB47dqdZaYUvu722YS0kqtyA9phI+QnPNeSDMr w9Ncwpr51vVqzOIdXgv6a34G1uKMFxYn6WvAQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=N3dB+SN39jTjEIE5b8rcSx/mS1sVZkM0WHfzE7Mz8Tk=; b=EMRr0GHPWy31SIUkDyVui1+Z6/TPNMBgcOg0pucyVicfDZpQeR2EBMv155waVd3iMy n1pfTy4OAjBdMF2qKXnvOc3iJqD7lrv2Am3T6RuLNB13F7uW5BItd12UvIZRtzS9KslF I0kQAMqB6YEQrdxeECI3PlLR0ykJYZ2hTHIWdkGkedrOEqG09jwR3TjZQ7Y3cMrcO+Mr xULX2pa793j81N6KNkPMsCUip47x2EdiTyutluacOWS/FX4b6ysSTjSHFl2BEG4UHHO4 QpLh8aRHrDzlJrtWbEacF4F6NSIEwBnvFC+MZSnKj4hSGoEtNKmGuNLkQVWvlLCKiEJ2 korQ== X-Gm-Message-State: ALoCoQkjDV6oTpeA0zMjo/FtYrNoi/SKkqJbATQC1pgFo0YMjjBaXE8fR8LQn+UQjAEYyT/TMaAi MIME-Version: 1.0 X-Received: by 10.58.118.84 with SMTP id kk20mr3321482veb.26.1385428832405; Mon, 25 Nov 2013 17:20:32 -0800 (PST) Received: by 10.220.167.74 with HTTP; Mon, 25 Nov 2013 17:20:32 -0800 (PST) In-Reply-To: <20131126075626.A4024@besplex.bde.org> References: <5293B333.9070804@wemm.org> <20131126075626.A4024@besplex.bde.org> Date: Mon, 25 Nov 2013 17:20:32 -0800 Message-ID: Subject: Re: 1 << 31 and related issues From: Peter Wemm To: Bruce Evans Content-Type: text/plain; charset=ISO-8859-1 Cc: FreeBSD Arch X-BeenThere: freebsd-arch@freebsd.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: Discussion related to FreeBSD architecture List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 26 Nov 2013 01:20:34 -0000 On Mon, Nov 25, 2013 at 1:17 PM, Bruce Evans wrote: > On Mon, 25 Nov 2013, Peter Wemm wrote: > >> On 11/25/13, 11:48 AM, Eitan Adler wrote: >>> >>> There are a few cases in FreeBSD where the expression (1 << 31) is used. >>> ... >>> >>> An incomplete listing of the issues available here: >>> http://people.freebsd.org/~eadler/files/1..31.txt >> >> >> I find it particularly enjoyable to see things like this in crypto code: >> >> crypto/heimdal/lib/hx509/ref/pkcs11.h:#define CKF_EXTENSION >> ((unsigned >> long) (1 << 31)) >> crypto/openssh/pkcs11.h:#define CKO_VENDOR_DEFINED ((unsigned long) >> (1 >> << 31)) > > > I almost said that in my earlier reply too. Yep. Invalid or undefined behavior in crypto or security critical code is hardly a good thing, even if it usually works out ok. >> FWIW, This came up in both ia64 and amd64 early days. Most of this was >> hunted down in the kernel back then. Obviously some has crept back in, >> or is in contrib or driver code. >> >> The problem there is bigger though. On 64 bit machines, 1u << N tends >> to get used where N > 32 as well. 1u << 33 is an overflow and doesn't >> extend up into the 33rd bit. We changed most uses to 1ul << N where >> this was likely. This did predate the BIT* macros you referenced. > > > I don't think anyone expected 1u << 33 to work. Well, when we had a cpumask_t as a 64 bit integer type and did (1 << cpu) in both MI and MD code, it was a pretty big deal before cpuset_t came along. -- Peter Wemm - peter@wemm.org; peter@FreeBSD.org; peter@yahoo-inc.com; KI6FJV UTF-8: for when a ' just won\342\200\231t do.