From patchwork Mon Oct 9 19:51:28 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Biggers X-Patchwork-Id: 9994161 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 EC84560230 for ; Mon, 9 Oct 2017 19:52:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E02B32878E for ; Mon, 9 Oct 2017 19:52:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D5506287D1; Mon, 9 Oct 2017 19:52:49 +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.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, 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 685A42878E for ; Mon, 9 Oct 2017 19:52:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755111AbdJITwr (ORCPT ); Mon, 9 Oct 2017 15:52:47 -0400 Received: from mail-pf0-f194.google.com ([209.85.192.194]:33726 "EHLO mail-pf0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754497AbdJITwp (ORCPT ); Mon, 9 Oct 2017 15:52:45 -0400 Received: by mail-pf0-f194.google.com with SMTP id m28so29926942pfi.0; Mon, 09 Oct 2017 12:52:45 -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=Yj1oknjLdljm4Z2yNUwd67bCHNxgpMUI1Lvu4Im4x6s=; b=Y6v0eY/WSQW78BAeVgWwapFeNswlhCSSKR753VSvGvWh71L6LCJOCeCGKulfEga+VS tni9b4+QSvxtTZ2RJEWx79yINg7BogLEzy9edhJGyNRUmbYeFB55P/2rIta4HEmKr4lw zNatdWhNKihu0a/1DKi20F5Tr+uly3zPhXmGIlx6m2DMqExsPTL+jHImLX/3dwNPA8Y/ sQ4kVadS/AmQrgGyTibfmB5Aluzv6iRl2MiI9BA/EhswaA5Kf2DNMn8pvY+X2I/UQ0fz v0ABe3ukomDRb9uZ2Ud3Yt93wuJH+sAff/42xcnTlWnpyC+GFlSo93Jv46hq2jOaKtyo SyIg== 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=Yj1oknjLdljm4Z2yNUwd67bCHNxgpMUI1Lvu4Im4x6s=; b=SOo7wzaCU9FYnDS0PWDRVAxjyGlIXr/z6tV8IIjDEuJ4NBp/l26jihw82qN6s2olQe dFGV6OckgN3YEGcnQTx5FT5uAGr8LttDecTPABzfia0m6amJ5YKyYbIQ69DZzdiHr7jd r49Yc3H+Zn2DCD9I2XvoVBpFbGHMuQQVvLHwqo6JTb5cziZH+szQ6En4sOXc5BCN9jun 7TePe+XPO1yQZkwdrAstEM+0JbLTFGm39ouB0CrITOvAOcfDh/lUkBJ9jM5bZfwCacVe OAHRKfrWRoEC4p//M2x0swcCxijdurN+qVPWD9AFYK4IUceGJbYdoREZkvS80YGr0qb0 pHnw== X-Gm-Message-State: AMCzsaXr0v2+fgNBHk73acAj3r8qg8kWyGHx/DOfbxMhKp5TcDbZ3SdI CL4Z4bb5efEHwVmNOmKWrheQjJDm X-Google-Smtp-Source: AOwi7QAtsSdaNl4CKFwDq5FoxbGFQr74sWdx93PN6ue1d3d9ZXfSHudYKvk26NUvBiiwYqFpOVs+CA== X-Received: by 10.84.231.193 with SMTP id g1mr668772pln.407.1507578764744; Mon, 09 Oct 2017 12:52:44 -0700 (PDT) Received: from ebiggers-linuxstation.kir.corp.google.com ([100.66.174.81]) by smtp.gmail.com with ESMTPSA id z26sm17260715pfa.49.2017.10.09.12.52.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 09 Oct 2017 12:52:44 -0700 (PDT) From: Eric Biggers To: ecryptfs@vger.kernel.org, Tyler Hicks Cc: keyrings@vger.kernel.org, linux-security-module@vger.kernel.org, Eric Biggers , stable@vger.kernel.org, Michael Halcrow Subject: [PATCH v2 2/3] ecryptfs: fix out-of-bounds read of key payload Date: Mon, 9 Oct 2017 12:51:28 -0700 Message-Id: <20171009195129.68610-2-ebiggers3@gmail.com> X-Mailer: git-send-email 2.14.2.920.gcf0c67979c-goog In-Reply-To: <20171009195129.68610-1-ebiggers3@gmail.com> References: <20171009195129.68610-1-ebiggers3@gmail.com> Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: 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") Reviewed-by: James Morris Cc: [v2.6.19+] Cc: Michael Halcrow Signed-off-by: Eric Biggers --- Changed since v1: added Reviewed-by and resent in series with just the ecryptfs patches. Can this please be taken through the ecryptfs tree? 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; }