Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp2398122pxa; Mon, 24 Aug 2020 13:03:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy3ta/geZuAhiH+gmgEM/wDaGXaL5mLZsONlFME5zy5PaDfM9XlmnNF7/bUEvV8VSGIk5MF X-Received: by 2002:a17:907:2078:: with SMTP id qp24mr7055941ejb.286.1598299416311; Mon, 24 Aug 2020 13:03:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598299416; cv=none; d=google.com; s=arc-20160816; b=zQqYGgWP+MAXY3VlAbuY/nlo7Celd0xrzoMGy4IAEhfeIxFZrdy62y9O47UXCy19kA eEewGv87UuzSkEgePFsWiQzPevCrc9D7KiLKShzdRU6vdSeFyjcSajvz/vwxq71GquiR uO0DGv2L6Jufax5SNjuIjmvYOt6DToArgBs0wh+V2dsCvMWCnI6aGIf8hY+lEHSYdCxh m41ouf6v0xQtwAlSY2aDI8fQ3UHPFUe3JmZmdGCZ3U4C/p3xdnrNa+gRSuDCYBAX+8xW oM/8AoSupVixHeo2J9mHA4HzYbLdzCKGlgvAtqA2+j4WE5s/4WwY+M7uKfHpTGlOk8aD orbA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=uscrMvCrVpuzBs8CCqTlviFEzNB9Ka9n9LSLMNlONOY=; b=E/gjmpqVJ8vQnDT/oTa0Nz/ech0zU3jjV8j9tt5QMCJkR7V2HL5Eu2TNB1f9Yu8wXd 4uPE+3QN+ztHgwRrqXr9hISVdkg//uLZkz7/RdM3W3l8Tqp69MtMWZ/lHIOGC9ti28cV 8rbhhl4VQ9hJhuqFivugpf7sABWXPSzeAZVt8rVFb8j2QL7k8PfoPeitGapVFeriydUK vQ5Pb54lNIEOM5f9k1qvDHZ/yC8+T2rGbNKK6il3uX4XxwwsNyNFioj01eEJ7k4qxUHF acfXmimNmqEALHf7RG6vHjQzCI9hUgHEZjcLjdifnvf/1fgwq8R0fgXn5xND6MCE9tg0 G4Dg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=FTnahnid; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q8si7497582edn.409.2020.08.24.13.03.11; Mon, 24 Aug 2020 13:03:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=FTnahnid; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726225AbgHXUBg (ORCPT + 99 others); Mon, 24 Aug 2020 16:01:36 -0400 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:20634 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726303AbgHXUBd (ORCPT ); Mon, 24 Aug 2020 16:01:33 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1598299292; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=uscrMvCrVpuzBs8CCqTlviFEzNB9Ka9n9LSLMNlONOY=; b=FTnahnid9yGVamkJ6PTh0ISzNCOnOc4w+AKRofG5FALXfAu0TuG3ZBjBgAz2CbyF4EzxIx tXoioG8cp7IdFBjWJFRxYSuoxnjbT/t+Es3kiC1Aijwc5HYFkOlsPYN9i3wKsDctNde2ZH FNfk/u6SXEYDtww/1C4w1ykpejN8Yfs= Received: from mail-lj1-f198.google.com (mail-lj1-f198.google.com [209.85.208.198]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-414-IydqITUBMw-ZmMUXiuW1UQ-1; Mon, 24 Aug 2020 16:01:29 -0400 X-MC-Unique: IydqITUBMw-ZmMUXiuW1UQ-1 Received: by mail-lj1-f198.google.com with SMTP id f14so3108242ljg.23 for ; Mon, 24 Aug 2020 13:01:29 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=uscrMvCrVpuzBs8CCqTlviFEzNB9Ka9n9LSLMNlONOY=; b=PmH3/ZDPAsfSfdinV3jYlwGrcd/RABXtDUMeIuCcmamuaZKf8//dgSk7mFrQTkdEJd Y7rSkJIAwezMz0WtOp/BflSeVP1M/B3/hBHOhKbmXRYue0Jt07/CkoZT1z7ow2lofuA1 18MtJ7lPLDnczxNgXb+jUlSmNQ0k6kIVn6ShqzWlOGdvTHfq9oBiC0CMA18z6ftxg0++ KGqtfskJuF9TAXmSx7oa54u83xkYO4wymFuK0f4XFUqajui0kkvoyrIxAdanAczbQghK 9wWV7Z+IvPFZxBT3MvI90B4imfMTDEjQfizvQkZB2MJcnZEXLMrpkMU+d2yZqQfTx/mq owPw== X-Gm-Message-State: AOAM530zlVXTajVR1pasG55kQxgesf9RtSCjmG/U89Vxwydtin5mcjMd DKI1WOcN9KY+ZoDwHOoKcjZ6TM/qc1GbFmAbwSLYihx0st1M5UvcdKRuX3eJEdN+2OeJ21C9Uv/ scMj2QKL/ZckXT0JUt8Udejm7iw3ZPxvxoPPoPmCJ X-Received: by 2002:a2e:7010:: with SMTP id l16mr3180390ljc.38.1598299288331; Mon, 24 Aug 2020 13:01:28 -0700 (PDT) X-Received: by 2002:a2e:7010:: with SMTP id l16mr3180369ljc.38.1598299288036; Mon, 24 Aug 2020 13:01:28 -0700 (PDT) MIME-Version: 1.0 References: <20200822010018.19453-1-nramas@linux.microsoft.com> <418618c4-a0c6-6b28-6718-2726a29b83c5@linux.microsoft.com> In-Reply-To: From: Ondrej Mosnacek Date: Mon, 24 Aug 2020 22:01:17 +0200 Message-ID: Subject: Re: [PATCH] SELinux: Measure state and hash of policy using IMA To: Stephen Smalley Cc: Lakshmi Ramasubramanian , Mimi Zohar , Casey Schaufler , Tyler Hicks , tusharsu@linux.microsoft.com, Sasha Levin , James Morris , linux-integrity@vger.kernel.org, SElinux list , LSM List , linux-kernel Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Aug 24, 2020 at 9:30 PM Stephen Smalley wrote: > On Mon, Aug 24, 2020 at 2:13 PM Lakshmi Ramasubramanian > wrote: > > > > On 8/24/20 7:00 AM, Stephen Smalley wrote: > > > > >> +int security_read_policy_kernel(struct selinux_state *state, > > >> + void **data, size_t *len) > > >> +{ > > >> + int rc; > > >> + > > >> + rc = security_read_policy_len(state, len); > > >> + if (rc) > > >> + return rc; > > >> + > > >> + *data = vmalloc(*len); > > >> + if (!*data) > > >> + return -ENOMEM; > > >> > > >> + return security_read_selinux_policy(state, data, len); > > >> } > > > > > > See the discussion here: > > > https://lore.kernel.org/selinux/20200824113015.1375857-1-omosnace@redhat.com/T/#t > > > > > > In order for this to be safe, you need to ensure that all callers of > > > security_read_policy_kernel() have taken fsi->mutex in selinuxfs and > > > any use of security_read_policy_len() occurs while holding the mutex. > > > Otherwise, the length can change between security_read_policy_len() > > > and security_read_selinux_policy() if policy is reloaded. > > > > > > > "struct selinux_fs_info" is available when calling > > security_read_policy_kernel() - currently in measure.c. > > Only "struct selinux_state" is. > > > > Is Ondrej's re-try approach I need to use to workaround policy reload issue? > > No, I think perhaps we should move the mutex to selinux_state instead > of selinux_fs_info. selinux_fs_info has a pointer to selinux_state so > it can then use it indirectly. Note that your patches are going to > conflict with other ongoing work in the selinux next branch that is > refactoring policy load and converting the policy rwlock to RCU. Yeah, and I'm experimenting with a patch on top of Stephen's RCU work that would allow you to do this in a straightforward way without even messing with the fsi->mutex. My patch may or may not be eventually committed, but either way I'd recommend holding off on this for a while until the dust settles around the RCU conversion. -- Ondrej Mosnacek Software Engineer, Platform Security - SELinux kernel Red Hat, Inc.