Received: by 10.223.185.116 with SMTP id b49csp1111989wrg; Fri, 16 Feb 2018 12:41:26 -0800 (PST) X-Google-Smtp-Source: AH8x225HoQTY86SH6coXAHre/GpbIc9D8Jw19NmQRWuCXfZthU1zresV8vXUC9Gms84k996SNAwT X-Received: by 2002:a17:902:1e5:: with SMTP id b92-v6mr6895911plb.383.1518813686829; Fri, 16 Feb 2018 12:41:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518813686; cv=none; d=google.com; s=arc-20160816; b=clSlhBPNnjs+k034rH356KLmvvgCrr75uPhriEpSOlCL9tf+hEYfQMnLQ/QOv6Deaw 55BsXuUYGKWkbO130bdA8d+GjhsQpVdZzkOV4PAv+LunNL2zeMJUQPuY835z/oExrQbE U12CrJMuyjOrmjIcCT5HrQICIyqjkJfT51+PT5Je1YklL5XaYL6c9GQxYob9ZC2dMl+r m1hV+Ih7ukcHO52nuDY8h6ytJfAcIfuecfRZilbUPQ4Nb/DOTuEHgrE7S/pIoQ1Bmm6k 2McLT1LTNlK5kAwp4onGIZl8bf9wCBQHi7eifjqRlWVYxp0QBfWt1cE6g8My42Pj9sgS A8Jw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=urSyVgp9/SjSIPBajuAG3e0dloW/Vk4CiNUVmyzMDFw=; b=S5X/WXiDUZ7HrdBwicncHq3Z6nXN6pciLNE/dreMGG/2Ymo0C/psHKG3Rf6RD3NAIc GMY3fHydn9rAmQ04zXUOvhrO0THR1p7CC3fk9Tq4c/myWudDSPwimapOI+bMfRAmxy5o Z5BCmpuPSoTJ1KgtIY5qM9Vk7KSaFE7ROTE4LSuD9L2Fiipr4SeFg8CBtTFwIQsVWiYi ZHqvNTy8SaoQPb1gsod7rN9m6tfR2ZklG9YTOkKddn5+x3A9+JXYkGQwPYNM0DcLnEjV g1BB44d1yUkz0TSHAclGjT5mLacSyretlGdc7oCPXWEK17LXKV+mBAZBYx/dnzOTEDEo +xvQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cisco.com header.s=iport header.b=BchP61rT; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=cisco.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o28si2313811pfa.209.2018.02.16.12.41.12; Fri, 16 Feb 2018 12:41:26 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@cisco.com header.s=iport header.b=BchP61rT; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=cisco.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751199AbeBPUi7 (ORCPT + 99 others); Fri, 16 Feb 2018 15:38:59 -0500 Received: from rcdn-iport-4.cisco.com ([173.37.86.75]:15587 "EHLO rcdn-iport-4.cisco.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750907AbeBPUeA (ORCPT ); Fri, 16 Feb 2018 15:34:00 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=cisco.com; i=@cisco.com; l=2499; q=dns/txt; s=iport; t=1518813240; x=1520022840; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=nvpl0b5eWYplhP1sX/h4M5FhyqcWUI82Pb+U0GTb0WU=; b=BchP61rTYB6VhmWCnCTwakG/h5Xx6+BtifmPo5d9xn4tzgrSGh+l1ebl wEC2Xd/dVPZIJaD9UqeuMdswzTQlTKIhmHol+T4sXZQP7/yqnsej7jClz eDTtzaoJTFxt3Q+tPlwL8MflfcQNSSIRKlxTe6ROmtCmfTC+V+kLllg+c 0=; X-IronPort-AV: E=Sophos;i="5.46,520,1511827200"; d="scan'208";a="356800564" Received: from rcdn-core-6.cisco.com ([173.37.93.157]) by rcdn-iport-4.cisco.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 16 Feb 2018 20:33:59 +0000 Received: from sjc-ads-7132.cisco.com (sjc-ads-7132.cisco.com [10.30.217.207]) (authenticated bits=0) by rcdn-core-6.cisco.com (8.14.5/8.14.5) with ESMTP id w1GKXsMT015412 (version=TLSv1/SSLv3 cipher=AES128-SHA256 bits=128 verify=NO); Fri, 16 Feb 2018 20:33:58 GMT From: Taras Kondratiuk To: "H. Peter Anvin" , Al Viro , Arnd Bergmann , Rob Landley , Mimi Zohar , Jonathan Corbet , James McMechan Cc: initramfs@vger.kernel.org, Victor Kamensky , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-security-module@vger.kernel.org, xe-linux-external@cisco.com Subject: [PATCH v3 04/15] initramfs: remove unnecessary symlinks processing shortcut Date: Fri, 16 Feb 2018 20:33:40 +0000 Message-Id: <1518813234-5874-5-git-send-email-takondra@cisco.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1518813234-5874-1-git-send-email-takondra@cisco.com> References: <1518813234-5874-1-git-send-email-takondra@cisco.com> X-Auto-Response-Suppress: DR, OOF, AutoReply X-Authenticated-User: takondra@cisco.com Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Special handling of symlinks in do_header() assumes that name and body entries are sequential and reads them together. This shortcut has no real performance benefits, but it complicates changes to the state machine. Make handling of symlinks more similar to a regular files. Store name in name_buf and destination in symlink_buf. Signed-off-by: Taras Kondratiuk --- init/initramfs.c | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/init/initramfs.c b/init/initramfs.c index b6ee675e5cdb..d0ab7ad6ac05 100644 --- a/init/initramfs.c +++ b/init/initramfs.c @@ -266,16 +266,7 @@ static int __init do_header(void) state = do_skip; if (name_len <= 0 || name_len > PATH_MAX) return 0; - if (S_ISLNK(mode)) { - if (body_len > PATH_MAX) - return 0; - collect = collected = symlink_buf; - remains = N_ALIGN(name_len) + body_len; - next_state = do_symlink; - state = do_collect; - return 0; - } - if (S_ISREG(mode) || !body_len) + if (S_ISREG(mode) || S_ISLNK(mode) || !body_len) read_into(name_buf, N_ALIGN(name_len), do_name); return 0; } @@ -372,6 +363,11 @@ static int __init do_name(void) sys_chmod(collected, mode); do_utime(collected, mtime); } + } else if (S_ISLNK(mode)) { + if (body_len > PATH_MAX) + return 0; + memcpy_optional(name_buf, collected, N_ALIGN(name_len)); + read_into(symlink_buf, body_len, do_symlink); } return 0; } @@ -397,11 +393,12 @@ static int __init do_copy(void) static int __init do_symlink(void) { - collected[N_ALIGN(name_len) + body_len] = '\0'; - clean_path(collected, 0); - sys_symlink(collected + N_ALIGN(name_len), collected); - sys_lchown(collected, uid, gid); - do_utime(collected, mtime); + memcpy_optional(symlink_buf, collected, body_len); + symlink_buf[body_len] = '\0'; + clean_path(name_buf, 0); + sys_symlink(symlink_buf, name_buf); + sys_lchown(name_buf, uid, gid); + do_utime(name_buf, mtime); state = do_skip; next_state = do_reset; return 0; @@ -453,7 +450,7 @@ static char * __init unpack_to_rootfs(char *buf, unsigned long len) static __initdata char msg_buf[64]; header_buf = kmalloc(110, GFP_KERNEL); - symlink_buf = kmalloc(PATH_MAX + N_ALIGN(PATH_MAX) + 1, GFP_KERNEL); + symlink_buf = kmalloc(PATH_MAX + 1, GFP_KERNEL); name_buf = kmalloc(N_ALIGN(PATH_MAX), GFP_KERNEL); if (!header_buf || !symlink_buf || !name_buf) -- 2.10.3.dirty