From patchwork Mon Dec 14 09:42:38 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Srinivas Kandagatla X-Patchwork-Id: 58325 Delivered-To: patch@linaro.org Received: by 10.112.73.68 with SMTP id j4csp1350893lbv; Mon, 14 Dec 2015 01:42:57 -0800 (PST) X-Received: by 10.66.216.73 with SMTP id oo9mr44446240pac.148.1450086175542; Mon, 14 Dec 2015 01:42:55 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 78si486225pfo.240.2015.12.14.01.42.55; Mon, 14 Dec 2015 01:42:55 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dkim=neutral (body hash did not verify) header.i=@linaro-org.20150623.gappssmtp.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932166AbbLNJmx (ORCPT + 28 others); Mon, 14 Dec 2015 04:42:53 -0500 Received: from mail-wm0-f46.google.com ([74.125.82.46]:35530 "EHLO mail-wm0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932065AbbLNJmw (ORCPT ); Mon, 14 Dec 2015 04:42:52 -0500 Received: by mail-wm0-f46.google.com with SMTP id p66so35263461wmp.0 for ; Mon, 14 Dec 2015 01:42:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=jOTGbjwzP6z/qW5YQuOb7F5hRffS0/fQjFJSHXRrnu8=; b=PsIlblM/Kxx1rnrPkjeE2zumwCkvBcNA5Rt4VjlymAjm/2a2j9GWe9uuAQ3h8eBQjx aJ7tdjyI/diEc3YbukjIb9zlNXv1S6eNyt7d0QKFwXO81I+hBgQ0ELYoFPY+eHELf/Yq BYGIYQBph8r5TiduWX34I4+T35PR08lIeubrAiRdF7T2cLmkEeImWEQJFGx9Smwtne4k IKqV3qKkRWZ5lJf4fuMd/Bz3Vb7Mi+HqO/rBGdfD22b9zrBM3OMTX5HD2D/4zDq4F5aZ 6u7v6dZ0uG5T1LOE6N3u+HvKxoSRiPk4W3pnIL7C2bgnoamrXoODqe42gYyhF0pDfYij hTAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=jOTGbjwzP6z/qW5YQuOb7F5hRffS0/fQjFJSHXRrnu8=; b=GrikXm05KhD2Vu1Ij4azVhF6AIpBywNF/FfnGch6NpCdb7av4JCEKLFoBH9gP1K+ia ufDydpArRGpuptvSJM2+MQUSKSXYQIMFNQpbhnbVcoofmMt0rHsGGUoZhGGvIJrwjGGz e092+PAP+jtycl0iHSQ9/PFTrUkf8Yz8Ho4BJsuh1ZwsO/JVPk67g5KbvxAjzHMmHcNn rp7h2GhXkmZXHjLskzCsW/E4eyMneqfDMz0+sqqFiMMntXddGu1PzNyWHZdoBgbrVkyW PFpbUhW0k9mXvnfgdbu4cdkuid2nStEtA/Swcwf8RNdg9U0PVdPx3Zr5PpicuRSKpuJe Jlaw== X-Gm-Message-State: ALoCoQkyGl49/GAKKomXXpwYIpAhrlFnT/iqYK/3nrM+TH58zb7XpihYhUDzozfZBVBBAR7upKBP2MldRbMTS4GxPSIHAzMn8A== X-Received: by 10.194.6.196 with SMTP id d4mr36165329wja.120.1450086171017; Mon, 14 Dec 2015 01:42:51 -0800 (PST) Received: from localhost.localdomain (host-92-13-246-184.as43234.net. [92.13.246.184]) by smtp.gmail.com with ESMTPSA id b84sm15259338wmh.15.2015.12.14.01.42.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 14 Dec 2015 01:42:50 -0800 (PST) From: Srinivas Kandagatla To: gregkh@linuxfoundation.org Cc: maxime.ripard@free-electrons.com, linux-arm-kernel@lists.infradead.org, djkurtz@chromium.org, linux-kernel@vger.kernel.org, andrew-ct.chen@mediatek.com, Srinivas Kandagatla Subject: [PATCH 1/4] nvmem: core: return error for non word aligned access Date: Mon, 14 Dec 2015 09:42:38 +0000 Message-Id: <1450086158-18756-1-git-send-email-srinivas.kandagatla@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1450086024-18297-1-git-send-email-srinivas.kandagatla@linaro.org> References: <1450086024-18297-1-git-send-email-srinivas.kandagatla@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org nvmem providers have restrictions on register strides, so return error when users attempt to read/write buffers with sizes which are less than word size. Without this patch the userspace would continue to try as it does not get any error from the nvmem core, resulting in a hang or endless loop in userspace. Reported-by: Ariel D'Alessandro Signed-off-by: Srinivas Kandagatla --- drivers/nvmem/core.c | 6 ++++++ 1 file changed, 6 insertions(+) -- 1.9.1 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/ diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index 6fd4e5a..9d11d98 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -70,6 +70,9 @@ static ssize_t bin_attr_nvmem_read(struct file *filp, struct kobject *kobj, if (pos >= nvmem->size) return 0; + if (count < nvmem->word_size) + return -EINVAL; + if (pos + count > nvmem->size) count = nvmem->size - pos; @@ -95,6 +98,9 @@ static ssize_t bin_attr_nvmem_write(struct file *filp, struct kobject *kobj, if (pos >= nvmem->size) return 0; + if (count < nvmem->word_size) + return -EINVAL; + if (pos + count > nvmem->size) count = nvmem->size - pos;