From owner-freebsd-bugs@FreeBSD.ORG Tue Nov 27 12:30:01 2012 Return-Path: Delivered-To: freebsd-bugs@smarthost.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id D09FD6F0 for ; Tue, 27 Nov 2012 12:30:01 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:1900:2254:206c::16:87]) by mx1.freebsd.org (Postfix) with ESMTP id A4CF38FC0C for ; Tue, 27 Nov 2012 12:30:01 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.5/8.14.5) with ESMTP id qARCU1on047854 for ; Tue, 27 Nov 2012 12:30:01 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.5/8.14.5/Submit) id qARCU1IE047853; Tue, 27 Nov 2012 12:30:01 GMT (envelope-from gnats) Resent-Date: Tue, 27 Nov 2012 12:30:01 GMT Resent-Message-Id: <201211271230.qARCU1IE047853@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Jan Mikkelsen Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id EC6512E4 for ; Tue, 27 Nov 2012 12:20:17 +0000 (UTC) (envelope-from nobody@FreeBSD.org) Received: from red.freebsd.org (red.freebsd.org [IPv6:2001:4f8:fff6::22]) by mx1.freebsd.org (Postfix) with ESMTP id D27148FC12 for ; Tue, 27 Nov 2012 12:20:17 +0000 (UTC) Received: from red.freebsd.org (localhost [127.0.0.1]) by red.freebsd.org (8.14.5/8.14.5) with ESMTP id qARCKHYC074772 for ; Tue, 27 Nov 2012 12:20:17 GMT (envelope-from nobody@red.freebsd.org) Received: (from nobody@localhost) by red.freebsd.org (8.14.5/8.14.5/Submit) id qARCKHNt074770; Tue, 27 Nov 2012 12:20:17 GMT (envelope-from nobody) Message-Id: <201211271220.qARCKHNt074770@red.freebsd.org> Date: Tue, 27 Nov 2012 12:20:17 GMT From: Jan Mikkelsen To: freebsd-gnats-submit@FreeBSD.org X-Send-Pr-Version: www-3.1 Subject: misc/173952: BN_add_word writes one past its buffer when certain values are added to a single word bignum X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 27 Nov 2012 12:30:01 -0000 >Number: 173952 >Category: misc >Synopsis: BN_add_word writes one past its buffer when certain values are added to a single word bignum >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Tue Nov 27 12:30:00 UTC 2012 >Closed-Date: >Last-Modified: >Originator: Jan Mikkelsen >Release: 9.1-RC3 >Organization: Transactionware >Environment: FreeBSD vanaheim.transactionware.com 9.1-RC3 FreeBSD 9.1-RC3 #0: Sun Nov 25 10:40:45 EST 2012 root@vanaheim.transactionware.com:/home/janm/p4/freebsd-image-std-2011.1/work/base-freebsd/home/janm/p4/freebsd-image-std-2011.1/FreeBSD/src/sys/TW amd64 >Description: The function BN_add_word() in crypto/bn/bn_word.c can write one word past the end of the memory pointed to by the 'd' member of the BIGNUM struct when adding a word to a single word bignum. This has been reported to the OpenSSL people. >How-To-Repeat: dc(1) is implemented in terms of BN_*. This will reproduce the problem: janm@gray: dc $ dc 18446744073709551616 18446744073709551616 / ps dc: big number failure 306b06b: No such file or directory >Fix: My patch below. The OpenSSL people have a different patch; they were more comfortable restructuring the code. --- //depot/vendor/freebsd/9.1-local/src/crypto/openssl/crypto/bn/bn_word.c 2012-08-13 00:32:35.000000000 1000 +++ /data/scratch/janm/p4/freebsd-image-std-2011.1/FreeBSD/src/crypto/openssl/crypto/bn/bn_word.c 2012-08-13 00:32:35.000000000 1000 @@ -145,9 +145,11 @@ return(i); } /* Only expand (and risk failing) if it's possibly necessary */ - if (((BN_ULONG)(a->d[a->top - 1] + 1) == 0) && - (bn_wexpand(a,a->top+1) == NULL)) - return(0); + if ( + (((a->top == 1) && (BN_MASK2 - w < a->d[0])) || + ((a->top > 1) && ((BN_ULONG)(a->d[a->top - 1] + 1) == 0))) && + (bn_wexpand(a,a->top+1) == NULL)) + return(0); i=0; for (;;) { >Release-Note: >Audit-Trail: >Unformatted: