From owner-freebsd-security@FreeBSD.ORG Sat Feb 14 23:42:51 2015 Return-Path: Delivered-To: freebsd-security@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 7B90A62A; Sat, 14 Feb 2015 23:42:51 +0000 (UTC) Received: from gold.funkthat.com (gate2.funkthat.com [208.87.223.18]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "gold.funkthat.com", Issuer "gold.funkthat.com" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4F03B783; Sat, 14 Feb 2015 23:42:50 +0000 (UTC) Received: from gold.funkthat.com (localhost [127.0.0.1]) by gold.funkthat.com (8.14.5/8.14.5) with ESMTP id t1ENghQs000860 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Sat, 14 Feb 2015 15:42:43 -0800 (PST) (envelope-from jmg@gold.funkthat.com) Received: (from jmg@localhost) by gold.funkthat.com (8.14.5/8.14.5/Submit) id t1ENghQ7000859; Sat, 14 Feb 2015 15:42:43 -0800 (PST) (envelope-from jmg) Date: Sat, 14 Feb 2015 15:42:43 -0800 From: John-Mark Gurney To: Jilles Tjoelker Subject: Re: [patch] libcrypt & friends - modular crypt format support in /etc/login.conf Message-ID: <20150214234243.GX1953@funkthat.com> References: <54D9F8DF.7070904@razorfever.net> <20150214231712.GA1360@stack.nl> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20150214231712.GA1360@stack.nl> X-Operating-System: FreeBSD 9.1-PRERELEASE amd64 X-PGP-Fingerprint: 54BA 873B 6515 3F10 9E88 9322 9CB1 8F74 6D3F A396 X-Files: The truth is out there X-URL: http://resnet.uoregon.edu/~gurney_j/ X-Resume: http://resnet.uoregon.edu/~gurney_j/resume.html X-TipJar: bitcoin:13Qmb6AeTgQecazTWph4XasEsP7nGRbAPE X-to-the-FBI-CIA-and-NSA: HI! HOW YA DOIN? can i haz chizburger? User-Agent: Mutt/1.5.21 (2010-09-15) X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.2.7 (gold.funkthat.com [127.0.0.1]); Sat, 14 Feb 2015 15:42:43 -0800 (PST) Cc: delphij@freebsd.org, freebsd-security@freebsd.org, "Derek \(freebsd lists\)" <482254ac@razorfever.net>, "A.J. Kehoe IV \(Nanoman\)" X-BeenThere: freebsd-security@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: "Security issues \[members-only posting\]" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 14 Feb 2015 23:42:51 -0000 Jilles Tjoelker wrote this message on Sun, Feb 15, 2015 at 00:17 +0100: > On Tue, Feb 10, 2015 at 07:26:07AM -0500, Derek (freebsd lists) wrote: > > 3. updates userland to use this API, and removes totally the > > {crypt_set_format, login_setcryptfmt, login_getcryptfmt} APIs > > Removing API functions completely requires a SHLIB_MAJOR bump. I think > this can be avoided by replacing the functions with a stub instead, so > they would behave as if the default always applied and not allow changes > to it. It shouldn't be hard to support crypt_{get,set}_format, since default is supported for find_format... As for login_getcryptfmt, I can't find it... and if we keep crypt_{get,set}_format, we can keep login_setcryptfmt, but just mark them as deprecated... > > 4. switches crypt algorithms to use thread-local storage, so the > > good old global crypt buffer is thread-local > > This uses quite a bit of memory for each thread created, even if it does > not call crypt() at all. Fortunately, libcrypt is not commonly used. And not linked against normally, so, I don't see an issue... > Given that crypt() has never been thread-safe, consider implementing > crypt_r() as in glibc and leaving crypt() thread-unsafe. We should go full thread safe, though that requirese some work on most of the functions, as it appears that only sha256 and sha512 are safe... > Thread-local storage via pthread_key_create() (one key for libcrypt) is > still "magic" but reduces the memory waste for threads that do not call > crypt(). With the way the crypt is pluggable, sharing storage between implementations doesn't seem doable... Also, I just realized that crypt_sha256 and crypt_sha512 are not safe in their use of __thread... As the buffer isn't static, if the same thread calls again, it could be previously returns memory gets free'd by the realloc call... > rand_buf is a salt, not a secret, so clearing it afterwards is > unnecessary. > > Consider memcpy() and adding '\0' afterward instead of strncpy(). It > seems unnecessary to clear the buffer completely. I had thought of both of these before, and agree that the salt is not a secret (it is kept hidden), but, it leaks information, and _makesalt is called so rarely, that saving the time doesn't make sense... So, I'd prefer to keep the code as is WRT these points.. -- John-Mark Gurney Voice: +1 415 225 5579 "All that I will do, has been done, All that I have, has not."