Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp2966983imm; Sun, 1 Jul 2018 09:20:11 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKQryl7S5JbdkGU/BrP5hIwSApOOiAwctLmLs+0C3IbfIaUVXcQ+DxVYe34uMTbzxe+JR+U X-Received: by 2002:a17:902:6903:: with SMTP id j3-v6mr22260325plk.313.1530462011718; Sun, 01 Jul 2018 09:20:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530462011; cv=none; d=google.com; s=arc-20160816; b=LNn79JSr7jT1esBDPZrbG/sA5UwEGQzqyuSD0ofbNsZDrUiOmmtZwRRMcwPMsVDYQZ EO5vTm7hJt8n6+qmCEzkIGxeirc3t3vL4eHbDD3ZgUVOaD9KKXpHwSt0N6Q4diSC9IMW uaY4us9o3fU6r0IiwQkH3Qetd2ubvzBm3PKZF46I8NkbkII7198eBEqu9xIsyMrrT7oK Mjur/UFbEEuWgn9mjmoLYupHc7vbaHoVwGTMshtAXRqxviV6qTuyLKAHE+ZTnBXTbeFY uv7akZAwc6IY7LKd1pd2dsmllyd+1k37zmGqJb0XTgBP6icfI2FTsTkSSeLvm6Jd2VdF o89A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=yEpyeIBoHbsljEDCz7ePIcJBetSqx9SMscXVz+e7/ec=; b=ye8DkUS2IKYuvWt0obLDGAMeFv4Mbus71mPQkf39/vD+/uZto5+Rsg6YsyX9YRp4bV PI0H4gOTrtxFxqFXM9Tem4IUP+nx5aO7tBDdZA/ZTBynKws5h7gQeJwMK4uzDAVOXZXD 6EBfDYYf4fASSx0Jr5suuNvhk6RUTs+bUfZh7VI7Do6jGZpzYtfX98oHFmiRHyKyxjY5 CoG99+/absk8qn9LmN0mrtAzKxzAqpJDx1wWHrCLJGV9LTbKcpvVdhblulwZdV00PWad 4BJQAxKRsv/bFqE3QWAuFJ3vFLcuwXqZzzjkft+NPS56YcAjEP1dgItoOZ9SMkw3YFy/ VQdA== 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 y123-v6si15180476pfc.302.2018.07.01.09.19.57; Sun, 01 Jul 2018 09:20:11 -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 S1753347AbeGAQSc (ORCPT + 99 others); Sun, 1 Jul 2018 12:18:32 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:33014 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753217AbeGAQS2 (ORCPT ); Sun, 1 Jul 2018 12:18:28 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 9A09E92B; Sun, 1 Jul 2018 16:18:27 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot , Miklos Szeredi Subject: [PATCH 4.4 042/105] fuse: fix control dir setup and teardown Date: Sun, 1 Jul 2018 18:01:52 +0200 Message-Id: <20180701153152.262946709@linuxfoundation.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180701153149.382300170@linuxfoundation.org> References: <20180701153149.382300170@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: Miklos Szeredi commit 6becdb601bae2a043d7fb9762c4d48699528ea6e upstream. syzbot is reporting NULL pointer dereference at fuse_ctl_remove_conn() [1]. Since fc->ctl_ndents is incremented by fuse_ctl_add_conn() when new_inode() failed, fuse_ctl_remove_conn() reaches an inode-less dentry and tries to clear d_inode(dentry)->i_private field. Fix by only adding the dentry to the array after being fully set up. When tearing down the control directory, do d_invalidate() on it to get rid of any mounts that might have been added. [1] https://syzkaller.appspot.com/bug?id=f396d863067238959c91c0b7cfc10b163638cac6 Reported-by: syzbot Fixes: bafa96541b25 ("[PATCH] fuse: add control filesystem") Cc: # v2.6.18 Signed-off-by: Miklos Szeredi Signed-off-by: Greg Kroah-Hartman --- fs/fuse/control.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) --- a/fs/fuse/control.c +++ b/fs/fuse/control.c @@ -211,10 +211,11 @@ static struct dentry *fuse_ctl_add_dentr if (!dentry) return NULL; - fc->ctl_dentry[fc->ctl_ndents++] = dentry; inode = new_inode(fuse_control_sb); - if (!inode) + if (!inode) { + dput(dentry); return NULL; + } inode->i_ino = get_next_ino(); inode->i_mode = mode; @@ -228,6 +229,9 @@ static struct dentry *fuse_ctl_add_dentr set_nlink(inode, nlink); inode->i_private = fc; d_add(dentry, inode); + + fc->ctl_dentry[fc->ctl_ndents++] = dentry; + return dentry; } @@ -284,7 +288,10 @@ void fuse_ctl_remove_conn(struct fuse_co for (i = fc->ctl_ndents - 1; i >= 0; i--) { struct dentry *dentry = fc->ctl_dentry[i]; d_inode(dentry)->i_private = NULL; - d_drop(dentry); + if (!i) { + /* Get rid of submounts: */ + d_invalidate(dentry); + } dput(dentry); } drop_nlink(d_inode(fuse_control_sb->s_root));