From patchwork Wed Dec 20 00:33:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Safonov X-Patchwork-Id: 181386 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:24d3:b0:fb:cd0c:d3e with SMTP id r19csp2330155dyi; Tue, 19 Dec 2023 16:38:09 -0800 (PST) X-Google-Smtp-Source: AGHT+IFo67OFMRyoqm6VM0vkGxDWoI/+HraZ6WHDcCGlfpb7C5NJsMifZDwgImAZOvHuCpPuvK/t X-Received: by 2002:a05:6e02:17cb:b0:35f:c0c2:4bc1 with SMTP id z11-20020a056e0217cb00b0035fc0c24bc1mr2043112ilu.10.1703032688861; Tue, 19 Dec 2023 16:38:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703032688; cv=none; d=google.com; s=arc-20160816; b=ZOC+tw5SPqdkLpJBJlp8mQkiLd8wxc3mp27nppnog8+xfPowtAjWuI2V6le3+7FapF 0KoMiOiOxP7hg5TewSuowQ7yzazn+Kh2ZegOCkXK3EC1bqBVSZRtVbGcfEq/mHFOg/v3 +vH63rb/nq21T3wDchZdrmYT8Xe2JJZ1Fe1A3E34WnrqklazPVanOVy7sZ3k2QpGwSqC DtVUweax9QNum3X7z8scd0ll3ix2GXG91JziYCoq5vcdfHL240/WJfYL6CbbAA912G3T HHqz3vMx4FvMFg78abF2c9C1WCqYdOYs14AYgSJChZwx+kvl5lj3j5U+zmHjfAliQ3Rm EvSw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=2ZU+vKUedcxvlMvLQvRGcy4W/7LE9vhnsOAwLDimoXo=; fh=CEpi/4QFng/WZb29MZIGPk7EQijn/PJi/csv2ZzgJ78=; b=tqV6UjRh7oOi2DGyoyhi5xhKsmpGtwjRAi+J4+tNpiRfj4W/Wm6/tG9YEQI8avVgKb 5jE2RJ6hSNwsnGFphUEz31Z0Dk9+mOpKj547cvFDjqsT070jlwh5ufI0fqSRNjVw9/AT yofVv1iOPrRCrj57nnZoo19CLZtlDoPnds6tErlk44bzoYiheBaF3YMyYN5xuOAKZwJh uQkaYErlwrpCYeo1TzxrmfBbWmRil+xALKjzprA2PnZB+yVusQnyjOBIsipiuJUt7p4w DxTt0hetmWLbJUx386O7np5jMWQ/cZNeJrVzmofnJSUiZFGUfb9/OwSZjJgTVJz3/4yx Ra3w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@arista.com header.s=google header.b="Fo/ku9Ia"; spf=pass (google.com: domain of linux-kernel+bounces-6188-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-6188-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=arista.com Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id b5-20020a63eb45000000b005b8ea4a4ab6si21020427pgk.623.2023.12.19.16.38.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Dec 2023 16:38:08 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-6188-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@arista.com header.s=google header.b="Fo/ku9Ia"; spf=pass (google.com: domain of linux-kernel+bounces-6188-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-6188-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=arista.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 25B10B24637 for ; Wed, 20 Dec 2023 00:36:53 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A7C9310A1E; Wed, 20 Dec 2023 00:33:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=arista.com header.i=@arista.com header.b="Fo/ku9Ia" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-wm1-f44.google.com (mail-wm1-f44.google.com [209.85.128.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6AAE8846B for ; Wed, 20 Dec 2023 00:33:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=arista.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arista.com Received: by mail-wm1-f44.google.com with SMTP id 5b1f17b1804b1-40d12ade25dso38257785e9.2 for ; Tue, 19 Dec 2023 16:33:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=arista.com; s=google; t=1703032405; x=1703637205; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=2ZU+vKUedcxvlMvLQvRGcy4W/7LE9vhnsOAwLDimoXo=; b=Fo/ku9Ia5s/JCrg4/dAYOai0d7SUqif2MoA7isXysdX+hIYHjGWfmMrcFLgW3XyLA+ pl1DRyvs3gOPqKFCU/7eeivWrFJN1ekfVL4G2MPZPJqY8zDdMV2dFpWvouAWtl64/3ZO sI0OwPnwjgr+Y3ZgzYl1Eg5p93V9VlrlL/LRf87sgmQ35M17r/xxdBiSA5oIKt1fJss3 hklc/FjkfH+FD7N+eFPEHof2Bu6C+7Dlkqh6psLU/v7sutydiKoIQ3VsFobzy0w8NrXw 3G4phh/3gyhJi1cWxdvzMD3LCshLsgz8sfPv6NTpfyYWckC6Z+lrPCF1qVtPV0yoFduJ 9k5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703032405; x=1703637205; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=2ZU+vKUedcxvlMvLQvRGcy4W/7LE9vhnsOAwLDimoXo=; b=YV5mc5iMvHNL56tL3Q2N5+8Nn48bCAzooAYpFiJ/1GsQdgn3dZ5s7Rx12jSWpzVbdd ScbKo4Ch7bZ0gMKu3zPofEw7RP8Ghp7f5hHxUGY/ksn4m3NiXW3XdY2gZHnW95EWyaJs 2CvHtI8g1TaSHw7QMmjhjsL8Q922s7I1jOSWevavRWdWerQ3agjzbernAQzQ3cb+9WMC fzRzdoVqFr5IjDthh4j9fssCTB4CRQHkvBgxNHYEUScreOg2Va64t1hk+yaO9r6wQsqS LQdI7rGAuSvT+bSKS+BZgMrU4rk8TmDp2TgEtoTh93uuHQWwg6sgZJ8t6PML3bly2Mvn P5JA== X-Gm-Message-State: AOJu0Yx3kNlaUlm4WDDSjpZZR436itkRnZ6gBno+WCZ29vy/A/bzujS6 4kFW4E4tU5MYYMapCZzU3HYCow== X-Received: by 2002:a05:600c:4591:b0:40c:6c80:efa4 with SMTP id r17-20020a05600c459100b0040c6c80efa4mr4027621wmo.35.1703032404687; Tue, 19 Dec 2023 16:33:24 -0800 (PST) Received: from Mindolluin.ire.aristanetworks.com ([217.173.96.166]) by smtp.gmail.com with ESMTPSA id w20-20020a05600c475400b0040b4fca8620sm5060620wmo.37.2023.12.19.16.33.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Dec 2023 16:33:23 -0800 (PST) From: Dmitry Safonov To: Masahiro Yamada , Nathan Chancellor , Nicolas Schier Cc: Dmitry Safonov , Baptiste Covolato , Benjamin Gray , Kevin Mitchell , linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, Dmitry Safonov <0x7f454c46@gmail.com> Subject: [PATCH] gen_init_cpio: Apply mtime supplied by user to all file types Date: Wed, 20 Dec 2023 00:33:15 +0000 Message-ID: <20231220-gen_init_cpio-reproducible-v1-1-d40da0b2c15c@arista.com> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Mailer: b4 0.13-dev-b6b4b X-Developer-Signature: v=1; a=ed25519-sha256; t=1703032397; l=4390; i=dima@arista.com; s=20231212; h=from:subject:message-id; bh=WO4So3owkEgbDEJz508Jr0jtYldh4JAlQaVVz0idt6E=; b=QJo6MWRgcyZxxGf7vSu4xmF/4R01Xhsvf4ITaDjWlDexwqI14kpOIsX+CmK5JjU98BeNpYumO u3dgh/Gn/1wC60sm+cS3RCbmhEKP9eeCdw+MnlQp/krlQMvz1UEvGG3 X-Developer-Key: i=dima@arista.com; a=ed25519; pk=hXINUhX25b0D/zWBKvd6zkvH7W2rcwh/CH6cjEa3OTk= X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785759205048631253 X-GMAIL-MSGID: 1785759205048631253 Currently gen_init_cpio -d is applied to symlinks, directories and special files. These files are created by gen_init_cpio from their description. Without option current time(NULL) is used. And regular files that go in initramfs are created before cpio generation, so their mtime(s) are preserved. This is usually not an issue as reproducible builds should rebuild everything in the distribution, including binaries, configs and whatever other regular files may find their way into kernel's initramfs. On the other hand, gen_initramfs.sh usage claims: > -d Use date for all file mtime values Ar Arista initramfs files are managed with version control system that preserves mtime. Those are configs, boot parameters, init scripts, version files, platform-specific files, probably some others, too. While it's certainly possible to work this around by copying the file into temp directory and adjusting mtime prior to gen_init_cpio call, I don't see why it needs workarounds. The intended user of -d option is the one that needs to create a reproducible build, see commit a8b8017c34fe ("initramfs: Use KBUILD_BUILD_TIMESTAMP for generated entries"). If a user wants the build reproduction, they use -d , which can be set on all types of files, without surprising exceptions and workarounds. Let's KISS here and just apply the time that user specified with -d option. Based-on-a-patch-by: Baptiste Covolato Link: https://lore.kernel.org/lkml/20181025215133.20138-1-baptiste@arista.com/ Signed-off-by: Dmitry Safonov --- usr/gen_init_cpio.c | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) --- base-commit: 55cb5f43689d7a9ea5bf35ef050f12334f197347 change-id: 20231219-gen_init_cpio-reproducible-99c707d8e66c Best regards, diff --git a/usr/gen_init_cpio.c b/usr/gen_init_cpio.c index 61230532fef1..edcdb8abfa31 100644 --- a/usr/gen_init_cpio.c +++ b/usr/gen_init_cpio.c @@ -27,6 +27,7 @@ static unsigned int offset; static unsigned int ino = 721; static time_t default_mtime; +static bool do_file_mtime; static bool do_csum = false; struct file_handler { @@ -329,6 +330,7 @@ static int cpio_mkfile(const char *name, const char *location, int file; int retval; int rc = -1; + time_t mtime; int namesize; unsigned int i; uint32_t csum = 0; @@ -347,16 +349,21 @@ static int cpio_mkfile(const char *name, const char *location, goto error; } - if (buf.st_mtime > 0xffffffff) { - fprintf(stderr, "%s: Timestamp exceeds maximum cpio timestamp, clipping.\n", - location); - buf.st_mtime = 0xffffffff; - } + if (do_file_mtime) { + mtime = default_mtime; + } else { + mtime = buf.st_mtime; + if (mtime > 0xffffffff) { + fprintf(stderr, "%s: Timestamp exceeds maximum cpio timestamp, clipping.\n", + location); + mtime = 0xffffffff; + } - if (buf.st_mtime < 0) { - fprintf(stderr, "%s: Timestamp negative, clipping.\n", - location); - buf.st_mtime = 0; + if (mtime < 0) { + fprintf(stderr, "%s: Timestamp negative, clipping.\n", + location); + mtime = 0; + } } if (buf.st_size > 0xffffffff) { @@ -387,7 +394,7 @@ static int cpio_mkfile(const char *name, const char *location, (long) uid, /* uid */ (long) gid, /* gid */ nlinks, /* nlink */ - (long) buf.st_mtime, /* mtime */ + (long) mtime, /* mtime */ size, /* filesize */ 3, /* major */ 1, /* minor */ @@ -536,8 +543,9 @@ static void usage(const char *prog) "file /sbin/kinit /usr/src/klibc/kinit/kinit 0755 0 0\n" "\n" " is time in seconds since Epoch that will be used\n" - "as mtime for symlinks, special files and directories. The default\n" - "is to use the current time for these entries.\n" + "as mtime for symlinks, directories, regular and special files.\n" + "The default is to use the current time for all files, but\n" + "preserve modification time for regular files.\n" "-c: calculate and store 32-bit checksums for file data.\n", prog); } @@ -594,6 +602,7 @@ int main (int argc, char *argv[]) usage(argv[0]); exit(1); } + do_file_mtime = true; break; case 'c': do_csum = true;