From owner-freebsd-bugs@FreeBSD.ORG Fri Dec 20 23:20:01 2013 Return-Path: Delivered-To: freebsd-bugs@smarthost.ysv.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 6C996ED4 for ; Fri, 20 Dec 2013 23:20:01 +0000 (UTC) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:1900:2254:206c::16:87]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 565FD1342 for ; Fri, 20 Dec 2013 23:20:01 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.7/8.14.7) with ESMTP id rBKNK18P080589 for ; Fri, 20 Dec 2013 23:20:01 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.7/8.14.7/Submit) id rBKNK0tT080587; Fri, 20 Dec 2013 23:20:00 GMT (envelope-from gnats) Date: Fri, 20 Dec 2013 23:20:00 GMT Message-Id: <201312202320.rBKNK0tT080587@freefall.freebsd.org> To: freebsd-bugs@FreeBSD.org Cc: From: Jilles Tjoelker Subject: Re: bin/184950: swapon aborts on gdbe device X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.17 Precedence: list Reply-To: Jilles Tjoelker List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 20 Dec 2013 23:20:01 -0000 The following reply was made to PR bin/184950; it has been noted by GNATS. From: Jilles Tjoelker To: bug-followup@FreeBSD.org, hsn@sendmail.cz Cc: Subject: Re: bin/184950: swapon aborts on gdbe device Date: Sat, 21 Dec 2013 00:11:18 +0100 In PR bin/184950, you wrote: > i have system configured for encrypted swap gdbe_swap_enabled=YES > in fstab > /dev/ada0s1b.bde none swap sw 0 0 > in backtrace: > function swap_on_off() fails at 0x0804a756 which triggers stack > checking routines from libc __stack_chk_fail() printing stack > underflow This bug is probably not that conspicuous because most people use geli instead of gbde for disk encryption. I looked at the code anyway, and I think the compiler and the buffer overflow detector are perfectly right. On platforms where char is signed (i.e. most, with the notable exception of arm), the sprintf() call in swap_on_off_gbde() may write 9 instead of the expected 3 bytes. There is a probability of 12.5% that the last 3 chars are all non-negative and therefore no buffer overflow occurs. The below patch should fix it. I have only tested that it compiles. Index: sbin/swapon/swapon.c =================================================================== --- sbin/swapon/swapon.c (revision 259508) +++ sbin/swapon/swapon.c (working copy) @@ -266,7 +266,8 @@ static const char * swap_on_off_gbde(const char *name, int doingall) { const char *ret; - char pass[64 * 2 + 1], bpass[64]; + char pass[64 * 2 + 1]; + unsigned char bpass[64]; char *dname; int i, error; -- Jilles Tjoelker