Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp6349598ybi; Wed, 29 May 2019 06:38:10 -0700 (PDT) X-Google-Smtp-Source: APXvYqy+irI9LdHnlMCTN+aneoZcixwreXRIBr4NEYdAfnOZz9ixARtyFHtce4w7LoHkIwm9H3U0 X-Received: by 2002:a65:454c:: with SMTP id x12mr3205227pgr.354.1559137089896; Wed, 29 May 2019 06:38:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559137089; cv=none; d=google.com; s=arc-20160816; b=AucXbgnDiW6MSkaYWZ3bvn+MxuZIh6O+fIsE/JPvHx+zXjJkWNSc9pP4o0b5kDm/pL mAnZVxeR57jw82nJx1eVEatmSW6tPVA+mBIWO1QHfkC8ZZeHYSY9g6fWKDV6ZVDHc/Z3 TfY0E4xSMUTKBir4QwfAxzK2fcB8oQ1uq9AXesuxm2oca8pAbwKvQUz9Cps0iVRa/24n ++blG0wbqRpRIIFYj8iSUroEBex6oNEql1T3kRf4MPX7r3e5TKTdIonn7TrLF20ApvQG aWxKbl8IUt1akDcE4oK6AXfQadZa4xsc7x7e8QGqbuaE92bAYv7heLTGChlwoPPd3N0K TQyA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=Y+56xqSSO+HeRy2haPFni8RNqhcTmFBhMt+Le95Dg2o=; b=vDULrZgYcYiIiGXlOO6UlNfasadjEgmWwVrjn4ntF7GIk50HaFIdZcFIoNmB2791kd SYS0qD+ULu0IHUPX3FZJipKTDYRk/NiIvtnEOuYCpyiu1sOl4rwQ2Ba4uJNkQmMlY+Mb DwinSYR5SHmKFTB1by8AEuqXt8VBtC4/5D0YePaIYHi9EaRgvfcPNOnTrAJ5Nnnbl8+R UpFcW5uoWNpfCILriM4UCmPbn3Cc6c3SqEUyiC4C5UM8jZxguEAbjiYYNmuZi2m2gXqn c57BCDMHeAJ7Xk8obsqQlK4qU7Gg4PutqjhWAimTiLaTiBG6Z6ZyLmgmHIo7E+P2nWXe g0Qw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u9si24761775pls.145.2019.05.29.06.37.52; Wed, 29 May 2019 06:38:09 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727182AbfE2NfH (ORCPT + 99 others); Wed, 29 May 2019 09:35:07 -0400 Received: from lhrrgout.huawei.com ([185.176.76.210]:32972 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726104AbfE2NfG (ORCPT ); Wed, 29 May 2019 09:35:06 -0400 Received: from lhreml709-cah.china.huawei.com (unknown [172.18.7.107]) by Forcepoint Email with ESMTP id 2D59B29D317FA73B2E71; Wed, 29 May 2019 14:35:05 +0100 (IST) Received: from roberto-HP-EliteDesk-800-G2-DM-65W.huawei.com (10.204.65.154) by smtpsuk.huawei.com (10.201.108.32) with Microsoft SMTP Server (TLS) id 14.3.408.0; Wed, 29 May 2019 14:34:58 +0100 From: Roberto Sassu To: , , CC: , , , , , Roberto Sassu , Subject: [PATCH v2 1/3] evm: check hash algorithm passed to init_desc() Date: Wed, 29 May 2019 15:30:33 +0200 Message-ID: <20190529133035.28724-2-roberto.sassu@huawei.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190529133035.28724-1-roberto.sassu@huawei.com> References: <20190529133035.28724-1-roberto.sassu@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.204.65.154] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch prevents memory access beyond the evm_tfm array by checking the validity of the index (hash algorithm) passed to init_desc(). The hash algorithm can be arbitrarily set if the security.ima xattr type is not EVM_XATTR_HMAC. Fixes: 5feeb61183dde ("evm: Allow non-SHA1 digital signatures") Signed-off-by: Roberto Sassu Cc: stable@vger.kernel.org --- security/integrity/evm/evm_crypto.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/security/integrity/evm/evm_crypto.c b/security/integrity/evm/evm_crypto.c index e11564eb645b..82a38e801ee4 100644 --- a/security/integrity/evm/evm_crypto.c +++ b/security/integrity/evm/evm_crypto.c @@ -89,6 +89,9 @@ static struct shash_desc *init_desc(char type, uint8_t hash_algo) tfm = &hmac_tfm; algo = evm_hmac; } else { + if (hash_algo >= HASH_ALGO__LAST) + return ERR_PTR(-EINVAL); + tfm = &evm_tfm[hash_algo]; algo = hash_algo_name[hash_algo]; } -- 2.17.1