From patchwork Mon Nov 4 14:14:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Disseldorp X-Patchwork-Id: 13861464 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) (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 668A83398B for ; Mon, 4 Nov 2024 14:18:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730729890; cv=none; b=G8wJELkTFZz5HkOgwUIestnVUY8KvyysA4CEZs+yomHVfUdo9HGW+vZ1LtJ/9fqkYL4d7ylPwK31mIUC/XRHXXk6w3NAdzWy5mhA3TOBt41o7dCx6S5R+zWEy1/qhGUrzakw3/KvG0bby9Cdri3Jn/IYvA/zFBFzCN2eo2bfobE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730729890; c=relaxed/simple; bh=vaMZZsDlsC0OXX4/YW6sLIRZcTjRr82/f+FZADYuu2Q=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=m5DHzliG28ZAFmWhQDcqr9xhzvrNzbr6on/YQd4uYxgVgs281TRK+FZdQsKwYo9g4L1KVqKzPIwAiyr+dCBWRSuDfYDZsicJ9ftPSbDPk0xCFnhbdGnpwbYLTg+3Y6GWns3bvvxClPwv9woLzV1gAUg/2t+6K1CLr+psoSbz4J8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de; spf=pass smtp.mailfrom=suse.de; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=o6Sy484V; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=eNDWp5mW; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=o6Sy484V; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=eNDWp5mW; arc=none smtp.client-ip=195.135.223.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="o6Sy484V"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="eNDWp5mW"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="o6Sy484V"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="eNDWp5mW" Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 9717F1FF36; Mon, 4 Nov 2024 14:18:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1730729886; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=tR4Otz75vEf5Pg16S0hLDPNqprTjRsnE7GGU4lnD1HQ=; b=o6Sy484VvdDNsSBBYRBeWSCmKlaDOe/mTrbWosPKntRdBVBlHRncB84ac65bcU21qjqWdL gyOW8v2HsWu6oNz3Rpb1q9d3MRkBlPXKt1PxJ5R1+HkBUErsxH6TM/8OWZypceR6rfcJj/ l2kPjDH2GeTIMEXDA1n8X1YzvLjHqKg= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1730729886; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=tR4Otz75vEf5Pg16S0hLDPNqprTjRsnE7GGU4lnD1HQ=; b=eNDWp5mWQmV6vFD0Sr9oJ36gqhXsSR2wrcVxXQLDi5L6RuNwGP3dS2ABwHa3tX0PwQsgtT CtO0p5VgpRl6rgDw== Authentication-Results: smtp-out2.suse.de; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=o6Sy484V; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=eNDWp5mW DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1730729886; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=tR4Otz75vEf5Pg16S0hLDPNqprTjRsnE7GGU4lnD1HQ=; b=o6Sy484VvdDNsSBBYRBeWSCmKlaDOe/mTrbWosPKntRdBVBlHRncB84ac65bcU21qjqWdL gyOW8v2HsWu6oNz3Rpb1q9d3MRkBlPXKt1PxJ5R1+HkBUErsxH6TM/8OWZypceR6rfcJj/ l2kPjDH2GeTIMEXDA1n8X1YzvLjHqKg= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1730729886; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=tR4Otz75vEf5Pg16S0hLDPNqprTjRsnE7GGU4lnD1HQ=; b=eNDWp5mWQmV6vFD0Sr9oJ36gqhXsSR2wrcVxXQLDi5L6RuNwGP3dS2ABwHa3tX0PwQsgtT CtO0p5VgpRl6rgDw== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id C55BB13736; Mon, 4 Nov 2024 14:18:04 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id eKllHpzXKGfGfAAAD6G6ig (envelope-from ); Mon, 04 Nov 2024 14:18:04 +0000 From: David Disseldorp To: linux-fsdevel@vger.kernel.org Cc: Al Viro , Christian Brauner , David Disseldorp Subject: [PATCH v2 1/9] init: add initramfs_internal.h Date: Tue, 5 Nov 2024 01:14:40 +1100 Message-ID: <20241104141750.16119-2-ddiss@suse.de> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241104141750.16119-1-ddiss@suse.de> References: <20241104141750.16119-1-ddiss@suse.de> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Rspamd-Queue-Id: 9717F1FF36 X-Spam-Score: -3.01 X-Rspamd-Action: no action X-Spamd-Result: default: False [-3.01 / 50.00]; BAYES_HAM(-3.00)[100.00%]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_MISSING_CHARSET(0.50)[]; R_DKIM_ALLOW(-0.20)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; MX_GOOD(-0.01)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:dkim,suse.de:mid,suse.de:email,imap1.dmz-prg2.suse.org:rdns,imap1.dmz-prg2.suse.org:helo]; ASN(0.00)[asn:25478, ipnet:::/0, country:RU]; ARC_NA(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; MIME_TRACE(0.00)[0:+]; TO_MATCH_ENVRCPT_ALL(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; FUZZY_BLOCKED(0.00)[rspamd.com]; RCVD_COUNT_TWO(0.00)[2]; RCVD_TLS_ALL(0.00)[]; RCPT_COUNT_THREE(0.00)[4]; DKIM_TRACE(0.00)[suse.de:+] X-Rspamd-Server: rspamd1.dmz-prg2.suse.org X-Spam-Flag: NO X-Spam-Level: The new header only exports a single unpack function and a CPIO_HDRLEN constant for future test use. Signed-off-by: David Disseldorp --- init/initramfs.c | 16 +++++++++++++--- init/initramfs_internal.h | 8 ++++++++ 2 files changed, 21 insertions(+), 3 deletions(-) create mode 100644 init/initramfs_internal.h diff --git a/init/initramfs.c b/init/initramfs.c index b2f7583bb1f5c..002e83ae12ac7 100644 --- a/init/initramfs.c +++ b/init/initramfs.c @@ -20,6 +20,7 @@ #include #include "do_mounts.h" +#include "initramfs_internal.h" static __initdata bool csum_present; static __initdata u32 io_csum; @@ -256,7 +257,7 @@ static __initdata char *header_buf, *symlink_buf, *name_buf; static int __init do_start(void) { - read_into(header_buf, 110, GotHeader); + read_into(header_buf, CPIO_HDRLEN, GotHeader); return 0; } @@ -497,14 +498,23 @@ static unsigned long my_inptr __initdata; /* index of next byte to be processed #include -static char * __init unpack_to_rootfs(char *buf, unsigned long len) +/** + * unpack_to_rootfs - decompress and extract an initramfs archive + * @buf: input initramfs archive to extract + * @len: length of initramfs data to process + * + * Returns: NULL for success or an error message string + * + * This symbol shouldn't be used externally. It's available for unit tests. + */ +char * __init unpack_to_rootfs(char *buf, unsigned long len) { long written; decompress_fn decompress; const char *compress_name; static __initdata char msg_buf[64]; - header_buf = kmalloc(110, GFP_KERNEL); + header_buf = kmalloc(CPIO_HDRLEN, GFP_KERNEL); symlink_buf = kmalloc(PATH_MAX + N_ALIGN(PATH_MAX) + 1, GFP_KERNEL); name_buf = kmalloc(N_ALIGN(PATH_MAX), GFP_KERNEL); diff --git a/init/initramfs_internal.h b/init/initramfs_internal.h new file mode 100644 index 0000000000000..233dad16b0a00 --- /dev/null +++ b/init/initramfs_internal.h @@ -0,0 +1,8 @@ +// SPDX-License-Identifier: GPL-2.0 +#ifndef __INITRAMFS_INTERNAL_H__ +#define __INITRAMFS_INTERNAL_H__ + +char *unpack_to_rootfs(char *buf, unsigned long len); +#define CPIO_HDRLEN 110 + +#endif From patchwork Mon Nov 4 14:14:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Disseldorp X-Patchwork-Id: 13861465 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) (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 E6F67146A69 for ; Mon, 4 Nov 2024 14:18:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730729894; cv=none; b=Cb9CwH1YrsMxeGhKAHXTP5Y3HZqXR/vodIbTeavdSRjsn1wZtj2NAGVgzvkduq6KFUq1Y+OJSwkDD8bmaHNLggA0fP768eu9GP/t0G8Ga+oLmaQALzaVMP3hhSKjG97wjo0bnkendxMr3+YOEMjfcVwAp9WE2suwpH+IeTlzBME= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730729894; c=relaxed/simple; bh=lKQlXiydO0FLDHkQB1DCagrT+rmVw8YztNz+LzA4Dm0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NNmjCq3tVfr4kFZpJ2jXwWj8UsnPYbuQAkAQEeXfh472WWgG5jD+HHqh68SDIBVxGxVbrBBYdszB2ZuNs2tTB+vm6gfnuFwT/YoYRF+A6eGb5oHamOlT+XjKjIYLQbCDDQeFR6breMRTR8be6UlAlAct8eCzqldBAhGF1gau8cM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de; spf=pass smtp.mailfrom=suse.de; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=jn0cb5T9; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=ibpXTAEY; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=feZrq9w7; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=WORYPS3x; arc=none smtp.client-ip=195.135.223.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="jn0cb5T9"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="ibpXTAEY"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="feZrq9w7"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="WORYPS3x" Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 0214E1FF37; Mon, 4 Nov 2024 14:18:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1730729890; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=eSCi8/GW+GEkFb6RqicIMkk6MWZaHKPmhp39ORJxyS8=; b=jn0cb5T9cN8k6jbiFZGh4HVPxN3iH37dDQpjo4Y1F9d0NOGNt+W+xxVZJYJEWfSeuEIBCK CPDrL33qPMTTxhMiCgs/y9uQhMkd9f/TseonBePyLvKorYqtqAViCF35cE5HC08mt6wSJg pIQ624Him/RGdZ41E9yKNbAUl+Lokhk= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1730729890; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=eSCi8/GW+GEkFb6RqicIMkk6MWZaHKPmhp39ORJxyS8=; b=ibpXTAEYLddrgos7fK+BmRfw/hmFaIHd00cWomoWfWu3mqOHb9q/iiSOKP+6dejSr8i4gt 16TPJxDbca8uZsCQ== Authentication-Results: smtp-out2.suse.de; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=feZrq9w7; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=WORYPS3x DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1730729889; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=eSCi8/GW+GEkFb6RqicIMkk6MWZaHKPmhp39ORJxyS8=; b=feZrq9w7xJQAckNJUdhy40E2ZqB0nowxvAcDP2NwoC7NP6XSX/E8sIp5xBcJ+Y4OJ6n3vk +PjOAEAuJuU0vNsOhxGCEmZelvtdBdF2JX1PGVDCUoOwgtc0xgvP/ppV2cxqF62q/jpKFI 9+1rfX54tOjgKr049LBozE3+57AzB3Y= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1730729889; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=eSCi8/GW+GEkFb6RqicIMkk6MWZaHKPmhp39ORJxyS8=; b=WORYPS3x/rlM9CgD70m5oBz/w+2oe6za1wfScEfD5dMsJ2Cqax2kUSk2Q6i/ICkrjCq03i TZ85ursw7SC3S7Cg== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 3028E13736; Mon, 4 Nov 2024 14:18:06 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id aNidNZ7XKGfGfAAAD6G6ig (envelope-from ); Mon, 04 Nov 2024 14:18:06 +0000 From: David Disseldorp To: linux-fsdevel@vger.kernel.org Cc: Al Viro , Christian Brauner , David Disseldorp Subject: [PATCH v2 2/9] initramfs_test: kunit tests for initramfs unpacking Date: Tue, 5 Nov 2024 01:14:41 +1100 Message-ID: <20241104141750.16119-3-ddiss@suse.de> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241104141750.16119-1-ddiss@suse.de> References: <20241104141750.16119-1-ddiss@suse.de> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Rspamd-Queue-Id: 0214E1FF37 X-Spam-Level: X-Spamd-Result: default: False [-3.01 / 50.00]; BAYES_HAM(-3.00)[100.00%]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_MISSING_CHARSET(0.50)[]; R_DKIM_ALLOW(-0.20)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; MX_GOOD(-0.01)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_TRACE(0.00)[0:+]; ARC_NA(0.00)[]; TO_DN_SOME(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; RBL_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:104:10:150:64:97:from]; FUZZY_BLOCKED(0.00)[rspamd.com]; RCVD_TLS_ALL(0.00)[]; DKIM_TRACE(0.00)[suse.de:+]; RCVD_COUNT_TWO(0.00)[2]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; SPAMHAUS_XBL(0.00)[2a07:de40:b281:104:10:150:64:97:from]; RECEIVED_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:106:10:150:64:167:received]; ASN(0.00)[asn:25478, ipnet:::/0, country:RU]; RCVD_VIA_SMTP_AUTH(0.00)[]; RCPT_COUNT_THREE(0.00)[4]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:email,suse.de:dkim,suse.de:mid,imap1.dmz-prg2.suse.org:helo,imap1.dmz-prg2.suse.org:rdns] X-Rspamd-Server: rspamd2.dmz-prg2.suse.org X-Rspamd-Action: no action X-Spam-Score: -3.01 X-Spam-Flag: NO Provide some basic initramfs unpack sanity tests covering: - simple file / dir extraction - filename field overrun, as reported and fixed separately via https://lore.kernel.org/r/20241030035509.20194-2-ddiss@suse.de - "070702" cpio data checksums - hardlinks Signed-off-by: David Disseldorp --- init/.kunitconfig | 3 + init/Kconfig | 7 + init/Makefile | 1 + init/initramfs_test.c | 393 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 404 insertions(+) create mode 100644 init/.kunitconfig create mode 100644 init/initramfs_test.c diff --git a/init/.kunitconfig b/init/.kunitconfig new file mode 100644 index 0000000000000..acb906b1a5f98 --- /dev/null +++ b/init/.kunitconfig @@ -0,0 +1,3 @@ +CONFIG_KUNIT=y +CONFIG_BLK_DEV_INITRD=y +CONFIG_INITRAMFS_TEST=y diff --git a/init/Kconfig b/init/Kconfig index c521e1421ad4a..cf8327cdd6739 100644 --- a/init/Kconfig +++ b/init/Kconfig @@ -1431,6 +1431,13 @@ config INITRAMFS_PRESERVE_MTIME If unsure, say Y. +config INITRAMFS_TEST + bool "Test initramfs cpio archive extraction" if !KUNIT_ALL_TESTS + depends on BLK_DEV_INITRD && KUNIT=y + default KUNIT_ALL_TESTS + help + Build KUnit tests for initramfs. See Documentation/dev-tools/kunit + choice prompt "Compiler optimization level" default CC_OPTIMIZE_FOR_PERFORMANCE diff --git a/init/Makefile b/init/Makefile index 10b652d33e872..d6f75d8907e09 100644 --- a/init/Makefile +++ b/init/Makefile @@ -12,6 +12,7 @@ else obj-$(CONFIG_BLK_DEV_INITRD) += initramfs.o endif obj-$(CONFIG_GENERIC_CALIBRATE_DELAY) += calibrate.o +obj-$(CONFIG_INITRAMFS_TEST) += initramfs_test.o obj-y += init_task.o diff --git a/init/initramfs_test.c b/init/initramfs_test.c new file mode 100644 index 0000000000000..2f64e7bf0a1c2 --- /dev/null +++ b/init/initramfs_test.c @@ -0,0 +1,393 @@ +// SPDX-License-Identifier: GPL-2.0 +#include +#include +#include +#include +#include "initramfs_internal.h" + +struct initramfs_test_cpio { + char *magic; + unsigned int ino; + unsigned int mode; + unsigned int uid; + unsigned int gid; + unsigned int nlink; + unsigned int mtime; + unsigned int filesize; + unsigned int devmajor; + unsigned int devminor; + unsigned int rdevmajor; + unsigned int rdevminor; + unsigned int namesize; + unsigned int csum; + char *fname; + char *data; +}; + +static size_t fill_cpio(struct initramfs_test_cpio *cs, size_t csz, char *out) +{ + int i; + size_t off = 0; + + for (i = 0; i < csz; i++) { + char *pos = &out[off]; + struct initramfs_test_cpio *c = &cs[i]; + size_t thislen; + + /* +1 to account for nulterm */ + thislen = sprintf(pos, "%s" + "%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x" + "%s", + c->magic, c->ino, c->mode, c->uid, c->gid, c->nlink, + c->mtime, c->filesize, c->devmajor, c->devminor, + c->rdevmajor, c->rdevminor, c->namesize, c->csum, + c->fname) + 1; + pr_debug("packing (%zu): %.*s\n", thislen, (int)thislen, pos); + off += thislen; + while (off & 3) + out[off++] = '\0'; + + memcpy(&out[off], c->data, c->filesize); + off += c->filesize; + while (off & 3) + out[off++] = '\0'; + } + + return off; +} + +static void __init initramfs_test_extract(struct kunit *test) +{ + char *err, *cpio_srcbuf; + size_t len; + struct kstat st = {}; + struct initramfs_test_cpio c[] = { { + .magic = "070701", + .ino = 1, + .mode = S_IFREG | 0777, + .uid = 12, + .gid = 34, + .nlink = 1, + .mtime = 56, + .filesize = 0, + .devmajor = 0, + .devminor = 1, + .rdevmajor = 0, + .rdevminor = 0, + .namesize = sizeof("initramfs_test_extract"), + .csum = 0, + .fname = "initramfs_test_extract", + }, { + .magic = "070701", + .ino = 2, + .mode = S_IFDIR | 0777, + .nlink = 1, + .mtime = 57, + .devminor = 1, + .namesize = sizeof("initramfs_test_extract_dir"), + .fname = "initramfs_test_extract_dir", + }, { + .magic = "070701", + .namesize = sizeof("TRAILER!!!"), + .fname = "TRAILER!!!", + } }; + + /* +3 to cater for any 4-byte end-alignment */ + cpio_srcbuf = kzalloc(ARRAY_SIZE(c) * (CPIO_HDRLEN + PATH_MAX + 3), + GFP_KERNEL); + len = fill_cpio(c, ARRAY_SIZE(c), cpio_srcbuf); + + err = unpack_to_rootfs(cpio_srcbuf, len); + if (err) { + KUNIT_FAIL(test, "unpack failed %s", err); + goto out; + } + + KUNIT_EXPECT_EQ(test, init_stat(c[0].fname, &st, 0), 0); + KUNIT_EXPECT_TRUE(test, S_ISREG(st.mode)); + KUNIT_EXPECT_TRUE(test, uid_eq(st.uid, KUIDT_INIT(c[0].uid))); + KUNIT_EXPECT_TRUE(test, gid_eq(st.gid, KGIDT_INIT(c[0].gid))); + KUNIT_EXPECT_EQ(test, st.nlink, 1); + KUNIT_EXPECT_EQ(test, st.mtime.tv_sec, + IS_ENABLED(CONFIG_INITRAMFS_PRESERVE_MTIME) ? c[0].mtime : 0); + KUNIT_EXPECT_EQ(test, st.blocks, c[0].filesize); + + KUNIT_EXPECT_EQ(test, init_stat(c[1].fname, &st, 0), 0); + KUNIT_EXPECT_TRUE(test, S_ISDIR(st.mode)); + KUNIT_EXPECT_EQ(test, st.mtime.tv_sec, + IS_ENABLED(CONFIG_INITRAMFS_PRESERVE_MTIME) ? c[1].mtime : 0); + + KUNIT_EXPECT_EQ(test, init_unlink(c[0].fname), 0); + KUNIT_EXPECT_EQ(test, init_rmdir(c[1].fname), 0); +out: + kfree(cpio_srcbuf); +} + +/* + * Don't terminate filename. Previously, the cpio filename field was passed + * directly to filp_open(collected, O_CREAT|..) without nulterm checks. See + * https://lore.kernel.org/linux-fsdevel/20241030035509.20194-2-ddiss@suse.de + */ +static void __init initramfs_test_fname_overrun(struct kunit *test) +{ + char *err, *cpio_srcbuf; + size_t len, suffix_off; + struct initramfs_test_cpio c[] = { { + .magic = "070701", + .ino = 1, + .mode = S_IFREG | 0777, + .uid = 0, + .gid = 0, + .nlink = 1, + .mtime = 1, + .filesize = 0, + .devmajor = 0, + .devminor = 1, + .rdevmajor = 0, + .rdevminor = 0, + .namesize = sizeof("initramfs_test_fname_overrun"), + .csum = 0, + .fname = "initramfs_test_fname_overrun", + } }; + + /* + * poison cpio source buffer, so we can detect overrun. source + * buffer is used by read_into() when hdr or fname + * are already available (e.g. no compression). + */ + cpio_srcbuf = kmalloc(CPIO_HDRLEN + PATH_MAX + 3, GFP_KERNEL); + memset(cpio_srcbuf, 'B', CPIO_HDRLEN + PATH_MAX + 3); + /* limit overrun to avoid crashes / filp_open() ENAMETOOLONG */ + cpio_srcbuf[CPIO_HDRLEN + strlen(c[0].fname) + 20] = '\0'; + + len = fill_cpio(c, ARRAY_SIZE(c), cpio_srcbuf); + /* overwrite trailing fname terminator and padding */ + suffix_off = len - 1; + while (cpio_srcbuf[suffix_off] == '\0') { + cpio_srcbuf[suffix_off] = 'P'; + suffix_off--; + } + + err = unpack_to_rootfs(cpio_srcbuf, len); + KUNIT_EXPECT_NOT_NULL(test, err); + + kfree(cpio_srcbuf); +} + +static void __init initramfs_test_data(struct kunit *test) +{ + char *err, *cpio_srcbuf; + size_t len; + struct file *file; + struct initramfs_test_cpio c[] = { { + .magic = "070701", + .ino = 1, + .mode = S_IFREG | 0777, + .uid = 0, + .gid = 0, + .nlink = 1, + .mtime = 1, + .filesize = sizeof("ASDF") - 1, + .devmajor = 0, + .devminor = 1, + .rdevmajor = 0, + .rdevminor = 0, + .namesize = sizeof("initramfs_test_data"), + .csum = 0, + .fname = "initramfs_test_data", + .data = "ASDF", + } }; + + /* +6 for max name and data 4-byte padding */ + cpio_srcbuf = kmalloc(CPIO_HDRLEN + c[0].namesize + c[0].filesize + 6, + GFP_KERNEL); + + len = fill_cpio(c, ARRAY_SIZE(c), cpio_srcbuf); + + err = unpack_to_rootfs(cpio_srcbuf, len); + KUNIT_EXPECT_NULL(test, err); + + file = filp_open(c[0].fname, O_RDONLY, 0); + if (!file) { + KUNIT_FAIL(test, "open failed"); + goto out; + } + + /* read back file contents into @cpio_srcbuf and confirm match */ + len = kernel_read(file, cpio_srcbuf, c[0].filesize, NULL); + KUNIT_EXPECT_EQ(test, len, c[0].filesize); + KUNIT_EXPECT_MEMEQ(test, cpio_srcbuf, c[0].data, len); + + fput(file); + KUNIT_EXPECT_EQ(test, init_unlink(c[0].fname), 0); +out: + kfree(cpio_srcbuf); +} + +static void __init initramfs_test_csum(struct kunit *test) +{ + char *err, *cpio_srcbuf; + size_t len; + struct initramfs_test_cpio c[] = { { + /* 070702 magic indicates a valid csum is present */ + .magic = "070702", + .ino = 1, + .mode = S_IFREG | 0777, + .nlink = 1, + .filesize = sizeof("ASDF") - 1, + .devminor = 1, + .namesize = sizeof("initramfs_test_csum"), + .csum = 'A' + 'S' + 'D' + 'F', + .fname = "initramfs_test_csum", + .data = "ASDF", + }, { + /* mix csum entry above with no-csum entry below */ + .magic = "070701", + .ino = 2, + .mode = S_IFREG | 0777, + .nlink = 1, + .filesize = sizeof("ASDF") - 1, + .devminor = 1, + .namesize = sizeof("initramfs_test_csum_not_here"), + /* csum ignored */ + .csum = 5555, + .fname = "initramfs_test_csum_not_here", + .data = "ASDF", + } }; + + cpio_srcbuf = kmalloc(8192, GFP_KERNEL); + + len = fill_cpio(c, ARRAY_SIZE(c), cpio_srcbuf); + + err = unpack_to_rootfs(cpio_srcbuf, len); + KUNIT_EXPECT_NULL(test, err); + + KUNIT_EXPECT_EQ(test, init_unlink(c[0].fname), 0); + KUNIT_EXPECT_EQ(test, init_unlink(c[1].fname), 0); + + /* mess up the csum and confirm that unpack fails */ + c[0].csum--; + len = fill_cpio(c, ARRAY_SIZE(c), cpio_srcbuf); + + err = unpack_to_rootfs(cpio_srcbuf, len); + KUNIT_EXPECT_NOT_NULL(test, err); + + /* + * file (with content) is still retained in case of bad-csum abort. + * Perhaps we should change this. + */ + KUNIT_EXPECT_EQ(test, init_unlink(c[0].fname), 0); + KUNIT_EXPECT_EQ(test, init_unlink(c[1].fname), -ENOENT); + kfree(cpio_srcbuf); +} + +static void __init initramfs_test_hardlink(struct kunit *test) +{ + char *err, *cpio_srcbuf; + size_t len; + struct kstat st0, st1; + struct initramfs_test_cpio c[] = { { + .magic = "070701", + .ino = 1, + .mode = S_IFREG | 0777, + .nlink = 2, + .devminor = 1, + .namesize = sizeof("initramfs_test_hardlink"), + .fname = "initramfs_test_hardlink", + }, { + /* hardlink data is present in last archive entry */ + .magic = "070701", + .ino = 1, + .mode = S_IFREG | 0777, + .nlink = 2, + .filesize = sizeof("ASDF") - 1, + .devminor = 1, + .namesize = sizeof("initramfs_test_hardlink_link"), + .fname = "initramfs_test_hardlink_link", + .data = "ASDF", + }, { + /* hardlink hashtable leaks when the archive omits a trailer */ + .magic = "070701", + .namesize = sizeof("TRAILER!!!"), + .fname = "TRAILER!!!", + } }; + + cpio_srcbuf = kmalloc(8192, GFP_KERNEL); + + len = fill_cpio(c, ARRAY_SIZE(c), cpio_srcbuf); + + err = unpack_to_rootfs(cpio_srcbuf, len); + KUNIT_EXPECT_NULL(test, err); + + KUNIT_EXPECT_EQ(test, init_stat(c[0].fname, &st0, 0), 0); + KUNIT_EXPECT_EQ(test, init_stat(c[1].fname, &st1, 0), 0); + KUNIT_EXPECT_EQ(test, st0.ino, st1.ino); + KUNIT_EXPECT_EQ(test, st0.nlink, 2); + KUNIT_EXPECT_EQ(test, st1.nlink, 2); + + KUNIT_EXPECT_EQ(test, init_unlink(c[0].fname), 0); + KUNIT_EXPECT_EQ(test, init_unlink(c[1].fname), 0); + + kfree(cpio_srcbuf); +} + +#define INITRAMFS_TEST_MANY_LIMIT 1000 +#define INITRAMFS_TEST_MANY_PATH_MAX (sizeof("initramfs_test_many-") \ + + sizeof(__stringify(INITRAMFS_TEST_MANY_LIMIT))) +static void __init initramfs_test_many(struct kunit *test) +{ + char *err, *cpio_srcbuf, *p; + size_t len = INITRAMFS_TEST_MANY_LIMIT * + (CPIO_HDRLEN + INITRAMFS_TEST_MANY_PATH_MAX + 3); + char thispath[INITRAMFS_TEST_MANY_PATH_MAX]; + int i; + + p = cpio_srcbuf = kmalloc(len, GFP_KERNEL); + + for (i = 0; i < INITRAMFS_TEST_MANY_LIMIT; i++) { + struct initramfs_test_cpio c = { + .magic = "070701", + .ino = i, + .mode = S_IFREG | 0777, + .nlink = 1, + .devminor = 1, + .fname = thispath, + }; + + c.namesize = 1 + sprintf(thispath, "initramfs_test_many-%d", i); + p += fill_cpio(&c, 1, p); + } + + len = p - cpio_srcbuf; + err = unpack_to_rootfs(cpio_srcbuf, len); + KUNIT_EXPECT_NULL(test, err); + + for (i = 0; i < INITRAMFS_TEST_MANY_LIMIT; i++) { + sprintf(thispath, "initramfs_test_many-%d", i); + KUNIT_EXPECT_EQ(test, init_unlink(thispath), 0); + } + + kfree(cpio_srcbuf); +} + +/* + * The kunit_case/_suite struct cannot be marked as __initdata as this will be + * used in debugfs to retrieve results after test has run. + */ +static struct kunit_case initramfs_test_cases[] = { + KUNIT_CASE(initramfs_test_extract), + KUNIT_CASE(initramfs_test_fname_overrun), + KUNIT_CASE(initramfs_test_data), + KUNIT_CASE(initramfs_test_csum), + KUNIT_CASE(initramfs_test_hardlink), + KUNIT_CASE(initramfs_test_many), + {}, +}; + +static struct kunit_suite initramfs_test_suite = { + .name = "initramfs", + .test_cases = initramfs_test_cases, +}; +kunit_test_init_section_suites(&initramfs_test_suite); + +MODULE_LICENSE("GPL"); From patchwork Mon Nov 4 14:14:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Disseldorp X-Patchwork-Id: 13861467 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) (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 81F264502B for ; Mon, 4 Nov 2024 14:18:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.130 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730729897; cv=none; b=k57FqQjz635ARy8teNp+ZyWtkKSEW6B79H9C0LuHHHxZLAD9yKNXowfGhFsHSnOdqlUGhslopGN3pQ2RoKNPU1Y7NzJgTtvSCqfnMSSxMOKHUgFxfKFKLq7Wd7mz1opsgsxL0G5yt0scD38d+zGBEhCkekyf33K3QQ1upmXWyzQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730729897; c=relaxed/simple; bh=kin+740lwCcp0CyjC81Xi4YNGVv3eLKrz5FJ9ljjtow=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Bp6/p5aVL87cJwOF8w4C7A7O6NHmNe03RtADJPoFgUF1MX7vOVHUiYmLTww+OPC1z2Yd2F9fM/qV2nIIu3Nk1J7X25QYKBUb6fpiET46SyjDmngKjFJmDUr0qzggho1CQlH1K60FEDukowOmO1MsjFSwRBFIPru5yLdZlUTU+AY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de; spf=pass smtp.mailfrom=suse.de; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=1ZqL7pYa; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=AR3zQnAv; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=1ZqL7pYa; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=AR3zQnAv; arc=none smtp.client-ip=195.135.223.130 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="1ZqL7pYa"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="AR3zQnAv"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="1ZqL7pYa"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="AR3zQnAv" Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 6127721B76; Mon, 4 Nov 2024 14:18:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1730729891; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=uEG6935H9x4NKordwMC2IWMDILAy9SobUxfDfYQ3qnE=; b=1ZqL7pYaizAvgoVBXkS9W4fT1vHz43/kt83lDh6ocgCsXT8XgK8oFQrYzw2zfZNKz3HcEm y/LswvmaiYNw3ZloaxHPaktrvjD+0C267IZO4/pFhyG9R5gptJlc6a3rcRS0dCv5rmNLM+ 9vkVqqey5mAAro6sAPTsejiIKsWZ/dY= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1730729891; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=uEG6935H9x4NKordwMC2IWMDILAy9SobUxfDfYQ3qnE=; b=AR3zQnAvuh8kvHa5HCgvdPwik71DQuRx7V1uhRf9tsbD3xCQsf/v3G3KyIFG0sFngvux/W dB3BkPy6IlvhHuCw== Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1730729891; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=uEG6935H9x4NKordwMC2IWMDILAy9SobUxfDfYQ3qnE=; b=1ZqL7pYaizAvgoVBXkS9W4fT1vHz43/kt83lDh6ocgCsXT8XgK8oFQrYzw2zfZNKz3HcEm y/LswvmaiYNw3ZloaxHPaktrvjD+0C267IZO4/pFhyG9R5gptJlc6a3rcRS0dCv5rmNLM+ 9vkVqqey5mAAro6sAPTsejiIKsWZ/dY= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1730729891; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=uEG6935H9x4NKordwMC2IWMDILAy9SobUxfDfYQ3qnE=; b=AR3zQnAvuh8kvHa5HCgvdPwik71DQuRx7V1uhRf9tsbD3xCQsf/v3G3KyIFG0sFngvux/W dB3BkPy6IlvhHuCw== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 8ED961373E; Mon, 4 Nov 2024 14:18:09 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id aIkgEaHXKGfGfAAAD6G6ig (envelope-from ); Mon, 04 Nov 2024 14:18:09 +0000 From: David Disseldorp To: linux-fsdevel@vger.kernel.org Cc: Al Viro , Christian Brauner , David Disseldorp Subject: [PATCH v2 3/9] vsprintf: add simple_strntoul Date: Tue, 5 Nov 2024 01:14:42 +1100 Message-ID: <20241104141750.16119-4-ddiss@suse.de> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241104141750.16119-1-ddiss@suse.de> References: <20241104141750.16119-1-ddiss@suse.de> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Score: -2.80 X-Spamd-Result: default: False [-2.80 / 50.00]; BAYES_HAM(-3.00)[100.00%]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_MISSING_CHARSET(0.50)[]; NEURAL_HAM_SHORT(-0.20)[-0.998]; MIME_GOOD(-0.10)[text/plain]; MIME_TRACE(0.00)[0:+]; TO_DN_SOME(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; ARC_NA(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_THREE(0.00)[4]; RCVD_COUNT_TWO(0.00)[2]; TO_MATCH_ENVRCPT_ALL(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:mid,suse.de:email,imap1.dmz-prg2.suse.org:helo]; RCVD_TLS_ALL(0.00)[] X-Spam-Flag: NO X-Spam-Level: cpio extraction currently does a memcpy to ensure that the archive hex fields are null terminated for simple_strtoul(). simple_strntoul() will allow us to avoid the memcpy. Signed-off-by: David Disseldorp --- include/linux/kstrtox.h | 1 + lib/vsprintf.c | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/include/linux/kstrtox.h b/include/linux/kstrtox.h index 7fcf29a4e0de4..6ea897222af1d 100644 --- a/include/linux/kstrtox.h +++ b/include/linux/kstrtox.h @@ -143,6 +143,7 @@ static inline int __must_check kstrtos32_from_user(const char __user *s, size_t */ extern unsigned long simple_strtoul(const char *,char **,unsigned int); +extern unsigned long simple_strntoul(const char *,char **,unsigned int,size_t); extern long simple_strtol(const char *,char **,unsigned int); extern unsigned long long simple_strtoull(const char *,char **,unsigned int); extern long long simple_strtoll(const char *,char **,unsigned int); diff --git a/lib/vsprintf.c b/lib/vsprintf.c index c5e2ec9303c5d..32eacaae97990 100644 --- a/lib/vsprintf.c +++ b/lib/vsprintf.c @@ -114,6 +114,13 @@ unsigned long simple_strtoul(const char *cp, char **endp, unsigned int base) } EXPORT_SYMBOL(simple_strtoul); +unsigned long simple_strntoul(const char *cp, char **endp, unsigned int base, + size_t max_chars) +{ + return simple_strntoull(cp, endp, base, max_chars); +} +EXPORT_SYMBOL(simple_strntoul); + /** * simple_strtol - convert a string to a signed long * @cp: The start of the string From patchwork Mon Nov 4 14:14:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Disseldorp X-Patchwork-Id: 13861466 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) (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 81F7E1B0F13 for ; Mon, 4 Nov 2024 14:18:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.130 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730729897; cv=none; b=ph+ScPcQpMUAwXEJ5dEuHFPI0g28R1SXBAJFozN38klvbFDSYboPNi0hGggjYbJV3vzQ+ufeoHomZu8IPHNHdOQRZV0SNZ8C3nMLTG/YS3u81BYrGzCLkT5HebWrRe1uqBXfZ3alF40SjcuXelPDtzTU78dzTnQGbznwiIsmdQ8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730729897; c=relaxed/simple; bh=IB8jHhAB3o1fuo+OyxgWuE+tj+u7wr+4MpHd1P5eJr8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tbJUlKM96d7I0cFV2MMpinbTS+hHHb6jAo37O0qmHq9fr76LnRbb5+DANmg7ogWYOiVCSL5DDfnTSfK0jsu2slmXx+p8lTJuXbUW3pbhnxIseoRr9sKG4dYqmTZYqt4oEJHHMqtaakQ5aeWt9J27nwoYlB5wn7607IJ6ZlpWGeA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de; spf=pass smtp.mailfrom=suse.de; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=KKoI4DvO; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=Lu2jguoE; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=KKoI4DvO; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=Lu2jguoE; arc=none smtp.client-ip=195.135.223.130 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="KKoI4DvO"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="Lu2jguoE"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="KKoI4DvO"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="Lu2jguoE" Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id BE89921B79; Mon, 4 Nov 2024 14:18:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1730729893; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=oJruo/PUqbsUiEslLAkM0UfjgrJI2RP7fQOA1xVkfsI=; b=KKoI4DvOqBjAy2daYA5fPNiP7TOmY4yABEEfJTwtxhTQNUAjRtEQENjVV6JElLNki2HDqi vcygeOFy17WODWjeLZP6427RP6A3X/hi3Hahs0d1A7D0X2kNPvlknJfEJzmUaYHFZCGY++ rrs0G93wr3U+UHYURGUW4mJBYzGuPcc= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1730729893; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=oJruo/PUqbsUiEslLAkM0UfjgrJI2RP7fQOA1xVkfsI=; b=Lu2jguoEHdHLiRZu+AjyNvcKeJZ30xYECsCvtrvZ50+NhNd3wKI8B4NTH6Es0C12LA23WV PBe7aTPql7AA1sBw== Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1730729893; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=oJruo/PUqbsUiEslLAkM0UfjgrJI2RP7fQOA1xVkfsI=; b=KKoI4DvOqBjAy2daYA5fPNiP7TOmY4yABEEfJTwtxhTQNUAjRtEQENjVV6JElLNki2HDqi vcygeOFy17WODWjeLZP6427RP6A3X/hi3Hahs0d1A7D0X2kNPvlknJfEJzmUaYHFZCGY++ rrs0G93wr3U+UHYURGUW4mJBYzGuPcc= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1730729893; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=oJruo/PUqbsUiEslLAkM0UfjgrJI2RP7fQOA1xVkfsI=; b=Lu2jguoEHdHLiRZu+AjyNvcKeJZ30xYECsCvtrvZ50+NhNd3wKI8B4NTH6Es0C12LA23WV PBe7aTPql7AA1sBw== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id EDEFC13736; Mon, 4 Nov 2024 14:18:11 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id 4JxLKKPXKGfGfAAAD6G6ig (envelope-from ); Mon, 04 Nov 2024 14:18:11 +0000 From: David Disseldorp To: linux-fsdevel@vger.kernel.org Cc: Al Viro , Christian Brauner , David Disseldorp Subject: [PATCH v2 4/9] initramfs: avoid memcpy for hex header fields Date: Tue, 5 Nov 2024 01:14:43 +1100 Message-ID: <20241104141750.16119-5-ddiss@suse.de> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241104141750.16119-1-ddiss@suse.de> References: <20241104141750.16119-1-ddiss@suse.de> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Score: -2.80 X-Spamd-Result: default: False [-2.80 / 50.00]; BAYES_HAM(-3.00)[99.99%]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_MISSING_CHARSET(0.50)[]; NEURAL_HAM_SHORT(-0.20)[-0.998]; MIME_GOOD(-0.10)[text/plain]; FUZZY_BLOCKED(0.00)[rspamd.com]; MIME_TRACE(0.00)[0:+]; TO_MATCH_ENVRCPT_ALL(0.00)[]; ARC_NA(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; RCVD_TLS_ALL(0.00)[]; RCPT_COUNT_THREE(0.00)[4]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; DBL_BLOCKED_OPENRESOLVER(0.00)[imap1.dmz-prg2.suse.org:helo,suse.de:mid,suse.de:email] X-Spam-Flag: NO X-Spam-Level: newc/crc cpio headers contain a bunch of 8-character hexadecimal fields which we convert via simple_strtoul(), following memcpy() into a zero-terminated stack buffer. The new simple_strntoul() helper allows us to pass in max_chars=8 to avoid zero-termination and memcpy(). Signed-off-by: David Disseldorp --- init/initramfs.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/init/initramfs.c b/init/initramfs.c index 002e83ae12ac7..6dd3b02c15d7e 100644 --- a/init/initramfs.c +++ b/init/initramfs.c @@ -189,14 +189,11 @@ static __initdata u32 hdr_csum; static void __init parse_header(char *s) { unsigned long parsed[13]; - char buf[9]; int i; - buf[8] = '\0'; - for (i = 0, s += 6; i < 13; i++, s += 8) { - memcpy(buf, s, 8); - parsed[i] = simple_strtoul(buf, NULL, 16); - } + for (i = 0, s += 6; i < 13; i++, s += 8) + parsed[i] = simple_strntoul(s, NULL, 16, 8); + ino = parsed[0]; mode = parsed[1]; uid = parsed[2]; From patchwork Mon Nov 4 14:14:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Disseldorp X-Patchwork-Id: 13861468 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) (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 C66E91B3939 for ; Mon, 4 Nov 2024 14:18:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.130 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730729899; cv=none; b=pxUZvtu+OuDA2AoK9XfLOR+4ipvg35OiAaNOvUkoDBVzv8PO3Yuoype1qc8JCB4DHUhszZiMEZuyXRlH/RylFQbFJUyDC8QEYwkuXli11kr0/6ximFfR6zdkIpg3omFwl4vd5pzIrLaZDqPYIBqp1aiejMAQvnMiwYNAuxmRi7g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730729899; c=relaxed/simple; bh=m5hJjlSJ1opmfVlIWfPqkvhhmAI65ZdzM180nHf+/VY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kpaEZuBAvR1q36jUobsjDyUYWQVc1X4wRN2B7y93PhyElHu5UkQjIRXO4hP+JqJHMXqB20qmvlSSrOssDaCOX311AZYBU4orjD3OO/yS9qAMTlo68Ehblliq485K887hM8b1SZk/MetV0y1oU+rVvXm4AHBmcphNi5XqzlylGa8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de; spf=pass smtp.mailfrom=suse.de; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=gqSYG7jZ; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=yc+VLUD5; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=gqSYG7jZ; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=yc+VLUD5; arc=none smtp.client-ip=195.135.223.130 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="gqSYG7jZ"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="yc+VLUD5"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="gqSYG7jZ"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="yc+VLUD5" Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 2962A21F03; Mon, 4 Nov 2024 14:18:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1730729896; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=PZr/lXIGLYGUZg9KDqFPOpqG1qTICHUflUpZQFG9iGg=; b=gqSYG7jZtOo/z5+DJpt4zt13kUv0a1PqplYvgRgURQ5No2uuiuthYTk/OPNLHDWve4TqiV SD2wPFe3cJfo5yzm25rV24+hqoVi/3/bd6vPknIid4RmWRhv2YN025CCASsr7YXR3GHFWU jHHeOY0LbHydU+W/Y4bK6XRnkbzPUVk= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1730729896; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=PZr/lXIGLYGUZg9KDqFPOpqG1qTICHUflUpZQFG9iGg=; b=yc+VLUD5oh2TnX9JqJ3Pjtte4GOW2SdwkTllEOpfZ4MI57SV8H7xagDArfvPhKS3g5FAW9 KFz76DMcKukaAnDg== Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1730729896; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=PZr/lXIGLYGUZg9KDqFPOpqG1qTICHUflUpZQFG9iGg=; b=gqSYG7jZtOo/z5+DJpt4zt13kUv0a1PqplYvgRgURQ5No2uuiuthYTk/OPNLHDWve4TqiV SD2wPFe3cJfo5yzm25rV24+hqoVi/3/bd6vPknIid4RmWRhv2YN025CCASsr7YXR3GHFWU jHHeOY0LbHydU+W/Y4bK6XRnkbzPUVk= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1730729896; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=PZr/lXIGLYGUZg9KDqFPOpqG1qTICHUflUpZQFG9iGg=; b=yc+VLUD5oh2TnX9JqJ3Pjtte4GOW2SdwkTllEOpfZ4MI57SV8H7xagDArfvPhKS3g5FAW9 KFz76DMcKukaAnDg== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 57CC813736; Mon, 4 Nov 2024 14:18:14 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id oKC7A6bXKGfGfAAAD6G6ig (envelope-from ); Mon, 04 Nov 2024 14:18:14 +0000 From: David Disseldorp To: linux-fsdevel@vger.kernel.org Cc: Al Viro , Christian Brauner , David Disseldorp Subject: [PATCH v2 5/9] initramfs: remove extra symlink path buffer Date: Tue, 5 Nov 2024 01:14:44 +1100 Message-ID: <20241104141750.16119-6-ddiss@suse.de> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241104141750.16119-1-ddiss@suse.de> References: <20241104141750.16119-1-ddiss@suse.de> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Level: X-Spamd-Result: default: False [-2.80 / 50.00]; BAYES_HAM(-3.00)[100.00%]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_MISSING_CHARSET(0.50)[]; NEURAL_HAM_SHORT(-0.20)[-0.998]; MIME_GOOD(-0.10)[text/plain]; MIME_TRACE(0.00)[0:+]; TO_DN_SOME(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; ARC_NA(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_THREE(0.00)[4]; RCVD_COUNT_TWO(0.00)[2]; TO_MATCH_ENVRCPT_ALL(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[imap1.dmz-prg2.suse.org:helo,suse.de:email,suse.de:mid]; RCVD_TLS_ALL(0.00)[] X-Spam-Score: -2.80 X-Spam-Flag: NO A (newc/crc) cpio entry with mode.S_IFLNK set carries the symlink target in the cpio data segment, following the padded name_len sized file path. symlink_buf is heap-allocated for staging both file path and symlink target, while name_buf is additionally allocated for staging paths for non-symlink cpio entries. Separate symlink / non-symlink buffers are unnecessary, so just extend the size of name_buf and use it for both. Signed-off-by: David Disseldorp --- init/initramfs.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/init/initramfs.c b/init/initramfs.c index 6dd3b02c15d7e..59b4a43fa491b 100644 --- a/init/initramfs.c +++ b/init/initramfs.c @@ -250,7 +250,7 @@ static void __init read_into(char *buf, unsigned size, enum state next) } } -static __initdata char *header_buf, *symlink_buf, *name_buf; +static __initdata char *header_buf, *name_buf; static int __init do_start(void) { @@ -294,7 +294,7 @@ static int __init do_header(void) if (S_ISLNK(mode)) { if (body_len > PATH_MAX) return 0; - collect = collected = symlink_buf; + collect = collected = name_buf; remains = N_ALIGN(name_len) + body_len; next_state = GotSymlink; state = Collect; @@ -512,10 +512,9 @@ char * __init unpack_to_rootfs(char *buf, unsigned long len) static __initdata char msg_buf[64]; header_buf = kmalloc(CPIO_HDRLEN, GFP_KERNEL); - symlink_buf = kmalloc(PATH_MAX + N_ALIGN(PATH_MAX) + 1, GFP_KERNEL); - name_buf = kmalloc(N_ALIGN(PATH_MAX), GFP_KERNEL); - - if (!header_buf || !symlink_buf || !name_buf) + /* 2x PATH_MAX as @name_buf is also used for staging symlink targets */ + name_buf = kmalloc(N_ALIGN(PATH_MAX) + PATH_MAX + 1, GFP_KERNEL); + if (!header_buf || !name_buf) panic_show_mem("can't allocate buffers"); state = Start; @@ -561,7 +560,6 @@ char * __init unpack_to_rootfs(char *buf, unsigned long len) } dir_utime(); kfree(name_buf); - kfree(symlink_buf); kfree(header_buf); return message; } From patchwork Mon Nov 4 14:14:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Disseldorp X-Patchwork-Id: 13861469 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) (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 3BE5B1B532F for ; Mon, 4 Nov 2024 14:18:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730729901; cv=none; b=iR66MY8Jn/0HI2aAGLUNc0Cz1KHqyA0vBTLwqrZEddyGpzfCmzb5voWmMWKyEnK2zJAxOKCGSf6G3a9GtJeRaZYIRsKG4Vhy/CK1n2F5ES5R3zfBR61sCndAAeuZ/MFDahNorgiUEP3sVEqbr1so4Ahc1+6HVnORkBX12h2bN70= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730729901; c=relaxed/simple; bh=r4sq3LI7v7kwFFXYAxXz5vmFrRMftt3nBQybD1gjXjE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=s94mqTZrecI+nzaJ0a3r89GWQ+QJZ/mcbau95TZTY+7zxucD73dQahGB49jwGPCWFMy2a2kQ98TUNWGUnhn8Zldnzwo2wTKrAD9M7CKiQ37Clq1384DP21z9p2waqpy/5EcJkz1d053t8Lio98CKXS8W+srzUYZjmmc2Go8jHDM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de; spf=pass smtp.mailfrom=suse.de; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=2B+djzp+; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=nLB7X39W; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=2B+djzp+; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=nLB7X39W; arc=none smtp.client-ip=195.135.223.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="2B+djzp+"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="nLB7X39W"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="2B+djzp+"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="nLB7X39W" Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 8776A1F7DD; Mon, 4 Nov 2024 14:18:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1730729898; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=funV3ntCCjs65WT4XelhOUCAGazAb0yRa0Q2DOqjLZQ=; b=2B+djzp+mA/6IK3SV3n/Pd/WGyiL3proTYOmwf/JWsD3CVvLkQT0jQ78rSgSAJnt+nhBXE xP8bNgym3RP0op53Agqe2mfX3qRuDOtXthX2ZM7CxGQ7jswNLpuXcoUknW2Hb4NjnKpeLL PIOnO7zJfgh0qTKQx1wsCy+S4rbwoq0= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1730729898; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=funV3ntCCjs65WT4XelhOUCAGazAb0yRa0Q2DOqjLZQ=; b=nLB7X39WIHAE83WNmVNkS02SEHgXDN1DRub2cj0dwhD/b778zqc7rb33LoJDwcAOH9t/rv 8CMeR1ApprXtuVBA== Authentication-Results: smtp-out2.suse.de; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=2B+djzp+; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=nLB7X39W DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1730729898; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=funV3ntCCjs65WT4XelhOUCAGazAb0yRa0Q2DOqjLZQ=; b=2B+djzp+mA/6IK3SV3n/Pd/WGyiL3proTYOmwf/JWsD3CVvLkQT0jQ78rSgSAJnt+nhBXE xP8bNgym3RP0op53Agqe2mfX3qRuDOtXthX2ZM7CxGQ7jswNLpuXcoUknW2Hb4NjnKpeLL PIOnO7zJfgh0qTKQx1wsCy+S4rbwoq0= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1730729898; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=funV3ntCCjs65WT4XelhOUCAGazAb0yRa0Q2DOqjLZQ=; b=nLB7X39WIHAE83WNmVNkS02SEHgXDN1DRub2cj0dwhD/b778zqc7rb33LoJDwcAOH9t/rv 8CMeR1ApprXtuVBA== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id B61D813736; Mon, 4 Nov 2024 14:18:16 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id SKi9GqjXKGfGfAAAD6G6ig (envelope-from ); Mon, 04 Nov 2024 14:18:16 +0000 From: David Disseldorp To: linux-fsdevel@vger.kernel.org Cc: Al Viro , Christian Brauner , David Disseldorp Subject: [PATCH v2 6/9] initramfs: merge header_buf and name_buf Date: Tue, 5 Nov 2024 01:14:45 +1100 Message-ID: <20241104141750.16119-7-ddiss@suse.de> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241104141750.16119-1-ddiss@suse.de> References: <20241104141750.16119-1-ddiss@suse.de> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Rspamd-Queue-Id: 8776A1F7DD X-Spam-Level: X-Spamd-Result: default: False [-3.01 / 50.00]; BAYES_HAM(-3.00)[100.00%]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_MISSING_CHARSET(0.50)[]; R_DKIM_ALLOW(-0.20)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; MX_GOOD(-0.01)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_TRACE(0.00)[0:+]; ARC_NA(0.00)[]; TO_DN_SOME(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; RBL_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:104:10:150:64:97:from]; FUZZY_BLOCKED(0.00)[rspamd.com]; RCVD_TLS_ALL(0.00)[]; DKIM_TRACE(0.00)[suse.de:+]; RCVD_COUNT_TWO(0.00)[2]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; SPAMHAUS_XBL(0.00)[2a07:de40:b281:104:10:150:64:97:from]; RECEIVED_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:106:10:150:64:167:received]; ASN(0.00)[asn:25478, ipnet:::/0, country:RU]; RCVD_VIA_SMTP_AUTH(0.00)[]; RCPT_COUNT_THREE(0.00)[4]; DBL_BLOCKED_OPENRESOLVER(0.00)[imap1.dmz-prg2.suse.org:helo,imap1.dmz-prg2.suse.org:rdns,suse.de:email,suse.de:dkim,suse.de:mid] X-Rspamd-Server: rspamd2.dmz-prg2.suse.org X-Rspamd-Action: no action X-Spam-Score: -3.01 X-Spam-Flag: NO header_buf is only used in FSM states up to GotHeader, while name_buf is only used in states following GotHeader (Collect is shared, but the collect pointer tracks each buffer). These buffers can therefore be combined into a single cpio_buf, which can be used for both header and file name storage. Signed-off-by: David Disseldorp --- init/initramfs.c | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/init/initramfs.c b/init/initramfs.c index 59b4a43fa491b..4e2506a4bc76f 100644 --- a/init/initramfs.c +++ b/init/initramfs.c @@ -250,11 +250,11 @@ static void __init read_into(char *buf, unsigned size, enum state next) } } -static __initdata char *header_buf, *name_buf; +static __initdata char *cpio_buf; static int __init do_start(void) { - read_into(header_buf, CPIO_HDRLEN, GotHeader); + read_into(cpio_buf, CPIO_HDRLEN, GotHeader); return 0; } @@ -294,14 +294,14 @@ static int __init do_header(void) if (S_ISLNK(mode)) { if (body_len > PATH_MAX) return 0; - collect = collected = name_buf; + collect = collected = cpio_buf; remains = N_ALIGN(name_len) + body_len; next_state = GotSymlink; state = Collect; return 0; } if (S_ISREG(mode) || !body_len) - read_into(name_buf, N_ALIGN(name_len), GotName); + read_into(cpio_buf, N_ALIGN(name_len), GotName); return 0; } @@ -511,11 +511,16 @@ char * __init unpack_to_rootfs(char *buf, unsigned long len) const char *compress_name; static __initdata char msg_buf[64]; - header_buf = kmalloc(CPIO_HDRLEN, GFP_KERNEL); - /* 2x PATH_MAX as @name_buf is also used for staging symlink targets */ - name_buf = kmalloc(N_ALIGN(PATH_MAX) + PATH_MAX + 1, GFP_KERNEL); - if (!header_buf || !name_buf) - panic_show_mem("can't allocate buffers"); + /* + * @cpio_buf can be used for staging the 110 byte newc/crc cpio header, + * after which parse_header() converts and stashes fields into + * corresponding types. The same buffer can then be reused for file + * path staging. 2 x PATH_MAX covers any possible symlink target. + */ + BUILD_BUG_ON(CPIO_HDRLEN > N_ALIGN(PATH_MAX) + PATH_MAX + 1); + cpio_buf = kmalloc(N_ALIGN(PATH_MAX) + PATH_MAX + 1, GFP_KERNEL); + if (!cpio_buf) + panic_show_mem("can't allocate buffer"); state = Start; this_header = 0; @@ -559,8 +564,7 @@ char * __init unpack_to_rootfs(char *buf, unsigned long len) len -= my_inptr; } dir_utime(); - kfree(name_buf); - kfree(header_buf); + kfree(cpio_buf); return message; } From patchwork Mon Nov 4 14:14:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Disseldorp X-Patchwork-Id: 13861470 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) (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 801B01632C7 for ; Mon, 4 Nov 2024 14:18:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730729904; cv=none; b=kpLcVEP0KOHkbaCRjTETgmof6mDYBw/VonoArGVS8z6kJvPBzrAddSYn1YxZCkVyfCxMZMhg9yT1xDfqaReU9luQZFMP2IXNCmRgZi2TFVXPSrsK0iA+o81IPTt///d/WSmnLsdBE70kuI2DgfoJUvgaST3MU/QLNjUBUufFamg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730729904; c=relaxed/simple; bh=KtCvMQnoTAGnjG8Y+Sk2AzwfZ4BixyKP/vWn/8eLMoo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KLMQZVWqVlfRfv7TH7z+ZlO9zHdZGRKpQBTbpTu+M+GemWAvWD2yyFcAwqIIZT0oSTFhisuqLSmsNUOH/RuqptN2g+3V7F/yOgLtilYEa6GmB2e73L5Vax5uGv7l98JcLOvIjaqQSX9hSJfRU0o9WzYU/pU0kZY/5NvOJ5VU/L8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de; spf=pass smtp.mailfrom=suse.de; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=FL9DAxJw; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=pVPVTXcO; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=1JLR+SGO; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=i+g6k+eZ; arc=none smtp.client-ip=195.135.223.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="FL9DAxJw"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="pVPVTXcO"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="1JLR+SGO"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="i+g6k+eZ" Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id E4FC71FB82; Mon, 4 Nov 2024 14:18:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1730729901; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=rXGzLqa7ndw2VlNeIeFuPasg/cAnz8Fj/bNSm06DPsg=; b=FL9DAxJwaiL/GEQfszvsbE3UWh2ryfN1fNV2bbP1uWRBbUMEIPfbF2S1ThYd0RunDSTwL0 DhhZzoWSLG63lP4BJq8qSDb14iWRygIaC3P3+20RVUgEhRR38S68os7Py4xabeReytkm1F V6sscPDS3RQdX4nWpKXbgPXLh1F4v/c= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1730729901; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=rXGzLqa7ndw2VlNeIeFuPasg/cAnz8Fj/bNSm06DPsg=; b=pVPVTXcO6w4l8inH37x0Mrfx/lv3AlkNkMP3UId3uFk33b3sCh1dOiHeOyZ1AJvfkgn5tK WfkktwVyozz7OXBQ== Authentication-Results: smtp-out2.suse.de; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=1JLR+SGO; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=i+g6k+eZ DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1730729900; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=rXGzLqa7ndw2VlNeIeFuPasg/cAnz8Fj/bNSm06DPsg=; b=1JLR+SGOJQzo9Ym1XIxC9Nsb6ZkBstzuNEUtF09XUMBpWOZ9MuFvcu0QNrDJ/Bg2puL4a1 vn2SRx9Lpn67klvnVaZS6DVxnZ9txNElE5/Y2YnVgJEAsd9cN6+WeRp3vxqr/NYBayr94V kde5scAN88tZRwjVmtvFX8x73NgviuY= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1730729900; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=rXGzLqa7ndw2VlNeIeFuPasg/cAnz8Fj/bNSm06DPsg=; b=i+g6k+eZlVk9Dn/nB9VKCv6pqhs9QR/dYVyvpKEyHLC9YDZu90GLI02+cfA+GStT01v9Pe 7p3zgu8BFaDzQOBg== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 1FFD913736; Mon, 4 Nov 2024 14:18:18 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id YKqvMarXKGfGfAAAD6G6ig (envelope-from ); Mon, 04 Nov 2024 14:18:18 +0000 From: David Disseldorp To: linux-fsdevel@vger.kernel.org Cc: Al Viro , Christian Brauner , David Disseldorp Subject: [PATCH v2 7/9] initramfs: reuse name_len for dir mtime tracking Date: Tue, 5 Nov 2024 01:14:46 +1100 Message-ID: <20241104141750.16119-8-ddiss@suse.de> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241104141750.16119-1-ddiss@suse.de> References: <20241104141750.16119-1-ddiss@suse.de> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Rspamd-Queue-Id: E4FC71FB82 X-Spam-Score: -3.01 X-Rspamd-Action: no action X-Spamd-Result: default: False [-3.01 / 50.00]; BAYES_HAM(-3.00)[100.00%]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_MISSING_CHARSET(0.50)[]; R_DKIM_ALLOW(-0.20)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; MX_GOOD(-0.01)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_TRACE(0.00)[0:+]; ARC_NA(0.00)[]; TO_DN_SOME(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; RBL_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:104:10:150:64:97:from]; FUZZY_BLOCKED(0.00)[rspamd.com]; RCVD_TLS_ALL(0.00)[]; DKIM_TRACE(0.00)[suse.de:+]; RCVD_COUNT_TWO(0.00)[2]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; SPAMHAUS_XBL(0.00)[2a07:de40:b281:104:10:150:64:97:from]; RECEIVED_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:106:10:150:64:167:received]; ASN(0.00)[asn:25478, ipnet:::/0, country:RU]; RCVD_VIA_SMTP_AUTH(0.00)[]; RCPT_COUNT_THREE(0.00)[4]; DBL_BLOCKED_OPENRESOLVER(0.00)[imap1.dmz-prg2.suse.org:rdns,imap1.dmz-prg2.suse.org:helo,suse.de:dkim,suse.de:mid,suse.de:email] X-Rspamd-Server: rspamd1.dmz-prg2.suse.org X-Spam-Flag: NO X-Spam-Level: We already have a nulterm-inclusive, checked name_len for the directory name, so use that instead of calling strlen(). Signed-off-by: David Disseldorp --- init/initramfs.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/init/initramfs.c b/init/initramfs.c index 4e2506a4bc76f..c264f136c5281 100644 --- a/init/initramfs.c +++ b/init/initramfs.c @@ -144,9 +144,8 @@ struct dir_entry { char name[]; }; -static void __init dir_add(const char *name, time64_t mtime) +static void __init dir_add(const char *name, size_t nlen, time64_t mtime) { - size_t nlen = strlen(name) + 1; struct dir_entry *de; de = kmalloc(sizeof(struct dir_entry) + nlen, GFP_KERNEL); @@ -170,7 +169,7 @@ static void __init dir_utime(void) #else static void __init do_utime(char *filename, time64_t mtime) {} static void __init do_utime_path(const struct path *path, time64_t mtime) {} -static void __init dir_add(const char *name, time64_t mtime) {} +static void __init dir_add(const char *name, size_t nlen, time64_t mtime) {} static void __init dir_utime(void) {} #endif @@ -394,7 +393,7 @@ static int __init do_name(void) init_mkdir(collected, mode); init_chown(collected, uid, gid, 0); init_chmod(collected, mode); - dir_add(collected, mtime); + dir_add(collected, name_len, mtime); } else if (S_ISBLK(mode) || S_ISCHR(mode) || S_ISFIFO(mode) || S_ISSOCK(mode)) { if (maybe_link() == 0) { From patchwork Mon Nov 4 14:14:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Disseldorp X-Patchwork-Id: 13861471 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) (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 163541632C7 for ; Mon, 4 Nov 2024 14:18:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.130 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730729906; cv=none; b=i9wfTbQdfQ1HxVdbk5BELEso5sYpnIMn79FD+Fdv0xGiVy1lJKmm3KBYNFpHkAnlDPinlFbyYGAJGKnZ/W4H+zcGVtbtl2FFn3IWAu2SlTVJtJMK7d5LJfZj0NLv2SPff/pvRE76Vr36H49JVtjF8uLKHdy8oM26cP9HT1i6ytI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730729906; c=relaxed/simple; bh=xocH7uQR0OhxFCaK8bmK1dY2mLxA+nr/PRhvhqoabX8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XblM9RYIftiFGdnKmnNdbkaI1/dO1zwIYotMcFwJIsQEaeKnyHQyQRzbua4uQEfq3Z9lsyOx7PZJDIb8+h5cYi7mVAnBeQTBspFAPgBYOU1UZxD3zAO3WbYMu4Sk6hYq6E4irxbqRS+EZwnA2wjeu/iToOSZb+j8jkNXGp2WKyQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de; spf=pass smtp.mailfrom=suse.de; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=ZD+D2EmV; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=zRshqpt6; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=ZD+D2EmV; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=zRshqpt6; arc=none smtp.client-ip=195.135.223.130 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="ZD+D2EmV"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="zRshqpt6"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="ZD+D2EmV"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="zRshqpt6" Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 4ED8A21B79; Mon, 4 Nov 2024 14:18:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1730729903; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=lyBPCm6M2ra7d0D0dksfoEN/EB3l6I2VvQJU5DTi/0I=; b=ZD+D2EmVFnYwWKLOv3KrXacRdU1M7vG1q3Lagz9wuAtzy7vVfiorGXKrF31sefqsNci3vW VDuID7+fSy7iHxvYF2pKleJ6srUWW3D7T3Lpw9SxBqsOxvwRefa+As8XjdmPJh0UDyleiv ZANi6+vLUo3OLa1R0nzLqk737XcZ644= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1730729903; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=lyBPCm6M2ra7d0D0dksfoEN/EB3l6I2VvQJU5DTi/0I=; b=zRshqpt6BhVmV+xOhlwW/ggXK6h+iaj67jD6Jt02y3oiyNMdTzGu2O6D2pttyAOK1UEqUQ /pnpzpURXeV+dICQ== Authentication-Results: smtp-out1.suse.de; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=ZD+D2EmV; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=zRshqpt6 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1730729903; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=lyBPCm6M2ra7d0D0dksfoEN/EB3l6I2VvQJU5DTi/0I=; b=ZD+D2EmVFnYwWKLOv3KrXacRdU1M7vG1q3Lagz9wuAtzy7vVfiorGXKrF31sefqsNci3vW VDuID7+fSy7iHxvYF2pKleJ6srUWW3D7T3Lpw9SxBqsOxvwRefa+As8XjdmPJh0UDyleiv ZANi6+vLUo3OLa1R0nzLqk737XcZ644= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1730729903; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=lyBPCm6M2ra7d0D0dksfoEN/EB3l6I2VvQJU5DTi/0I=; b=zRshqpt6BhVmV+xOhlwW/ggXK6h+iaj67jD6Jt02y3oiyNMdTzGu2O6D2pttyAOK1UEqUQ /pnpzpURXeV+dICQ== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 7D23E13736; Mon, 4 Nov 2024 14:18:21 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id mFbXDK3XKGfGfAAAD6G6ig (envelope-from ); Mon, 04 Nov 2024 14:18:21 +0000 From: David Disseldorp To: linux-fsdevel@vger.kernel.org Cc: Al Viro , Christian Brauner , David Disseldorp Subject: [PATCH v2 8/9] initramfs: fix hardlink hash leak without TRAILER Date: Tue, 5 Nov 2024 01:14:47 +1100 Message-ID: <20241104141750.16119-9-ddiss@suse.de> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241104141750.16119-1-ddiss@suse.de> References: <20241104141750.16119-1-ddiss@suse.de> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Rspamd-Queue-Id: 4ED8A21B79 X-Spam-Level: X-Spamd-Result: default: False [-3.01 / 50.00]; BAYES_HAM(-3.00)[100.00%]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_MISSING_CHARSET(0.50)[]; R_DKIM_ALLOW(-0.20)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; MX_GOOD(-0.01)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_TRACE(0.00)[0:+]; ARC_NA(0.00)[]; TO_DN_SOME(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; RBL_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:104:10:150:64:97:from]; FUZZY_BLOCKED(0.00)[rspamd.com]; RCVD_TLS_ALL(0.00)[]; DKIM_TRACE(0.00)[suse.de:+]; RCVD_COUNT_TWO(0.00)[2]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; SPAMHAUS_XBL(0.00)[2a07:de40:b281:104:10:150:64:97:from]; RECEIVED_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:106:10:150:64:167:received]; ASN(0.00)[asn:25478, ipnet:::/0, country:RU]; RCVD_VIA_SMTP_AUTH(0.00)[]; RCPT_COUNT_THREE(0.00)[4]; DBL_BLOCKED_OPENRESOLVER(0.00)[imap1.dmz-prg2.suse.org:helo,imap1.dmz-prg2.suse.org:rdns,suse.de:email,suse.de:dkim,suse.de:mid] X-Rspamd-Server: rspamd2.dmz-prg2.suse.org X-Rspamd-Action: no action X-Spam-Score: -3.01 X-Spam-Flag: NO Covered in Documentation/driver-api/early-userspace/buffer-format.rst , initramfs archives can carry an optional "TRAILER!!!" entry which serves as a boundary for collecting and associating hardlinks with matching inode and major / minor device numbers. Although optional, if hardlinks are found in an archive without a subsequent "TRAILER!!!" entry then the hardlink state hash table is leaked, e.g. unfixed kernel, with initramfs_test.c hunk applied only: unreferenced object 0xffff9405408cc000 (size 8192): comm "kunit_try_catch", pid 53, jiffies 4294892519 hex dump (first 32 bytes): 01 00 00 00 01 00 00 00 00 00 00 00 ff 81 00 00 ................ 00 00 00 00 00 00 00 00 69 6e 69 74 72 61 6d 66 ........initramf backtrace (crc a9fb0ee0): [<0000000066739faa>] __kmalloc_cache_noprof+0x11d/0x250 [<00000000fc755219>] maybe_link.part.5+0xbc/0x120 [<000000000526a128>] do_name+0xce/0x2f0 [<00000000145c1048>] write_buffer+0x22/0x40 [<000000003f0b4f32>] unpack_to_rootfs+0xf9/0x2a0 [<00000000d6f7e5af>] initramfs_test_hardlink+0xe3/0x3f0 [<0000000014fde8d6>] kunit_try_run_case+0x5f/0x130 [<00000000dc9dafc5>] kunit_generic_run_threadfn_adapter+0x18/0x30 [<000000001076c239>] kthread+0xc8/0x100 [<00000000d939f1c1>] ret_from_fork+0x2b/0x40 [<00000000f848ad1a>] ret_from_fork_asm+0x1a/0x30 Fix this by calling free_hash() after initramfs buffer processing in unpack_to_rootfs(). An extra hardlink_seen global is added as an optimization to avoid walking the 32 entry hash array unnecessarily. The expectation is that a "TRAILER!!!" entry will normally be present, and initramfs hardlinks are uncommon. There is one user facing side-effect of this fix: hardlinks can currently be associated across built-in and external initramfs archives, *if* the built-in initramfs archive lacks a "TRAILER!!!" terminator. I'd consider this cross-archive association broken, but perhaps it's used. Signed-off-by: David Disseldorp --- init/initramfs.c | 7 ++++++- init/initramfs_test.c | 5 ----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/init/initramfs.c b/init/initramfs.c index c264f136c5281..99f3cac10d392 100644 --- a/init/initramfs.c +++ b/init/initramfs.c @@ -76,6 +76,7 @@ static __initdata struct hash { struct hash *next; char name[N_ALIGN(PATH_MAX)]; } *head[32]; +static __initdata bool hardlink_seen; static inline int hash(int major, int minor, int ino) { @@ -109,19 +110,21 @@ static char __init *find_link(int major, int minor, int ino, strcpy(q->name, name); q->next = NULL; *p = q; + hardlink_seen = true; return NULL; } static void __init free_hash(void) { struct hash **p, *q; - for (p = head; p < head + 32; p++) { + for (p = head; hardlink_seen && p < head + 32; p++) { while (*p) { q = *p; *p = q->next; kfree(q); } } + hardlink_seen = false; } #ifdef CONFIG_INITRAMFS_PRESERVE_MTIME @@ -563,6 +566,8 @@ char * __init unpack_to_rootfs(char *buf, unsigned long len) len -= my_inptr; } dir_utime(); + /* free any hardlink state collected without optional TRAILER!!! */ + free_hash(); kfree(cpio_buf); return message; } diff --git a/init/initramfs_test.c b/init/initramfs_test.c index 2f64e7bf0a1c2..d2d307d52e83f 100644 --- a/init/initramfs_test.c +++ b/init/initramfs_test.c @@ -305,11 +305,6 @@ static void __init initramfs_test_hardlink(struct kunit *test) .namesize = sizeof("initramfs_test_hardlink_link"), .fname = "initramfs_test_hardlink_link", .data = "ASDF", - }, { - /* hardlink hashtable leaks when the archive omits a trailer */ - .magic = "070701", - .namesize = sizeof("TRAILER!!!"), - .fname = "TRAILER!!!", } }; cpio_srcbuf = kmalloc(8192, GFP_KERNEL); From patchwork Mon Nov 4 14:14:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Disseldorp X-Patchwork-Id: 13861472 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) (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 728BB1632C7 for ; Mon, 4 Nov 2024 14:18:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730729910; cv=none; b=ej1BpFKFcPkzuIcaHHI9710tmkn25uL2Xg4t+uRnllMwbpHtFwFRDH2rnnaXPBmqOomVFB2iiXHI3qZiAkgAxkYlQNlexrkdmLWdUw0IquF6PD4zjFTFTBzpudUpPqgRHCVSwv7N0Qz73h0lMOQOVgp94X74vWwjU6TUqhINOAI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730729910; c=relaxed/simple; bh=E4bOtcamvsZQyV8i49+tvTolrYnEthbpE/LTW55KkK0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GFOr7SAocrDTB1nmhoFr4NQDBDxyCYDso4NmS/ADcIArksrl1leHC6kAur3CCR2aWzQZ/JcjPr2kBjrI4Qvpz4K6ODHVG963JUS1ri0ugZhvol8Xxd4072N/ZkL7pGZ7KA/Pos8C+zShuvkj29WliweMV7I6BlmbnXPb0LU9R3E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de; spf=pass smtp.mailfrom=suse.de; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=jGH91hMJ; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=XMyecr1d; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=jGH91hMJ; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=XMyecr1d; arc=none smtp.client-ip=195.135.223.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="jGH91hMJ"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="XMyecr1d"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="jGH91hMJ"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="XMyecr1d" Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id AC6CF1F7DD; Mon, 4 Nov 2024 14:18:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1730729905; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=wUNvOOFuGt9tkdf6fAWxzGM7alCqjdS46d9Z5/BWrlE=; b=jGH91hMJIo5SbzdHdoDBrEJbV5GpzVbCmxBPV7wnaJuC9Q0OwGitkn9EqXhYsEkmbf2guM I9wEucyBpwdgvusEgUNqOvjW6oMX+U52XXHTXCBzfoYrgYmiaXKsq7K2r+PRoLJrVqLZLG Bx5KuSNMHlDwLMFd1gTKT6B42FjezcY= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1730729905; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=wUNvOOFuGt9tkdf6fAWxzGM7alCqjdS46d9Z5/BWrlE=; b=XMyecr1dk3vcrQvUI2wT9/LLUQs0GOFsNlZH8M6U/DEKPfdmv3zWM2X3o1/eQixA3TvnUC 2j4D3mXj6NvBEECg== Authentication-Results: smtp-out2.suse.de; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=jGH91hMJ; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=XMyecr1d DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1730729905; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=wUNvOOFuGt9tkdf6fAWxzGM7alCqjdS46d9Z5/BWrlE=; b=jGH91hMJIo5SbzdHdoDBrEJbV5GpzVbCmxBPV7wnaJuC9Q0OwGitkn9EqXhYsEkmbf2guM I9wEucyBpwdgvusEgUNqOvjW6oMX+U52XXHTXCBzfoYrgYmiaXKsq7K2r+PRoLJrVqLZLG Bx5KuSNMHlDwLMFd1gTKT6B42FjezcY= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1730729905; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=wUNvOOFuGt9tkdf6fAWxzGM7alCqjdS46d9Z5/BWrlE=; b=XMyecr1dk3vcrQvUI2wT9/LLUQs0GOFsNlZH8M6U/DEKPfdmv3zWM2X3o1/eQixA3TvnUC 2j4D3mXj6NvBEECg== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id DB97713736; Mon, 4 Nov 2024 14:18:23 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id 4BrSI6/XKGfGfAAAD6G6ig (envelope-from ); Mon, 04 Nov 2024 14:18:23 +0000 From: David Disseldorp To: linux-fsdevel@vger.kernel.org Cc: Al Viro , Christian Brauner , David Disseldorp Subject: [PATCH v2 9/9] initramfs: avoid static buffer for error message Date: Tue, 5 Nov 2024 01:14:48 +1100 Message-ID: <20241104141750.16119-10-ddiss@suse.de> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241104141750.16119-1-ddiss@suse.de> References: <20241104141750.16119-1-ddiss@suse.de> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Rspamd-Queue-Id: AC6CF1F7DD X-Spam-Score: -3.01 X-Rspamd-Action: no action X-Spamd-Result: default: False [-3.01 / 50.00]; BAYES_HAM(-3.00)[100.00%]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_MISSING_CHARSET(0.50)[]; R_DKIM_ALLOW(-0.20)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; MX_GOOD(-0.01)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_TRACE(0.00)[0:+]; ARC_NA(0.00)[]; TO_DN_SOME(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; RBL_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:104:10:150:64:97:from]; FUZZY_BLOCKED(0.00)[rspamd.com]; RCVD_TLS_ALL(0.00)[]; DKIM_TRACE(0.00)[suse.de:+]; RCVD_COUNT_TWO(0.00)[2]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; SPAMHAUS_XBL(0.00)[2a07:de40:b281:104:10:150:64:97:from]; RECEIVED_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:106:10:150:64:167:received]; ASN(0.00)[asn:25478, ipnet:::/0, country:RU]; RCVD_VIA_SMTP_AUTH(0.00)[]; RCPT_COUNT_THREE(0.00)[4]; DBL_BLOCKED_OPENRESOLVER(0.00)[imap1.dmz-prg2.suse.org:rdns,imap1.dmz-prg2.suse.org:helo,suse.de:dkim,suse.de:mid,suse.de:email] X-Rspamd-Server: rspamd1.dmz-prg2.suse.org X-Spam-Flag: NO X-Spam-Level: The dynamic error message printed if CONFIG_RD_$ALG compression support is missing needn't be propagated up to the caller via a static buffer. Print it immediately via pr_err() and set @message to a const string to flag error. Before: text data bss dec hex filename 7695 1102 8 8805 2265 ./init/initramfs.o After: text data bss dec hex filename 7683 1006 8 8697 21f9 ./init/initramfs.o Signed-off-by: David Disseldorp --- init/initramfs.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/init/initramfs.c b/init/initramfs.c index 99f3cac10d392..f946b7680867b 100644 --- a/init/initramfs.c +++ b/init/initramfs.c @@ -511,7 +511,6 @@ char * __init unpack_to_rootfs(char *buf, unsigned long len) long written; decompress_fn decompress; const char *compress_name; - static __initdata char msg_buf[64]; /* * @cpio_buf can be used for staging the 110 byte newc/crc cpio header, @@ -551,12 +550,9 @@ char * __init unpack_to_rootfs(char *buf, unsigned long len) if (res) error("decompressor failed"); } else if (compress_name) { - if (!message) { - snprintf(msg_buf, sizeof msg_buf, - "compression method %s not configured", - compress_name); - message = msg_buf; - } + pr_err("compression method %s not configured\n", + compress_name); + error("decompressor failed"); } else error("invalid magic at start of compressed archive"); if (state != Reset)