From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-14.6 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1,USER_IN_DEF_DKIM_WL autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B99A1C433DF for ; Mon, 3 Aug 2020 22:08:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CED1D22B40 for ; Mon, 3 Aug 2020 22:08:13 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b="WYjnd6dI" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728854AbgHCWIK (ORCPT ); Mon, 3 Aug 2020 18:08:10 -0400 Received: from linux.microsoft.com ([13.77.154.182]:60894 "EHLO linux.microsoft.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728708AbgHCWIK (ORCPT ); Mon, 3 Aug 2020 18:08:10 -0400 Received: from [192.168.0.104] (c-73-42-176-67.hsd1.wa.comcast.net [73.42.176.67]) by linux.microsoft.com (Postfix) with ESMTPSA id 3F70520B4908; Mon, 3 Aug 2020 15:08:09 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 3F70520B4908 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1596492489; bh=lOuSme48DtaAahlNbilkFH/6Rv176zUXrsFgRlysqqs=; h=Subject:To:Cc:References:From:Date:In-Reply-To:From; b=WYjnd6dI4uoxBT0ptGFkjCRUWPUHavtt0YrQ+lPKDy6IEvcbD5UPs8HJ3W6vikKvE TiEHmYJcr9dIdemFW9y/E4Z45wzY7Fcf1YQc1I/0SA/teBekYShIVQOvFhhLfizxUE bX0N0toB9j6tQQ4f1YHNrFtNkSQ/72Ghl9PWNFJw= Subject: Re: [PATCH v5 3/4] LSM: Define SELinux function to measure state and policy To: Stephen Smalley Cc: Mimi Zohar , Casey Schaufler , Tyler Hicks , sashal@kernel.org, James Morris , linux-integrity@vger.kernel.org, SElinux list , LSM List , linux-kernel References: <20200730034724.3298-1-nramas@linux.microsoft.com> <20200730034724.3298-4-nramas@linux.microsoft.com> <6371efa9-5ae6-05ac-c357-3fbe1a5a93d5@linux.microsoft.com> <5c843a3d-713c-e71f-8d4f-c6e5f51422f1@gmail.com> From: Lakshmi Ramasubramanian Message-ID: <3e766eed-7a0b-afca-6139-ac43dea053d7@linux.microsoft.com> Date: Mon, 3 Aug 2020 15:08:05 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: <5c843a3d-713c-e71f-8d4f-c6e5f51422f1@gmail.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: On 8/3/20 2:07 PM, Stephen Smalley wrote: >>>> [   68.870715] irq event stamp: 23486085 >>>> [   68.870715] hardirqs last  enabled at (23486085): >>>> [] _raw_spin_unlock_irqrestore+0x46/0x60 >>>> [   68.870715] hardirqs last disabled at (23486084): >>>> [] _raw_spin_lock_irqsave+0x23/0x90 >>>> [   68.870715] softirqs last  enabled at (23486074): >>>> [] __do_softirq+0x4f3/0x662 >>>> [   68.870715] softirqs last disabled at (23486067): >>>> [] asm_call_on_stack+0x12/0x20 >>>> [   68.870715] ---[ end trace fb02740ff6f4d0cd ]--- >>> >>> I think one issue here is that systemd loads SELinux policy first, >>> then IMA policy, so it doesn't know whether it needs to measure >>> SELinux policy on first policy load, and another issue is that the >>> policy is too large to just queue the policy data itself this way (or >>> you need to use an allocator that can handle larger sizes). >>> >> >> The problem seems to be that a lock is held when the IMA hook to >> measure the LSM state is called. So memory allocation is not allowed, >> but the hook is doing an allocation. I'll address this - thanks for >> catching it. >> >> I have the following CONFIGs enabled, but I still don't see the above >> issue on my machine. >> > The warning has to do with the memory allocation order being above the > max order supported for kmalloc.  I think the problem is that > ima_alloc_data_entry() is using kmemdup() to duplicate a payload of > arbitrary size.  Policies on e.g. Fedora can be quite large, so you > can't assume they can be allocated with kmalloc and friends. > Thanks for clarifying. Yes ima_alloc_entry() does use kmemdup to save the given buffer (to be measured) until IMA loads custom policy. On my machine the SELinux policy size is about 2MB. Perhaps vmalloc would be better than using kmalloc? If there are better options for such large buffer allocation, please let me know. -lakshmi