From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932720AbcDEBlX (ORCPT ); Mon, 4 Apr 2016 21:41:23 -0400 Received: from out02.mta.xmission.com ([166.70.13.232]:41315 "EHLO out02.mta.xmission.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757072AbcDEBlT (ORCPT ); Mon, 4 Apr 2016 21:41:19 -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:19 -0500 Message-Id: <1459819769-30387-3-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: U2FsdGVkX191p3GmShUuoKgXpPsqXRkU2IQjfb6t2/s= 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 * 1.5 XMNoVowels Alpha-numberic number with no vowels * 0.0 TVD_RCVD_IP Message was received from an IP address * 0.8 BAYES_50 BODY: Bayes spam probability is 40 to 60% * [score: 0.5000] * -0.0 DCC_CHECK_NEGATIVE Not listed in DCC * [sa01 1397; Body=1 Fuz1=1 Fuz2=1] X-Spam-DCC: XMission; sa01 1397; Body=1 Fuz1=1 Fuz2=1 X-Spam-Combo: *;Linus Torvalds X-Spam-Relay-Country: X-Spam-Timing: total 1028 ms - load_scoreonly_sql: 0.05 (0.0%), signal_user_changed: 3.8 (0.4%), b_tie_ro: 2.7 (0.3%), parse: 1.46 (0.1%), extract_message_metadata: 28 (2.7%), get_uri_detail_list: 4.4 (0.4%), tests_pri_-1000: 11 (1.1%), tests_pri_-950: 2.1 (0.2%), tests_pri_-900: 1.68 (0.2%), tests_pri_-400: 42 (4.1%), check_bayes: 40 (3.9%), b_tokenize: 18 (1.8%), b_tok_get_all: 10 (0.9%), b_comp_prob: 4.8 (0.5%), b_tok_touch_all: 3.8 (0.4%), b_finish: 0.88 (0.1%), tests_pri_0: 926 (90.0%), check_dkim_signature: 0.85 (0.1%), check_dkim_adsp: 4.4 (0.4%), tests_pri_500: 6 (0.6%), rewrite_mail: 0.00 (0.0%) Subject: [PATCH 03/13] 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 in02.mta.xmission.com) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 9f22c959d1f7..c3d53d2f7c3e 100644 --- a/fs/devpts/inode.c +++ b/fs/devpts/inode.c @@ -105,7 +105,6 @@ struct pts_mount_opts { kgid_t gid; umode_t mode; umode_t ptmxmode; - int newinstance; int max; }; @@ -228,19 +227,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; @@ -254,10 +261,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; @@ -298,9 +301,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) || @@ -399,7 +399,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 @@ -528,20 +528,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, @@ -557,7 +555,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.6.3