Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp891799ybk; Wed, 13 May 2020 16:15:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzO1jdDl3z2K0CH7VSJnGnReKG1bohkgAii4gicmPwHxBlySNzQBcAHcZDC2nukng6C0ISd X-Received: by 2002:a17:906:2296:: with SMTP id p22mr1280978eja.269.1589411730704; Wed, 13 May 2020 16:15:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589411730; cv=none; d=google.com; s=arc-20160816; b=0S900lGeBLBgzSSqaoJ5gF0CYR6ZCviPYSFuFtF4zTzgMcrAeB7t78t0CMHzn8i1i5 FZ3uOOuDp0IfJCaL5Hhe4BwzklnIOxtaP+vJsdcZz7Mz/Mq1JscIhPCEqzQh8QeufeLU nKPo5cyjWghEAsirbNxsdFih0z1BVMEtN/+joVUUo3iXOu24Gz9O77DmwT042HuQuVMg R16qrZyYpGXuZ2VGkYNaD894n77H4lSDMc38OSQDwFUGSTGuxUg0ylOyd4ZY3jRjsmMs u+3fmxdU4TvB5rxd4HZVzgOqeRRAT3b7OX/MJiOBnM6QJZOZ5l1NjwHLVVFyktNSBMdD HjZw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:content-id:mime-version :subject:cc:to:references:in-reply-to:from:organization :dkim-signature; bh=ZmMD6XDgyrg0kIPXb2cMEKa1A3azrPgvq+3AzZZ9RcQ=; b=yDwH3qEVQsaBaj4mbXH/dsaLS0dliAqbXdwQxaNwWEOZvLEvxdy4QkUW4l828yfZ2y ToOwvmCex2r2PjqPe8/yFOULX7nV6mXMR5grXg1IgfeJyCf3k1IcAZIYfrVFjpaBCvwq nDdakXmiDbc3fGtgvB4nvDMEqTrba4feK9lLq+hWsBSzdnSfVF+hiQokbLejxDJkHncm quu6eeusk3iM7Vn6gs2FpBuPMWZIxCE7mWX4vXytuS4dDdjNgFyORU2rhlSYMUvA2VM5 D2YPvffSznJi7fS2lvigrD9iC6T4nYjC+u2QE/e73N0FxLNCus8YzaufYY2tRAFrxnHl 70lg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=a5Qhy201; 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 cx18si659529edb.73.2020.05.13.16.15.07; Wed, 13 May 2020 16:15:30 -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=a5Qhy201; 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 S1732380AbgEMXNm (ORCPT + 99 others); Wed, 13 May 2020 19:13:42 -0400 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:38904 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1732331AbgEMXNm (ORCPT ); Wed, 13 May 2020 19:13:42 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1589411619; 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=ZmMD6XDgyrg0kIPXb2cMEKa1A3azrPgvq+3AzZZ9RcQ=; b=a5Qhy201W4tBuL2ZziApVeE9mAYN7wDsBEVEJvDGvgqGaLTO+1GH0doMx2Nkdf2Pf3rsL6 GguQDj8TFoyKeO3+RMhM9O31by+F9b5f7iNtcnTF94N8rVTxR473NoSWKDlFruc2gDgOE1 sRTOmIqrv0HQuEL6lSHCaJrpd9FFyG0= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-394-Q9t9zeVRNwCXxVJMkBsddA-1; Wed, 13 May 2020 19:13:35 -0400 X-MC-Unique: Q9t9zeVRNwCXxVJMkBsddA-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E2DA118FE860; Wed, 13 May 2020 23:13:33 +0000 (UTC) Received: from warthog.procyon.org.uk (ovpn-112-59.rdu2.redhat.com [10.10.112.59]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2E6F45C1D3; Wed, 13 May 2020 23:13:32 +0000 (UTC) Organization: Red Hat UK Ltd. Registered Address: Red Hat UK Ltd, Amberley Place, 107-111 Peascod Street, Windsor, Berkshire, SI4 1TE, United Kingdom. Registered in England and Wales under Company Registration No. 3798903 From: David Howells In-Reply-To: References: <158932282880.2885325.2688622278854566047.stgit@warthog.procyon.org.uk> To: Stephen Smalley Cc: dhowells@redhat.com, Jarkko Sakkinen , Paul Moore , Casey Schaufler , keyrings@vger.kernel.org, SElinux list , LSM List , linux-kernel Subject: Re: [PATCH] keys: Make the KEY_NEED_* perms an enum rather than a mask MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <3611506.1589411611.1@warthog.procyon.org.uk> Date: Thu, 14 May 2020 00:13:31 +0100 Message-ID: <3611507.1589411611@warthog.procyon.org.uk> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Stephen Smalley wrote: > > (3) An override due to CAP_SYS_ADMIN. > > CAP_SYS_ADMIN should never skip SELinux checking. Even for Smack, > there is a separate capability (CAP_MAC_ADMIN) for that purpose. The LSM doesn't get consulted at the moment. With this patch, it will get consulted. > > (4) An override due to an instantiation token being present. > > Not sure what this means but again we shouldn't skip SELinux checking > based on mere possession of an object capability (not a POSIX > capability). The kernel has delegated the instantiation of a key to the calling process and has given it a temporary key of type ".request_key_auth" which it has put into force with keyctl(KEYCTL_ASSUME_AUTHORITY). This authorisation token grants the caller the ability to (a) perform operations on the key it wouldn't otherwise have permission to do, (b) use the key instantiation keyctls and (c) temporarily search the keyrings of the caller of request_key() using the creds of that caller and to read/use the keys found therein if the caller was permitted to do so. > It would be better if the permission indicated the actual operation > (e.g. KEY_NEED_INVALIDATE_SPECIAL), and the decision whether to permit > CAP_SYS_ADMIN processes to override was left to the security modules. > SELinux doesn't automatically allow CAP_SYS_ADMIN processes to do > everything. These individual permissions don't exist yet. I have an ACL patchset that allows me to add a greater range - though there's issues with SELinux there also. Also, the keyrings are specially marked to say that the sysadmin is allowed to flush them at the moment - but that can go away with the ACL stuff. > > + switch (need_perm) { > > + case KEY_NEED_UNLINK: > > + case KEY_SYSADMIN_OVERRIDE: > > + case KEY_AUTHTOKEN_OVERRIDE: > > + case KEY_DEFER_PERM_CHECK: > > return 0; > > We really shouldn't be skipping any/all checking on CAP_SYS_ADMIN or > an AUTHTOKEN; those should still be subject to MAC policy. I'm not sure how to do that. Note that KEY_NEED_UNLINK *must not* be overruled by the MAC policy. The value is only there because lookup_user_key() requires something to be put into that parameter - it's more of a courtesy thing, I suppose. Why should AUTHTOKEN be subject to MAC policy? The kernel has told the process to go and instantiate a key. It shouldn't really then turn around and tell the process "oh, but you're not actually allowed to do that". David