Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752485AbcDOPrr (ORCPT ); Fri, 15 Apr 2016 11:47:47 -0400 Received: from out03.mta.xmission.com ([166.70.13.233]:37323 "EHLO out03.mta.xmission.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751366AbcDOPqy (ORCPT ); Fri, 15 Apr 2016 11:46:54 -0400 From: "Eric W. Biederman" To: Linus Torvalds Cc: "H. Peter Anvin" , Andy Lutomirski , security@debian.org, security@kernel.org, Al Viro , security@ubuntu.com, Peter Hurley , Serge Hallyn , Willy Tarreau , Aurelien Jarno , One Thousand Gnomes , Jann Horn , Greg KH , Linux Kernel Mailing List , Jiri Slaby , Florian Weimer , "Eric W. Biederman" Date: Fri, 15 Apr 2016 10:35:23 -0500 Message-Id: <1460734532-20134-7-git-send-email-ebiederm@xmission.com> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1460734532-20134-1-git-send-email-ebiederm@xmission.com> References: <877ffyzy1j.fsf_-_@x220.int.ebiederm.org> <1460734532-20134-1-git-send-email-ebiederm@xmission.com> X-XM-AID: U2FsdGVkX1+4ZNHAoSWc8zuvGS6UkrWn8XNzdx00G24= 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.5000] * -0.0 DCC_CHECK_NEGATIVE Not listed in DCC * [sa06 1397; Body=1 Fuz1=1 Fuz2=28] X-Spam-DCC: XMission; sa06 1397; Body=1 Fuz1=1 Fuz2=28 X-Spam-Combo: *;Linus Torvalds X-Spam-Relay-Country: X-Spam-Timing: total 495 ms - load_scoreonly_sql: 0.05 (0.0%), signal_user_changed: 3.8 (0.8%), b_tie_ro: 2.7 (0.5%), parse: 1.00 (0.2%), extract_message_metadata: 16 (3.3%), get_uri_detail_list: 2.7 (0.5%), tests_pri_-1000: 7 (1.4%), tests_pri_-950: 1.37 (0.3%), tests_pri_-900: 1.23 (0.2%), tests_pri_-400: 30 (6.0%), check_bayes: 28 (5.7%), b_tokenize: 10 (2.0%), b_tok_get_all: 8 (1.7%), b_comp_prob: 2.5 (0.5%), b_tok_touch_all: 4.1 (0.8%), b_finish: 0.98 (0.2%), tests_pri_0: 424 (85.6%), check_dkim_signature: 0.57 (0.1%), check_dkim_adsp: 3.4 (0.7%), tests_pri_500: 8 (1.6%), rewrite_mail: 0.00 (0.0%) Subject: [PATCH 07/16] devpts: Cleanup newinstance parsing 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 in01.mta.xmission.com) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 4032 Lines: 126 Add a dedicated parsing routing for newinstance that does not modify data, so parsing out newinstance can be separate from the parsing of the other mount options. Allways pass as data to parse_mount_options the filesystem specific portion of the super_block that holds the mount options. Signed-off-by: "Eric W. Biederman" --- fs/devpts/inode.c | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/fs/devpts/inode.c b/fs/devpts/inode.c index 752b2cc6be1c..d65be43b6fe9 100644 --- a/fs/devpts/inode.c +++ b/fs/devpts/inode.c @@ -97,7 +97,6 @@ struct pts_mount_opts { kgid_t gid; umode_t mode; umode_t ptmxmode; - int newinstance; int max; }; @@ -140,19 +139,27 @@ static inline struct super_block *pts_sb_from_inode(struct inode *inode) return devpts_mnt->mnt_sb; } -#define PARSE_MOUNT 0 -#define PARSE_REMOUNT 1 +static bool parse_newinstance(const char *data) +{ + while (data) { + const char *p = strchr(data, ','); + size_t len = p ? p - data : strlen(data); + if ((len == 11) && (memcmp(data, "newinstance", 11) == 0)) { + return true; + } + data = p ? p + 1 : NULL; + } + return false; +} /* * parse_mount_options(): * Set @opts to mount options specified in @data. If an option is not - * specified in @data, set it to its default value. The exception is - * 'newinstance' option which can only be set/cleared on a mount (i.e. - * cannot be changed during remount). + * specified in @data, set it to its default value. * * Note: @data may be NULL (in which case all options are set to default). */ -static int parse_mount_options(char *data, int op, struct pts_mount_opts *opts) +static int parse_mount_options(char *data, struct pts_mount_opts *opts) { char *p; kuid_t uid; @@ -166,10 +173,6 @@ static int parse_mount_options(char *data, int op, struct pts_mount_opts *opts) opts->ptmxmode = DEVPTS_DEFAULT_PTMX_MODE; opts->max = NR_UNIX98_PTY_MAX; - /* newinstance makes sense only on initial mount */ - if (op == PARSE_MOUNT) - opts->newinstance = 0; - while ((p = strsep(&data, ",")) != NULL) { substring_t args[MAX_OPT_ARGS]; int token; @@ -210,9 +213,6 @@ static int parse_mount_options(char *data, int op, struct pts_mount_opts *opts) opts->ptmxmode = option & S_IALLUGO; break; case Opt_newinstance: - /* newinstance makes sense only on initial mount */ - if (op == PARSE_MOUNT) - opts->newinstance = 1; break; case Opt_max: if (match_int(&args[0], &option) || @@ -311,7 +311,7 @@ static int devpts_remount(struct super_block *sb, int *flags, char *data) struct pts_mount_opts *opts = &fsi->mount_opts; sync_filesystem(sb); - err = parse_mount_options(data, PARSE_REMOUNT, opts); + err = parse_mount_options(data, opts); /* * parse_mount_options() restores options to default values @@ -440,20 +440,18 @@ static struct dentry *devpts_mount(struct file_system_type *fs_type, int flags, const char *dev_name, void *data) { int error; - struct pts_mount_opts opts; struct super_block *s; + bool newinstance; - error = parse_mount_options(data, PARSE_MOUNT, &opts); - if (error) - return ERR_PTR(error); + newinstance = parse_newinstance(data); /* Require newinstance for all user namespace mounts to ensure * the mount options are not changed. */ - if ((current_user_ns() != &init_user_ns) && !opts.newinstance) + if ((current_user_ns() != &init_user_ns) && !newinstance) return ERR_PTR(-EINVAL); - if (opts.newinstance) + if (newinstance) s = sget(fs_type, NULL, set_anon_super, flags, NULL); else s = sget(fs_type, compare_init_pts_sb, set_anon_super, flags, @@ -469,7 +467,9 @@ static struct dentry *devpts_mount(struct file_system_type *fs_type, s->s_flags |= MS_ACTIVE; } - memcpy(&(DEVPTS_SB(s))->mount_opts, &opts, sizeof(opts)); + error = parse_mount_options(data, &DEVPTS_SB(s)->mount_opts); + if (error) + goto out_undo_sget; error = mknod_ptmx(s); if (error) -- 2.8.1