From patchwork Tue Jun 6 13:31:58 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Engraf X-Patchwork-Id: 771873 X-Patchwork-Delegate: david.oberhollenzer@sigma-star.at Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3wht1804y7z9s7B for ; Tue, 6 Jun 2017 23:33:16 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="sgCDXECV"; dkim-atps=neutral DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=wYSVSS3/D6W2nVv0boV3sF37dVd2DuWH9UD1S7y3Ru8=; b=sgC DXECVgpFv0pIo0pF0kV8K1Mbwn70LRiPEhCtHaLSOEyvr2nC5KPTdtPzwFG2ptKNYLhecpzheyKlD ZOzQLnUUwdevt2MHVslU1oYK6rdmoS+Y7/KA7GUOIeizDsCK11XKtyz3hJQcU3yZKaAg2LnOYzsBC i6y4aOAImDj7hr9hfP8oIEBKcTy/qSxmhcMq7Znvv+t52buMzhte8Zy3hu+0nNFDlM5cyBjw/ee8Y Codq+tbPQ99lKccmIj42cpFy7vgp6GimWSPoUmlkGMoGaCdpdBVqeQyDP09SEqVwgkcPFYpa5amCq giVVZOgcHknITRm40mvGrVokeDF2CIA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1dIEbc-0006oy-As; Tue, 06 Jun 2017 13:33:08 +0000 Received: from mail.sysgo.com ([176.9.12.79]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dIEbD-0006mI-Sh for linux-mtd@lists.infradead.org; Tue, 06 Jun 2017 13:32:45 +0000 From: David Engraf To: linux-mtd@lists.infradead.org Subject: [PATCH] mkfs.ubifs: Allow root entry in device table Date: Tue, 6 Jun 2017 15:31:58 +0200 Message-Id: <20170606133158.6973-1-david.engraf@sysgo.com> X-Mailer: git-send-email 2.11.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170606_063244_095235_74ACDDC8 X-CRM114-Status: GOOD ( 13.53 ) X-Spam-Score: -1.9 (-) X-Spam-Report: SpamAssassin version 3.4.1 on bombadil.infradead.org summary: Content analysis details: (-1.9 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 T_RP_MATCHES_RCVD Envelope sender domain matches handover relay domain -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: David Engraf MIME-Version: 1.0 Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org When using a local root folder the permissions, user and group settings are taken from the local folder. These permissions might be incorrect if the folder has been created for the local user. Creating an UBIFS image on my local system resulted in the following output on the target: drwx------ 17 1000 1000 1264 Jan 1 00:00 . drwx------ 17 1000 1000 1264 Jan 1 00:00 .. drwxr-xr-x 2 root root 9104 May 30 2017 bin drwxr-xr-x 7 root root 2760 Jan 1 00:00 dev ... mkfs.ubifs aborts with an error message when the device table contains a root entry. This patch allows setting the root folder permissions, user and group to overwrite local configurations. Signed-off-by: David Engraf --- ubifs-utils/mkfs.ubifs/devtable.c | 8 ++++---- ubifs-utils/mkfs.ubifs/mkfs.ubifs.c | 13 +++++++++++++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/ubifs-utils/mkfs.ubifs/devtable.c b/ubifs-utils/mkfs.ubifs/devtable.c index 3b46abc..10faaca 100644 --- a/ubifs-utils/mkfs.ubifs/devtable.c +++ b/ubifs-utils/mkfs.ubifs/devtable.c @@ -146,16 +146,16 @@ static int interpret_table_entry(const char *line) increment, count); len = strnlen(buf, 1024); + if (len == 0) + return err_msg("empty path"); if (len == 1024) return err_msg("too long path"); - if (!strcmp(buf, "/")) + if (buf[0] != '/') return err_msg("device table entries require absolute paths"); - if (buf[1] == '\0') - return err_msg("root directory cannot be created"); if (strstr(buf, "//")) return err_msg("'//' cannot be used in the path"); - if (buf[len - 1] == '/') + if (len > 1 && buf[len - 1] == '/') return err_msg("do not put '/' at the end"); if (strstr(buf, "/./") || strstr(buf, "/../") || diff --git a/ubifs-utils/mkfs.ubifs/mkfs.ubifs.c b/ubifs-utils/mkfs.ubifs/mkfs.ubifs.c index a60052d..52ed511 100644 --- a/ubifs-utils/mkfs.ubifs/mkfs.ubifs.c +++ b/ubifs-utils/mkfs.ubifs/mkfs.ubifs.c @@ -1823,6 +1823,8 @@ static int write_data(void) { int err; mode_t mode = S_IFDIR | S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH; + struct path_htbl_element *ph_elt; + struct name_htbl_element *nh_elt; if (root) { err = stat(root, &root_st); @@ -1835,6 +1837,17 @@ static int write_data(void) root_st.st_mode = mode; } + /* + * Check for root entry and update permissions if it exists. This will + * also remove the entry from the device table list. + */ + ph_elt = devtbl_find_path("/"); + if (ph_elt) { + nh_elt = devtbl_find_name(ph_elt, ""); + if (nh_elt && override_attributes(&root_st, ph_elt, nh_elt)) + return -1; + } + head_flags = 0; err = create_inum_attr(UBIFS_ROOT_INO, root);