From owner-svn-soc-all@freebsd.org Mon Nov 30 21:23:02 2015 Return-Path: Delivered-To: svn-soc-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 31996A3DC2B for ; Mon, 30 Nov 2015 21:23:02 +0000 (UTC) (envelope-from def@FreeBSD.org) 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 165921241 for ; Mon, 30 Nov 2015 21:23:02 +0000 (UTC) (envelope-from def@FreeBSD.org) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.15.2/8.15.2) with ESMTP id tAULN1dZ057303 for ; Mon, 30 Nov 2015 21:23:01 GMT (envelope-from def@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.15.2/8.15.2/Submit) id tAULN1wv057301 for svn-soc-all@FreeBSD.org; Mon, 30 Nov 2015 21:23:01 GMT (envelope-from def@FreeBSD.org) Date: Mon, 30 Nov 2015 21:23:01 GMT Message-Id: <201511302123.tAULN1wv057301@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: r294582 - soc2013/def/crashdump-head/sbin/dumpon 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, 30 Nov 2015 21:23:02 -0000 Author: def Date: Mon Nov 30 21:23:00 2015 New Revision: 294582 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=294582 Log: Don't free resources but exit immediately after an error. Clear keys after use. Modified: soc2013/def/crashdump-head/sbin/dumpon/dumpon.c Modified: soc2013/def/crashdump-head/sbin/dumpon/dumpon.c ============================================================================== --- soc2013/def/crashdump-head/sbin/dumpon/dumpon.c Mon Nov 30 21:19:16 2015 (r294581) +++ soc2013/def/crashdump-head/sbin/dumpon/dumpon.c Mon Nov 30 21:23:00 2015 (r294582) @@ -113,56 +113,39 @@ pubkey = NULL; fp = fopen(pubkeyfile, "r"); - if (fp == NULL) { - warn("Unable to open %s", pubkeyfile); - goto failed; - } + if (fp == NULL) + err(1, "Unable to open %s", pubkeyfile); - if (cap_enter() == -1) { - warn("Unable to enter capability mode"); - goto failed; - } + if (cap_enter() == -1) + err(1, "Unable to enter capability mode"); pubkey = RSA_new(); if (pubkey == NULL) { - warnx("Unable to allocate an RSA structure: %s", + errx(1, "Unable to allocate an RSA structure: %s", ERR_error_string(ERR_get_error(), NULL)); - goto failed; } pubkey = PEM_read_RSA_PUBKEY(fp, &pubkey, NULL, NULL); fclose(fp); fp = NULL; - if (pubkey == NULL) { - warnx("Unable to read data from %s.", pubkeyfile); - goto failed; - } + if (pubkey == NULL) + errx(1, "Unable to read data from %s.", pubkeyfile); kda->kda_encryptedkeysize = RSA_size(pubkey); kda->kda_encryptedkey = calloc(1, kda->kda_encryptedkeysize); - if (kda->kda_encryptedkey == NULL) { - warn("Unable to allocate encrypted key"); - goto failed; - } + if (kda->kda_encryptedkey == NULL) + err(1, "Unable to allocate encrypted key"); + kda->kda_encryption = KERNELDUMP_ENC_AES_256_CBC; arc4random_buf(kda->kda_key, sizeof(kda->kda_key)); if (RSA_public_encrypt(sizeof(kda->kda_key), kda->kda_key, kda->kda_encryptedkey, pubkey, RSA_PKCS1_PADDING) != (int)kda->kda_encryptedkeysize) { - warn("Unable to encrypt the one-time key"); - goto failed; + errx(1, "Unable to encrypt the one-time key."); } RSA_free(pubkey); - pubkey = NULL; kda->kda_encrypt = 1; - return; -failed: - if (fp != NULL) - fclose(fp); - free(kda->kda_encryptedkey); - RSA_free(pubkey); - exit(1); } static void @@ -200,7 +183,6 @@ int i, fd; int do_listdumpdev = 0; - bzero(&kda, sizeof(kda)); pubkeyfile = NULL; while ((ch = getopt(argc, argv, "k:lv")) != -1) @@ -234,12 +216,15 @@ if (fd < 0) err(EX_OSFILE, "%s", argv[0]); check_size(fd, argv[0]); + bzero(&kda, sizeof(kda)); kda.kda_enable = 0; i = ioctl(fd, DIOCSEKCD, &kda); + bzero(&kda, sizeof(kda)); if (pubkeyfile != NULL) genkey(pubkeyfile, &kda); kda.kda_enable = 1; i = ioctl(fd, DIOCSEKCD, &kda); + bzero(kda.kda_encryptedkey, kda.kda_encryptedkeysize); free(kda.kda_encryptedkey); bzero(&kda, sizeof(kda)); if (i == 0 && verbose)