From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757296AbcDEBoH (ORCPT ); Mon, 4 Apr 2016 21:44:07 -0400 Received: from out02.mta.xmission.com ([166.70.13.232]:41469 "EHLO out02.mta.xmission.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932822AbcDEBmI (ORCPT ); Mon, 4 Apr 2016 21:42:08 -0400 From: "Eric W. Biederman" To: Linus Torvalds Cc: "H. Peter Anvin" , Peter Hurley , Greg KH , Jiri Slaby , Aurelien Jarno , Andy Lutomirski , Florian Weimer , Al Viro , Serge Hallyn , Jann Horn , "security@kernel.org" , security@ubuntu.com, security@debian.org, Willy Tarreau , Linux Kernel Mailing List , "Eric W. Biederman" Date: Mon, 4 Apr 2016 20:29:27 -0500 Message-Id: <1459819769-30387-11-git-send-email-ebiederm@xmission.com> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1459819769-30387-1-git-send-email-ebiederm@xmission.com> References: <878u0s3orx.fsf_-_@x220.int.ebiederm.org> <1459819769-30387-1-git-send-email-ebiederm@xmission.com> X-XM-AID: U2FsdGVkX19xZnuNH0p7p5CmjTJPmoBzjJQCZjBcu9k= X-SA-Exim-Connect-IP: 67.3.249.252 X-SA-Exim-Mail-From: ebiederm@xmission.com X-Spam-Report: * -1.0 ALL_TRUSTED Passed through trusted hosts only via SMTP * 0.0 TVD_RCVD_IP Message was received from an IP address * 1.5 XMNoVowels Alpha-numberic number with no vowels * 0.8 BAYES_50 BODY: Bayes spam probability is 40 to 60% * [score: 0.5001] * -0.0 DCC_CHECK_NEGATIVE Not listed in DCC * [sa03 1397; Body=1 Fuz1=1 Fuz2=1] * 0.0 T_TooManySym_01 4+ unique symbols in subject X-Spam-DCC: XMission; sa03 1397; Body=1 Fuz1=1 Fuz2=1 X-Spam-Combo: *;Linus Torvalds X-Spam-Relay-Country: X-Spam-Timing: total 609 ms - load_scoreonly_sql: 0.05 (0.0%), signal_user_changed: 4.0 (0.7%), b_tie_ro: 2.8 (0.5%), parse: 1.28 (0.2%), extract_message_metadata: 26 (4.3%), get_uri_detail_list: 2.6 (0.4%), tests_pri_-1000: 12 (1.9%), tests_pri_-950: 2.0 (0.3%), tests_pri_-900: 1.70 (0.3%), tests_pri_-400: 35 (5.8%), check_bayes: 33 (5.4%), b_tokenize: 14 (2.3%), b_tok_get_all: 8 (1.3%), b_comp_prob: 4.0 (0.7%), b_tok_touch_all: 3.6 (0.6%), b_finish: 0.87 (0.1%), tests_pri_0: 515 (84.6%), check_dkim_signature: 0.89 (0.1%), check_dkim_adsp: 4.1 (0.7%), tests_pri_500: 7 (1.1%), rewrite_mail: 0.00 (0.0%) Subject: [PATCH 11/13] vfs: Implement mount_super_once X-Spam-Flag: No X-SA-Exim-Version: 4.2.1 (built Wed, 24 Sep 2014 11:00:52 -0600) X-SA-Exim-Scanned: Yes (on in02.mta.xmission.com) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The devpts filesystem has a notion of a system or primary instance of devpts. To retain the notion of a primary system instance of devpts the code needs a way to allow userspace to mount the internally mounted instance of devpts when it is not currently mounted by userspace. The new helper mount_super_once allows that. Ideally mount_super_once would ignore still referenced lazy unmounts, but in testing I was not able to find an existing distribution that cared. Since no one actually cares I did not try and solve the formidable challenges of adding a test to ignore still referenced lazy mounts in a race free way. Signed-off-by: "Eric W. Biederman" --- fs/super.c | 12 ++++++++++++ include/linux/fs.h | 2 ++ 2 files changed, 14 insertions(+) diff --git a/fs/super.c b/fs/super.c index 74914b1bae70..98a569412036 100644 --- a/fs/super.c +++ b/fs/super.c @@ -1101,6 +1101,18 @@ struct dentry *mount_single(struct file_system_type *fs_type, } EXPORT_SYMBOL(mount_single); +struct dentry *mount_super_once(struct super_block *sb, int flags, void *data) +{ + /* Allow mounting the specified superblock by userspace if there + * are not any existing userspace mounts of it. + */ + if (atomic_cmpxchg(&sb->s_active, 1, 2) != 1) + return ERR_PTR(-EBUSY); + down_write(&sb->s_umount); + do_remount_sb(sb, flags, data, 0); + return dget(sb->s_root); +} + struct dentry * mount_fs(struct file_system_type *type, int flags, const char *name, void *data) { diff --git a/include/linux/fs.h b/include/linux/fs.h index 02a980bfad5c..515f874a6907 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -2002,6 +2002,8 @@ extern struct dentry *mount_single(struct file_system_type *fs_type, extern struct dentry *mount_nodev(struct file_system_type *fs_type, int flags, void *data, int (*fill_super)(struct super_block *, void *, int)); +extern struct dentry *mount_super_once(struct super_block *sb, + int flags, void *data); extern struct dentry *mount_subtree(struct vfsmount *mnt, const char *path); void generic_shutdown_super(struct super_block *sb); void kill_block_super(struct super_block *sb); -- 2.6.3