From: Sebastian Capella <sebastian.capella@linaro.org> To: linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linaro-kernel@lists.linaro.org, patches@linaro.org Cc: Sebastian Capella <sebastian.capella@linaro.org>, "Eric W. Biederman" <ebiederm@xmission.com>, Serge Hallyn <serge.hallyn@canonical.com>, Andrew Morton <akpm@linux-foundation.org>, Stephen Warren <swarren@nvidia.com>, Jens Axboe <axboe@kernel.dk>, Greg Kroah-Hartman <gregkh@linuxfoundation.org>, Al Viro <viro@zeniv.linux.org.uk> Subject: [PATCH v3 1/2] init/do_mounts.c: ignore final \n in name_to_dev_t Date: Thu, 3 Oct 2013 14:10:37 -0700 [thread overview] Message-ID: <1380834638-24035-2-git-send-email-sebastian.capella@linaro.org> (raw) In-Reply-To: <1380834638-24035-1-git-send-email-sebastian.capella@linaro.org> Enhance name_to_dev_t to handle trailing newline characters on device paths. Some inputs to name_to_dev_t may come from userspace where oftentimes a '\n' is appended to the path. Added const to the name buffer in both the function declaration and the prototype to reflect input buffer handling. By handling trailing newlines in name_to_dev_t, userspace buffers may be directly passed to name_to_dev_t without modification. Signed-off-by: Sebastian Capella <sebastian.capella@linaro.org> Reviewed-by: Pavel Machek <pavel@ucw.cz> Cc: "Eric W. Biederman" <ebiederm@xmission.com> Cc: Serge Hallyn <serge.hallyn@canonical.com> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: Stephen Warren <swarren@nvidia.com> Cc: Jens Axboe <axboe@kernel.dk> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Cc: Al Viro <viro@zeniv.linux.org.uk> --- include/linux/mount.h | 2 +- init/do_mounts.c | 25 +++++++++++++++++++------ 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/include/linux/mount.h b/include/linux/mount.h index 38cd98f..fdbb3e6 100644 --- a/include/linux/mount.h +++ b/include/linux/mount.h @@ -77,6 +77,6 @@ extern struct vfsmount *vfs_kern_mount(struct file_system_type *type, extern void mnt_set_expiry(struct vfsmount *mnt, struct list_head *expiry_list); extern void mark_mounts_for_expiry(struct list_head *mounts); -extern dev_t name_to_dev_t(char *name); +extern dev_t name_to_dev_t(const char *name); #endif /* _LINUX_MOUNT_H */ diff --git a/init/do_mounts.c b/init/do_mounts.c index a51cddc..69d74ff 100644 --- a/init/do_mounts.c +++ b/init/do_mounts.c @@ -145,6 +145,13 @@ static dev_t devt_from_partuuid(const char *uuid_str) clear_root_wait = true; goto done; } + if (uuid_str[cmp.len - 1] == '\n') { + cmp.len--; + if (!cmp.len) { + clear_root_wait = true; + goto done; + } + } dev = class_find_device(&block_class, NULL, &cmp, &match_dev_by_uuid); @@ -204,12 +211,13 @@ done: * bangs. */ -dev_t name_to_dev_t(char *name) +dev_t name_to_dev_t(const char *name) { char s[32]; char *p; dev_t res = 0; int part; + int n; #ifdef CONFIG_BLOCK if (strncmp(name, "PARTUUID=", 9) == 0) { @@ -230,7 +238,7 @@ dev_t name_to_dev_t(char *name) goto fail; } else { res = new_decode_dev(simple_strtoul(name, &p, 16)); - if (*p) + if (*p && *p != '\n') goto fail; } goto done; @@ -238,15 +246,20 @@ dev_t name_to_dev_t(char *name) name += 5; res = Root_NFS; - if (strcmp(name, "nfs") == 0) + if (strncmp(name, "nfs", 3) == 0) goto done; res = Root_RAM0; - if (strcmp(name, "ram") == 0) + if (strncmp(name, "ram", 3) == 0) goto done; - if (strlen(name) > 31) + n = strlen(name); + if (n != 0 && name[n - 1] == '\n') + n--; + if (n > 31) goto fail; - strcpy(s, name); + strncpy(s, name, n); + s[n] = '\0'; + for (p = s; *p; p++) if (*p == '/') *p = '!'; -- 1.7.9.5
WARNING: multiple messages have this Message-ID (diff)
From: sebastian.capella@linaro.org (Sebastian Capella) To: linux-arm-kernel@lists.infradead.org Subject: [PATCH v3 1/2] init/do_mounts.c: ignore final \n in name_to_dev_t Date: Thu, 3 Oct 2013 14:10:37 -0700 [thread overview] Message-ID: <1380834638-24035-2-git-send-email-sebastian.capella@linaro.org> (raw) In-Reply-To: <1380834638-24035-1-git-send-email-sebastian.capella@linaro.org> Enhance name_to_dev_t to handle trailing newline characters on device paths. Some inputs to name_to_dev_t may come from userspace where oftentimes a '\n' is appended to the path. Added const to the name buffer in both the function declaration and the prototype to reflect input buffer handling. By handling trailing newlines in name_to_dev_t, userspace buffers may be directly passed to name_to_dev_t without modification. Signed-off-by: Sebastian Capella <sebastian.capella@linaro.org> Reviewed-by: Pavel Machek <pavel@ucw.cz> Cc: "Eric W. Biederman" <ebiederm@xmission.com> Cc: Serge Hallyn <serge.hallyn@canonical.com> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: Stephen Warren <swarren@nvidia.com> Cc: Jens Axboe <axboe@kernel.dk> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Cc: Al Viro <viro@zeniv.linux.org.uk> --- include/linux/mount.h | 2 +- init/do_mounts.c | 25 +++++++++++++++++++------ 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/include/linux/mount.h b/include/linux/mount.h index 38cd98f..fdbb3e6 100644 --- a/include/linux/mount.h +++ b/include/linux/mount.h @@ -77,6 +77,6 @@ extern struct vfsmount *vfs_kern_mount(struct file_system_type *type, extern void mnt_set_expiry(struct vfsmount *mnt, struct list_head *expiry_list); extern void mark_mounts_for_expiry(struct list_head *mounts); -extern dev_t name_to_dev_t(char *name); +extern dev_t name_to_dev_t(const char *name); #endif /* _LINUX_MOUNT_H */ diff --git a/init/do_mounts.c b/init/do_mounts.c index a51cddc..69d74ff 100644 --- a/init/do_mounts.c +++ b/init/do_mounts.c @@ -145,6 +145,13 @@ static dev_t devt_from_partuuid(const char *uuid_str) clear_root_wait = true; goto done; } + if (uuid_str[cmp.len - 1] == '\n') { + cmp.len--; + if (!cmp.len) { + clear_root_wait = true; + goto done; + } + } dev = class_find_device(&block_class, NULL, &cmp, &match_dev_by_uuid); @@ -204,12 +211,13 @@ done: * bangs. */ -dev_t name_to_dev_t(char *name) +dev_t name_to_dev_t(const char *name) { char s[32]; char *p; dev_t res = 0; int part; + int n; #ifdef CONFIG_BLOCK if (strncmp(name, "PARTUUID=", 9) == 0) { @@ -230,7 +238,7 @@ dev_t name_to_dev_t(char *name) goto fail; } else { res = new_decode_dev(simple_strtoul(name, &p, 16)); - if (*p) + if (*p && *p != '\n') goto fail; } goto done; @@ -238,15 +246,20 @@ dev_t name_to_dev_t(char *name) name += 5; res = Root_NFS; - if (strcmp(name, "nfs") == 0) + if (strncmp(name, "nfs", 3) == 0) goto done; res = Root_RAM0; - if (strcmp(name, "ram") == 0) + if (strncmp(name, "ram", 3) == 0) goto done; - if (strlen(name) > 31) + n = strlen(name); + if (n != 0 && name[n - 1] == '\n') + n--; + if (n > 31) goto fail; - strcpy(s, name); + strncpy(s, name, n); + s[n] = '\0'; + for (p = s; *p; p++) if (*p == '/') *p = '!'; -- 1.7.9.5
next prev parent reply other threads:[~2013-10-03 21:11 UTC|newest] Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top 2013-10-03 21:10 [PATCH v3 0/2] PM / Hibernate: sysfs resume Sebastian Capella 2013-10-03 21:10 ` Sebastian Capella 2013-10-03 21:10 ` Sebastian Capella [this message] 2013-10-03 21:10 ` [PATCH v3 1/2] init/do_mounts.c: ignore final \n in name_to_dev_t Sebastian Capella 2013-10-03 21:15 ` Andrew Morton 2013-10-03 21:15 ` Andrew Morton 2013-10-03 21:42 ` Sebastian Capella 2013-10-03 21:42 ` Sebastian Capella 2013-10-03 23:47 ` Sebastian Capella 2013-10-03 23:47 ` Sebastian Capella 2013-10-10 17:50 ` Sebastian Capella 2013-10-10 17:50 ` Sebastian Capella 2013-10-10 22:47 ` Eric W. Biederman 2013-10-10 22:47 ` Eric W. Biederman 2013-10-10 23:39 ` Sebastian Capella 2013-10-10 23:39 ` Sebastian Capella 2013-10-22 17:54 ` Sebastian Capella 2013-10-22 17:54 ` Sebastian Capella 2014-01-28 18:59 ` Sebastian Capella 2014-01-28 18:59 ` Sebastian Capella 2014-01-28 20:54 ` Andrew Morton 2014-01-28 20:54 ` Andrew Morton 2014-01-28 20:58 ` Sebastian Capella 2014-01-28 20:58 ` Sebastian Capella 2014-01-29 18:29 ` Sebastian Capella 2014-01-29 18:29 ` Sebastian Capella 2014-01-29 18:41 ` Andrew Morton 2014-01-29 18:41 ` Andrew Morton 2013-10-03 21:10 ` [PATCH v3 2/2] PM / Hibernate: use name_to_dev_t to parse resume Sebastian Capella 2013-10-03 21:10 ` Sebastian Capella
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=1380834638-24035-2-git-send-email-sebastian.capella@linaro.org \ --to=sebastian.capella@linaro.org \ --cc=akpm@linux-foundation.org \ --cc=axboe@kernel.dk \ --cc=ebiederm@xmission.com \ --cc=gregkh@linuxfoundation.org \ --cc=linaro-kernel@lists.linaro.org \ --cc=linux-arm-kernel@lists.infradead.org \ --cc=linux-kernel@vger.kernel.org \ --cc=linux-pm@vger.kernel.org \ --cc=patches@linaro.org \ --cc=serge.hallyn@canonical.com \ --cc=swarren@nvidia.com \ --cc=viro@zeniv.linux.org.uk \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.