Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp2874332img; Sun, 24 Mar 2019 22:00:10 -0700 (PDT) X-Google-Smtp-Source: APXvYqxAoX8eC/Ffk1lzeUg5WzRp83KSvINoGaMuZVm8Ydl6BiPGBUtl/R9WBstqyMtZhi0fIife X-Received: by 2002:a63:c61:: with SMTP id 33mr14622411pgm.293.1553490010764; Sun, 24 Mar 2019 22:00:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553490010; cv=none; d=google.com; s=arc-20160816; b=dUlDKJGh5SZ0EiZX180GKbgWp6CQxRX20R7pG3rEnl2fyXvGby5o3SQjt/u89KGBgK jZD3wXQXXHsZ678UjcCMb+F+7PamCMiIZ/H4aFSUstj5tBP2Iwm+nlL+PKzft0dw5qRq MaFfwcdbCYhyvY/2m25j3fUQRITe7eD545Vt4H9HjMIt69QYzYvnsKVF+6zlMfQqY0om qLFH5K7SU7mFZgMn0h1Ur0l0eujq7tUwSHn3tHCiH3k6nflBZeiGo1mx92tj5yny4AzA 9OJl6/M3JxEUNtTNOis5Wk2Nf9tXbks4VY7nKDh1res2hiKP0AQ1aBKdXkktboxCpjqh 9T4Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=YaIGNVl0xVodd/a8K9/QF/kSRKvIXLQSNtNe/IFRjkM=; b=qMT7t4VpbBYZdlaLJtzToZDKjK6a8ajDxGXrPalNbX3lp1Ki1d8eT6Bggw/Qh5AIhq vJREm3S4GSPUBP19S9P/WZUgfWRZlVxlhlpe/3RixuAWH3FuDxgM03m+iio6NbuKdyt+ 7HmK9mLz812eM9Leps2/PKfsAugArkkCHjLF991sUzPZc39kf/0u9qa93FM2z3PNGU8u bGPiqsTI2ho3RB+nIfESDuTSPYJxpMKGNwwF9W69WiyreRu+WgLtlMOuPxwD62GjOl60 cyLT+SzecaLZMiv0siOf5VSYemmEw1tZguYSbQ2OlTYXikcmPm2WiF8XMqBJJycKSIh4 XZew== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k75si4307356pgc.515.2019.03.24.21.59.55; Sun, 24 Mar 2019 22:00:10 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729336AbfCYE5w (ORCPT + 99 others); Mon, 25 Mar 2019 00:57:52 -0400 Received: from zeniv.linux.org.uk ([195.92.253.2]:43772 "EHLO ZenIV.linux.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725810AbfCYE5w (ORCPT ); Mon, 25 Mar 2019 00:57:52 -0400 Received: from viro by ZenIV.linux.org.uk with local (Exim 4.92 #3 (Red Hat Linux)) id 1h8Hg9-0005VV-0J; Mon, 25 Mar 2019 04:57:45 +0000 Date: Mon, 25 Mar 2019 04:57:44 +0000 From: Al Viro To: Linus Torvalds Cc: syzbot , Alexei Starovoitov , Daniel Borkmann , linux-fsdevel , Linux List Kernel Mailing , syzkaller-bugs Subject: Re: KASAN: use-after-free Read in path_lookupat Message-ID: <20190325045744.GK2217@ZenIV.linux.org.uk> References: <0000000000006946d2057bbd0eef@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Mar 24, 2019 at 06:23:24PM -0700, Linus Torvalds wrote: > Al, comments? At the very least, if we don't make > simple_symlink_inode_operations() do that, we should have a *big* > comment that if it's not part of the inode data, it needs to be > RCU-delayed. simple_symlink_inode_operations is red herring here - what matters is ->i_link being set; those have ->get_link == simple_get_link, but note that it is *not* called: res = inode->i_link; if (!res) { const char * (*get)(struct dentry *, struct inode *, struct delayed_call *); get = inode->i_op->get_link; if (nd->flags & LOOKUP_RCU) { res = get(NULL, inode, &last->done); if (res == ERR_PTR(-ECHILD)) { if (unlikely(unlazy_walk(nd))) return ERR_PTR(-ECHILD); res = get(dentry, inode, &last->done); } } else { res = get(dentry, inode, &last->done); } if (IS_ERR_OR_NULL(res)) return res; } for traversal and similar for readlink(2). And we certainly don't want to allocate copies in those cases - it would fuck RCU traversals for all fast symlinks (i.e. for the majority of symlinks out there). Actual situation: * shmem, erofs: OK, kfree() from the thing ->destroy_inode() is calling via call_rcu(). * befs, ext2, ext4, freevxfs, jfs, orangefs, ufs: OK, coallocated with inode * debugfs: broken * jffs2: broken, freeing of f->target should be moved to jffs2_i_callback(). * ubifs: broken, ought to move kfree(ui->data); from ubifs_destroy_inode() to ubifs_i_callback() * ceph: broken, needs to move kfree(ci->symlink) from ceph_destroy_inode() to ceph_i_callback(). * bpf: broken So we have 5 broken cases, all with the same kind of fix: move freeing into the RCU-delayed part of ->destroy_inode(); for debugfs and bpf that requires adding ->alloc_inode()/->destroy_inode(), rather than relying upon the defaults from fs/inode.c > Or maybe we could add a final inode callback function for "rcu_free" > that is called as the RCU-delayed freeing of the inode itself happens? > And then people could hook into that for freeing the inode->i_link > data. You mean, split ->destroy_inode() into immediate and RCU-delayed parts? There are filesystems where both parts are non-empty - we can't just switch all ->destroy_inode() work to call_rcu(). > So many choices.. But the current situation seems unnecessarily > complex for the filesystem, and isn't really documented. > > Our documentation currently says for get_link(): "If the body won't go > away until the inode is gone, nothing else is needed", which is wrong > (or at least very misleading, since the last "inode is gone" callback > we have is that evict() function). s/inode is gone/struct inode is freed/, but it's obviously not clear enough.