From patchwork Fri Feb 16 20:33:39 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Taras Kondratiuk X-Patchwork-Id: 10225613 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 0775E60231 for ; Fri, 16 Feb 2018 20:34:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E190A29653 for ; Fri, 16 Feb 2018 20:34:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DFA3C29667; Fri, 16 Feb 2018 20:34:03 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-14.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_HI, USER_IN_DEF_DKIM_WL autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 533BA2965F for ; Fri, 16 Feb 2018 20:34:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750734AbeBPUeB (ORCPT ); Fri, 16 Feb 2018 15:34:01 -0500 Received: from rcdn-iport-5.cisco.com ([173.37.86.76]:37473 "EHLO rcdn-iport-5.cisco.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750783AbeBPUd7 (ORCPT ); Fri, 16 Feb 2018 15:33:59 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=cisco.com; i=@cisco.com; l=1686; q=dns/txt; s=iport; t=1518813239; x=1520022839; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=7ti1CmKalB2rOy6NHEJ+DZLJMKGu7wCBQHH/kiDtVEo=; b=kmG/0WdO4oZV60wz9NqXUEO2MfEC3TfHa1RjegV/Ek8OE+JfOVx1XnWU uXwEilHbrdhvMWadTcT02qesuLYZc6gpcWZnX4VHG9XuWImdXH5QSUCXl k07K/1VwFno75wuJ3Pm9MP6n7C7oXICM46RCAfgboHDKANXcQgvhMMMcC U=; X-IronPort-AV: E=Sophos;i="5.46,520,1511827200"; d="scan'208";a="139025483" Received: from rcdn-core-6.cisco.com ([173.37.93.157]) by rcdn-iport-5.cisco.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 16 Feb 2018 20:33:58 +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 w1GKXsMS015412 (version=TLSv1/SSLv3 cipher=AES128-SHA256 bits=128 verify=NO); Fri, 16 Feb 2018 20:33:57 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 03/15] initramfs: store file name in name_buf Date: Fri, 16 Feb 2018 20:33:39 +0000 Message-Id: <1518813234-5874-4-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: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: X-Virus-Scanned: ClamAV using ClamSMTP There is already name_buf buffer pre-allocated for a file name. No need to allocate vcollected for every file. More over a name can be already stored in name_buf by read_info() function. Add memcpy_optional() function to handle such case. Signed-off-by: Taras Kondratiuk --- init/initramfs.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/init/initramfs.c b/init/initramfs.c index 49cd2681a26f..b6ee675e5cdb 100644 --- a/init/initramfs.c +++ b/init/initramfs.c @@ -210,7 +210,6 @@ static inline void __init eat(unsigned n) byte_count -= n; } -static __initdata char *vcollected; static __initdata char *collected; static long remains __initdata; static __initdata char *collect; @@ -324,6 +323,13 @@ static void __init clean_path(char *path, umode_t fmode) } } +static void *memcpy_optional(void *dest, const void *src, size_t n) +{ + if (dest != src) + return memcpy(dest, src, n); + return dest; +} + static __initdata int wfd; static int __init do_name(void) @@ -348,7 +354,8 @@ static int __init do_name(void) sys_fchmod(wfd, mode); if (body_len) sys_ftruncate(wfd, body_len); - vcollected = kstrdup(collected, GFP_KERNEL); + memcpy_optional(name_buf, collected, + N_ALIGN(name_len)); state = do_copy; } } @@ -375,8 +382,7 @@ static int __init do_copy(void) if (xwrite(wfd, victim, body_len) != body_len) error("write error"); sys_close(wfd); - do_utime(vcollected, mtime); - kfree(vcollected); + do_utime(name_buf, mtime); eat(body_len); state = do_skip; return 0;