From mboxrd@z Thu Jan 1 00:00:00 1970 From: Al Viro Subject: Re: [PATCH bpf-next v9 05/10] bpf,landlock: Add a new map type: inode Date: Tue, 25 Jun 2019 23:52:01 +0100 Message-ID: <20190625225201.GJ17978@ZenIV.linux.org.uk> References: <20190625215239.11136-1-mic@digikod.net> <20190625215239.11136-6-mic@digikod.net> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Return-path: Content-Disposition: inline In-Reply-To: <20190625215239.11136-6-mic@digikod.net> Sender: linux-kernel-owner@vger.kernel.org To: =?iso-8859-1?Q?Micka=EBl_Sala=FCn?= Cc: linux-kernel@vger.kernel.org, Aleksa Sarai , Alexei Starovoitov , Andrew Morton , Andy Lutomirski , Arnaldo Carvalho de Melo , Casey Schaufler , Daniel Borkmann , David Drysdale , "David S . Miller" , "Eric W . Biederman" , James Morris , Jann Horn , John Johansen , Jonathan Corbet , Kees Cook , Michael Kerrisk , =?iso-8859-1?Q?Micka=EBl_Sala=FCn?= , Paul Moore , Sargun List-Id: linux-api@vger.kernel.org On Tue, Jun 25, 2019 at 11:52:34PM +0200, Mickaël Salaün wrote: > +/* must call iput(inode) after this call */ > +static struct inode *inode_from_fd(int ufd, bool check_access) > +{ > + struct inode *ret; > + struct fd f; > + int deny; > + > + f = fdget(ufd); > + if (unlikely(!f.file || !file_inode(f.file))) { > + ret = ERR_PTR(-EBADF); > + goto put_fd; > + } Just when does one get a NULL file_inode()? The reason I'm asking is that arseloads of code would break if one managed to create such a beast... Incidentally, that should be return ERR_PTR(-EBADF); fdput() is wrong there. > + } > + /* check if the FD is tied to a mount point */ > + /* TODO: add this check when called from an eBPF program too */ > + if (unlikely(!f.file->f_path.mnt Again, the same question - when the hell can that happen? If you are sitting on an exploitable roothole, do share it... || f.file->f_path.mnt->mnt_flags & > + MNT_INTERNAL)) { > + ret = ERR_PTR(-EINVAL); > + goto put_fd; What does it have to do with mountpoints, anyway? > +/* called from syscall */ > +static int sys_inode_map_delete_elem(struct bpf_map *map, struct inode *key) > +{ > + struct inode_array *array = container_of(map, struct inode_array, map); > + struct inode *inode; > + int i; > + > + WARN_ON_ONCE(!rcu_read_lock_held()); > + for (i = 0; i < array->map.max_entries; i++) { > + if (array->elems[i].inode == key) { > + inode = xchg(&array->elems[i].inode, NULL); > + array->nb_entries--; Umm... Is that intended to be atomic in any sense? > + iput(inode); > + return 0; > + } > + } > + return -ENOENT; > +} > + > +/* called from syscall */ > +int bpf_inode_map_delete_elem(struct bpf_map *map, int *key) > +{ > + struct inode *inode; > + int err; > + > + inode = inode_from_fd(*key, false); > + if (IS_ERR(inode)) > + return PTR_ERR(inode); > + err = sys_inode_map_delete_elem(map, inode); > + iput(inode); > + return err; > +} Wait a sec... So we have those beasties that can have long-term references to arbitrary inodes stuck in them? What will happen if you get umount(2) called while such a thing exists?