From patchwork Fri Jan 3 00:46:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Petr_=C5=A0tetiar?= X-Patchwork-Id: 1217175 X-Patchwork-Delegate: ynezz@true.cz Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.openwrt.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=true.cz Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="pEhJRPaV"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (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 47pmSm0C2Cz9sPK for ; Fri, 3 Jan 2020 11:47:04 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Subject:MIME-Version:References: In-Reply-To:Message-Id:Date:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=Gfqm8w5OEhJ4cpdnGekVyjHRypkYGJzwQWxgWB8Iha0=; b=pEhJRPaVRMeh8j PchzTmuoCaiTttiimDen/XkfZ1pf4ChxroF0wULXzm24UC1gdSwngPIysQvDMgxd/qzCwzDFgHQ31 2XA8b2Bb7uWizYsCBhDHHqy9P7ZMo1aH77nWu40l5qIrVmA1Ss2H+4Aa9mMacdDclVuVl3/cn4mVl 8+boTtDHAIH84zxaZNAaSjlLX/xR8iBivZpPWIBsDsyiJoVxI7AO5w4IrC1Cm0EYgdOVAPR2IS/lQ U/XCvXYVHZVQqKPCdAnjvmeqcce1Ai3d0XwPmMFenpfssJFyxd9dhJVSzCNEJBa0tmnjtHEFJ8ZDC 0k4NG48zuXR3wvoH/MTw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1inB7B-0008Mq-09; Fri, 03 Jan 2020 00:46:57 +0000 Received: from smtp-out.xnet.cz ([178.217.244.18]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1inB70-0008D3-Mn for openwrt-devel@lists.openwrt.org; Fri, 03 Jan 2020 00:46:48 +0000 Received: from meh.true.cz (meh.true.cz [108.61.167.218]) (Authenticated sender: petr@true.cz) by smtp-out.xnet.cz (Postfix) with ESMTPSA id CBFDB36CD; Fri, 3 Jan 2020 01:46:42 +0100 (CET) Received: by meh.true.cz (OpenSMTPD) with ESMTP id 9ceca4fd; Fri, 3 Jan 2020 01:46:32 +0100 (CET) From: =?utf-8?q?Petr_=C5=A0tetiar?= To: openwrt-devel@lists.openwrt.org Date: Fri, 3 Jan 2020 01:46:36 +0100 Message-Id: <20200103004638.16307-3-ynezz@true.cz> In-Reply-To: <20200103004638.16307-1-ynezz@true.cz> References: <20200103004638.16307-1-ynezz@true.cz> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200102_164646_912249_FF75D04A X-CRM114-Status: UNSURE ( 9.02 ) X-CRM114-Notice: Please train this message. X-Spam-Score: 0.0 (/) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [178.217.244.18 listed in list.dnswl.org] 0.0 SPF_NONE SPF: sender does not publish an SPF Record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record Subject: [OpenWrt-Devel] [PATCH procd 2/4] system: fix failing image validation due to EINTR X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= , =?utf-8?q?Petr_=C5=A0tetiar?= Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org It was quite common to see following error during sysupgrade on serial console: Failed to parse JSON: 4 This is happening due to the fact, that validate_firmware_image_call fork()s then waits in blocking read() for the input from the child process, but child finishes its tasks and exits, thus emitting SIGCHLD signal which then leads to the interruption of the blocking read() in the parent process with EINTR error. It seems like the recent fixes in the libubox library, particulary in the jshn sub-component (which empowers json_dump used in the shell script executed by the child process) made the execution somehow faster, thus exposing this racy behaviour in the validate_firmware_image_call at least on RPi-4 (Cortex-A72) target. So this patch fixes this issue by checking the read() return value and retrying the read() if interrupted due to the EINTR error. Ref: http://lists.infradead.org/pipermail/openwrt-devel/2020-January/020994.html Fixes: e990e215e8a3 ("system: add "validate_firmware_image" ubus method") Cc: Rafał Miłecki Reported-by: Petr Novák Signed-off-by: Petr Štetiar Reviewed-by: Hauke Mehrtens --- system.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/system.c b/system.c index 65d3f09b7fb6..5cd88e0d8227 100644 --- a/system.c +++ b/system.c @@ -466,6 +466,9 @@ static int validate_firmware_image_call(const char *file) blob_buf_init(&b, 0); while ((len = read(fds[0], buf, sizeof(buf)))) { + if (len < 0 && errno == EINTR) + continue; + jsobj = json_tokener_parse_ex(tok, buf, len); if (json_tokener_get_error(tok) == json_tokener_success)