From patchwork Tue Aug 30 16:51:44 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Biggers X-Patchwork-Id: 9306035 X-Patchwork-Delegate: snitzer@redhat.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 91305607F0 for ; Tue, 30 Aug 2016 21:04:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 814A228D20 for ; Tue, 30 Aug 2016 21:04:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7604D28D4F; Tue, 30 Aug 2016 21:04:38 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, RCVD_IN_DNSWL_MED, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from mx6-phx2.redhat.com (mx6-phx2.redhat.com [209.132.183.39]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id E1C4B28D47 for ; Tue, 30 Aug 2016 21:04:37 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by mx6-phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u7UL11Oj007518; Tue, 30 Aug 2016 17:01:01 -0400 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id u7UGr15c000847 for ; Tue, 30 Aug 2016 12:53:01 -0400 Received: from mx1.redhat.com (ext-mx10.extmail.prod.ext.phx2.redhat.com [10.5.110.39]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u7UGr0Jw022499 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO) for ; Tue, 30 Aug 2016 12:53:01 -0400 Received: from mail-pa0-f45.google.com (mail-pa0-f45.google.com [209.85.220.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 44B4A635C4 for ; Tue, 30 Aug 2016 16:53:00 +0000 (UTC) Received: by mail-pa0-f45.google.com with SMTP id fi15so9203157pac.1 for ; Tue, 30 Aug 2016 09:53:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=UFBDDgvwnkskRj0VLJVvqvH5bYvcJ/JywQVPUwty4wA=; b=I1XWSvogBMQSR0NyPHokwjaa5EY0UjEBYR1FQUMkIBisFMGz6mz0zHI+q0Zp87J3/H ko3GgKDz1tFlSeZbsLX/Nz8cCM6806D7uyvusqv9rUbe8WeUyvPPY3nypUzVtPCpO9k5 b43Y0qamGDDR5wzNBMG/yBrGYJdUJXdmtb5njAUULMZL69AZeNE9GU5N+d3Do35x8PHl b+PeJA5ua2UzDuEQ2YdEGm4Jm75Xe+5R6CbVqaT73f4P+PVZScTnkuW7fTy7JXkboWrg G/QM1aIK4MJIY8gpVGnA3IVfq33IE3atktG5UI2h6EFgSXde9XGPLZuCaTperQ3pnKyb dfSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=UFBDDgvwnkskRj0VLJVvqvH5bYvcJ/JywQVPUwty4wA=; b=N6lFW09mS53G/EQ9ptvBosLLZl1UcCaMAqXMTYqJ1PijP8bHnPCUSzJeNeR1lkjOHk vOw1OvXhrzUy1cyTec6L/dzVF7+V+b6STkehfAf+zJapmlFwiz5dxJ/jDbKQUXJwErs/ NaaHlIgZHuL193BonAp1nZvtVkTa28l7M557jBGuuaJb+towpxs8cyoLLG1wwWuL1Q+O 9eVNQL9lficCR63PrYkFR3B48c+0m0QLvdVj3NnwMhOUo31+OM8H2ZlO9iNStQ5V+mjq UroLLJgUW5VtD8BiyEGKb0baybWAPSdl63+D7RiEkCY+GZkiRidTx3tM5CKRW2Ipo9Zq SbBA== X-Gm-Message-State: AE9vXwMgfdUl7rS6JVpZHWRJFHRy8tKPgNiEc6es4FvFMqDIZyAkTp59152WhubkcMLCYf6j X-Received: by 10.66.197.131 with SMTP id iu3mr7900958pac.97.1472575979412; Tue, 30 Aug 2016 09:52:59 -0700 (PDT) Received: from ebiggers-linuxstation.kir.corp.google.com ([172.23.164.123]) by smtp.gmail.com with ESMTPSA id x184sm58421128pfd.70.2016.08.30.09.52.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 30 Aug 2016 09:52:58 -0700 (PDT) From: Eric Biggers To: agk@redhat.com, snitzer@redhat.com Date: Tue, 30 Aug 2016 09:51:44 -0700 Message-Id: <1472575904-52443-1-git-send-email-ebiggers@google.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Tue, 30 Aug 2016 16:53:00 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Tue, 30 Aug 2016 16:53:00 +0000 (UTC) for IP:'209.85.220.45' DOMAIN:'mail-pa0-f45.google.com' HELO:'mail-pa0-f45.google.com' FROM:'ebiggers@google.com' RCPT:'' X-RedHat-Spam-Score: -1.922 (BAYES_50, DCC_REPUT_00_12, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, RP_MATCHES_RCVD, SPF_PASS) 209.85.220.45 mail-pa0-f45.google.com 209.85.220.45 mail-pa0-f45.google.com X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Scanned-By: MIMEDefang 2.78 on 10.5.110.39 X-loop: dm-devel@redhat.com X-Mailman-Approved-At: Tue, 30 Aug 2016 17:00:34 -0400 Cc: dm-devel@redhat.com, Eric Biggers Subject: [dm-devel] [PATCH] dm crypt: fix free of bad values after tfm allocation failure X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com X-Virus-Scanned: ClamAV using ClamSMTP If crypt_alloc_tfms() had to allocate multiple tfms and it failed before the last allocation, then it would call crypt_free_tfms() and free pointers from uninitialized memory. Fix by allocating zeroed memory. Signed-off-by: Eric Biggers --- drivers/md/dm-crypt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/md/dm-crypt.c b/drivers/md/dm-crypt.c index eedba67..fb8fd42 100644 --- a/drivers/md/dm-crypt.c +++ b/drivers/md/dm-crypt.c @@ -1453,7 +1453,7 @@ static int crypt_alloc_tfms(struct crypt_config *cc, char *ciphermode) unsigned i; int err; - cc->tfms = kmalloc(cc->tfms_count * sizeof(struct crypto_skcipher *), + cc->tfms = kzalloc(cc->tfms_count * sizeof(struct crypto_skcipher *), GFP_KERNEL); if (!cc->tfms) return -ENOMEM;