From patchwork Thu Sep 28 21:26:01 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Biggers X-Patchwork-Id: 9976775 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 1F9F960568 for ; Thu, 28 Sep 2017 21:30:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1264B29759 for ; Thu, 28 Sep 2017 21:30:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0422E2975B; Thu, 28 Sep 2017 21:30:29 +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=-6.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9D2312975A for ; Thu, 28 Sep 2017 21:30:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751850AbdI1Va2 (ORCPT ); Thu, 28 Sep 2017 17:30:28 -0400 Received: from mail-pf0-f196.google.com ([209.85.192.196]:33299 "EHLO mail-pf0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751816AbdI1V3w (ORCPT ); Thu, 28 Sep 2017 17:29:52 -0400 Received: by mail-pf0-f196.google.com with SMTP id h4so2509198pfk.0; Thu, 28 Sep 2017 14:29:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=88SSaQWlQyxbsBBXz7PpvErAFkc5n1nlCagQO5fjoBs=; b=ItstE2lgVzS7JecsP+NwTz18S3i5rR+mM1S9VSCpCVErlInxc4sohxr7kjzkjk4h8/ iTg18VKlve62BVBm23xVz9ouLzdZY2FlecyKa4X1BYsjtuLFt/H++45qUDxk3b4GIRV3 n9AjzXCxNJ9oOukPW5XAYf9Kr7Sj2gJ93DQMk9WGbmLLy5BMHT2BouZDVKl54jkXBruN qmVvbEeDV8pLVxsD0q0Q8Cl/1Zmi8wiQXkYtXfijVkilhnYtKLmUsH8kvJAhfISDC8wb pLWtzNW3MB7vLZ60MEHb4jpTvwQv7l3tHUD/7iNFDMAd1i+e+/Icn6Bb0IZIApb/v5is RaSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=88SSaQWlQyxbsBBXz7PpvErAFkc5n1nlCagQO5fjoBs=; b=NsY88VeR9t0kRC0Xp9ie3qSBqMWViSWxLU/SUV2IQpiTY2mD+fOA+Ya41X7CHg2Ivb 1NtVjGoeOyORLOcNMcn5+Dw8u7gAMyVx4P9O8UTeL2w8nAuj9UrORWrO+6LVsWl3w2ke JCrM/J70GopA4Vn8oEiHc1i7yffOFgL6+wOH4y220cp2ifQGTnjCYfFK8xKLChEcoSWH J84g5bIu/wnLhOwt9Ow9rmR2L9kIzJs5TIL3MtMxmPrrfiq/G0+DtoQPlT1rmq/DD4Q8 cEwUBa6teQ+aFYPKlQH/lsHt7NkzQcWHaaIwSP4BvxYoLOrdqHBXeUrA7aguus4jXuv5 /A1w== X-Gm-Message-State: AHPjjUjTlK8MFYG5G29sqkgp3HsQGNmzUO2AFtiytCFn6GEXfEL/s6eg 1r5inSovO+gu9OQG2SNr24wY1//Y X-Google-Smtp-Source: AOwi7QChfC/GZTDFkaDYjYL5Bj4iIhhOOWd3cVZBe1fptmzQJsiJem9vpw/xczZlBP1/Pdyvocc97g== X-Received: by 10.98.205.72 with SMTP id o69mr5495946pfg.194.1506634191289; Thu, 28 Sep 2017 14:29:51 -0700 (PDT) Received: from ebiggers-linuxstation.kir.corp.google.com ([100.66.174.81]) by smtp.gmail.com with ESMTPSA id o128sm3810672pga.5.2017.09.28.14.29.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 28 Sep 2017 14:29:50 -0700 (PDT) From: Eric Biggers To: keyrings@vger.kernel.org Cc: David Howells , Michael Halcrow , linux-cachefs@redhat.com, ecryptfs@vger.kernel.org, linux-fscrypt@vger.kernel.org, linux-security-module@vger.kernel.org, Eric Biggers , stable@vger.kernel.org Subject: [PATCH 6/7] ecryptfs: fix out-of-bounds read of key payload Date: Thu, 28 Sep 2017 14:26:01 -0700 Message-Id: <20170928212602.41744-7-ebiggers3@gmail.com> X-Mailer: git-send-email 2.14.2.822.g60be5d43e6-goog In-Reply-To: <20170928212602.41744-1-ebiggers3@gmail.com> References: <20170928212602.41744-1-ebiggers3@gmail.com> Sender: linux-fscrypt-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fscrypt@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Eric Biggers eCryptfs blindly casts the user-supplied key payload to a 'struct ecryptfs_auth_tok' without validating that the payload does, in fact, have the size of a 'struct ecryptfs_auth_tok'. Fix it. Fixes: 237fead61998 ("[PATCH] ecryptfs: fs/Makefile and fs/Kconfig") Cc: [v2.6.19+] Signed-off-by: Eric Biggers Reviewed-by: James Morris --- fs/ecryptfs/ecryptfs_kernel.h | 6 ++++++ fs/ecryptfs/keystore.c | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/fs/ecryptfs/ecryptfs_kernel.h b/fs/ecryptfs/ecryptfs_kernel.h index 3fbc0ff79699..945844d5f0ef 100644 --- a/fs/ecryptfs/ecryptfs_kernel.h +++ b/fs/ecryptfs/ecryptfs_kernel.h @@ -93,6 +93,9 @@ ecryptfs_get_encrypted_key_payload_data(struct key *key) if (!payload) return ERR_PTR(-EKEYREVOKED); + if (payload->payload_datalen != sizeof(struct ecryptfs_auth_tok)) + return ERR_PTR(-EINVAL); + return (struct ecryptfs_auth_tok *)payload->payload_data; } @@ -129,6 +132,9 @@ ecryptfs_get_key_payload_data(struct key *key) if (!ukp) return ERR_PTR(-EKEYREVOKED); + if (ukp->datalen != sizeof(struct ecryptfs_auth_tok)) + return ERR_PTR(-EINVAL); + return (struct ecryptfs_auth_tok *)ukp->data; } diff --git a/fs/ecryptfs/keystore.c b/fs/ecryptfs/keystore.c index fa218cd64f74..95e20ab67df3 100644 --- a/fs/ecryptfs/keystore.c +++ b/fs/ecryptfs/keystore.c @@ -471,6 +471,10 @@ ecryptfs_verify_auth_tok_from_key(struct key *auth_tok_key, (*auth_tok) = ecryptfs_get_key_payload_data(auth_tok_key); if (IS_ERR(*auth_tok)) { rc = PTR_ERR(*auth_tok); + if (rc == -EINVAL) { + ecryptfs_printk(KERN_ERR, + "Authentication token payload has wrong length\n"); + } *auth_tok = NULL; goto out; }