From owner-svn-soc-all@FreeBSD.ORG Mon May 4 16:50:22 2015 Return-Path: Delivered-To: svn-soc-all@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 C6F1D372 for ; Mon, 4 May 2015 16:50:22 +0000 (UTC) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 9C67B174B for ; Mon, 4 May 2015 16:50:22 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.9/8.14.9) with ESMTP id t44GoMw0091644 for ; Mon, 4 May 2015 16:50:22 GMT (envelope-from def@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.9/8.14.9/Submit) id t44GoLuZ091632 for svn-soc-all@FreeBSD.org; Mon, 4 May 2015 16:50:21 GMT (envelope-from def@FreeBSD.org) Date: Mon, 4 May 2015 16:50:21 GMT Message-Id: <201505041650.t44GoLuZ091632@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to def@FreeBSD.org using -f From: def@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r284993 - in soc2013/def/crashdump-head: sbin/cryptcore sbin/savecore sys/amd64/conf MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 04 May 2015 16:50:22 -0000 Author: def Date: Mon May 4 16:50:20 2015 New Revision: 284993 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=284993 Log: Style. Modified: soc2013/def/crashdump-head/sbin/cryptcore/cryptcore.c soc2013/def/crashdump-head/sbin/savecore/savecore.c soc2013/def/crashdump-head/sys/amd64/conf/GENERIC Modified: soc2013/def/crashdump-head/sbin/cryptcore/cryptcore.c ============================================================================== --- soc2013/def/crashdump-head/sbin/cryptcore/cryptcore.c Mon May 4 15:04:39 2015 (r284992) +++ soc2013/def/crashdump-head/sbin/cryptcore/cryptcore.c Mon May 4 16:50:20 2015 (r284993) @@ -73,11 +73,11 @@ if (RSA_public_encrypt(KERNELDUMP_KEY_SIZE + KERNELDUMP_IV_SIZE, buf, ciphertext, pubkey, RSA_PKCS1_PADDING) != pubkeysize) { - pjdlog_exit(1, "Unable to encrypt an one-time key"); + pjdlog_exit(1, "Unable to encrypt the one-time key"); } /* - * From this moment keys have to be erased before exit. + * From this moment on keys have to be erased before exit. */ if (sysctlbyname("kern.ekcd.keymaterial", NULL, NULL, buf, KERNELDUMP_KEY_SIZE) != 0) { @@ -149,7 +149,7 @@ pjdlog_exit(1, "Unable to read data from %s", privkeyfile); } /* - * From this moment keys have to be erased before exit. + * From this moment on keys have to be erased before exit. */ privkeysize = RSA_size(privkey); if (RSA_size(privkey) > 8 * KERNELDUMP_CIPHERTEXT_SIZE) { Modified: soc2013/def/crashdump-head/sbin/savecore/savecore.c ============================================================================== --- soc2013/def/crashdump-head/sbin/savecore/savecore.c Mon May 4 15:04:39 2015 (r284992) +++ soc2013/def/crashdump-head/sbin/savecore/savecore.c Mon May 4 16:50:20 2015 (r284993) @@ -190,12 +190,12 @@ fd = open(keyname, O_WRONLY | O_CREAT | O_TRUNC, 0600); if (fd == -1) { - syslog(LOG_ERR, "Unable to open %s to write a key.", keyname); + syslog(LOG_ERR, "Unable to open %s to write the key.", keyname); exit(1); } if (write(fd, kdh->ciphertext, KERNELDUMP_CIPHERTEXT_SIZE) != KERNELDUMP_CIPHERTEXT_SIZE) { - syslog(LOG_ERR, "Unable to write a key to %s.", keyname); + syslog(LOG_ERR, "Unable to write the key to %s.", keyname); exit(1); } close(fd); Modified: soc2013/def/crashdump-head/sys/amd64/conf/GENERIC ============================================================================== --- soc2013/def/crashdump-head/sys/amd64/conf/GENERIC Mon May 4 15:04:39 2015 (r284992) +++ soc2013/def/crashdump-head/sys/amd64/conf/GENERIC Mon May 4 16:50:20 2015 (r284993) @@ -354,5 +354,5 @@ # Netmap provides direct access to TX/RX rings on supported NICs device netmap # netmap(4) support -# Unattended encrypted kernel crash dumps +# Unattended encrypted kernel crash dumps options EKCD From owner-svn-soc-all@FreeBSD.ORG Mon May 4 17:19:43 2015 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 57BAF1C7 for ; Mon, 4 May 2015 17:19:43 +0000 (UTC) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 46D251A12 for ; Mon, 4 May 2015 17:19:43 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.9/8.14.9) with ESMTP id t44HJhl6052622 for ; Mon, 4 May 2015 17:19:43 GMT (envelope-from def@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.9/8.14.9/Submit) id t44HJgSl052605 for svn-soc-all@FreeBSD.org; Mon, 4 May 2015 17:19:42 GMT (envelope-from def@FreeBSD.org) Date: Mon, 4 May 2015 17:19:42 GMT Message-Id: <201505041719.t44HJgSl052605@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to def@FreeBSD.org using -f From: def@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r284997 - soc2013/def/crashdump-head/sbin/cryptcore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 04 May 2015 17:19:43 -0000 Author: def Date: Mon May 4 17:19:42 2015 New Revision: 284997 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=284997 Log: Use arc4random_buf(3). Modified: soc2013/def/crashdump-head/sbin/cryptcore/cryptcore.c Modified: soc2013/def/crashdump-head/sbin/cryptcore/cryptcore.c ============================================================================== --- soc2013/def/crashdump-head/sbin/cryptcore/cryptcore.c Mon May 4 16:59:09 2015 (r284996) +++ soc2013/def/crashdump-head/sbin/cryptcore/cryptcore.c Mon May 4 17:19:42 2015 (r284997) @@ -9,13 +9,12 @@ #include #include +#include #include #include #include -#define CRYPTCORE_DEVRANDOM "/dev/random" - #define CRYPTCORE_CMD_GENKEY 0x01 #define CRYPTCORE_CMD_DECRYPT 0x02 @@ -35,7 +34,7 @@ uint8_t ciphertext[KERNELDUMP_CIPHERTEXT_SIZE]; FILE *fp; RSA *pubkey; - int err, fd, pubkeysize, size; + int err, pubkeysize; PJDLOG_ASSERT(pubkeyfile != NULL); @@ -43,18 +42,6 @@ if (pubkey == NULL) pjdlog_exit(1, "Unable to allocate an RSA structure"); - fd = open(CRYPTCORE_DEVRANDOM, O_RDONLY); - if (fd == -1) - pjdlog_exit(1, "Unable to open %s", CRYPTCORE_DEVRANDOM); - size = (int)read(fd, buf, KERNELDUMP_KEY_SIZE + KERNELDUMP_IV_SIZE); - err = errno; - close(fd); - if (size != KERNELDUMP_KEY_SIZE + KERNELDUMP_IV_SIZE) { - errno = err; - pjdlog_exit(1, "Unable to read data from %s", - CRYPTCORE_DEVRANDOM); - } - fp = fopen(pubkeyfile, "r"); if (fp == NULL) pjdlog_exit(1, "Unable to open %s", pubkeyfile); @@ -71,6 +58,7 @@ 8 * KERNELDUMP_CIPHERTEXT_SIZE); } + arc4random_buf(buf, sizeof(buf)); if (RSA_public_encrypt(KERNELDUMP_KEY_SIZE + KERNELDUMP_IV_SIZE, buf, ciphertext, pubkey, RSA_PKCS1_PADDING) != pubkeysize) { pjdlog_exit(1, "Unable to encrypt the one-time key"); From owner-svn-soc-all@FreeBSD.ORG Mon May 4 17:38:40 2015 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id DE34E973 for ; Mon, 4 May 2015 17:38:39 +0000 (UTC) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id BF62A1C8E for ; Mon, 4 May 2015 17:38:39 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.9/8.14.9) with ESMTP id t44HcdfA071792 for ; Mon, 4 May 2015 17:38:39 GMT (envelope-from def@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.9/8.14.9/Submit) id t44Hcd9L071789 for svn-soc-all@FreeBSD.org; Mon, 4 May 2015 17:38:39 GMT (envelope-from def@FreeBSD.org) Date: Mon, 4 May 2015 17:38:39 GMT Message-Id: <201505041738.t44Hcd9L071789@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to def@FreeBSD.org using -f From: def@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r284998 - soc2013/def/crashdump-head/sbin/cryptcore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 04 May 2015 17:38:40 -0000 Author: def Date: Mon May 4 17:38:38 2015 New Revision: 284998 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=284998 Log: EVP_DecryptUpdate(3), PEM_read_RSA_PUBKEY(3), PEM_read_RSAPrivateKey(3), RSA_new(3), RSA_private_decrypt(3) and RSA_public_encrypt(3) don't set errno. Modified: soc2013/def/crashdump-head/sbin/cryptcore/cryptcore.c Modified: soc2013/def/crashdump-head/sbin/cryptcore/cryptcore.c ============================================================================== --- soc2013/def/crashdump-head/sbin/cryptcore/cryptcore.c Mon May 4 17:19:42 2015 (r284997) +++ soc2013/def/crashdump-head/sbin/cryptcore/cryptcore.c Mon May 4 17:38:38 2015 (r284998) @@ -34,24 +34,21 @@ uint8_t ciphertext[KERNELDUMP_CIPHERTEXT_SIZE]; FILE *fp; RSA *pubkey; - int err, pubkeysize; + int pubkeysize; PJDLOG_ASSERT(pubkeyfile != NULL); pubkey = RSA_new(); if (pubkey == NULL) - pjdlog_exit(1, "Unable to allocate an RSA structure"); + pjdlog_exitx(1, "Unable to allocate an RSA structure."); fp = fopen(pubkeyfile, "r"); if (fp == NULL) pjdlog_exit(1, "Unable to open %s", pubkeyfile); pubkey = PEM_read_RSA_PUBKEY(fp, &pubkey, NULL, NULL); - err = errno; fclose(fp); - if (pubkey == NULL) { - errno = err; - pjdlog_exit(1, "Unable to read data from %s", pubkeyfile); - } + if (pubkey == NULL) + pjdlog_exitx(1, "Unable to read data from %s.", pubkeyfile); pubkeysize = RSA_size(pubkey); if (RSA_size(pubkey) > 8 * KERNELDUMP_CIPHERTEXT_SIZE) { pjdlog_exitx(1, "The maximum RSA modulus size is %db.", @@ -61,7 +58,7 @@ arc4random_buf(buf, sizeof(buf)); if (RSA_public_encrypt(KERNELDUMP_KEY_SIZE + KERNELDUMP_IV_SIZE, buf, ciphertext, pubkey, RSA_PKCS1_PADDING) != pubkeysize) { - pjdlog_exit(1, "Unable to encrypt the one-time key"); + pjdlog_exitx(1, "Unable to encrypt the one-time key."); } /* @@ -112,7 +109,7 @@ privkey = RSA_new(); if (privkey == NULL) - pjdlog_exit(1, "Unable to allocate an RSA structure"); + pjdlog_exitx(1, "Unable to allocate an RSA structure."); EVP_CIPHER_CTX_init(&ctx); fd = open(keyfile, O_RDONLY); @@ -130,12 +127,9 @@ if (fp == NULL) pjdlog_exit(1, "Unable to open %s", privkeyfile); privkey = PEM_read_RSAPrivateKey(fp, &privkey, NULL, NULL); - err = errno; fclose(fp); - if (privkey == NULL) { - errno = err; - pjdlog_exit(1, "Unable to read data from %s", privkeyfile); - } + if (privkey == NULL) + pjdlog_exitx(1, "Unable to read data from %s.", privkeyfile); /* * From this moment on keys have to be erased before exit. */ @@ -149,7 +143,7 @@ if (RSA_private_decrypt(KERNELDUMP_CIPHERTEXT_SIZE, ciphertext, buf, privkey, RSA_PKCS1_PADDING) != KERNELDUMP_KEY_SIZE + KERNELDUMP_IV_SIZE) { - pjdlog_errno(LOG_ERR, "Unable to decrypt key and IV"); + pjdlog_error("Unable to decrypt key and IV."); goto failed; } @@ -178,7 +172,7 @@ if (EVP_DecryptUpdate(&ctx, buf, &size, buf, KERNELDUMP_BUFFER_SIZE) == 0) { - pjdlog_errno(LOG_ERR, "Unable to decrypt core."); + pjdlog_error("Unable to decrypt core."); goto failed; } PJDLOG_ASSERT(size == KERNELDUMP_BUFFER_SIZE); From owner-svn-soc-all@FreeBSD.ORG Mon May 4 17:52:05 2015 Return-Path: Delivered-To: svn-soc-all@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 B2BB193 for ; Mon, 4 May 2015 17:52:05 +0000 (UTC) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id A093B1E93 for ; Mon, 4 May 2015 17:52:05 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.9/8.14.9) with ESMTP id t44Hq5I2089369 for ; Mon, 4 May 2015 17:52:05 GMT (envelope-from def@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.9/8.14.9/Submit) id t44Hq45w089355 for svn-soc-all@FreeBSD.org; Mon, 4 May 2015 17:52:04 GMT (envelope-from def@FreeBSD.org) Date: Mon, 4 May 2015 17:52:04 GMT Message-Id: <201505041752.t44Hq45w089355@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to def@FreeBSD.org using -f From: def@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r284999 - in soc2013/def/crashdump-head: etc/rc.d sbin/cryptcore sys/kern MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 04 May 2015 17:52:05 -0000 Author: def Date: Mon May 4 17:52:03 2015 New Revision: 284999 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=284999 Log: Rename sysctl nodes kern.ekcd.* to security.ekcd.*. Modified: soc2013/def/crashdump-head/etc/rc.d/cryptcore soc2013/def/crashdump-head/sbin/cryptcore/cryptcore.c soc2013/def/crashdump-head/sys/kern/kern_shutdown.c Modified: soc2013/def/crashdump-head/etc/rc.d/cryptcore ============================================================================== --- soc2013/def/crashdump-head/etc/rc.d/cryptcore Mon May 4 17:38:38 2015 (r284998) +++ soc2013/def/crashdump-head/etc/rc.d/cryptcore Mon May 4 17:52:03 2015 (r284999) @@ -14,7 +14,7 @@ cryptcore_start() { - sysctl -Nq kern.ekcd.enable >/dev/null + sysctl -Nq security.ekcd.enable >/dev/null if [ $? -ne 0 ]; then err 1 "Kernel is missing encrypted kernel crash dumps." fi @@ -28,7 +28,7 @@ err 1 "Unable to generate an one-time key." fi - sysctl kern.ekcd.enable=1 + sysctl security.ekcd.enable=1 } load_rc_config $name Modified: soc2013/def/crashdump-head/sbin/cryptcore/cryptcore.c ============================================================================== --- soc2013/def/crashdump-head/sbin/cryptcore/cryptcore.c Mon May 4 17:38:38 2015 (r284998) +++ soc2013/def/crashdump-head/sbin/cryptcore/cryptcore.c Mon May 4 17:52:03 2015 (r284999) @@ -64,17 +64,17 @@ /* * From this moment on keys have to be erased before exit. */ - if (sysctlbyname("kern.ekcd.keymaterial", NULL, NULL, buf, + if (sysctlbyname("security.ekcd.keymaterial", NULL, NULL, buf, KERNELDUMP_KEY_SIZE) != 0) { pjdlog_errno(LOG_ERR, "Unable to set key material"); goto failed; } - if (sysctlbyname("kern.ekcd.iv", NULL, NULL, buf + KERNELDUMP_KEY_SIZE, - KERNELDUMP_IV_SIZE) != 0) { + if (sysctlbyname("security.ekcd.iv", NULL, NULL, + buf + KERNELDUMP_KEY_SIZE, KERNELDUMP_IV_SIZE) != 0) { pjdlog_errno(LOG_ERR, "Unable to set IV"); goto failed; } - if (sysctlbyname("kern.ekcd.ciphertext", NULL, NULL, ciphertext, + if (sysctlbyname("security.ekcd.ciphertext", NULL, NULL, ciphertext, pubkeysize) != 0) { pjdlog_errno(LOG_ERR, "Unable to set ciphertext"); goto failed; Modified: soc2013/def/crashdump-head/sys/kern/kern_shutdown.c ============================================================================== --- soc2013/def/crashdump-head/sys/kern/kern_shutdown.c Mon May 4 17:38:38 2015 (r284998) +++ soc2013/def/crashdump-head/sys/kern/kern_shutdown.c Mon May 4 17:52:03 2015 (r284999) @@ -144,20 +144,20 @@ static int kerneldump_sysctl_keymaterial(SYSCTL_HANDLER_ARGS); static int kerneldump_sysctl_iv(SYSCTL_HANDLER_ARGS); -SYSCTL_NODE(_kern, OID_AUTO, ekcd, CTLFLAG_RW, 0, +SYSCTL_NODE(_security, OID_AUTO, ekcd, CTLFLAG_RW, 0, "Encrypted kernel crash dumps"); -SYSCTL_INT(_kern_ekcd, OID_AUTO, enable, CTLFLAG_RW, &dumperkey.kdk_enable, +SYSCTL_INT(_security_ekcd, OID_AUTO, enable, CTLFLAG_RW, &dumperkey.kdk_enable, 0, "Enable encrypted kernel crash dumps"); -SYSCTL_PROC(_kern_ekcd, OID_AUTO, keymaterial, CTLTYPE_OPAQUE | CTLFLAG_WR, +SYSCTL_PROC(_security_ekcd, OID_AUTO, keymaterial, CTLTYPE_OPAQUE | CTLFLAG_WR, NULL, 0, kerneldump_sysctl_keymaterial, "", "Key material used to encrypt a crash dump"); -SYSCTL_PROC(_kern_ekcd, OID_AUTO, iv, CTLTYPE_OPAQUE | CTLFLAG_WR, NULL, 0, +SYSCTL_PROC(_security_ekcd, OID_AUTO, iv, CTLTYPE_OPAQUE | CTLFLAG_WR, NULL, 0, kerneldump_sysctl_iv, "", "IV used to encrypt a crash dump"); -SYSCTL_OPAQUE(_kern_ekcd, OID_AUTO, ciphertext, CTLFLAG_WR, +SYSCTL_OPAQUE(_security_ekcd, OID_AUTO, ciphertext, CTLFLAG_WR, &dumperkey.kdk_ciphertext, KERNELDUMP_CIPHERTEXT_SIZE, "", "Encrypted key material and IV"); #endif /* EKCD */ From owner-svn-soc-all@FreeBSD.ORG Mon May 4 18:57:12 2015 Return-Path: Delivered-To: svn-soc-all@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 8D11C6C1 for ; Mon, 4 May 2015 18:57:12 +0000 (UTC) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 7B78B1643 for ; Mon, 4 May 2015 18:57:12 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.9/8.14.9) with ESMTP id t44IvCou021846 for ; Mon, 4 May 2015 18:57:12 GMT (envelope-from def@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.9/8.14.9/Submit) id t44IvBnB021843 for svn-soc-all@FreeBSD.org; Mon, 4 May 2015 18:57:11 GMT (envelope-from def@FreeBSD.org) Date: Mon, 4 May 2015 18:57:11 GMT Message-Id: <201505041857.t44IvBnB021843@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to def@FreeBSD.org using -f From: def@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r285002 - soc2013/def/crashdump-head/sbin/cryptcore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 04 May 2015 18:57:12 -0000 Author: def Date: Mon May 4 18:57:11 2015 New Revision: 285002 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=285002 Log: Remove file descriptor leaks. Modified: soc2013/def/crashdump-head/sbin/cryptcore/cryptcore.c Modified: soc2013/def/crashdump-head/sbin/cryptcore/cryptcore.c ============================================================================== --- soc2013/def/crashdump-head/sbin/cryptcore/cryptcore.c Mon May 4 17:59:39 2015 (r285001) +++ soc2013/def/crashdump-head/sbin/cryptcore/cryptcore.c Mon May 4 18:57:11 2015 (r285002) @@ -107,6 +107,8 @@ PJDLOG_ASSERT(input != NULL); PJDLOG_ASSERT(output != NULL); + ofd = -1; + fd = -1; privkey = RSA_new(); if (privkey == NULL) pjdlog_exitx(1, "Unable to allocate an RSA structure."); @@ -118,6 +120,7 @@ size = (int)read(fd, ciphertext, KERNELDUMP_CIPHERTEXT_SIZE); err = errno; close(fd); + fd = -1; if (size != KERNELDUMP_CIPHERTEXT_SIZE) { errno = err; pjdlog_exit(1, "Unable to read data from %s", keyfile); @@ -195,6 +198,10 @@ return; failed: + if (ofd >= 0) + close(ofd); + if (fd >= 0) + close(fd); bzero(buf, KERNELDUMP_KEY_SIZE + KERNELDUMP_IV_SIZE); EVP_CIPHER_CTX_cleanup(&ctx); RSA_free(privkey); From owner-svn-soc-all@FreeBSD.ORG Mon May 4 19:23:45 2015 Return-Path: Delivered-To: svn-soc-all@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 C273DC4B for ; Mon, 4 May 2015 19:23:45 +0000 (UTC) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id ACA101A2C for ; Mon, 4 May 2015 19:23:45 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.9/8.14.9) with ESMTP id t44JNjTE081534 for ; Mon, 4 May 2015 19:23:45 GMT (envelope-from def@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.9/8.14.9/Submit) id t44JNj36081512 for svn-soc-all@FreeBSD.org; Mon, 4 May 2015 19:23:45 GMT (envelope-from def@FreeBSD.org) Date: Mon, 4 May 2015 19:23:45 GMT Message-Id: <201505041923.t44JNj36081512@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to def@FreeBSD.org using -f From: def@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r285005 - soc2013/def/crashdump-head/sbin/cryptcore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 04 May 2015 19:23:45 -0000 Author: def Date: Mon May 4 19:23:44 2015 New Revision: 285005 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=285005 Log: Use sizeof instead of constants for buf and ciphertext. Modified: soc2013/def/crashdump-head/sbin/cryptcore/cryptcore.c Modified: soc2013/def/crashdump-head/sbin/cryptcore/cryptcore.c ============================================================================== --- soc2013/def/crashdump-head/sbin/cryptcore/cryptcore.c Mon May 4 18:49:25 2015 (r285004) +++ soc2013/def/crashdump-head/sbin/cryptcore/cryptcore.c Mon May 4 19:23:44 2015 (r285005) @@ -50,14 +50,14 @@ if (pubkey == NULL) pjdlog_exitx(1, "Unable to read data from %s.", pubkeyfile); pubkeysize = RSA_size(pubkey); - if (RSA_size(pubkey) > 8 * KERNELDUMP_CIPHERTEXT_SIZE) { - pjdlog_exitx(1, "The maximum RSA modulus size is %db.", - 8 * KERNELDUMP_CIPHERTEXT_SIZE); + if (pubkeysize > (int)sizeof(ciphertext)) { + pjdlog_exitx(1, "The maximum RSA modulus size is %lub.", + 8 * sizeof(ciphertext)); } arc4random_buf(buf, sizeof(buf)); - if (RSA_public_encrypt(KERNELDUMP_KEY_SIZE + KERNELDUMP_IV_SIZE, buf, - ciphertext, pubkey, RSA_PKCS1_PADDING) != pubkeysize) { + if (RSA_public_encrypt(sizeof(buf), buf, ciphertext, pubkey, + RSA_PKCS1_PADDING) != pubkeysize) { pjdlog_exitx(1, "Unable to encrypt the one-time key."); } @@ -80,12 +80,12 @@ goto failed; } - bzero(buf, KERNELDUMP_KEY_SIZE + KERNELDUMP_IV_SIZE); + bzero(buf, sizeof(buf)); RSA_free(pubkey); return; failed: - bzero(buf, KERNELDUMP_KEY_SIZE + KERNELDUMP_IV_SIZE); + bzero(buf, sizeof(buf)); RSA_free(pubkey); exit(1); } @@ -117,11 +117,11 @@ fd = open(keyfile, O_RDONLY); if (fd == -1) pjdlog_exit(1, "Unable to open %s", keyfile); - size = (int)read(fd, ciphertext, KERNELDUMP_CIPHERTEXT_SIZE); + size = (int)read(fd, ciphertext, sizeof(ciphertext)); err = errno; close(fd); fd = -1; - if (size != KERNELDUMP_CIPHERTEXT_SIZE) { + if (size != sizeof(ciphertext)) { errno = err; pjdlog_exit(1, "Unable to read data from %s", keyfile); } @@ -137,15 +137,14 @@ * From this moment on keys have to be erased before exit. */ privkeysize = RSA_size(privkey); - if (RSA_size(privkey) > 8 * KERNELDUMP_CIPHERTEXT_SIZE) { - pjdlog_error("The maximum RSA modulus size is %db.", - 8 * KERNELDUMP_CIPHERTEXT_SIZE); + if (privkeysize > (int)sizeof(ciphertext)) { + pjdlog_error("The maximum RSA modulus size is %lub.", + 8 * sizeof(ciphertext)); goto failed; } - if (RSA_private_decrypt(KERNELDUMP_CIPHERTEXT_SIZE, ciphertext, buf, - privkey, RSA_PKCS1_PADDING) != - KERNELDUMP_KEY_SIZE + KERNELDUMP_IV_SIZE) { + if (RSA_private_decrypt(sizeof(ciphertext), ciphertext, buf, privkey, + RSA_PKCS1_PADDING) != KERNELDUMP_KEY_SIZE + KERNELDUMP_IV_SIZE) { pjdlog_error("Unable to decrypt key and IV."); goto failed; } @@ -167,21 +166,19 @@ EVP_CIPHER_CTX_set_padding(&ctx, 0); bufused = 0; - while ((bytes = read(fd, buf + bufused, - KERNELDUMP_BUFFER_SIZE - bufused)) > 0) { + while ((bytes = read(fd, buf + bufused, sizeof(buf) - bufused)) > 0) { bufused += bytes; - if (bufused != KERNELDUMP_BUFFER_SIZE) + if (bufused != sizeof(buf)) continue; if (EVP_DecryptUpdate(&ctx, buf, &size, buf, - KERNELDUMP_BUFFER_SIZE) == 0) { + sizeof(buf)) == 0) { pjdlog_error("Unable to decrypt core."); goto failed; } - PJDLOG_ASSERT(size == KERNELDUMP_BUFFER_SIZE); + PJDLOG_ASSERT(size == sizeof(buf)); - if (write(ofd, buf, KERNELDUMP_BUFFER_SIZE) != - KERNELDUMP_BUFFER_SIZE) { + if (write(ofd, buf, sizeof(buf)) != sizeof(buf)) { pjdlog_errno(LOG_ERR, "Unable to write data to %s", output); goto failed; @@ -189,7 +186,7 @@ bufused = 0; } - bzero(buf, KERNELDUMP_KEY_SIZE + KERNELDUMP_IV_SIZE); + bzero(buf, sizeof(buf)); EVP_CIPHER_CTX_cleanup(&ctx); RSA_free(privkey); @@ -202,7 +199,7 @@ close(ofd); if (fd >= 0) close(fd); - bzero(buf, KERNELDUMP_KEY_SIZE + KERNELDUMP_IV_SIZE); + bzero(buf, sizeof(buf)); EVP_CIPHER_CTX_cleanup(&ctx); RSA_free(privkey); exit(1); From owner-svn-soc-all@FreeBSD.ORG Mon May 4 19:27:43 2015 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 8673DCE3 for ; Mon, 4 May 2015 19:27:43 +0000 (UTC) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 74B921A63 for ; Mon, 4 May 2015 19:27:43 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.9/8.14.9) with ESMTP id t44JRhnV082762 for ; Mon, 4 May 2015 19:27:43 GMT (envelope-from def@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.9/8.14.9/Submit) id t44JRgF4082745 for svn-soc-all@FreeBSD.org; Mon, 4 May 2015 19:27:42 GMT (envelope-from def@FreeBSD.org) Date: Mon, 4 May 2015 19:27:42 GMT Message-Id: <201505041927.t44JRgF4082745@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to def@FreeBSD.org using -f From: def@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r285006 - soc2013/def/crashdump-head/etc/defaults MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 04 May 2015 19:27:43 -0000 Author: def Date: Mon May 4 19:27:42 2015 New Revision: 285006 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=285006 Log: Set default value of cryptcore_pubkey. Modified: soc2013/def/crashdump-head/etc/defaults/rc.conf Modified: soc2013/def/crashdump-head/etc/defaults/rc.conf ============================================================================== --- soc2013/def/crashdump-head/etc/defaults/rc.conf Mon May 4 19:23:44 2015 (r285005) +++ soc2013/def/crashdump-head/etc/defaults/rc.conf Mon May 4 19:27:42 2015 (r285006) @@ -582,7 +582,7 @@ cron_dst="YES" # Handle DST transitions intelligently (YES/NO) cron_flags="" # Which options to pass to the cron daemon. cryptcore_enable="NO" # Enable encrypted kernel crash dumps. -cryptcore_pubkey="" # Path to a public key. +cryptcore_pubkey="/etc/ekcd_pubkey.pem" # Path to a public key. lpd_enable="NO" # Run the line printer daemon. lpd_program="/usr/sbin/lpd" # path to lpd, if you want a different one. lpd_flags="" # Flags to lpd (if enabled).