From patchwork Tue Oct 15 13:11:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Disseldorp X-Patchwork-Id: 13836430 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 C8E5A14EC47 for ; Tue, 15 Oct 2024 13:30:30 +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=1728999032; cv=none; b=BPBZfJ7A7O/wLK+c/J01si815650gNFJK0X7kNGuE2HDQzC0cdFmfo6o5sYARozocnOscxwZmBfvraEhMA5KIHj2K717M+vLkkGzhN9R3FvMA5FQZBfkTp/sXD5ALWD5j6Yxgz29lEZNv7C6BN2M9wxK9VFOZ3NwfL3XpYIWgaA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728999032; c=relaxed/simple; bh=kin+740lwCcp0CyjC81Xi4YNGVv3eLKrz5FJ9ljjtow=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BmbAMcEWuKmpQ8L39cEVSboQJTmek+vf50X52jRQK3EwS86QOyeDVzjXFlH4YMzdRLRM1LDAhiifqfwTe+Lo10ZYOcL6eEFq/0uc2Ql61DGVnWvwfAiWsgiNGsLu79oV/hO+QPPI3TgZQW1/FfCFKq+0fY7cT7HijSKzIf/+DFc= 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=fqLZqUds; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=Fg6zJk2D; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=u3Glv2v6; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=8Pl2yyvT; 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="fqLZqUds"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="Fg6zJk2D"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="u3Glv2v6"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="8Pl2yyvT" 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-out2.suse.de (Postfix) with ESMTPS id EB0371FE44; Tue, 15 Oct 2024 13:30:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1728999029; 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=fqLZqUdsgmsE4z0isWVgv1jFHsvishQGJBjpYHpfl1lmb6yfGAm5OgmfC4cgx2z7BSGyAn rGLEfm5BuR1OmAtrzw3bQoVS6XyMr/EPH5qz0uZrBnPsabgQwBNMu6gHyBWA8WUaj1WFHz FkS0O77L3Wjedav2svmq2YSj/0weXkI= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1728999029; 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=Fg6zJk2DTfLXTDTUbQ4yypy54SMi48xHAUtIp57TD3Z1Rk0mAV9kPl4kW3ZuTxLvhVRWc8 UZKp1suNWoFCfECg== Authentication-Results: smtp-out2.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1728999028; 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=u3Glv2v6ixg/QlP2u2MV681c2m0DNRhAWTeaOyGoPqrQvt2oWBIoTFrfKeo/dr1eUi0U/k Cew8CTBbM1nmYwf8a5gQxuXjQWnYwtVYUS+SMH2ffpv9fk02EtPPebjsb3m2/I18wnd/Df tJ8FdNWDb87JxEybrAGIrJVptoniDgs= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1728999028; 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=8Pl2yyvTPbJzCKUjK+oq1I2nG66BfjANvVXamqCghntmh4LJKMv8dOZrEpqE9quZaCI6PX 5H/t5Hfr/HEjKdAA== 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 1AEC513A42; Tue, 15 Oct 2024 13:30:26 +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 GGbyL3JuDmcvcgAAD6G6ig (envelope-from ); Tue, 15 Oct 2024 13:30:26 +0000 From: David Disseldorp To: linux-fsdevel@vger.kernel.org Cc: Al Viro , Christian Brauner , David Disseldorp Subject: [RFC PATCH 1/6] vsprintf: add simple_strntoul Date: Tue, 15 Oct 2024 13:11:58 +0000 Message-ID: <20241015133016.23468-2-ddiss@suse.de> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241015133016.23468-1-ddiss@suse.de> References: <20241015133016.23468-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 [-6.80 / 50.00]; REPLY(-4.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)[-1.000]; 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]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:email,suse.de:mid,imap1.dmz-prg2.suse.org:helo]; RCVD_COUNT_TWO(0.00)[2]; TO_MATCH_ENVRCPT_ALL(0.00)[]; RCVD_TLS_ALL(0.00)[] X-Spam-Score: -6.80 X-Spam-Flag: NO 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 Tue Oct 15 13:11:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Disseldorp X-Patchwork-Id: 13836431 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 221B21FC7FD for ; Tue, 15 Oct 2024 13:30:32 +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=1728999034; cv=none; b=YSvY8kWiODD4IvfhRYhBfv7K292wCXqzl4XKvh1M3hHYmzPuC+vsBKWgRmKBIhbdCPFlzgd1E/tV3kI86isNIbog7dIlot1sze4ePLHqOE0BCaBP5cK++fpqtZq+oZ0Fr9CjarKO7T5jhn70MWt5nV5kJHznkHJAML6idSdpkc0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728999034; c=relaxed/simple; bh=O+KBLKM6Yf9s5KLhm3OfZRWcBrBo+IyLs7NfN0hMrnc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pAeykw36W6x2hVFLe5HghFFdxcyeFaczeXxbWpVahRTMxz/hwRs9u0CwOfKaSoUt7IpbEMRk+kyeRykbrsuU9Fv5SInsimi16AO6DgYaLmXvr8HRh6WmDOw9kUGLzKnxiWLPRFOXhsATd3ugVp1kua1n6EWHPZFKgNxXysm1Eg8= 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=tT8MBG5n; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=Be++y2SS; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=tT8MBG5n; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=Be++y2SS; 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="tT8MBG5n"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="Be++y2SS"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="tT8MBG5n"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="Be++y2SS" 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-out2.suse.de (Postfix) with ESMTPS id 693141FE5F; Tue, 15 Oct 2024 13:30:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1728999031; 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=mDNb8oDu2lGdm5lXbyvY3SJ/EskAXqrEHvs4ykIAALo=; b=tT8MBG5nIM03OIsZmjz/xT5ncEs5e+CxNVbpHw/6XLk9FqJ2azes4vIaGnqc7tqk+zpMz5 YHCUDWQuW+UR70nF7ki0qyTAuRge+2tNcJA/7H72m8DiYX1CPTjjiEp1H0aiMSvnwXZQqV ffMH4v4WXOU1Hr4LyisAQ4YQs8yF3QI= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1728999031; 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=mDNb8oDu2lGdm5lXbyvY3SJ/EskAXqrEHvs4ykIAALo=; b=Be++y2SSNaFLRiPxfhV6uCEtwPXQWqS2SWhQimh5yCXsFeMovzfZ5WKR7+Rj0qsIIBf5kR qL4axNULa6c8DsAA== Authentication-Results: smtp-out2.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1728999031; 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=mDNb8oDu2lGdm5lXbyvY3SJ/EskAXqrEHvs4ykIAALo=; b=tT8MBG5nIM03OIsZmjz/xT5ncEs5e+CxNVbpHw/6XLk9FqJ2azes4vIaGnqc7tqk+zpMz5 YHCUDWQuW+UR70nF7ki0qyTAuRge+2tNcJA/7H72m8DiYX1CPTjjiEp1H0aiMSvnwXZQqV ffMH4v4WXOU1Hr4LyisAQ4YQs8yF3QI= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1728999031; 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=mDNb8oDu2lGdm5lXbyvY3SJ/EskAXqrEHvs4ykIAALo=; b=Be++y2SSNaFLRiPxfhV6uCEtwPXQWqS2SWhQimh5yCXsFeMovzfZ5WKR7+Rj0qsIIBf5kR qL4axNULa6c8DsAA== 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 881D113A42; Tue, 15 Oct 2024 13:30:29 +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 MGv7DnVuDmcvcgAAD6G6ig (envelope-from ); Tue, 15 Oct 2024 13:30:29 +0000 From: David Disseldorp To: linux-fsdevel@vger.kernel.org Cc: Al Viro , Christian Brauner , David Disseldorp Subject: [RFC PATCH 2/6] initramfs: avoid memcpy for hex header fields Date: Tue, 15 Oct 2024 13:11:59 +0000 Message-ID: <20241015133016.23468-3-ddiss@suse.de> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241015133016.23468-1-ddiss@suse.de> References: <20241015133016.23468-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: -6.80 X-Spamd-Result: default: False [-6.80 / 50.00]; REPLY(-4.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)[-1.000]; 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]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:mid,suse.de:email,imap1.dmz-prg2.suse.org:helo]; RCVD_COUNT_TWO(0.00)[2]; TO_MATCH_ENVRCPT_ALL(0.00)[]; RCVD_TLS_ALL(0.00)[] 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 bc911e466d5bb..c35600d49a50a 100644 --- a/init/initramfs.c +++ b/init/initramfs.c @@ -188,14 +188,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 Tue Oct 15 13:12:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Disseldorp X-Patchwork-Id: 13836432 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 82E611AF0BA for ; Tue, 15 Oct 2024 13:30:35 +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=1728999037; cv=none; b=C8ZqOSaGBG0+Or1acI03Jan21kzZlJTLou1SkYRw1+KH7njdjA7LHOegDDGxj5/RCsYunv+CZkVKLYAs0l4VAQcH2I981pOEgm0DGQHg5BJGZUSMOhH8j+H/NEbiWKx7l4AmD3Aykr88VgNUWkKxcaojZD2wNMwIi/vUTnv/jWA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728999037; c=relaxed/simple; bh=ac6FvTfBGLWOGFEiJupZW3Nyb4bFepsDOdlrqAPMPdA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lZ4sVtYIPkR7fbjNsG8iJ1q60b55h8X1gZxTwVLB2h4Py5z5BV6jp3ybUNXS3wKCTIqvuJYuSzqB5WrGcoQi9yYOJFYDDgtyq9pspRB+R0jbLb4E2WoFQ5YPQQxGV4cYokP/rZTXRGZBpVNoG9yEDU+1fDn9AQwLmIh9RVkGRLQ= 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; 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 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 CF8BE21D8E; Tue, 15 Oct 2024 13:30:33 +0000 (UTC) Authentication-Results: smtp-out1.suse.de; none 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 F41F513AAF; Tue, 15 Oct 2024 13:30:31 +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 MHBtKXduDmcvcgAAD6G6ig (envelope-from ); Tue, 15 Oct 2024 13:30:31 +0000 From: David Disseldorp To: linux-fsdevel@vger.kernel.org Cc: Al Viro , Christian Brauner , David Disseldorp Subject: [RFC PATCH 3/6] initramfs: remove extra symlink path buffer Date: Tue, 15 Oct 2024 13:12:00 +0000 Message-ID: <20241015133016.23468-4-ddiss@suse.de> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241015133016.23468-1-ddiss@suse.de> References: <20241015133016.23468-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-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Spam-Level: X-Spamd-Result: default: False [-4.00 / 50.00]; REPLY(-4.00)[] X-Spam-Score: -4.00 X-Spam-Flag: NO X-Rspamd-Queue-Id: CF8BE21D8E X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Rspamd-Action: no action X-Rspamd-Server: rspamd2.dmz-prg2.suse.org 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 the path 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 c35600d49a50a..4b7f20fbf23ae 100644 --- a/init/initramfs.c +++ b/init/initramfs.c @@ -249,7 +249,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) { @@ -293,7 +293,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; @@ -487,10 +487,9 @@ static char * __init unpack_to_rootfs(char *buf, unsigned long len) static __initdata char msg_buf[64]; header_buf = kmalloc(110, GFP_KERNEL); - symlink_buf = kmalloc(PATH_MAX + N_ALIGN(PATH_MAX) + 1, GFP_KERNEL); - 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; @@ -536,7 +535,6 @@ static 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 Tue Oct 15 13:12:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Disseldorp X-Patchwork-Id: 13836433 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 1538B147C91 for ; Tue, 15 Oct 2024 13:30:37 +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=1728999039; cv=none; b=jjbLfz0oH4UVgadkfA5aqfOY+Eqay3pMamZ0Yn32DYTdsf28TxHKTm0can7rb05yU0GdbEo4ZUajaGCiBYt2MgwaaeF4QyTj9XMbQ53TCauwUENcHJ8ao0GHCIMntjWBLTJoUs5/YGcFoJKJnaSZczg0jTLEgDCU4AIvBCXwsTk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728999039; c=relaxed/simple; bh=+ruySnQ8RYBA9ugiLnAnW/Oq6X69aW3703tf8hhlwdo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=s5Xt/v5BDIISnMABfsvNgM5+7QUoHlfb6JnffyHjYbz7EEAfraWsjA2GNVenZxi14sf4GHTXdbXy+egwPcG732DpYOjiaJknC/Pu7+wIHyjkIEmqFGlH9A43Zh+6DRsy32O4li1mInKIP8iF1pvyGUzUFORryQr6Q/qC/7Dm/Zg= 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=B3kU8P+1; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=cq+Mk/XR; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=B3kU8P+1; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=cq+Mk/XR; 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="B3kU8P+1"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="cq+Mk/XR"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="B3kU8P+1"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="cq+Mk/XR" 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-out2.suse.de (Postfix) with ESMTPS id 4819F1FE44; Tue, 15 Oct 2024 13:30:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1728999036; 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=qAUCatqpnqiacXQDuxmwbSwhGqqLisoaQvkF8TeSibw=; b=B3kU8P+1ncpqcI0f1FNd7voZhMDspIH6xSWpCxoaD25c87RkvCiYlqsdAOTKaWFZGK4WQj OToeK2mZ5hf9eHu1odGeINQrOEo+l8KpxZp/FEUJ9srWYGy2bQlbylRbY6Xhzm52+at29K +bJ3FLFx/kgYneXFCexagRZY7flm6cI= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1728999036; 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=qAUCatqpnqiacXQDuxmwbSwhGqqLisoaQvkF8TeSibw=; b=cq+Mk/XR2HPzNLcB7lu7Yz9nv2sfzOh7i9derkDFp5xBrew59R0bIezJxA3weSUbGwmXQk 99HiZiB82FfjtzAw== Authentication-Results: smtp-out2.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1728999036; 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=qAUCatqpnqiacXQDuxmwbSwhGqqLisoaQvkF8TeSibw=; b=B3kU8P+1ncpqcI0f1FNd7voZhMDspIH6xSWpCxoaD25c87RkvCiYlqsdAOTKaWFZGK4WQj OToeK2mZ5hf9eHu1odGeINQrOEo+l8KpxZp/FEUJ9srWYGy2bQlbylRbY6Xhzm52+at29K +bJ3FLFx/kgYneXFCexagRZY7flm6cI= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1728999036; 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=qAUCatqpnqiacXQDuxmwbSwhGqqLisoaQvkF8TeSibw=; b=cq+Mk/XR2HPzNLcB7lu7Yz9nv2sfzOh7i9derkDFp5xBrew59R0bIezJxA3weSUbGwmXQk 99HiZiB82FfjtzAw== 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 6BD3613A42; Tue, 15 Oct 2024 13:30:34 +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 UB4qCHpuDmcvcgAAD6G6ig (envelope-from ); Tue, 15 Oct 2024 13:30:34 +0000 From: David Disseldorp To: linux-fsdevel@vger.kernel.org Cc: Al Viro , Christian Brauner , David Disseldorp Subject: [RFC PATCH 4/6] initramfs: merge header_buf and name_buf Date: Tue, 15 Oct 2024 13:12:01 +0000 Message-ID: <20241015133016.23468-5-ddiss@suse.de> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241015133016.23468-1-ddiss@suse.de> References: <20241015133016.23468-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 [-6.80 / 50.00]; REPLY(-4.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)[-1.000]; 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]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:email,suse.de:mid,imap1.dmz-prg2.suse.org:helo]; RCVD_COUNT_TWO(0.00)[2]; TO_MATCH_ENVRCPT_ALL(0.00)[]; RCVD_TLS_ALL(0.00)[] X-Spam-Score: -6.80 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 is used for both header and file name storage. Signed-off-by: David Disseldorp --- init/initramfs.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/init/initramfs.c b/init/initramfs.c index 4b7f20fbf23ae..c0aea453d2792 100644 --- a/init/initramfs.c +++ b/init/initramfs.c @@ -249,11 +249,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, 110, GotHeader); + read_into(cpio_buf, 110, GotHeader); return 0; } @@ -293,14 +293,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; } @@ -486,10 +486,14 @@ static char * __init unpack_to_rootfs(char *buf, unsigned long len) const char *compress_name; static __initdata char msg_buf[64]; - header_buf = kmalloc(110, 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) + /* + * @cpio_buf is first used for staging the 110 byte newc/crc cpio + * header, after which parse_header() converts and stashes fields into + * corresponding types. The same buffer is then reused for file path + * staging. 2 x PATH_MAX covers any possible symlink target. + */ + cpio_buf = kmalloc(N_ALIGN(PATH_MAX) + PATH_MAX + 1, GFP_KERNEL); + if (!cpio_buf) panic_show_mem("can't allocate buffers"); state = Start; @@ -534,8 +538,7 @@ static 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 Tue Oct 15 13:12:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Disseldorp X-Patchwork-Id: 13836434 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 42BE914A60D for ; Tue, 15 Oct 2024 13:30:40 +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=1728999041; cv=none; b=AePn42mrPGWCy2YbLdc2H9sisxdKI7naN2tAROJ8UxeZB1ma6+CyH2moXMgbVxairOOPrcB+IU7uAfuuuBU0dPKUQrSGhEUipHC0gZSU6Cuzi9BBYBR8UOjbXuZS+fqe5RZjXN4SzlE5RMwr1n3vcpu8MZ8kYoVPK51SRFJywiA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728999041; c=relaxed/simple; bh=C+TJgwOTuSZURjB6iXcKZ3Q9z0aJ94sz0D01lXhND2E=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rHQ43kiEhFqGAjqVHvHOv2kBeJ5ZOIg1tvcBz6xbrSFj9wu2Mmpeh4SwfsTVHI+WdsFOEFrlO69cwoSlpMx/08FwuJOKGHgO5dCFCcrKedKTAlh20Kh2GQ8Eg2vkWYDQSzixwpkJ8KznvIBXuWnnQUWbAz2NoL8gtYqFaFrIdEc= 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; 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 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 B524C21D8E; Tue, 15 Oct 2024 13:30:38 +0000 (UTC) Authentication-Results: smtp-out1.suse.de; none 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 D920713A42; Tue, 15 Oct 2024 13:30:36 +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 EIvEInxuDmcvcgAAD6G6ig (envelope-from ); Tue, 15 Oct 2024 13:30:36 +0000 From: David Disseldorp To: linux-fsdevel@vger.kernel.org Cc: Al Viro , Christian Brauner , David Disseldorp Subject: [RFC PATCH 5/6] initramfs: reuse buf for built-in and bootloader initramfs Date: Tue, 15 Oct 2024 13:12:02 +0000 Message-ID: <20241015133016.23468-6-ddiss@suse.de> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241015133016.23468-1-ddiss@suse.de> References: <20241015133016.23468-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-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Spamd-Result: default: False [-4.00 / 50.00]; REPLY(-4.00)[] X-Spam-Flag: NO X-Spam-Score: -4.00 X-Rspamd-Queue-Id: B524C21D8E X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Rspamd-Action: no action X-Rspamd-Server: rspamd1.dmz-prg2.suse.org X-Spam-Level: cpio_buf is allocated and freed within unpack_to_rootfs(), while the do_populate_rootfs() parent function may call it twice to unpack both built-in and bootloader-provided cpio archives. Move allocation out into the caller and reuse cpio_buf. Signed-off-by: David Disseldorp --- init/initramfs.c | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/init/initramfs.c b/init/initramfs.c index c0aea453d2792..7594a176d8d91 100644 --- a/init/initramfs.c +++ b/init/initramfs.c @@ -486,16 +486,6 @@ static char * __init unpack_to_rootfs(char *buf, unsigned long len) const char *compress_name; static __initdata char msg_buf[64]; - /* - * @cpio_buf is first used for staging the 110 byte newc/crc cpio - * header, after which parse_header() converts and stashes fields into - * corresponding types. The same buffer is then reused for file path - * staging. 2 x PATH_MAX covers any possible symlink target. - */ - cpio_buf = kmalloc(N_ALIGN(PATH_MAX) + PATH_MAX + 1, GFP_KERNEL); - if (!cpio_buf) - panic_show_mem("can't allocate buffers"); - state = Start; this_header = 0; message = NULL; @@ -538,7 +528,6 @@ static char * __init unpack_to_rootfs(char *buf, unsigned long len) len -= my_inptr; } dir_utime(); - kfree(cpio_buf); return message; } @@ -688,8 +677,20 @@ static void __init populate_initrd_image(char *err) static void __init do_populate_rootfs(void *unused, async_cookie_t cookie) { + char *err; + + /* + * @cpio_buf is first used for staging the 110 byte newc/crc cpio + * header, after which parse_header() converts and stashes fields into + * corresponding types. The same buffer is then reused for file path + * staging. 2 x PATH_MAX covers any possible symlink target. + */ + cpio_buf = kmalloc(N_ALIGN(PATH_MAX) + PATH_MAX + 1, GFP_KERNEL); + if (!cpio_buf) + panic_show_mem("can't allocate buffers"); + /* Load the built in initramfs */ - char *err = unpack_to_rootfs(__initramfs_start, __initramfs_size); + err = unpack_to_rootfs(__initramfs_start, __initramfs_size); if (err) panic_show_mem("%s", err); /* Failed to decompress INTERNAL initramfs */ @@ -711,6 +712,7 @@ static void __init do_populate_rootfs(void *unused, async_cookie_t cookie) } done: + kfree(cpio_buf); security_initramfs_populated(); /* From patchwork Tue Oct 15 13:12:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Disseldorp X-Patchwork-Id: 13836435 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 D750F14A60D for ; Tue, 15 Oct 2024 13:30:42 +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=1728999044; cv=none; b=R9jf/7bVwC86TRmf7368j2dnoFcyr9nJKOIeR0737FEhwnGRbhVhjPyOdNwsgInQWllmNyDicnly9cEGI6h4/9+yzRoI2uu71Rsyj7ZqVCBtA3z0Tq5I3RK2L2IpYvoREIOE5M9U9LwguzKwdxEyswBDDpq741V9ukhNN2etsw0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728999044; c=relaxed/simple; bh=TEZF/t8lA82lb7rM98auy44WfIzJGUwGTyKJvID814E=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jG7H4tKGG2U+relVQ0Onf4efc/O0G5LHzD/vlt9ulbEio7I7iVgv6bs6sjjRQppk4IrDxIvPtE96eo7VjDTF5ua+b+fXTaGQgbmwGxXyr7gH6UrI+jB4bpiKWgZrwyrb20sBMEzGx53xRX91S8GNTCtJMgkfIqfen+k2AUfF+f8= 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=RpJrs7M1; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=VZvtRKps; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=RpJrs7M1; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=VZvtRKps; 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="RpJrs7M1"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="VZvtRKps"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="RpJrs7M1"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="VZvtRKps" 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 2E97721DAF; Tue, 15 Oct 2024 13:30:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1728999041; 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=RsaCBDbLaw9klUnmeEZEErbNcuRPrGKCoviTHPf7KjI=; b=RpJrs7M1lF7rbYTtdhLpZmSupKgU0Esldx7YL58qDCIrSyccIC0H5fXRj+7x18zBf0qgut GY3Z7ojl0umnbV5S8ZccRhv9hjjMeMA5vU52mqga/nNMcvwRoPh7wlsgAUnXG+Qaw71q/n Hwe8w31tt9dA8xO+jXYsiAJLDtsJv94= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1728999041; 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=RsaCBDbLaw9klUnmeEZEErbNcuRPrGKCoviTHPf7KjI=; b=VZvtRKps2Iaxh9GlN+bs5fjKdq4E56ZzBJWGsvWjQjcRfqRoV8uj8O1HxCCPP83eHpxwim 2nrIcevrrE5BowCg== Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1728999041; 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=RsaCBDbLaw9klUnmeEZEErbNcuRPrGKCoviTHPf7KjI=; b=RpJrs7M1lF7rbYTtdhLpZmSupKgU0Esldx7YL58qDCIrSyccIC0H5fXRj+7x18zBf0qgut GY3Z7ojl0umnbV5S8ZccRhv9hjjMeMA5vU52mqga/nNMcvwRoPh7wlsgAUnXG+Qaw71q/n Hwe8w31tt9dA8xO+jXYsiAJLDtsJv94= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1728999041; 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=RsaCBDbLaw9klUnmeEZEErbNcuRPrGKCoviTHPf7KjI=; b=VZvtRKps2Iaxh9GlN+bs5fjKdq4E56ZzBJWGsvWjQjcRfqRoV8uj8O1HxCCPP83eHpxwim 2nrIcevrrE5BowCg== 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 5250C13A42; Tue, 15 Oct 2024 13:30:39 +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 mP/oAX9uDmcvcgAAD6G6ig (envelope-from ); Tue, 15 Oct 2024 13:30:39 +0000 From: David Disseldorp To: linux-fsdevel@vger.kernel.org Cc: Al Viro , Christian Brauner , David Disseldorp Subject: [RFC PATCH 6/6] initramfs: avoid static buffer for error message Date: Tue, 15 Oct 2024 13:12:03 +0000 Message-ID: <20241015133016.23468-7-ddiss@suse.de> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241015133016.23468-1-ddiss@suse.de> References: <20241015133016.23468-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 [-6.80 / 50.00]; REPLY(-4.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)[-1.000]; 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]; DBL_BLOCKED_OPENRESOLVER(0.00)[imap1.dmz-prg2.suse.org:helo,suse.de:email,suse.de:mid]; RCVD_COUNT_TWO(0.00)[2]; TO_MATCH_ENVRCPT_ALL(0.00)[]; RCVD_TLS_ALL(0.00)[] X-Spam-Score: -6.80 X-Spam-Flag: NO With cpio_buf now allocated / freed by the unpack_to_rootfs() caller, FSM-exit error messages can now be stashed in cpio_buf instead of in a static buffer. Before: text data bss dec hex filename 7423 1062 8 8493 212d ./init/initramfs.o After: text data bss dec hex filename 7423 966 8 8397 20cd ./init/initramfs.o Signed-off-by: David Disseldorp --- init/initramfs.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/init/initramfs.c b/init/initramfs.c index 7594a176d8d91..815a5daaa27ce 100644 --- a/init/initramfs.c +++ b/init/initramfs.c @@ -484,7 +484,6 @@ static 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]; state = Start; this_header = 0; @@ -514,10 +513,12 @@ static char * __init unpack_to_rootfs(char *buf, unsigned long len) error("decompressor failed"); } else if (compress_name) { if (!message) { - snprintf(msg_buf, sizeof msg_buf, + /* FSM exit: cpio_buf reuse is safe */ + snprintf(cpio_buf, + N_ALIGN(PATH_MAX) + PATH_MAX + 1, "compression method %s not configured", compress_name); - message = msg_buf; + message = cpio_buf; } } else error("invalid magic at start of compressed archive"); @@ -684,6 +685,7 @@ static void __init do_populate_rootfs(void *unused, async_cookie_t cookie) * header, after which parse_header() converts and stashes fields into * corresponding types. The same buffer is then reused for file path * staging. 2 x PATH_MAX covers any possible symlink target. + * On error, @err may point to a @cpio_buf backed error message. */ cpio_buf = kmalloc(N_ALIGN(PATH_MAX) + PATH_MAX + 1, GFP_KERNEL); if (!cpio_buf)