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=-6.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS 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 0AA8AC433E1 for ; Fri, 15 May 2020 20:56:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E2C78205CB for ; Fri, 15 May 2020 20:56:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726646AbgEOU4m (ORCPT ); Fri, 15 May 2020 16:56:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39002 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726179AbgEOU4m (ORCPT ); Fri, 15 May 2020 16:56:42 -0400 Received: from ZenIV.linux.org.uk (zeniv.linux.org.uk [IPv6:2002:c35c:fd02::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D092AC061A0C; Fri, 15 May 2020 13:56:41 -0700 (PDT) Received: from viro by ZenIV.linux.org.uk with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1jZhNV-009Hh7-7g; Fri, 15 May 2020 20:56:21 +0000 Date: Fri, 15 May 2020 21:56:21 +0100 From: Al Viro To: Olga Kornievskaia Cc: Alexey Gladkov , "Eric W. Biederman" , syzbot , jmorris@namei.org, linux-kernel@vger.kernel.org, linux-next@vger.kernel.org, linux-security-module@vger.kernel.org, serge@hallyn.com, sfr@canb.auug.org.au, syzkaller-bugs@googlegroups.com, linux-fsdevel , ".Tetsuo Handa" Subject: Re: linux-next boot error: general protection fault in tomoyo_get_local_path Message-ID: <20200515205621.GH23230@ZenIV.linux.org.uk> References: <0000000000002f0c7505a5b0e04c@google.com> <72cb7aea-92bd-d71b-2f8a-63881a35fad8@i-love.sakura.ne.jp> <20200515201357.GG23230@ZenIV.linux.org.uk> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200515201357.GG23230@ZenIV.linux.org.uk> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, May 15, 2020 at 09:13:57PM +0100, Al Viro wrote: > On Sat, May 16, 2020 at 12:36:28AM +0900, Tetsuo Handa wrote: > > On 2020/05/16 0:18, Tetsuo Handa wrote: [snip] > > A similar bug (racing inode destruction with open() on proc filesystem) was fixed as > > commit 6f7c41374b62fd80 ("tomoyo: Don't use nifty names on sockets."). Then, it might > > not be safe to replace dentry->d_sb->s_fs_info with dentry->d_inode->i_sb->s_fs_info . > > Could you explain why do you want to bother with d_inode() anyway? Anything that > does dentry->d_inode->i_sb can bloody well use dentry->d_sb. And that's never > changed over the struct dentry lifetime - ->d_sb is set on allocation and never > modified afterwards. Incidentally, this r_ino = nfs_fhget(ss_mnt->mnt_root->d_inode->i_sb, src_fh, &fattr, NULL); (in nfs42_ssc_open()) is just plain weird. 1) d->d_inode->i_sb is equal to d->d_sb 2) m->mnt_root->d_sb is equal to m->mnt_sb IOW, the whole thing should be r_ino = nfs_fhget(ss_mnt->mnt_sb, src_fh, &fattr, NULL); Moreover, server = NFS_SERVER(ss_mnt->mnt_root->d_inode); in the same function is again too convoluted for no good reason, seeing that NFS_SERVER(inode) is NFS_SB(inode->i_sb). Something along the lines of nfs: don't obfuscate ->mnt_sb as ->mnt_root->d_inode->i_sb Signed-off-by: Al Viro --- diff --git a/fs/nfs/nfs4file.c b/fs/nfs/nfs4file.c index 8e5d6223ddd3..1e8ca45bc806 100644 --- a/fs/nfs/nfs4file.c +++ b/fs/nfs/nfs4file.c @@ -317,15 +317,14 @@ nfs42_ssc_open(struct vfsmount *ss_mnt, struct nfs_fh *src_fh, { struct nfs_fattr fattr; struct file *filep, *res; - struct nfs_server *server; + struct super_block *sb = ss_mnt->mnt_sb; + struct nfs_server *server = NFS_SB(sb); struct inode *r_ino = NULL; struct nfs_open_context *ctx; struct nfs4_state_owner *sp; char *read_name = NULL; int len, status = 0; - server = NFS_SERVER(ss_mnt->mnt_root->d_inode); - nfs_fattr_init(&fattr); status = nfs4_proc_getattr(server, src_fh, &fattr, NULL, NULL); @@ -341,8 +340,7 @@ nfs42_ssc_open(struct vfsmount *ss_mnt, struct nfs_fh *src_fh, goto out; snprintf(read_name, len, SSC_READ_NAME_BODY, read_name_gen++); - r_ino = nfs_fhget(ss_mnt->mnt_root->d_inode->i_sb, src_fh, &fattr, - NULL); + r_ino = nfs_fhget(sb, src_fh, &fattr, NULL); if (IS_ERR(r_ino)) { res = ERR_CAST(r_ino); goto out_free_name;