Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp8073122ybi; Thu, 6 Jun 2019 06:19:22 -0700 (PDT) X-Google-Smtp-Source: APXvYqwbFhSAy/UDkxvfHikgBg4XcS6YN86EXdJrPYn1J50/6Gx3fPsosNedthKOdH8RZV2nIAPM X-Received: by 2002:aa7:80ce:: with SMTP id a14mr21670937pfn.249.1559827162390; Thu, 06 Jun 2019 06:19:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559827162; cv=none; d=google.com; s=arc-20160816; b=gDhaWQKqVajPB2umpAmhBTImrjJBzjRbQr1+jHlbU+tp8I/ijPp8JfjYnoiiXcv0o6 ORNT06iPXhsf8hJuQ5VmOdVeCWpPoW+62BddNhu38OmZpnUOFKkYcZNO9K4Mszn9hC5N 77RpXafzvWc5z93pWQbSsvVF2rRU0psWTrOXG0YUUon6RzMBGNTi4CKXMaOFXJftYt9u LCoVyuKNdtpUIAi5ablyNAOeifluIjn+I282nvDwXnN/fMrpuczuGpsF74CItuhg1T45 jnYEzRLc0j+ASea8wKZtpb+Y6tievc2wLpPPdQxdmHrUv3FCTVLm6J3mufhM4QvNQvLZ YZjw== 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-transfer-encoding :content-id:mime-version:subject:cc:to:references:in-reply-to:from :organization; bh=IWvZHlsN0tBqqcKP2rdu1pNABfiy8ZrYtVo9NKzn6tU=; b=YWiAnHluqgoQ+IsgwudX/g9A/bjp4jTcYUUAIQTi1WZonvNlfuubGiybncW7mGa3EH 9wL5Se0OWJydrZoIRMz+Ex+mPmT6mSmIjyM8uRdPzr2Vu0mcR9eblzVIzvpkCDFkMJUt 3I5FMQvqeERO5YP57AoAgfc2Yo6PPPoUKpqKRPjFymn2bnog+654z9hRLete3LoaAH+b pajQVOj3BbLvRcvxhX3XISx9XTFWUSnLmW/FjHNnEIom14RpmbtOxj0iziaZMbF82m4O aWZhGz7nsRHqgq4gkVrWcABQAVfeJdlguC9wAWDJi31gaK7TXcyGh/f+jJutSNJ7bHuS 70gQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k10si2113604pgo.0.2019.06.06.06.19.04; Thu, 06 Jun 2019 06:19:22 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727738AbfFFNRA convert rfc822-to-8bit (ORCPT + 99 others); Thu, 6 Jun 2019 09:17:00 -0400 Received: from mx1.redhat.com ([209.132.183.28]:49902 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726877AbfFFNQ7 (ORCPT ); Thu, 6 Jun 2019 09:16:59 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2AC1F85546; Thu, 6 Jun 2019 13:16:54 +0000 (UTC) Received: from warthog.procyon.org.uk (ovpn-120-173.rdu2.redhat.com [10.10.120.173]) by smtp.corp.redhat.com (Postfix) with ESMTP id E50DF108427E; Thu, 6 Jun 2019 13:16:43 +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: <155981411940.17513.7137844619951358374.stgit@warthog.procyon.org.uk> To: Stephen Smalley Cc: dhowells@redhat.com, viro@zeniv.linux.org.uk, Greg Kroah-Hartman , Casey Schaufler , linux-usb@vger.kernel.org, raven@themaw.net, linux-fsdevel@vger.kernel.org, linux-api@vger.kernel.org, linux-block@vger.kernel.org, keyrings@vger.kernel.org, linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org, Paul Moore Subject: Re: [RFC][PATCH 00/10] Mount, FS, Block and Keyrings notifications [ver #3] MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <3812.1559827003.1@warthog.procyon.org.uk> Content-Transfer-Encoding: 8BIT Date: Thu, 06 Jun 2019 14:16:43 +0100 Message-ID: <3813.1559827003@warthog.procyon.org.uk> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Thu, 06 Jun 2019 13:16:59 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Stephen Smalley wrote: This might be easier to discuss if you can reply to: https://lore.kernel.org/lkml/5393.1559768763@warthog.procyon.org.uk/ which is on the ver #2 posting of this patchset. > > LSM support is included, but controversial: > > > > (1) The creds of the process that did the fput() that reduced the refcount > > to zero are cached in the file struct. > > > > (2) __fput() overrides the current creds with the creds from (1) whilst > > doing the cleanup, thereby making sure that the creds seen by the > > destruction notification generated by mntput() appears to come from > > the last fputter. > > > > (3) security_post_notification() is called for each queue that we might > > want to post a notification into, thereby allowing the LSM to prevent > > covert communications. > > > > (?) Do I need to add security_set_watch(), say, to rule on whether a watch > > may be set in the first place? I might need to add a variant per > > watch-type. > > > > (?) Do I really need to keep track of the process creds in which an > > implicit object destruction happened? For example, imagine you create > > an fd with fsopen()/fsmount(). It is marked to dissolve the mount it > > refers to on close unless move_mount() clears that flag. Now, imagine > > someone looking at that fd through procfs at the same time as you exit > > due to an error. The LSM sees the destruction notification come from > > the looker if they happen to do their fput() after yours. > > > I'm not in favor of this approach. Which bit? The last point? Keeping track of the process creds after an implicit object destruction. > Can we check permission to the object being watched when a watch is set > (read-like access), Yes, and I need to do that. I think it's likely to require an extra hook for each entry point added because the objects are different: int security_watch_key(struct watch *watch, struct key *key); int security_watch_sb(struct watch *watch, struct path *path); int security_watch_mount(struct watch *watch, struct path *path); int security_watch_devices(struct watch *watch); > make sure every access that can trigger a notification requires a > (write-like) permission to the accessed object, "write-like permssion" for whom? The triggerer or the watcher? There are various 'classes' of events: (1) System events (eg. hardware I/O errors, automount points expiring). (2) Direct events (eg. automounts, manual mounts, EDQUOT, key linkage). (3) Indirect events (eg. exit/close doing the last fput and causing an unmount). Class (1) are uncaused by a process, so I use init_cred for them. One could argue that the automount point expiry should perhaps take place under the creds of whoever triggered it in the first place, but we need to be careful about long-term cred pinning. Class (2) the causing process must've had permission to cause them - otherwise we wouldn't have got the event. Class (3) is interesting since it's currently entirely cleanup events and the process may have the right to do them (close, dup2, exit, but also execve) whether the LSM thinks it should be able to cause the object to be destroyed or not. It gets more complicated than that, though: multiple processes with different security attributes can all have fds pointing to a common file object - and the last one to close carries the can as far as the LSM is concerned. And yet more complicated when you throw in unix sockets with partially passed fds still in their queues. That's what patch 01 is designed to try and cope with. > and make sure there is some sane way to control the relationship between the > accessed object and the watched object (write-like)? This is the trick. Keys and superblocks have object labels of their own and don't - for now - propagate their watches. With these, the watch is on the object you initially assign it to and it goes no further than that. mount_notify() is the interesting case since we want to be able to detect mount topology change events from within the vfs subtree rooted at the watched directory without having to manually put a watch on every directory in that subtree - or even just every mount object. Or, maybe, that's what I'll have to do: make it mount_notify() can only apply to the subtree within its superblock, and the caller must call mount_notify() for every mount object it wants to monitor. That would at least ensure that the caller can, at that point, reach all those mount points. > For cases where we have no object per se or at least no security > structure/label associated with it, we may have to fall back to a > coarse-grained "Can the watcher get this kind of notification in general?". Agreed - and we should probably have that anyway. David