Received: by 10.223.176.46 with SMTP id f43csp1568792wra; Wed, 24 Jan 2018 19:38:13 -0800 (PST) X-Google-Smtp-Source: AH8x225DZAjoNAXqOQrmVLbjsS8mBELVT9lBQ1YDHcLE/yOTSdRyaTfgn7AJ/SNu6PASDHCcnv0g X-Received: by 2002:a17:902:6c44:: with SMTP id h4-v6mr10170018pln.373.1516851493572; Wed, 24 Jan 2018 19:38:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516851493; cv=none; d=google.com; s=arc-20160816; b=eRILluXZ5JH08ki/GDyxraZzuQMxhvOWHgIGpnYcKLT1jM3tsp03hJGx4tR+X2Ht3s WaJH41c3nsWiPUNH+VgoiV+M8eGf0CX86KMvvRm3lghPogyUW5PfDIH5iDX7ew5FrKxu k73MEZZt0qabOfnxottRjaGGvSSdBD3bnPv21iMX2y1o83olKqkF7QfTTXQAZAFHp/cu X3Aa4qHsc9++NOsokovefonWTCbGIuVoJ9H0Z80TWf9XO+tttMcIyZK6nq4wIvtqYE18 Bw5/qcTSXGL736d1HY0U0er2VL9bwwp4ORRjgFAkHgw2jv3JZ4XfyG9Lj888ABYPDa3O 2VLw== 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=dMQL0S2XyPSjUKdSm2uGihxhuuxGAmBWF1vptOqnYaF8CiD5wju6DvPlOtlrnXnRqW nSzkJrWy/pmEwqut8hHPMq/mpgds844UC9t+r8KHdJXeL2gn3Z/Kj2wcgAhCM8l3+DmP wyNbMQ+hJgszA9P/SAu4uYcPWoYeDFSovwnhWTi43yQkj04qgtsPQmWKY5qqrav8YYI+ S2KKyoGVpvMkfWFqjn2Apl5i/yMkrSr3JIWnhGyCA1sPLUV9JeJsLD/G16YwIUnoeobg dsCjxLkhjp1ciJxk+IWSs9SpgQVytOm9CscHwL34O5THR3iZa4A7LNLRMsiNWlBtpt0i An9A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cisco.com header.s=iport header.b=RPW6eYAz; 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 f9-v6si1208157plo.697.2018.01.24.19.37.59; Wed, 24 Jan 2018 19:38:13 -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=RPW6eYAz; 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 S933314AbeAYDhU (ORCPT + 99 others); Wed, 24 Jan 2018 22:37:20 -0500 Received: from alln-iport-7.cisco.com ([173.37.142.94]:42689 "EHLO alln-iport-7.cisco.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932998AbeAYDhS (ORCPT ); Wed, 24 Jan 2018 22:37:18 -0500 X-Greylist: delayed 560 seconds by postgrey-1.27 at vger.kernel.org; Wed, 24 Jan 2018 22:37:18 EST DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=cisco.com; i=@cisco.com; l=2499; q=dns/txt; s=iport; t=1516851438; x=1518061038; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=nvpl0b5eWYplhP1sX/h4M5FhyqcWUI82Pb+U0GTb0WU=; b=RPW6eYAzDGxV6JRtw20Z3xaO1K0FiskDNpqkRT2ERLeP6A/DXWMSFla8 tb06Vyy6ua14qyWv+EUEj1SYHi5Q2ajlL83Kdvyr+9XndKbWLY0uznnDT 2URt2j4fk2QMLJ1Jgr61Ca/PAm8uYpEoiBjM2NlgRgjuZ6L8vAJqavsKi s=; X-IronPort-AV: E=Sophos;i="5.46,409,1511827200"; d="scan'208";a="60756978" Received: from rcdn-core-6.cisco.com ([173.37.93.157]) by alln-iport-7.cisco.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 25 Jan 2018 03:28:00 +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 w0P3Ruit007601 (version=TLSv1/SSLv3 cipher=AES128-SHA256 bits=128 verify=NO); Thu, 25 Jan 2018 03:28:00 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 v2 04/15] initramfs: remove unnecessary symlinks processing shortcut Date: Thu, 25 Jan 2018 03:27:44 +0000 Message-Id: <1516850875-25066-5-git-send-email-takondra@cisco.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1516850875-25066-1-git-send-email-takondra@cisco.com> References: <1516850875-25066-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