From patchwork Thu Oct 3 21:10:37 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Capella X-Patchwork-Id: 20818 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-qa0-f72.google.com (mail-qa0-f72.google.com [209.85.216.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 12956266EC for ; Thu, 3 Oct 2013 21:11:04 +0000 (UTC) Received: by mail-qa0-f72.google.com with SMTP id j7sf1040180qaq.3 for ; Thu, 03 Oct 2013 14:11:03 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=mime-version:x-gm-message-state:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=ViLID+0ihrFfmARKn269yKbeCtYx5gVsGgHQO2vcJuY=; b=Lv2NKf0chsqNXpAdLU9HCfIIuHPhtjW3LWGCBiUy1fvpx7ssC2F74fZYyuT26W0iBz E+sMQZhbPVae9qcQKyxA/rYeqGXZxlQsdB72AAUp9rq17G5DT/NErT6DRPsUZHzJMkNK ACcizQef6XDabROPv5eShq4hrqYCuG9HuJar1m3MifQLFKsn4OoxvFrRB81Ug/4fewm/ 4LABSB8094T3By+geea3MdGUFy1Tbm5/Y7MWKbBxgQ1rVnWeiLsjkF1XuU6Bk6qnKdGS ph2CHAfN4ejbUvhHmFkd35oHV89IVmNeNma1my2agAMN+ncO2GovNdsluthGJXvPyeFA wLDg== X-Received: by 10.236.186.101 with SMTP id v65mr10054078yhm.12.1380834663826; Thu, 03 Oct 2013 14:11:03 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.14.106 with SMTP id o10ls1087564qec.36.gmail; Thu, 03 Oct 2013 14:11:03 -0700 (PDT) X-Received: by 10.220.188.66 with SMTP id cz2mr20324vcb.33.1380834663674; Thu, 03 Oct 2013 14:11:03 -0700 (PDT) Received: from mail-vc0-f176.google.com (mail-vc0-f176.google.com [209.85.220.176]) by mx.google.com with ESMTPS id tj6si2166648vcb.118.1969.12.31.16.00.00 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 03 Oct 2013 14:11:03 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.220.176 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.220.176; Received: by mail-vc0-f176.google.com with SMTP id lf11so1328878vcb.35 for ; Thu, 03 Oct 2013 14:11:03 -0700 (PDT) X-Gm-Message-State: ALoCoQktRy7z3YVZH2zM9ZSN/DL0KjKnSIeKHGi5ULsBoXsjdzK5meWRL/3RvHxeLjqcNPpJUZnA X-Received: by 10.220.74.69 with SMTP id t5mr9236453vcj.18.1380834663561; Thu, 03 Oct 2013 14:11:03 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.220.174.196 with SMTP id u4csp210084vcz; Thu, 3 Oct 2013 14:11:02 -0700 (PDT) X-Received: by 10.68.130.34 with SMTP id ob2mr2645195pbb.155.1380834662561; Thu, 03 Oct 2013 14:11:02 -0700 (PDT) Received: from mail-pa0-f45.google.com (mail-pa0-f45.google.com [209.85.220.45]) by mx.google.com with ESMTPS id ye6si7583989pab.107.1969.12.31.16.00.00 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 03 Oct 2013 14:11:02 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.220.45 is neither permitted nor denied by best guess record for domain of sebastian.capella@linaro.org) client-ip=209.85.220.45; Received: by mail-pa0-f45.google.com with SMTP id rd3so3175679pab.32 for ; Thu, 03 Oct 2013 14:11:02 -0700 (PDT) X-Received: by 10.68.196.227 with SMTP id ip3mr2601934pbc.163.1380834662121; Thu, 03 Oct 2013 14:11:02 -0700 (PDT) Received: from localhost (rrcs-108-178-170-106.west.biz.rr.com. [108.178.170.106]) by mx.google.com with ESMTPSA id f2sm10206599pbg.44.1969.12.31.16.00.00 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Thu, 03 Oct 2013 14:11:01 -0700 (PDT) From: Sebastian Capella 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 , "Eric W. Biederman" , Serge Hallyn , Andrew Morton , Stephen Warren , Jens Axboe , Greg Kroah-Hartman , Al Viro 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 Message-Id: <1380834638-24035-2-git-send-email-sebastian.capella@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1380834638-24035-1-git-send-email-sebastian.capella@linaro.org> References: <1380834638-24035-1-git-send-email-sebastian.capella@linaro.org> X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: sebastian.capella@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.220.176 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , 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 Reviewed-by: Pavel Machek Cc: "Eric W. Biederman" Cc: Serge Hallyn Cc: Andrew Morton Cc: Stephen Warren Cc: Jens Axboe Cc: Greg Kroah-Hartman Cc: Al Viro --- 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 = '!';