From patchwork Mon Jul 27 13:47:10 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michal Suchanek X-Patchwork-Id: 500439 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2001:1868:205::9]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 566DE140216 for ; Tue, 28 Jul 2015 00:06:18 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZJj1T-0001DS-87; Mon, 27 Jul 2015 14:04:55 +0000 Received: from dec59.ruk.cuni.cz ([2001:718:1e03:4::11]) by bombadil.infradead.org with smtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZJj1Q-000115-8e for linux-mtd@lists.infradead.org; Mon, 27 Jul 2015 14:04:53 +0000 Received: (qmail 54478 invoked by uid 2313); 27 Jul 2015 14:04:21 -0000 MBOX-Line: From c14fec4f9669c06d3d20ef44ad02033b6cc6d51b Mon Sep 17 00:00:00 2001 Message-Id: From: Michal Suchanek Date: Mon, 27 Jul 2015 15:47:10 +0200 Subject: mtd-utils: mtd_debug: check amount of data read. To: linux-mtd@lists.infradead.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150727_070452_709658_CCC1214F X-CRM114-Status: UNSURE ( 7.11 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -4.3 (----) X-Spam-Report: SpamAssassin version 3.4.0 on bombadil.infradead.org summary: Content analysis details: (-4.3 points) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at http://www.dnswl.org/, medium trust [2001:718:1e03:4:0:0:0:11 listed in] [list.dnswl.org] -1.3 RP_MATCHES_RCVD Envelope sender domain matches handover relay domain 0.0 HEADER_FROM_DIFFERENT_DOMAINS From and EnvelopeFrom 2nd level mail domains are different -0.0 SPF_HELO_PASS SPF: HELO matches SPF record 0.0 DKIM_ADSP_CUSTOM_MED No valid author signature, adsp_override is CUSTOM_MED 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (hramrach[at]gmail.com) -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] 0.2 FREEMAIL_FORGED_FROMDOMAIN 2nd level domains in From and EnvelopeFrom freemail headers are different 0.9 NML_ADSP_CUSTOM_MED ADSP custom_med hit, and not from a mailing list X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org The kernel refuses to read more data from a MTD device than the device size. However, mtd_debug does not check the amount of data read as returned by read(2) and assumes the requested amount is always read when there is no error. Reading 8M data from a 4M flash chip results in 8M file containing the flash data at the start. Signed-off-by: Michal Suchanek --- mtd_debug.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/mtd_debug.c b/mtd_debug.c index d6993ce..f3826cf 100644 --- a/mtd_debug.c +++ b/mtd_debug.c @@ -141,7 +141,10 @@ retry: perror("read()"); goto err2; } - err = write(outfd, buf, size); + if (err < size) { + fprintf(stderr, "%s: short read, requested %#x, read %#x\n", __func__, size, err); + } + err = write(outfd, buf, err); if (err < 0) { fprintf(stderr, "%s: write, size %#x, n %#x\n", __func__, size, n); perror("write()");