From patchwork Tue Sep 7 15:23:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Babic X-Patchwork-Id: 1525453 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=googlegroups.com header.i=@googlegroups.com header.a=rsa-sha256 header.s=20210112 header.b=HTe4H30/; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=googlegroups.com (client-ip=2a00:1450:4864:20::439; helo=mail-wr1-x439.google.com; envelope-from=swupdate+bncbcxploxj6ikrbz4h32eqmgqevwjpwmi@googlegroups.com; receiver=) Received: from mail-wr1-x439.google.com (mail-wr1-x439.google.com [IPv6:2a00:1450:4864:20::439]) (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 ozlabs.org (Postfix) with ESMTPS id 4H3ptz08Z7z9sW8 for ; Wed, 8 Sep 2021 01:23:22 +1000 (AEST) Received: by mail-wr1-x439.google.com with SMTP id t15-20020a5d42cf000000b001565f9c9ee8sf2240318wrr.2 for ; Tue, 07 Sep 2021 08:23:22 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1631028200; cv=pass; d=google.com; s=arc-20160816; b=GDfAeKfXP01lSpObxkKMJoAgnHU1Igaql+3jYJnb5uu198U4mcN0gDE6yw9CVu7YzB VIJar1cf/rmzfn565mfIxkRwcPgk2E7ceNfPFXwcERYxA0m+Y0kTrAPRwjXybHAFhuXE PvcTiABYAOVjUQz954VtpHMxGMtI+cvWvTSn44RBvPt8ZmoVGc/XhD4BWkkHoAL66yKE 1Ma9kpDWivJ+xqNOQBzRyS2WkTRz8HTpGH9Iw9VDAMYqZxEEmpN0pzRCvezivOqb+FW3 lDRpaCsO6B1VMPxrduM+v6WmYWWeqpi0idSC3EYyEsu6vmk7tN4wY11zBMrkiNwitLqn SoRg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :list-id:mailing-list:precedence:mime-version:message-id:date :subject:cc:to:from:sender:dkim-signature; bh=xmsOy3LPSsdeX23BuHJugbR/xaihMuGtR4zSqLbK5/I=; b=aI8qT5w8oVg5Elqs/239D+XCf/ZUQmceK1JKPwg3lPKW3O94XIMgb57r19qkVhl4Fx 0+nqBLP/1VI4f/AmBuz26NjFqK2Jp+6bLmz2Prt9a3ZDudbJwWfBISeOeqh/kUZAZjUs zU1sM5MfQcsXY/ni9CYzIVot5EBd2q4yPI4j2l1GA3KduHXY+/ZHijczNn/IA4Qaoslp 8uxx+4BVLBYTLFokzxVwgtHetghMxFGF5jdOWAY0BIahOzEWu5UDEqkBb5rHVsESmieZ uFUOTth3DFQNtarImRZ2rgI3vIHcemmC6Scu6OF4EZ5U+f5AHYzRQ0j1+FJQx3iXSimL Y34A== ARC-Authentication-Results: i=2; gmr-mx.google.com; spf=neutral (google.com: 212.18.0.10 is neither permitted nor denied by domain of sbabic@denx.de) smtp.mailfrom=sbabic@denx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:mime-version :x-original-sender:x-original-authentication-results:precedence :mailing-list:list-id:list-post:list-help:list-archive :list-subscribe:list-unsubscribe; bh=xmsOy3LPSsdeX23BuHJugbR/xaihMuGtR4zSqLbK5/I=; b=HTe4H30/3SOnvTLB5kiZxtnbNfnV5HGyRdBwJgIPGuiizM5ltATSc1m5xC26BAox9d KhWZ1pXEBvHEVBhQi8PDZK8W/ennDqeZJyPSuppHW6D+2M/t6AIvxEEBbpcTI+7+UFaP UgKrfo4is27DoD6PZ3EvZJ3ygwue/FzB8D6izaLiNzr9fZZRhApQtgaq2Us+6xeCIlUW ivjEeIC/9ExRNOERK3iY677LQugHtcOISm0S667JH/gAFzy8lQ6fwVXPGkPgOMtPkQjZ 47Qy3OTtv4jpsuE/SqUbvkAQxZT05D/g7QvdGnW3T3BnNfwEHvtYHaIjy/VAmWk2FEHn D7IQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=sender:x-gm-message-state:from:to:cc:subject:date:message-id :mime-version:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:x-spam-checked-in-group:list-post :list-help:list-archive:list-subscribe:list-unsubscribe; bh=xmsOy3LPSsdeX23BuHJugbR/xaihMuGtR4zSqLbK5/I=; b=H9w8bHKljps/XwczisJjjVGDsNhJYKgJZDpm50uBYY0f3L4wB7xix3nhS3xAsRYPlV nz8YwwVf4veYaIVH+0vF4AIpWT8P72ADg9DVbjFx6XgFTkQduJH20mZ/WpP1kuIIji7w FhOATYmCF00vWbJ+g35KAxa627hb+Tm//EvF2KwD0RinCJavOqdw1+vQwK4ic3Rgu9J+ C5/3srmwjb9UpC8Gis75om4Vyon50NWPqLlnY2c+uh2P/tmhTWhrBmBWnXx4Tiaji3OT dLQAzycDKtoHUz0a7mhyxiYM7DBYNwc5/w83P6NsMqOZ1hu1dnSYCDMa4xL/IPe96zFq CrMw== Sender: swupdate@googlegroups.com X-Gm-Message-State: AOAM531CMN5KKJIEqeYYQTnGB0e1ASd5e7/cJ1ncyYDK5R4varq8TlMP bnp6ezcXZbvHzKpL/OVvuV4= X-Google-Smtp-Source: ABdhPJyh56AssbqzAirzsJ0oVl8uAxb6Iizv3zKv8+HPf4U97YlQ+RzOQs5jWSjJ0mIWTvJv5PnFlw== X-Received: by 2002:a5d:4e51:: with SMTP id r17mr19317244wrt.308.1631028200122; Tue, 07 Sep 2021 08:23:20 -0700 (PDT) X-BeenThere: swupdate@googlegroups.com Received: by 2002:a7b:cb09:: with SMTP id u9ls1825261wmj.1.gmail; Tue, 07 Sep 2021 08:23:19 -0700 (PDT) X-Received: by 2002:a05:600c:1d27:: with SMTP id l39mr4521997wms.146.1631028199371; Tue, 07 Sep 2021 08:23:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631028199; cv=none; d=google.com; s=arc-20160816; b=Vy1gv8ZcPlGlKK8s4nr6Nphy+4rDu2JqWDRUh+IeBApB0YNrty4Zxl2B+Q7QS66BVE H7ccB6rhbTJfX8dtse1BDT44jJ2KLtV+5TKX1WR19n/nmq6xv6k/AasR5Lp0XEllB9Ny 29iR8lHxbKkeLNSeoNgmDqxeyS0EWPC/KeSBxkwmqqz37ajoIagNofZBmVLNXlj4j9Xq rWO+iJ3N9+9/lX/Me2n1Eh8woJNm+ZK/T2ZqLSNzjXIOs/cFAwnbFGsGaMu2fOVvLID8 Wryh//GyAbM+5jHqzhfZ1f10oalYA911znAd8vLKvipj2lN4e+4P5bEoddIVMu36VUIl o8oQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from; bh=6EP3kAklsk3UWegLfNSKG+e2fqC8/ULY2L2NsczORPI=; b=rw31BQg8mmQF7laNjnPKqVdf3ai9ME1wMRDsL6PSTKZbvAuxsY7GS/RxRptealtbKj xY6XPO6Gz8igjbo8Uy1GVuraEAnom0cBko1msGuvorzvCdnhbNcT5eX3Du6eWz65xE8X cyED48CDd3gbsiza6sdUTLgr65Rk7SGGRZvjkTAXZkRw4O+sZOE1h7XvJAURbmyq439z 55Oie0CAm4RhLPosYKi6CiuKtGxZH6JhioHxvGeBV3pKuMfuC2+U0kb7bAmMO3eQv4xu N/5dJU5yqWSddKyFsPDcQfBL1wJAHeA4TA7ZrWR6xk7+pcP5eTDPKS/c4eCoY4xA1Ppf on+w== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=neutral (google.com: 212.18.0.10 is neither permitted nor denied by domain of sbabic@denx.de) smtp.mailfrom=sbabic@denx.de Received: from mail-out.m-online.net (mail-out.m-online.net. [212.18.0.10]) by gmr-mx.google.com with ESMTPS id g8si382059wrh.0.2021.09.07.08.23.19 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 07 Sep 2021 08:23:19 -0700 (PDT) Received-SPF: neutral (google.com: 212.18.0.10 is neither permitted nor denied by domain of sbabic@denx.de) client-ip=212.18.0.10; Received: from frontend01.mail.m-online.net (unknown [192.168.8.182]) by mail-out.m-online.net (Postfix) with ESMTP id 4H3ptv0mskz1rk5D; Tue, 7 Sep 2021 17:23:19 +0200 (CEST) Received: from localhost (dynscan1.mnet-online.de [192.168.6.70]) by mail.m-online.net (Postfix) with ESMTP id 4H3ptv0Cm9z1qqkB; Tue, 7 Sep 2021 17:23:19 +0200 (CEST) X-Virus-Scanned: amavisd-new at mnet-online.de Received: from mail.mnet-online.de ([192.168.8.182]) by localhost (dynscan1.mail.m-online.net [192.168.6.70]) (amavisd-new, port 10024) with ESMTP id 6fhSn1STGrPs; Tue, 7 Sep 2021 17:23:18 +0200 (CEST) Received: from babic.homelinux.org (host-88-217-136-221.customer.m-online.net [88.217.136.221]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.mnet-online.de (Postfix) with ESMTPS; Tue, 7 Sep 2021 17:23:17 +0200 (CEST) Received: from localhost (mail.babic.homelinux.org [127.0.0.1]) by babic.homelinux.org (Postfix) with ESMTP id 5DE83454134E; Tue, 7 Sep 2021 17:23:17 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at babic.homelinux.org Received: from babic.homelinux.org ([IPv6:::1]) by localhost (mail.babic.homelinux.org [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id 1WCLQN2qcAfl; Tue, 7 Sep 2021 17:23:14 +0200 (CEST) Received: from paperino.fritz.box (paperino.fritz.box [192.168.178.48]) by babic.homelinux.org (Postfix) with ESMTP id A552E4540776; Tue, 7 Sep 2021 17:23:14 +0200 (CEST) From: Stefano Babic To: swupdate@googlegroups.com Cc: Stefano Babic Subject: [swupdate] [PATCH 1/2] Simplify footprint for get_cpiohdr Date: Tue, 7 Sep 2021 17:23:11 +0200 Message-Id: <20210907152312.93144-1-sbabic@denx.de> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Original-Sender: sbabic@denx.de X-Original-Authentication-Results: gmr-mx.google.com; spf=neutral (google.com: 212.18.0.10 is neither permitted nor denied by domain of sbabic@denx.de) smtp.mailfrom=sbabic@denx.de Precedence: list Mailing-list: list swupdate@googlegroups.com; contact swupdate+owners@googlegroups.com List-ID: X-Spam-Checked-In-Group: swupdate@googlegroups.com X-Google-Group-Id: 605343134186 List-Post: , List-Help: , List-Archive: , List-Unsubscribe: , Pass the pointer to the structure instead of the single fields. Signed-off-by: Stefano Babic --- core/cpio_utils.c | 13 ++++++------- core/stream_interface.c | 2 +- include/cpiohdr.h | 3 +-- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/core/cpio_utils.c b/core/cpio_utils.c index 67cc805..d1e2d6d 100644 --- a/core/cpio_utils.c +++ b/core/cpio_utils.c @@ -29,12 +29,11 @@ #define NPAD_BYTES(o) ((4 - (o % 4)) % 4) -int get_cpiohdr(unsigned char *buf, unsigned long *size, - unsigned long *namesize, unsigned long *chksum) +int get_cpiohdr(unsigned char *buf, struct filehdr *fhdr) { struct new_ascii_header *cpiohdr; - if (!buf) + if (!buf || !fhdr) return -EINVAL; cpiohdr = (struct new_ascii_header *)buf; @@ -45,9 +44,9 @@ int get_cpiohdr(unsigned char *buf, unsigned long *size, ERROR("CPIO Format not recognized: magic not found"); return -EINVAL; } - *size = FROM_HEX(cpiohdr->c_filesize); - *namesize = FROM_HEX(cpiohdr->c_namesize); - *chksum = FROM_HEX(cpiohdr->c_chksum); + fhdr->size = FROM_HEX(cpiohdr->c_filesize); + fhdr->namesize = FROM_HEX(cpiohdr->c_namesize); + fhdr->chksum = FROM_HEX(cpiohdr->c_chksum); return 0; } @@ -654,7 +653,7 @@ int extract_cpio_header(int fd, struct filehdr *fhdr, unsigned long *offset) unsigned char buf[sizeof(fhdr->filename)]; if (fill_buffer(fd, buf, sizeof(struct new_ascii_header), offset, NULL, NULL) < 0) return -EINVAL; - if (get_cpiohdr(buf, &fhdr->size, &fhdr->namesize, &fhdr->chksum) < 0) { + if (get_cpiohdr(buf, fhdr) < 0) { ERROR("CPIO Header corrupted, cannot be parsed"); return -EINVAL; } diff --git a/core/stream_interface.c b/core/stream_interface.c index da0c733..32d1da0 100644 --- a/core/stream_interface.c +++ b/core/stream_interface.c @@ -401,7 +401,7 @@ static int save_stream(int fdin, struct swupdate_cfg *software) ret = -EFAULT; goto no_copy_output; } - if (get_cpiohdr(buf, &fdh.size, &fdh.namesize, &fdh.chksum) < 0) { + if (get_cpiohdr(buf, &fdh) < 0) { ERROR("CPIO Header corrupted, cannot be parsed"); ret = -EINVAL; goto no_copy_output; diff --git a/include/cpiohdr.h b/include/cpiohdr.h index 21b8578..9d4bb92 100644 --- a/include/cpiohdr.h +++ b/include/cpiohdr.h @@ -49,8 +49,7 @@ struct filehdr { char filename[MAX_IMAGE_FNAME]; }; -int get_cpiohdr(unsigned char *buf, unsigned long *size, - unsigned long *namesize, unsigned long *chksum); +int get_cpiohdr(unsigned char *buf, struct filehdr *fhdr); int extract_cpio_header(int fd, struct filehdr *fhdr, unsigned long *offset); int extract_img_from_cpio(int fd, unsigned long offset, struct filehdr *fdh); void extract_padding(int fd, unsigned long *offset); From patchwork Tue Sep 7 15:23:12 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Babic X-Patchwork-Id: 1525454 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=googlegroups.com header.i=@googlegroups.com header.a=rsa-sha256 header.s=20210112 header.b=T+1sQbHx; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=googlegroups.com (client-ip=2a00:1450:4864:20::53e; helo=mail-ed1-x53e.google.com; envelope-from=swupdate+bncbcxploxj6ikrb2mh32eqmgqeptwnkda@googlegroups.com; receiver=) Received: from mail-ed1-x53e.google.com (mail-ed1-x53e.google.com [IPv6:2a00:1450:4864:20::53e]) (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 ozlabs.org (Postfix) with ESMTPS id 4H3pv618shz9sXk for ; Wed, 8 Sep 2021 01:23:30 +1000 (AEST) Received: by mail-ed1-x53e.google.com with SMTP id y19-20020a056402441300b003cd8ce2b987sf5486089eda.6 for ; Tue, 07 Sep 2021 08:23:29 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1631028201; cv=pass; d=google.com; s=arc-20160816; b=UBxLVkQ4vHNBKDB8du7fHU9d6EQdYLn/HKIoaZeGGHgjZPyGpcrS+NgdUBoM8zF5ui gCLUbYUlYAjw1i6QjsSJH9Yq67YIilY+RcjAQwJ2yQnaLrXY4Lo8ojRwxLf3jR6y5YUs Yu08BQxzwFm94yjQnQcCbgCUfoSzGOMkNJiHjq3ScvkvGLrEtb9L6dBQQ3J9of0JSeV+ t0sWp9vDWn65WBJJ4QvMahiUxxwxgfsTO39OzEyjoWlR8MoXHC8W5VlLhHVcib71hWYe uASnIJktFaHYvDOmAIqqBbixUq16Zj7IekzOwB4DyJCpIPeFWEzFrpfEVLi+1sf1rY4O Tlgw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :list-id:mailing-list:precedence:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:dkim-signature; bh=nF4+HA6UyfTE7Aag8mxz1zQlmy71TaW2bonaJCcCh3g=; b=DJ6G3LiKjcIaG2oAq/gkrOVWwTxqSAaWZYbkbZHHFG4aRCO0s606OaP/fPj7gcS4sf rmPsTvzoTcnbaC8YGBPDukogJYXafmXXqiI0cRUxzGTIwHYnOHOMqPyDVh1di8jZAfMx leVDhcPuCyuf1S1qVgQTbYgy8CmqQ4oxtkHE9xW5b5iPJr9Jn7oE5ZxTcEmcoa+8NRAL KszAVugikfvRhSMgHTMOokBXNdN6e8RF5Oc1dlg3+KIp31p733YWOWIu7jnlGZngx2IM 2C8n+2Ti3IrEBzzehFqM3d5yA5d4Ku/Tgl7sicKX5BVjP0A9bOR1VIIZMNOJDMKmZnGf n8CA== ARC-Authentication-Results: i=2; gmr-mx.google.com; spf=neutral (google.com: 212.18.0.9 is neither permitted nor denied by domain of sbabic@denx.de) smtp.mailfrom=sbabic@denx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-subscribe:list-unsubscribe; bh=nF4+HA6UyfTE7Aag8mxz1zQlmy71TaW2bonaJCcCh3g=; b=T+1sQbHxjW1+CHJ2XGRESkS0UJy7ZV3ld0sq7Ah8PTzKMt8VHTqbRVMy8Axp3j7lNH SmXq1Z87UmmoIHqHMWWM2LU8qZYxkIS5qoNKKTfWgwm77K50vLAJz8T4bHzbF6TmFWCm q6doYtbRAzHq/lLguLlxAU44i0iVCnzo/lmN8bISPGxvYVOC7xdLssTuI8Ar5scXJ33Y HPTeUVXyCWpt1EK9P25LtArORdkUjRvm9XMcN2Eic23AXBxda1w1NvcHQzN7nSukyUrc 0j9pOhmkX2CHrG+dA1qkIpsSuyr11/W6qmT4I/v7Ey4ltcWWw2EypIwIt9fsfAsQuPUS 9y8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=sender:x-gm-message-state:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :x-spam-checked-in-group:list-post:list-help:list-archive :list-subscribe:list-unsubscribe; bh=nF4+HA6UyfTE7Aag8mxz1zQlmy71TaW2bonaJCcCh3g=; b=glDbWLd9/ZL8RHgbRtejLF6upx2q3S1HAEHfx2LMEeEkVJODVNaXu+v9nKP4paY2ex NwqOq9CJuYLFcJCBrIQswmSdJ4lwuqtiyZYhttbToEPF+fkQ/PJYJ1E4HgwdrE0UkmtJ DUXDiS7Ft32rp+M6dutVAPyPul8g1UTD//gcTYT+RCeSq4aaH4FlyqQ1hTiU09wui5Dv tdw0kHw6xfFcel0nljTCbARkMMZ3H4isB5fHISRwvGRLnkl39zrsY7oDrsUgPGwL9WFV 5+IbbPK7b1XdkUMsi1R5p26tDSutDWuMR+vJXCouacI4Nc8qp3JSdMBwlsBoit85/Pzr 5lOA== Sender: swupdate@googlegroups.com X-Gm-Message-State: AOAM531BmsiZq/UMkJK4QHqgw0ySbu2ymVRiZ3UUXlhzsOKNN+buN7sd AqLQReEuZXohMxh/RqlROIY= X-Google-Smtp-Source: ABdhPJxHTLsExjgyLFono1ON0ijXHI38xL5VoSCO7mF72uWLyh9tA/S9zXqMaUlxS5wT3qcS9h47jQ== X-Received: by 2002:a17:906:1289:: with SMTP id k9mr19344553ejb.2.1631028201692; Tue, 07 Sep 2021 08:23:21 -0700 (PDT) X-BeenThere: swupdate@googlegroups.com Received: by 2002:aa7:c348:: with SMTP id j8ls4201393edr.0.gmail; Tue, 07 Sep 2021 08:23:20 -0700 (PDT) X-Received: by 2002:a50:8ad7:: with SMTP id k23mr19250343edk.310.1631028200252; Tue, 07 Sep 2021 08:23:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631028200; cv=none; d=google.com; s=arc-20160816; b=Q7xgTDvjVL64i9wiM/AcVy4UGhsQvuh4uqcicg8NckcBpQzSIDYJ+Cn886WGgdIADx keCJMP/uV2aZU/yMYvt5Bnw4BbLcHcWAZVptOnu0xlG/d+jQfhSH4ajDpTVmxU4FPqN/ NDKFQ8/5BGxkHuYsNIYf5kLnhYCk7zrtf/rwBvItfr4czxme/NmrmkRCXvcnCumIUxDj Npk2kHeHijkNmBwigmG14gODf0hwttwCNfvBv8nPcnvoYDcCy7yxI5+jQdYDR9d+JqCN JMSKrjptHmsHzlKmiEamEkBkYKfmMYkDQn4PtEQhRBWogvKev+ICfOSFvTQK0YqMmJEv B+0Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=NyWXVsEgE1cnC2XYw2k1yNKlKPrNVF3geUWbapGq0OA=; b=dVSB4Fs4oEIJKyBqy16xC1QTQ8l67FEViT1MQsB66HCHQNwATpwj+AMhRzP/iG7XXL 10iv7wQL9tWfzeq/AdxEiSIfGOKx5ifFmNYvghMWK0qW4xrpqf8T+z61b0RkqExksRAL nfNjT2Dej0AHfx60JvkPnDRSQUCYo4sHPOhNWpMWvZ/lsKONPMaaJf+wfulNtgdIrgII iUlWwJXvISmSER3rdmYH4CePPtAYpu376sqBz1nB09VbAEnj6fK+EJssq23672FQGnFB jlH0hUfVyBlUXhHX2HUa44/1UR+QRF+nvKJC25Ewk0klqgHN2Nv8RDApXJXhVC91H43L ha7Q== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=neutral (google.com: 212.18.0.9 is neither permitted nor denied by domain of sbabic@denx.de) smtp.mailfrom=sbabic@denx.de Received: from mail-out.m-online.net (mail-out.m-online.net. [212.18.0.9]) by gmr-mx.google.com with ESMTPS id w12si750046edj.5.2021.09.07.08.23.20 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 07 Sep 2021 08:23:20 -0700 (PDT) Received-SPF: neutral (google.com: 212.18.0.9 is neither permitted nor denied by domain of sbabic@denx.de) client-ip=212.18.0.9; Received: from frontend01.mail.m-online.net (unknown [192.168.8.182]) by mail-out.m-online.net (Postfix) with ESMTP id 4H3ptv6NTxz1qwdN; Tue, 7 Sep 2021 17:23:19 +0200 (CEST) Received: from localhost (dynscan1.mnet-online.de [192.168.6.70]) by mail.m-online.net (Postfix) with ESMTP id 4H3ptv69Blz1qqkB; Tue, 7 Sep 2021 17:23:19 +0200 (CEST) X-Virus-Scanned: amavisd-new at mnet-online.de Received: from mail.mnet-online.de ([192.168.8.182]) by localhost (dynscan1.mail.m-online.net [192.168.6.70]) (amavisd-new, port 10024) with ESMTP id arEUXjSqrlf9; Tue, 7 Sep 2021 17:23:18 +0200 (CEST) Received: from babic.homelinux.org (host-88-217-136-221.customer.m-online.net [88.217.136.221]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.mnet-online.de (Postfix) with ESMTPS; Tue, 7 Sep 2021 17:23:18 +0200 (CEST) Received: from localhost (mail.babic.homelinux.org [127.0.0.1]) by babic.homelinux.org (Postfix) with ESMTP id 913414540776; Tue, 7 Sep 2021 17:23:18 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at babic.homelinux.org Received: from babic.homelinux.org ([127.0.0.1]) by localhost (mail.babic.homelinux.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id KXb3fY3kTLPn; Tue, 7 Sep 2021 17:23:14 +0200 (CEST) Received: from paperino.fritz.box (paperino.fritz.box [192.168.178.48]) by babic.homelinux.org (Postfix) with ESMTP id B4D1D4540C3E; Tue, 7 Sep 2021 17:23:14 +0200 (CEST) From: Stefano Babic To: swupdate@googlegroups.com Cc: Stefano Babic Subject: [swupdate] [PATCH 2/2] Replace CONFIG_DISABLE_CPIO_CRC with dynamic check Date: Tue, 7 Sep 2021 17:23:12 +0200 Message-Id: <20210907152312.93144-2-sbabic@denx.de> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210907152312.93144-1-sbabic@denx.de> References: <20210907152312.93144-1-sbabic@denx.de> MIME-Version: 1.0 X-Original-Sender: sbabic@denx.de X-Original-Authentication-Results: gmr-mx.google.com; spf=neutral (google.com: 212.18.0.9 is neither permitted nor denied by domain of sbabic@denx.de) smtp.mailfrom=sbabic@denx.de Precedence: list Mailing-list: list swupdate@googlegroups.com; contact swupdate+owners@googlegroups.com List-ID: X-Spam-Checked-In-Group: swupdate@googlegroups.com X-Google-Group-Id: 605343134186 List-Post: , List-Help: , List-Archive: , List-Unsubscribe: , SWUpdate supports both new ascii and crc ascii (default) formats. If checksum in CPIO should not be verified, just simply switch to new ascii and the check is disabled automatically by SWUpdate. Signed-off-by: Stefano Babic --- Kconfig | 15 --------------- core/cpio_utils.c | 26 +++++++++++++++++++------- core/stream_interface.c | 6 +++--- include/cpiohdr.h | 8 ++++++++ include/util.h | 16 ---------------- 5 files changed, 30 insertions(+), 41 deletions(-) diff --git a/Kconfig b/Kconfig index dc86957..cb86d55 100644 --- a/Kconfig +++ b/Kconfig @@ -423,21 +423,6 @@ config HASH_VERIFY comment "Hash checking needs an SSL implementation" depends on !SSL_IMPL_OPENSSL && !SSL_IMPL_WOLFSSL && !SSL_IMPL_MBEDTLS -config DISABLE_CPIO_CRC - bool "Disable cpio CRC verify if SHA 256 is enabled" - depends on HASH_VERIFY - default n - help - Disable CRC check in cpio header if sha256 is enabled. - CRC in CPIO is not a real crc, but it is simply the sum - of all bytes belonging to a file as 32 bit value. It is - very weak and does not add any further safety if sha256 - is activated. CPIO in Linux distros has also a bug and - CRC field is set to 0 when a file is larger as 2GB. - - SWUpdate supports the newc cpio format if this is - selected. That format does not have a checksum. - config SIGNED_IMAGES bool "Enable verification of signed images" depends on SSL_IMPL_OPENSSL || SSL_IMPL_WOLFSSL || SSL_IMPL_MBEDTLS diff --git a/core/cpio_utils.c b/core/cpio_utils.c index d1e2d6d..2e4aca3 100644 --- a/core/cpio_utils.c +++ b/core/cpio_utils.c @@ -37,12 +37,13 @@ int get_cpiohdr(unsigned char *buf, struct filehdr *fhdr) return -EINVAL; cpiohdr = (struct new_ascii_header *)buf; -#ifdef CONFIG_DISABLE_CPIO_CRC - if (strncmp(cpiohdr->c_magic, "070701", 6) != 0) -#endif - if (strncmp(cpiohdr->c_magic, "070702", 6) != 0) { + if (!strncmp(cpiohdr->c_magic, "070701", 6)) + fhdr->format = CPIO_NEWASCII; + else if (!strncmp(cpiohdr->c_magic, "070702", 6)) + fhdr->format = CPIO_CRCASCII; + else { ERROR("CPIO Format not recognized: magic not found"); - return -EINVAL; + return -EINVAL; } fhdr->size = FROM_HEX(cpiohdr->c_filesize); fhdr->namesize = FROM_HEX(cpiohdr->c_namesize); @@ -736,7 +737,7 @@ off_t extract_next_file(int fd, int fdout, off_t start, int compressed, (unsigned long)checksum, (checksum == fdh.chksum) ? "VERIFIED" : "WRONG"); - if (!swupdate_verify_chksum(checksum, fdh.chksum)) { + if (!swupdate_verify_chksum(checksum, &fdh)) { return -EINVAL; } @@ -780,7 +781,7 @@ int cpio_scan(int fd, struct swupdate_cfg *cfg, off_t start) return -1; } - if (!swupdate_verify_chksum(fdh.chksum, checksum)) { + if (!swupdate_verify_chksum(checksum, &fdh)) { return -1; } @@ -794,3 +795,14 @@ int cpio_scan(int fd, struct swupdate_cfg *cfg, off_t start) return 0; } + +bool swupdate_verify_chksum(const uint32_t chk1, struct filehdr *fhdr) { + bool ret = (chk1 == fhdr->chksum); + if (fhdr->format == CPIO_NEWASCII) + return true; + if (!ret) { + ERROR("Checksum WRONG ! Computed 0x%ux, it should be 0x%ux", + chk1, (uint32_t)fhdr->chksum); + } + return ret; +} diff --git a/core/stream_interface.c b/core/stream_interface.c index 32d1da0..19ce3ce 100644 --- a/core/stream_interface.c +++ b/core/stream_interface.c @@ -108,7 +108,7 @@ static int extract_file_to_tmp(int fd, const char *fname, unsigned long *poffs, close(fdout); return -1; } - if (!swupdate_verify_chksum(checksum, fdh.chksum)) { + if (!swupdate_verify_chksum(checksum, &fdh)) { close(fdout); return -1; } @@ -230,7 +230,7 @@ static int extract_files(int fd, struct swupdate_cfg *software) close(fdout); return -1; } - if (!swupdate_verify_chksum(checksum, fdh.chksum)) { + if (!swupdate_verify_chksum(checksum, &fdh)) { close(fdout); return -1; } @@ -241,7 +241,7 @@ static int extract_files(int fd, struct swupdate_cfg *software) if (copyfile(fd, &fdout, fdh.size, &offset, 0, skip, 0, &checksum, NULL, false, NULL, NULL) < 0) { return -1; } - if (!swupdate_verify_chksum(checksum, fdh.chksum)) { + if (!swupdate_verify_chksum(checksum, &fdh)) { return -1; } break; diff --git a/include/cpiohdr.h b/include/cpiohdr.h index 9d4bb92..d263776 100644 --- a/include/cpiohdr.h +++ b/include/cpiohdr.h @@ -15,7 +15,10 @@ #define _CPIOHDR_SWUPD_H /* Global swupdate defines */ +#include +#include #include "globals.h" +#include /* * cpio header - swupdate does not @@ -24,6 +27,9 @@ * documentation is supported. */ +#define CPIO_NEWASCII 070701 +#define CPIO_CRCASCII 070702 + struct new_ascii_header { char c_magic[6]; @@ -43,6 +49,7 @@ struct new_ascii_header }; struct filehdr { + unsigned long format; unsigned long size; unsigned long namesize; unsigned long chksum; @@ -53,5 +60,6 @@ int get_cpiohdr(unsigned char *buf, struct filehdr *fhdr); int extract_cpio_header(int fd, struct filehdr *fhdr, unsigned long *offset); int extract_img_from_cpio(int fd, unsigned long offset, struct filehdr *fdh); void extract_padding(int fd, unsigned long *offset); +bool swupdate_verify_chksum(const uint32_t chk1, struct filehdr *fhdr); #endif diff --git a/include/util.h b/include/util.h index 9f29f5f..3d1b2ff 100644 --- a/include/util.h +++ b/include/util.h @@ -134,22 +134,6 @@ void notifier_set_color(int level, char *col); #define LG_16 4 #define FROM_HEX(f) from_ascii (f, sizeof f, LG_16) -#if !defined(CONFIG_DISABLE_CPIO_CRC) -static inline bool swupdate_verify_chksum(const uint32_t chk1, const uint32_t chk2) { - bool ret = (chk1 == chk2); - if (!ret) { - ERROR("Checksum WRONG ! Computed 0x%ux, it should be 0x%ux", - chk1, chk2); - } - return ret; -} -#else -static inline bool swupdate_verify_chksum( - const uint32_t __attribute__ ((__unused__))chk1, - const uint32_t __attribute__ ((__unused__))chk2) { - return true; -} -#endif uintmax_t from_ascii (char const *where, size_t digs, unsigned logbase); int ascii_to_hash(unsigned char *hash, const char *s);