From patchwork Mon Aug 1 13:19:10 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Seth Forshee X-Patchwork-Id: 9254401 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 EB9416075F for ; Mon, 1 Aug 2016 13:20:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DD1EB28330 for ; Mon, 1 Aug 2016 13:20:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D0099284A2; Mon, 1 Aug 2016 13:20:30 +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_SIGNED, 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 BF78B283F2 for ; Mon, 1 Aug 2016 13:20:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753333AbcHANU2 (ORCPT ); Mon, 1 Aug 2016 09:20:28 -0400 Received: from mail-oi0-f53.google.com ([209.85.218.53]:34718 "EHLO mail-oi0-f53.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753279AbcHANU1 (ORCPT ); Mon, 1 Aug 2016 09:20:27 -0400 Received: by mail-oi0-f53.google.com with SMTP id l65so191547613oib.1 for ; Mon, 01 Aug 2016 06:19:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=2KAOf+9skumINRju7gWMRVBaMbDp7BRosGk6SUmHn1E=; b=rtb+Rp7oGbD3A9L+CjfR15jEszeEiJiLzuqeCr/jTfb8xNQ+bW1kILafPH2pZNOVvM Rcsa+oEQClTH218Rhio0yjxkVDLls134LobghfZpJnROZHWviuf/7k4a0GuMSR9iC16z A6qze/haLNh/bD9tYsbYV4KSWG0aUMoUJV2BRtbRe8sYud0p+5edVvQm0P0zY+YlL0dn zNUnomdtpwt9F4pmrsx3Dwy6v2VGua4Wpa2+V81WpVBd2zprgvqk0xMDWj7dDvOcQQNu 8VmOKa7oivIaYi5x8v4z3ePK0xEwpy6yUTtGaJdQwe+NbB5IfLYjrGY9yjszG9bcyyf6 DU0A== 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:in-reply-to :references; bh=2KAOf+9skumINRju7gWMRVBaMbDp7BRosGk6SUmHn1E=; b=AjD2yNPnNamNP1BLg/zWUbH4XuJaS4Jg+ryza3vuswiaTK41OzwIu70l9gJ/u3idR+ Xo7vH/IXzXaex1blYDCz/8u7b+phqno5V+5r7k3tnuX6UH0Phz7YH+/mw2nJ8ZMNe6js 5Ujqto0JpuHX5JkikrdRsnZQq8G53UkiALyiGA4OdzHagm3ylKuzzenglKldR0E2jKke 0YfxMxQ/81i9hFjxm1yOP01bzJJKg+jq2QOla4UrkB+U9g6X4123675jM89/2ox6FSvX IdiN2wsOYgl3At6l8iJSYeAhm4lcg4IxwENP8A1VF3MtgdGStL6K3ZkZFT8asOqJgWgY w/fg== X-Gm-Message-State: AEkoouvbH/THc8qXgO/amqM5La6zODMWrf7k/3oIJv1tz18+AS0CfbSVZS/o5k67kxe6ESb8 X-Received: by 10.202.108.10 with SMTP id h10mr34249771oic.117.1470057559390; Mon, 01 Aug 2016 06:19:19 -0700 (PDT) Received: from localhost ([2605:a601:aab:f920:e5ce:793c:1866:9ee]) by smtp.gmail.com with ESMTPSA id 3sm12710822otx.3.2016.08.01.06.19.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 01 Aug 2016 06:19:18 -0700 (PDT) From: Seth Forshee To: Mimi Zohar , Dmitry Kasatkin Cc: "Eric W. Biederman" , linux-ima-devel@lists.sourceforge.net, linux-ima-user@lists.sourceforge.net, linux-security-module@vger.kernel.org, Seth Forshee Subject: [PATCH 1/1] security/integrity: Harden against malformed xattrs Date: Mon, 1 Aug 2016 08:19:10 -0500 Message-Id: <1470057550-58098-2-git-send-email-seth.forshee@canonical.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1470057550-58098-1-git-send-email-seth.forshee@canonical.com> References: <1470057550-58098-1-git-send-email-seth.forshee@canonical.com> Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: X-Virus-Scanned: ClamAV using ClamSMTP In general the handling of IMA/EVM xattrs is good, but I found a few locations where either the xattr size or the value of the type field in the xattr are not checked. Add a few simple checks to these locations to prevent malformed or malicious xattrs from causing problems. Signed-off-by: Seth Forshee --- security/integrity/digsig.c | 2 +- security/integrity/evm/evm_main.c | 4 ++++ security/integrity/ima/ima_appraise.c | 5 ++++- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/security/integrity/digsig.c b/security/integrity/digsig.c index 4304372b323f..106e855e2d9d 100644 --- a/security/integrity/digsig.c +++ b/security/integrity/digsig.c @@ -51,7 +51,7 @@ static bool init_keyring __initdata; int integrity_digsig_verify(const unsigned int id, const char *sig, int siglen, const char *digest, int digestlen) { - if (id >= INTEGRITY_KEYRING_MAX) + if (id >= INTEGRITY_KEYRING_MAX || siglen < 2) return -EINVAL; if (!keyring[id]) { diff --git a/security/integrity/evm/evm_main.c b/security/integrity/evm/evm_main.c index b9e26288d30c..35ab453ce861 100644 --- a/security/integrity/evm/evm_main.c +++ b/security/integrity/evm/evm_main.c @@ -145,6 +145,10 @@ static enum integrity_status evm_verify_hmac(struct dentry *dentry, /* check value type */ switch (xattr_data->type) { case EVM_XATTR_HMAC: + if (xattr_len != sizeof(struct evm_ima_xattr_data)) { + evm_status = INTEGRITY_FAIL; + goto out; + } rc = evm_calc_hmac(dentry, xattr_name, xattr_value, xattr_value_len, calc.digest); if (rc) diff --git a/security/integrity/ima/ima_appraise.c b/security/integrity/ima/ima_appraise.c index 1bcbc12e03d9..11a17073e8a2 100644 --- a/security/integrity/ima/ima_appraise.c +++ b/security/integrity/ima/ima_appraise.c @@ -130,6 +130,7 @@ enum hash_algo ima_get_hash_algo(struct evm_ima_xattr_data *xattr_value, int xattr_len) { struct signature_v2_hdr *sig; + enum hash_algo ret; if (!xattr_value || xattr_len < 2) /* return default hash algo */ @@ -143,7 +144,9 @@ enum hash_algo ima_get_hash_algo(struct evm_ima_xattr_data *xattr_value, return sig->hash_algo; break; case IMA_XATTR_DIGEST_NG: - return xattr_value->digest[0]; + ret = xattr_value->digest[0]; + if (ret < HASH_ALGO__LAST) + return ret; break; case IMA_XATTR_DIGEST: /* this is for backward compatibility */