From patchwork Mon Dec 13 23:20:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Disseldorp X-Patchwork-Id: 12674825 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6D14BC433EF for ; Mon, 13 Dec 2021 23:27:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242172AbhLMX1r (ORCPT ); Mon, 13 Dec 2021 18:27:47 -0500 Received: from smtp-out2.suse.de ([195.135.220.29]:46204 "EHLO smtp-out2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237209AbhLMX1r (ORCPT ); Mon, 13 Dec 2021 18:27:47 -0500 Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id 67D7C1F3C4; Mon, 13 Dec 2021 23:27:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1639438066; 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=1ly1qWDMyzaC9LSjWtQrvzZF4gUZP1qfdd/b/C0c1M4=; b=Z6pq6063Bn93u4jVS40eSlDsB4bwuLxRSjb9OeHXzsZ7dLd1RkFKdKTH4RfcFpSbmVlo8i wv8M7n8fAIuueQxw/IJpO807/FvI4eRkJo6R1NtBbxIjdVESXLoCt17O4mWdhOVy4MDYoN EFB1d4Q/yfG9NiwxO2Q6No4JWMvp7q0= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1639438066; 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=1ly1qWDMyzaC9LSjWtQrvzZF4gUZP1qfdd/b/C0c1M4=; b=qJeWp/qQ8ILoHU7oHdx/qqnBEl8ah9U3hv1hGTLLgZk0Tg53u+pQ1GT1HKuOSm3S4zp2Ik 3S8EdR7hTcsOhcDQ== Received: from echidna.suse.de (unknown [10.163.47.146]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id 3C6B2A3B83; Mon, 13 Dec 2021 23:27:46 +0000 (UTC) From: David Disseldorp To: linux-fsdevel@vger.kernel.org Cc: Martin Wilck , viro@zeniv.linux.org.uk, willy@infradead.org, David Disseldorp Subject: [PATCH v5 1/5] initramfs: refactor do_header() cpio magic checks Date: Tue, 14 Dec 2021 00:20:04 +0100 Message-Id: <20211213232007.26851-2-ddiss@suse.de> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211213232007.26851-1-ddiss@suse.de> References: <20211213232007.26851-1-ddiss@suse.de> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org do_header() is called for each cpio entry and fails if the first six bytes don't match "newc" magic. The magic check includes a special case error message if POSIX.1 ASCII (cpio -H odc) magic is detected. This special case POSIX.1 check can be nested under the "newc" mismatch code path to avoid calling memcmp() twice in a non-error case. Signed-off-by: David Disseldorp Reviewed-by: Martin Wilck --- init/initramfs.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/init/initramfs.c b/init/initramfs.c index 2f3d96dc3db6..2f79b3ec0b40 100644 --- a/init/initramfs.c +++ b/init/initramfs.c @@ -257,12 +257,11 @@ static int __init do_collect(void) static int __init do_header(void) { - if (memcmp(collected, "070707", 6)==0) { - error("incorrect cpio method used: use -H newc option"); - return 1; - } if (memcmp(collected, "070701", 6)) { - error("no cpio magic"); + if (memcmp(collected, "070707", 6) == 0) + error("incorrect cpio method used: use -H newc option"); + else + error("no cpio magic"); return 1; } parse_header(collected);