From patchwork Thu Oct 3 05:53:39 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jeffery X-Patchwork-Id: 1171079 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 46kMrm1GMvz9sN1 for ; Thu, 3 Oct 2019 16:03:52 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=aj.id.au Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=aj.id.au header.i=@aj.id.au header.b="QBwPcBth"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="wRxfuPXB"; dkim-atps=neutral Received: from bilbo.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 46kMrm0BZgzDqXV for ; Thu, 3 Oct 2019 16:03:52 +1000 (AEST) X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=aj.id.au (client-ip=64.147.123.25; helo=wout2-smtp.messagingengine.com; envelope-from=andrew@aj.id.au; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=aj.id.au Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=aj.id.au header.i=@aj.id.au header.b="QBwPcBth"; dkim=pass (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="wRxfuPXB"; dkim-atps=neutral Received: from wout2-smtp.messagingengine.com (wout2-smtp.messagingengine.com [64.147.123.25]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 46kMnZ01nNzDqSy for ; Thu, 3 Oct 2019 16:01:05 +1000 (AEST) Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.west.internal (Postfix) with ESMTP id 68272507 for ; Thu, 3 Oct 2019 01:53:03 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Thu, 03 Oct 2019 01:53:03 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aj.id.au; h=from :to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; s=fm3; bh=Ax0xfGhEJYZgpO2nuPz+kvC3h9 Xk8Zw+z5zTTdukF/Q=; b=QBwPcBthtXddcttpwOVt164XyQnNN3Xh+mlEcg318s gb3gNKlhRPTQ+fDWVUN98QdrF3b6rwGr6t2QhpEWALJlGcFkvMQ3ad3W6WFSkB/L h461EAOCu0/mv2fIbnO3urw3P433WDo5uIMfL0V8Y5HU+6fe+SN2+157h12sSEK0 u0H5YWukwlwsnOQFG6VukHlKCTIZmyeQCZpP86AtEeGiTt7W9fw6SPDwTv6VU16J 52Zgv8Oz6MQ8mI5di5SK8rjWZjmmoY9b4mbqtM9KEP8o1VqqJAXKduMiSkhNv3M1 PiOaFuBdJf0Ixy1QpOgLGWlTL5VBrOwI9ij2mB9YpTEw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; bh=Ax0xfGhEJYZgpO2nuPz+kvC3h9Xk8Zw+z5zTTdukF/Q=; b=wRxfuPXB 0OgoUAuy+J9wUg2D3l05WQBllSrkL61BbJBy6v3b/FBPBvC5i9OuwHolCou6ox9L IRBkKP/LQfosyUURzEDUhWOnuV0xNBFgtuI3aIcQHz3baAz4EXRaiIIy93f0I0at wyBR38A9/jGJB73p5g9zWqoCBqdYBxvpJp4Un7ME5HamHgCvJyN9N+wgi9ttEwPk DCgjCnBCGnUMTlEfjvlRr/C07roh9Tf23LVASTiM9Srgj1xT2TEMKtcWpQA1P1eK ov5QOiEytkkUF3/vx5WaOMCP74IunaOJZkACW5rrrK5pK/6tkUJ2POpylWOjk9nk tWPg9zQUVTQffg== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedufedrgeejgdellecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhephffvufffkffojghfggfgsedtkeertd ertddtnecuhfhrohhmpeetnhgurhgvficulfgvfhhfvghrhicuoegrnhgurhgvfiesrghj rdhiugdrrghuqeenucfkphepvddtfedrheejrddvudehrddujeeknecurfgrrhgrmhepmh grihhlfhhrohhmpegrnhgurhgvfiesrghjrdhiugdrrghunecuvehluhhsthgvrhfuihii vgepge X-ME-Proxy: Received: from localhost.localdomain (203-57-215-178.dyn.iinet.net.au [203.57.215.178]) by mail.messagingengine.com (Postfix) with ESMTPA id D53C180065 for ; Thu, 3 Oct 2019 01:53:01 -0400 (EDT) From: Andrew Jeffery To: skiboot@lists.ozlabs.org Date: Thu, 3 Oct 2019 15:23:39 +0930 Message-Id: <20191003055342.7868-7-andrew@aj.id.au> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191003055342.7868-1-andrew@aj.id.au> References: <20191003055342.7868-1-andrew@aj.id.au> MIME-Version: 1.0 Subject: [Skiboot] [PATCH 6/9] blocklevel: smart_write: Deny writes intersecting ECC protected regions X-BeenThere: skiboot@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Mailing list for skiboot development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Skiboot" Other code paths don't handle writes spanning mixed regions, and it's a headache, so deny it here too. Signed-off-by: Andrew Jeffery --- libflash/blocklevel.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/libflash/blocklevel.c b/libflash/blocklevel.c index a72bed7422ae..f63fb5d266c6 100644 --- a/libflash/blocklevel.c +++ b/libflash/blocklevel.c @@ -512,6 +512,7 @@ int blocklevel_smart_write(struct blocklevel_device *bl, uint64_t pos, const voi uint64_t ecc_start; void *erase_buf; int rc = 0; + int ecc_protection; if (!buf || !bl) { errno = EINVAL; @@ -529,7 +530,14 @@ int blocklevel_smart_write(struct blocklevel_device *bl, uint64_t pos, const voi if (rc) return rc; - if (ecc_protected(bl, pos, len, &ecc_start)) { + ecc_protection = ecc_protected(bl, pos, len, &ecc_start); + if (ecc_protection == -1) { + FL_ERR("%s: Can't cope with partial ecc\n", __func__); + errno = EINVAL; + return FLASH_ERR_PARM_ERROR; + } + + if (ecc_protection) { FL_DBG("%s: region has ECC\n", __func__); len = ecc_buffer_size(len);