From patchwork Thu Dec 1 10:06:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roberto Sassu X-Patchwork-Id: 13061138 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5B9B9C47088 for ; Thu, 1 Dec 2022 10:07:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230115AbiLAKHF (ORCPT ); Thu, 1 Dec 2022 05:07:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40620 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230078AbiLAKHB (ORCPT ); Thu, 1 Dec 2022 05:07:01 -0500 Received: from frasgout11.his.huawei.com (frasgout11.his.huawei.com [14.137.139.23]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 045412F67F; Thu, 1 Dec 2022 02:06:58 -0800 (PST) Received: from mail02.huawei.com (unknown [172.18.147.227]) by frasgout11.his.huawei.com (SkyGuard) with ESMTP id 4NNBQ11lDXz9xFVM; Thu, 1 Dec 2022 17:59:53 +0800 (CST) Received: from huaweicloud.com (unknown [10.204.63.22]) by APP1 (Coremail) with SMTP id LxC2BwCnkm+tfIhjWgGvAA--.50191S2; Thu, 01 Dec 2022 11:06:44 +0100 (CET) From: Roberto Sassu To: zohar@linux.ibm.com, dmitry.kasatkin@gmail.com, paul@paul-moore.com, jmorris@namei.org, serge@hallyn.com Cc: linux-integrity@vger.kernel.org, linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org, Roberto Sassu Subject: [PATCH v2 0/2] ima/evm: Ensure digest to verify is in linear mapping area Date: Thu, 1 Dec 2022 11:06:23 +0100 Message-Id: <20221201100625.916781-1-roberto.sassu@huaweicloud.com> X-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xUOyCJDUUUU X-CM-SenderInfo: purev21wro2thvvxqx5xdzvxpfor3voofrz/1tbiAgANBF1jj4IjIgACs7 X-CFilter-Loop: Reflected Precedence: bulk List-ID: From: Roberto Sassu As sg_set_buf() requires the buffer for a crypto operation to be in the linear mapping area, so that it is always in adjacent pages, ensure that this requirement is met for IMA/EVM. Currently, evm_verify_hmac() and xattr_verify() put the evm_digest and ima_max_digest_data structures in the stack. As normally the stack is in the linear mapping area, passing them to sg_set_buf() would not be a problem. However, if CONFIG_VMAP_STACK is enabled, these structures will reside in the vmalloc area instead. If CONFIG_DEBUG_SG is enabled, the kernel will panic: [ 467.077359] kernel BUG at include/linux/scatterlist.h:163! [ 467.077939] invalid opcode: 0000 [#1] PREEMPT SMP NOPTI [...] [ 467.095225] Call Trace: [ 467.096088] [ 467.096928] ? rcu_read_lock_held_common+0xe/0x50 [ 467.097569] ? rcu_read_lock_sched_held+0x13/0x70 [ 467.098123] ? trace_hardirqs_on+0x2c/0xd0 [ 467.098647] ? public_key_verify_signature+0x470/0x470 [ 467.099237] asymmetric_verify+0x14c/0x300 [ 467.099869] evm_verify_hmac+0x245/0x360 [ 467.100391] evm_inode_setattr+0x43/0x190 To overcome this problem, dynamically allocate the structures with kmalloc() if CONFIG_VMAP_STACK is enabled, so that they are placed in the linear mapping area, and use them instead of the in-stack counterparts. A test report is available here: https://github.com/robertosassu/ima-evm-utils/actions/runs/3590837109/jobs/6045608579 which contains the following test (include tests for EVM portable signatures and IMA verity signatures): https://github.com/robertosassu/ima-evm-utils/commit/41cf11d299e9fc2d13a60dce4b275c2675d9cc23 Changelog: v1: - Dynamically allocate the data structures in IMA and EVM, when necessary, instead of always making a copy in asymmetric_verify() (suggested by Mimi) Roberto Sassu (2): evm: Alloc evm_digest in evm_verify_hmac() if CONFIG_VMAP_STACK=y ima: Alloc ima_max_digest_data in xattr_verify() if CONFIG_VMAP_STACK=y security/integrity/evm/evm_main.c | 26 +++++++++++++++++++++----- security/integrity/ima/ima_appraise.c | 19 ++++++++++++++++--- 2 files changed, 37 insertions(+), 8 deletions(-)