Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp329775pxu; Wed, 14 Oct 2020 02:25:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyfsAlvepOqkrWD0zs5U81oGpyQuCR3I6ErNimtbEXm0/H+x68CB/2Qo/jlJlZ8+m99Wtdh X-Received: by 2002:aa7:c98f:: with SMTP id c15mr4273031edt.200.1602667553278; Wed, 14 Oct 2020 02:25:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1602667553; cv=none; d=google.com; s=arc-20160816; b=0fpSDqpAYi+GiqdTaDEEQe+lieIWgkQw45+p+PnmEl7murIEnpwVP2CwO/AoRMxSdy VLO9baZzOHoE65QwT/K4Z47H7rlcS2Abk5Lc6JtC+eubDL2uGFxb4LZeJ1oiD0mqX+kg Gz0T7UqhqEHbqfaV4SOZkQ7OsBFcb9vBWZxXWl95ip7bvVZXvipQkAdLTwQvuXjgYB8E 8e0RO8bOsfZ8wjtdhIbUCC+83uMaYOSqCG55ryNHl7kfNwvcmy3iFSmGk10Bn+mdM7xQ wxgdd4lyD2lLdzRFA8/rd9dkJqnR4VITWxv2qCoDtmMTlcrA8Ud4MSKSNnhHIZ73dY/d QkHw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=mwiq0cHvxvCFFdBqldyHBoh7ygTFzicDwxfYmkbMjvI=; b=LlZj24/5Oq3BTn1uZXXXVUXct1/V1jkHIuf/IchSDu8GRvwZ55S8wfZSfAl0F93uRe kbrFV7TnN4wxeHfR26WsxBpSh2zriP5oXq1Lo09B3tS+ZDyVMVijPiNfWg/kwfobPshk 2UlcMvjZFjO8WId+w6zlCGImKYqxzERURPz/QkKksgNfsDjY/vSMpR5KkQgWOvSwd8l7 +un19m57RhDcVoPRxDdCa2hux9/nkShqlWuXKa9piZqHng847IUhreC0tEuIesbIM+um xTtcRbmHHPtoQbx0SeUG6m1mmixaeehF9kETJIFKQrCZUD1jvcz90HAwOZRvc/SGJGyX GafA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=ZT5bB6MV; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b19si1802587edw.132.2020.10.14.02.25.20; Wed, 14 Oct 2020 02:25:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-nfs-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=@gmail.com header.s=20161025 header.b=ZT5bB6MV; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728499AbgJNJXi (ORCPT + 99 others); Wed, 14 Oct 2020 05:23:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39942 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731234AbgJNJWy (ORCPT ); Wed, 14 Oct 2020 05:22:54 -0400 Received: from mail-oi1-x244.google.com (mail-oi1-x244.google.com [IPv6:2607:f8b0:4864:20::244]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1FBFDC08EC3F; Tue, 13 Oct 2020 16:51:15 -0700 (PDT) Received: by mail-oi1-x244.google.com with SMTP id 16so1299303oix.9; Tue, 13 Oct 2020 16:51:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=mwiq0cHvxvCFFdBqldyHBoh7ygTFzicDwxfYmkbMjvI=; b=ZT5bB6MVZOz0NPvFfCWXS40k9jyKHm/6LIA5cY53PivsZU1VxzoDHg1pKUfWAKMQ1w bWgO0YI00SzR2Osl6rZjYUo5UTQpkeM5RFOBZSlZw7K7EIA9jb19fGyJoY7+OghdzI+v NPEu11T7y8ZrzEkhIdksqqpHz9/pIq/pfH2J9eZPX/QVqwxSgFlaHhrwmXHZpyi5nV5h aaXSxZuT5I/BHP5i4AGem/ZSocqwLFvL1K3i41ZThTEFJ2YlSQnx7S9nXe0oTWdEOVA6 2Itvnp0geFMu1d9+7rpZDNgonp1+TGRVxYljRx0Dnx0fD2aadYz54Q/nysRyA+wDlqUf +lmw== 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=mwiq0cHvxvCFFdBqldyHBoh7ygTFzicDwxfYmkbMjvI=; b=liHxatreOvvJPmR4vuUQoUl8xu9bSLPvh1eHNKWsL4Hmvzw6eYfnxFrAymWNtPrfWA G0EiaLnSulLcnvhw6nzFxWE3R+HTjKrGPXrU0cT/MLmQVpqwwpusqwroKQHVx1YIKYfI 5aoSQd1zSFNNs6PKQxMntsjhL8diKubneWqVyJmSHJZA1OtqVhljJDDSYHgq+1/x97oh k/0Y7YNGYvi2zzLvkzFwB+qYThq3O8yu6SqLgfQ5a83kNpGHpOlhYAGbPtrNifmndx5W ZNRWlB33WnVYmXBu9HCBNv7Z5E04Seo9zG4JujFAOCWz+nsFo5hzbwQbELpmO8aEEOgQ fOFg== X-Gm-Message-State: AOAM532T37CjTnmSqC3CqT93vhGUW1KJu4hIbAtbBFbYTGjjSgQipirg 92+fomi8Cu2e5OikU/rSUxCUuRJ2LOuXVTrdZd4= X-Received: by 2002:aca:498b:: with SMTP id w133mr495627oia.138.1602633074480; Tue, 13 Oct 2020 16:51:14 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Stephen Smalley Date: Tue, 13 Oct 2020 19:51:03 -0400 Message-ID: Subject: Re: selinux: how to query if selinux is enabled To: Olga Kornievskaia Cc: Chuck Lever , Paul Moore , Linux Security Module list , SElinux list , Linux NFS Mailing List Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org On Fri, Oct 9, 2020 at 12:36 PM Olga Kornievskaia wrote: > > On Fri, Oct 9, 2020 at 10:08 AM Chuck Lever wrote: > > > > > > > > > On Oct 9, 2020, at 7:49 AM, Olga Kornievskaia wrote: > > > > > > On Thu, Oct 8, 2020 at 9:03 PM Paul Moore wrote: > > >> > > >> ->On Thu, Oct 8, 2020 at 9:50 AM Olga Kornievskaia wrote: > > >>> On Wed, Oct 7, 2020 at 9:07 PM Paul Moore wrote: > > >>>> On Wed, Oct 7, 2020 at 8:41 PM Olga Kornievskaia wrote: > > >>>>> Hi folks, > > >>>>> > > >>>>> From some linux kernel module, is it possible to query and find out > > >>>>> whether or not selinux is currently enabled or not? > > >>>>> > > >>>>> Thank you. > > >>>> > > >>>> [NOTE: CC'ing the SELinux list as it's probably a bit more relevant > > >>>> that the LSM list] > > >>>> > > >>>> In general most parts of the kernel shouldn't need to worry about what > > >>>> LSMs are active and/or enabled; the simply interact with the LSM(s) > > >>>> via the interfaces defined in include/linux/security.h (there are some > > >>>> helpful comments in include/linux/lsm_hooks.h). Can you elaborate a > > >>>> bit more on what you are trying to accomplish? > > >>> > > >>> Hi Paul, > > >>> > > >>> Thank you for the response. What I'm trying to accomplish is the > > >>> following. Within a file system (NFS), typically any queries for > > >>> security labels are triggered by the SElinux (or I guess an LSM in > > >>> general) (thru the xattr_handler hooks). However, when the VFS is > > >>> calling to get directory entries NFS will always get the labels > > >>> (baring server not supporting it). However this is useless and affects > > >>> performance (ie., this makes servers do extra work and adds to the > > >>> network traffic) when selinux is disabled. It would be useful if NFS > > >>> can check if there is anything that requires those labels, if SElinux > > >>> is enabled or disabled. > > >> > > >> [Adding Chuck Lever to the CC line as I believe he has the most recent > > >> LSM experience from the NFS side - sorry Chuck :)] > > >> > > >> I'll need to ask your patience on this as I am far from a NFS expert. > > >> > > >> Looking through the NFS readdir/getdents code this evening, I was > > >> wondering if the solution in the readdir case is to simply tell the > > >> server you are not interested in the security label by masking out > > >> FATTR4_WORD2_SECURITY_LABEL in the nfs4_readdir_arg->bitmask in > > >> _nfs4_proc_readdir()? Of course this assumes that the security label > > >> genuinely isn't needed in this case (and not requesting it doesn't > > >> bypass access controls or break something on the server side), and we > > >> don't screw up some NFS client side cache by *not* fetching the > > >> security label attribute. > > >> > > >> Is this remotely close to workable, or am I missing something fundamental? > > >> > > > > > > No this is not going to work, as NFS requires labels when labels are > > > indeed needed by the LSM. What I'm looking for is an optimization. > > > What we have is functionality correct but performance might suffer for > > > the standard case of NFSv4.2 seclabel enabled server and clients that > > > don't care about seclabels. > > > > Initial thought: We should ask linux-nfs for help with this. > > I've added them to the Cc: list. > > > > Olga, are you asking if the kernel NFS client module can somehow find > > out whether the rest of the kernel is configured to care about security > > labels before it forms an NFSv4 READDIR or LOOKUP request? > > Yes exactly, but I'm having a hard time trying to figure out how to > use security_ismaclabel() function as has been suggested by Casey. I would suggest either introducing a new hook for your purpose, or altering the existing one to support a form of query that isn't based on a particular xattr name but rather just checking whether the module supports/uses MAC labels at all. Options: 1) NULL argument to the existing hook indicates a general query (could hide a bug in the caller, so not optimal), 2) Add a new bool argument to the existing hook to indicate whether the name should be used, or 3) Add a new hook that doesn't take any arguments. > > > I would certainly like to take the security label query out of every > > LOOKUP operation if that is feasible! > > A LOOKUP doesn't add the seclabel query (by default) like READDIR does > (it's hard-coded in the xdr code). LOOKUP uses server's bitmask and > chooses the version without the seclabel bitmask because no label is > passed into it. It looks like LOOKUP just allocates a label in > nfs_lookup_revalidate_dentry(). So it's not driven by the something > that I see used by the xattr_handle example in the NFS code.