From patchwork Sun May 17 19:46:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Thibaut X-Patchwork-Id: 1292228 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=fail (p=quarantine dis=none) header.from=slashdirt.org Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20170209 header.b=hc6biKt2; dkim=fail reason="signature verification failed" (1024-bit key; secure) header.d=slashdirt.org header.i=@slashdirt.org header.a=rsa-sha256 header.s=mail header.b=p7G1CBee; 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 49QCMT0WM9z9sT4 for ; Mon, 18 May 2020 05:46:41 +1000 (AEST) 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=j9qxyyeVJ9qNdce9I6k76sxbvUEHNSMirwvvl+hkeog=; b=hc6biKt2aLuqAi ij2Gul4ta1qObHYTeVlnP2IOswij6xPDzAerB/GFzcfBLxAJJIOYjw38OO0xHNxlS2TGytIciXFVk jqDSJmIGI2kkZHy9ZA5e3xVVdUwzvVq1qHNMs+I59FAzL3/LfF9aHwmWU1ps6FL3N1elVnYybqGeo In5VuVyAc8oYIyzt5zLhX+mssAM5geDabxwEUF0ogwGzPufGaoQuJgAPnhPyE6ZTGCXICrsM8S/Aa +JhjbJXvxlY+8+Mz+ovaVZnYWgYGBHOyrQHSboxl2yll6wS9a/iXhNenr6L9uBrErOHBexk6iKhrg g2a4fwYEcAX7RaTID2pQ==; 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 1jaPF5-00019O-S7; Sun, 17 May 2020 19:46:35 +0000 Received: from vps.slashdirt.org ([144.91.108.218]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jaPF2-00018u-DU for openwrt-devel@lists.openwrt.org; Sun, 17 May 2020 19:46:34 +0000 Received: from supercopter (82-64-212-153.subs.proxad.net [82.64.212.153]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by vps.slashdirt.org (Postfix) with ESMTPS id 6E1F5600A8; Sun, 17 May 2020 21:46:26 +0200 (CEST) DMARC-Filter: OpenDMARC Filter v1.3.2 vps.slashdirt.org 6E1F5600A8 Authentication-Results: vps.slashdirt.org; dmarc=fail (p=quarantine dis=none) header.from=slashdirt.org DKIM-Filter: OpenDKIM Filter v2.11.0 vps.slashdirt.org 6E1F5600A8 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=slashdirt.org; s=mail; t=1589744787; bh=16bOLaFzsL+NulB1dYzP+imKj6BWLNZXemoqL+KrSKs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=p7G1CBeeDh4Rj3DJQZyygqyYaFxx214FEIQygBmYk/J+cZVDAK3A0Po4/dKGUTBYf 0pjCAd8EGbIeASz+0I9n6jPxZhLOfqtRkg+JTZqOg5gLiF36Ngk3N6aMvyQH/iTKJY u0HuGbsURX3YaKLCZ5O81/vDHLGa2GG2NmqS/wy0= Received: by supercopter (sSMTP sendmail emulation); Sun, 17 May 2020 21:46:26 +0200 From: =?utf-8?q?Thibaut_VAR=C3=88NE?= To: openwrt-devel@lists.openwrt.org Date: Sun, 17 May 2020 21:46:09 +0200 Message-Id: <20200517194609.34294-1-hacks@slashdirt.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20200517182851.33553-1-hacks@slashdirt.org> References: <20200517182851.33553-1-hacks@slashdirt.org> MIME-Version: 1.0 X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NO_DNS_FOR_FROM,TXREP, UNPARSEABLE_RELAY shortcircuit=no autolearn=no autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on vps.slashdirt.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200517_124632_617666_870C87DA X-CRM114-Status: GOOD ( 14.81 ) X-Spam-Score: 0.2 (/) X-Spam-Report: SpamAssassin version 3.4.4 on bombadil.infradead.org summary: Content analysis details: (0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- 0.4 NO_DNS_FOR_FROM RBL: Envelope sender has no MX or A DNS records [listed in slashdirt.org. IN A] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid Subject: [OpenWrt-Devel] [PATCH v2] package/base-files: caldata: work around dd's limitation 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?q?Thibaut_VAR=C3=88NE?= Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org tl;dr: dd will silently truncate the output if reading from special files (e.g. sysfs attributes) with a too large bs parameter. This problem was exposed on some RouterBOARD ipq40xx devices which use a caldata payload which is larger than PAGE_SIZE, contrary to all other currently supported RouterBOARD devices: the caldata would fail to properly load with the current scripts. Background: dd doesn't seem to correctly handle read() results that return less than requested data. sysfs attributes have a kernel exchange buffer which is at most PAGE_SIZE big, so only 1 page can be read() at a time. In this case, if bs is larger than PAGE_SIZE, dd will silently truncate blocks to PAGE_SIZE. With the current scripts using bs= count=1, the data is truncated to PAGE_SIZE as soon as the requested exceeds this value. This commit works around this problem by using `cat` in the caldata routines that can read from a file (routines that read from mtd devices are untouched). cat correctly handles partial read requests. The output is then piped to dd with the same parameters as before, to ensure that the resulting file remains exactly the same. This is a simple workaround, the downside is that it uses a pipe and one more executable, and therefore has a larger memory footprint and is slower. This is deemed acceptable considering these routines are only used at boot time. Tested-by: Robert Marko Signed-off-by: Thibaut VARĂˆNE --- v2: leave a comment in scripts --- package/base-files/Makefile | 2 +- package/base-files/files/lib/functions/caldata.sh | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/package/base-files/Makefile b/package/base-files/Makefile index d8e7c31878..5fb275533d 100644 --- a/package/base-files/Makefile +++ b/package/base-files/Makefile @@ -12,7 +12,7 @@ include $(INCLUDE_DIR)/version.mk include $(INCLUDE_DIR)/feeds.mk PKG_NAME:=base-files -PKG_RELEASE:=220 +PKG_RELEASE:=221 PKG_FLAGS:=nonshared PKG_FILE_DEPENDS:=$(PLATFORM_DIR)/ $(GENERIC_PLATFORM_DIR)/base-files/ diff --git a/package/base-files/files/lib/functions/caldata.sh b/package/base-files/files/lib/functions/caldata.sh index 6862da7164..e22c7d27e6 100644 --- a/package/base-files/files/lib/functions/caldata.sh +++ b/package/base-files/files/lib/functions/caldata.sh @@ -64,7 +64,8 @@ caldata_from_file() { [ -n "$target" ] || target=/lib/firmware/$FIRMWARE - dd if=$source of=$target iflag=skip_bytes bs=$count skip=$offset count=1 2>/dev/null || \ + # dd doesn't handle partial reads from special files: use cat + cat $source | dd of=$target iflag=skip_bytes bs=$count skip=$offset count=1 2>/dev/null || \ caldata_die "failed to extract calibration data from $source" } @@ -73,13 +74,14 @@ caldata_sysfsload_from_file() { local offset=$(($2)) local count=$(($3)) + # dd doesn't handle partial reads from special files: use cat # test extract to /dev/null first - dd if=$source of=/dev/null iflag=skip_bytes bs=$count skip=$offset count=1 2>/dev/null || \ + cat $source | dd of=/dev/null iflag=skip_bytes bs=$count skip=$offset count=1 2>/dev/null || \ caldata_die "failed to extract calibration data from $source" # can't fail now echo 1 > /sys/$DEVPATH/loading - dd if=$source of=/sys/$DEVPATH/data iflag=skip_bytes bs=$count skip=$offset count=1 2>/dev/null + cat $source | dd of=/sys/$DEVPATH/data iflag=skip_bytes bs=$count skip=$offset count=1 2>/dev/null echo 0 > /sys/$DEVPATH/loading }