From patchwork Thu Jul 26 08:21:24 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Babic X-Patchwork-Id: 949534 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=googlegroups.com (client-ip=2a00:1450:400c:c09::23c; helo=mail-wm0-x23c.google.com; envelope-from=swupdate+bncbcxploxj6ikrbcuj43nakgqe7pttw3a@googlegroups.com; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=denx.de Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=googlegroups.com header.i=@googlegroups.com header.b="Zvzki+Ux"; dkim-atps=neutral Received: from mail-wm0-x23c.google.com (mail-wm0-x23c.google.com [IPv6:2a00:1450:400c:c09::23c]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41blRx3JV1z9ryl for ; Thu, 26 Jul 2018 18:21:32 +1000 (AEST) Received: by mail-wm0-x23c.google.com with SMTP id c14-v6sf636275wmb.2 for ; Thu, 26 Jul 2018 01:21:32 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1532593290; cv=pass; d=google.com; s=arc-20160816; b=gi/fD92Teqx1xqRpKpnHaUfVhlju+4HKnyiX4HgT5A6I9L24VA3X/1vSFacK14Mjjv fHewp1adXXtq5yCkCcvC546HsR79DID0vEc4nmMFfS994Fpi3tSdXYE78Ygsf2K3nG1o fas1npOL1nfRuQ/TtFlCgdCm07q87zuc62UiXM6ZcFt8pszP0miNhpoTqReg1/KHy5hA WIT0w5uEMqQaNCtGiEK+tTMpn6ZurDdLNNLclnAquVvyDZOWrZHYV7quqTc2vJQGFmAz xzLayiHwws4/HLPS4kcwd/3ByOSMkZzlFwCXpFK/uC2ckwRYwqwq0nTIf1xxaSFkarTT MfBQ== 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:message-id:date:subject:cc:to:from :arc-authentication-results:arc-message-signature:mime-version :sender:dkim-signature:arc-authentication-results; bh=WWkh400KItwQpr1UkHuY/bm0YVb2Jm/CjbcQ/YYTea4=; b=V+g7Ob4PR6WaWVa+MfTuZk/BLeTBNI5Kwdfc0qPb3IB0+dBVcuY0RwpGAc66N+aOtX egoc4/DHfK5Z561w9wtPWMx5G4KZl/vJgn2YdWUYYHftufWlAXGbWrsKVgvGYGJRXu6w 9aT18cnsSxuaYUuPlBZefefFsKTkXjHCpwlL+lV/JTWNlyUYdd3t7V6QD1uG2yDt1i8c pnOnd9bxUDwAxo0ct9JINvht+mrxV7ALfUzMWrKqqq3iVOTKGMavqTUSMLLRTj+XH8XS oSMB3k5TIKRaOe90ISn5VlPKGe1aomLSG/pvN0PJd7pzoSrSVBxJMwtXPOjsQR0Ggmk3 xiYA== ARC-Authentication-Results: i=2; gmr-mx.google.com; spf=neutral (google.com: 212.18.0.9 is neither permitted nor denied by best guess record for domain of sbabic@denx.de) smtp.mailfrom=sbabic@denx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20161025; h=sender:mime-version:from:to:cc:subject:date:message-id :x-original-sender:x-original-authentication-results:precedence :mailing-list:list-id:list-post:list-help:list-archive :list-subscribe:list-unsubscribe; bh=WWkh400KItwQpr1UkHuY/bm0YVb2Jm/CjbcQ/YYTea4=; b=Zvzki+UxCK7L5zqJxqbJRXOIdOpILznlqJLIhZfIPZuG0QWwWoWyOjuDO+VNdVtRKX fNMFeA+N+Oeib3HqDw1UN696kUiKahkvC20nZo783VO4a/HwjpQsYb0esh8Qaqpqewzv CvOK34dVDrIcomhamhnk4Dt6ZdgK8o4b/zNfRDupN4ltcC07tOl/qevWPyrT7RbaU36a yQ/83pN5fHbEqDe6TDJ0N88CuN9Lu5zAEvRAECo0nCMQy2wFmhXsOOwEXnBifJrMxcDr WVT+opgmyHyrHQOX09zOrjUcLw9IpgrHxBykeEmKsprp7abf/CjNFHXCRjppbZAM/tbb YXJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=sender:x-gm-message-state:mime-version:from:to:cc:subject:date :message-id: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=WWkh400KItwQpr1UkHuY/bm0YVb2Jm/CjbcQ/YYTea4=; b=K/oaJOGlfBWn5akiqjr2h/o6bLWCUgCb/0cmcQG8TPPAJYBYtIQUz4/1wnFHWVyPkW vo3En5nFoiaxvL7riULgk3S/ZPf9cR5nPlfBpy0zbB1Yp3e2Ool3Nbw1CgDmY9oTnjGC fAvu//ydS362wHcqkwBBsx3g37La6AiMLPW+SHbD779WbHRJuXn8+QcuoxDKK3WbGQr0 GBQ3m+Y3ZyA1DsbWmppVCP+a8Th4GSf6EsJ/mbTHmp/MhjbyIL9pVFGfchY8SEKE/BZ5 Ir7DqtN7hFD4tvh9nF7TC4TPOCd2B2vpIrlFyK9xjISiDulgKZDhR8SiviBI6epVNWi4 ontg== Sender: swupdate@googlegroups.com X-Gm-Message-State: AOUpUlH9kfEt9BX5VQ+ckbjDvQ89gHXa3cL1tmn2N5yz4fntEFqLtF31 sBgc5bXZqGhWfA01lDTRVSY= X-Google-Smtp-Source: AAOMgpcthNtGF4bN5uQNNCwOiQCcotpNZ5jIE8RT7FSnYsHnzZu8f4kYH9fBOSs+csRtRL1Fr2jXwA== X-Received: by 2002:adf:fec3:: with SMTP id q3-v6mr10627wrs.2.1532593290284; Thu, 26 Jul 2018 01:21:30 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: swupdate@googlegroups.com Received: by 2002:a5d:654c:: with SMTP id z12-v6ls1424673wrv.2.gmail; Thu, 26 Jul 2018 01:21:29 -0700 (PDT) X-Received: by 2002:adf:e943:: with SMTP id m3-v6mr77060wrn.13.1532593289852; Thu, 26 Jul 2018 01:21:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532593289; cv=none; d=google.com; s=arc-20160816; b=PQGtJq8G17oIyTSTUMwQyxlX2i8/jzaSK7j4wuNvJo1H3/0sUuRxAjftYV+t4liKHV 5duW/twE23eoCx/5wluNQA56IQOyjZD5YggFBW7RSvBGSNIlFF64kUpcW7RwC2TX3jAz ptnoX+Yl/bd8a3bBId0Vt53eX1EH0kxskdUNOId4Pq5HCpb0bi9mKIVf2x+juudJCzG7 pfEcrK9qcTNAPZX0Xn2uY0Fw+DfGWWtcOOb66QrC7HeEAqd3frgvDly5VXub3YRJFd3a 7HfpCRBFHr/pobaTcxLCkPy7g02uCEWDiiP+/5+0cHwNdJJ8N+NNVY/zqUIFph9h5E+6 FqcA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:date:subject:cc:to:from:arc-authentication-results; bh=v+eWSb4ys2xwCU7WMGwpMv22xHwYGdDPUQGeUwLYOg0=; b=x2ptU/iDicRHI42Jckfqb9Wz+Mav8RHKSmysvLXp8dVj4hfSeW3EIht+nu5uuAHVDH beDuzVjxyiTT6Qryzj+xBH19lN9CjL/p7eoc0fFLm4igE6Gvvi+x1IwgqN5i8bT3iNjw gIahtszVLvjvbnjWF2r3PX7WyDnzvvLj3+OyL2/GHlXbzlXB/4noh32sUDaKyGzSraBR Piw1qtExlXz0OAsBN/Ox2yaCHSLJwd4FoP1HneXQ4OEMjLg7VMk8Ef4GzKi6ztXPZ7xA rfnsenkRRHRfauhRXMqAAUzvth7Z68K5EHFogji/tMw3AU3OfEsnfsXp8IQuo7+hJ4DQ tWhg== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=neutral (google.com: 212.18.0.9 is neither permitted nor denied by best guess record for 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 s11-v6si26913wrr.3.2018.07.26.01.21.29 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 26 Jul 2018 01:21:29 -0700 (PDT) Received-SPF: neutral (google.com: 212.18.0.9 is neither permitted nor denied by best guess record for 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 41blRs4q47z1qxR2; Thu, 26 Jul 2018 10:21:29 +0200 (CEST) Received: from localhost (dynscan1.mnet-online.de [192.168.6.70]) by mail.m-online.net (Postfix) with ESMTP id 41blRs4X0nz1qqkt; Thu, 26 Jul 2018 10:21:29 +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 H0YCgNu4i4sV; Thu, 26 Jul 2018 10:21:28 +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; Thu, 26 Jul 2018 10:21:28 +0200 (CEST) Received: from localhost (mail.babic.homelinux.org [127.0.0.1]) by babic.homelinux.org (Postfix) with ESMTP id 458854540439; Thu, 26 Jul 2018 10:21:28 +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 9IVxjap2t1FH; Thu, 26 Jul 2018 10:21:25 +0200 (CEST) Received: from papero.fritz.box (papero.fritz.box [192.168.178.132]) by babic.homelinux.org (Postfix) with ESMTP id 943BF4540374; Thu, 26 Jul 2018 10:21:25 +0200 (CEST) From: Stefano Babic To: swupdate@googlegroups.com Cc: karim.lazhard@gmail.com, Stefano Babic Subject: [swupdate] [PATCH] Check if sw-description is really extracted when installed from file Date: Thu, 26 Jul 2018 10:21:24 +0200 Message-Id: <1532593284-10004-1-git-send-email-sbabic@denx.de> X-Mailer: git-send-email 2.7.4 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 best guess record for 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: , The -c (check) option verifies sw-description and signature. However, it does not check if the files are correctly extracted before verifying. If files were already extracted by a previous run, the result can still be successful even if the SWU is completely wrong. This does not happen in case of network install because files are cleaned up after run. Check that the extraction of sw-description and sw-description.sig is successful before parsing them. Signed-off-by: Stefano Babic Reported-by: Karim Lazhard --- core/cpio_utils.c | 8 +++++--- core/swupdate.c | 14 +++++++++++--- include/swupdate.h | 1 - include/util.h | 2 +- 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/core/cpio_utils.c b/core/cpio_utils.c index 4930277..bd713af 100644 --- a/core/cpio_utils.c +++ b/core/cpio_utils.c @@ -509,10 +509,10 @@ int extract_cpio_header(int fd, struct filehdr *fhdr, unsigned long *offset) return 0; } -off_t extract_sw_description(int fd, const char *descfile, off_t start) +int extract_sw_description(int fd, const char *descfile, off_t *offs) { struct filehdr fdh; - unsigned long offset = start; + unsigned long offset = *offs; char output_file[64]; uint32_t checksum; int fdout; @@ -562,7 +562,9 @@ off_t extract_sw_description(int fd, const char *descfile, off_t start) return -1; } - return offset; + *offs = offset; + + return 0; } int extract_img_from_cpio(int fd, unsigned long offset, struct filehdr *fdh) diff --git a/core/swupdate.c b/core/swupdate.c index ec944d0..3f872e4 100644 --- a/core/swupdate.c +++ b/core/swupdate.c @@ -299,11 +299,19 @@ static int install_from_file(char *fname, int check) } } - pos = extract_sw_description(fdsw, SW_DESCRIPTION_FILENAME, 0); + pos = 0; + ret = extract_sw_description(fdsw, SW_DESCRIPTION_FILENAME, &pos); #ifdef CONFIG_SIGNED_IMAGES - pos = extract_sw_description(fdsw, SW_DESCRIPTION_FILENAME ".sig", - pos); + ret = extract_sw_description(fdsw, SW_DESCRIPTION_FILENAME ".sig", + &pos); #endif + /* + * Check if files could be extracted + */ + if (ret) { + ERROR("Failed to extract meta information"); + exit(1); + } char* swdescfilename = alloca(strlen(get_tmpdir())+strlen(SW_DESCRIPTION_FILENAME)+1); sprintf(swdescfilename, "%s%s", get_tmpdir(), SW_DESCRIPTION_FILENAME); diff --git a/include/swupdate.h b/include/swupdate.h index 455e4ad..741d24c 100644 --- a/include/swupdate.h +++ b/include/swupdate.h @@ -150,7 +150,6 @@ struct swupdate_cfg { } \ } while(0) -off_t extract_sw_description(int fd, const char *descfile, off_t start); int cpio_scan(int fd, struct swupdate_cfg *cfg, off_t start); struct swupdate_cfg *get_swupdate_cfg(void); void free_image(struct img_type *img); diff --git a/include/util.h b/include/util.h index 48dc538..c64e462 100644 --- a/include/util.h +++ b/include/util.h @@ -139,7 +139,7 @@ int copyfile(int fdin, void *out, unsigned int nbytes, unsigned long *offs, int skip_file, int compressed, uint32_t *checksum, unsigned char *hash, int encrypted, writeimage callback); int copyimage(void *out, struct img_type *img, writeimage callback); -off_t extract_sw_description(int fd, const char *descfile, off_t start); +int extract_sw_description(int fd, const char *descfile, off_t *offs); off_t extract_next_file(int fd, int fdout, off_t start, int compressed, int encrypted, unsigned char *hash); int openfileoutput(const char *filename);