From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.3 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_MUTT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7343DC48BD5 for ; Tue, 25 Jun 2019 22:52:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 53ED620659 for ; Tue, 25 Jun 2019 22:52:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726376AbfFYWwR (ORCPT ); Tue, 25 Jun 2019 18:52:17 -0400 Received: from zeniv.linux.org.uk ([195.92.253.2]:40498 "EHLO ZenIV.linux.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725782AbfFYWwQ (ORCPT ); Tue, 25 Jun 2019 18:52:16 -0400 Received: from viro by ZenIV.linux.org.uk with local (Exim 4.92 #3 (Red Hat Linux)) id 1hfuID-0001yb-63; Tue, 25 Jun 2019 22:52:01 +0000 Date: Tue, 25 Jun 2019 23:52:01 +0100 From: Al Viro 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 Dhillon , "Serge E . Hallyn" , Shuah Khan , Stephen Smalley , Tejun Heo , Tetsuo Handa , Thomas Graf , Tycho Andersen , Will Drewry , kernel-hardening@lists.openwall.com, linux-api@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-security-module@vger.kernel.org, netdev@vger.kernel.org Subject: Re: [PATCH bpf-next v9 05/10] bpf,landlock: Add a new map type: inode 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-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20190625215239.11136-6-mic@digikod.net> User-Agent: Mutt/1.11.3 (2019-02-01) Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@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?