From patchwork Tue Nov 17 09:12:41 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Srinivas Kandagatla X-Patchwork-Id: 56716 Delivered-To: patch@linaro.org Received: by 10.112.155.196 with SMTP id vy4csp1812325lbb; Tue, 17 Nov 2015 01:13:13 -0800 (PST) X-Received: by 10.68.102.33 with SMTP id fl1mr61555190pbb.40.1447751592936; Tue, 17 Nov 2015 01:13:12 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id sp3si56858727pbc.195.2015.11.17.01.13.12; Tue, 17 Nov 2015 01:13:12 -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 S1753333AbbKQJNK (ORCPT + 28 others); Tue, 17 Nov 2015 04:13:10 -0500 Received: from mail-wm0-f47.google.com ([74.125.82.47]:34815 "EHLO mail-wm0-f47.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752950AbbKQJND (ORCPT ); Tue, 17 Nov 2015 04:13:03 -0500 Received: by wmvv187 with SMTP id v187so216491537wmv.1 for ; Tue, 17 Nov 2015 01:13:01 -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; bh=QMawvA+QVTrmAaI0M5Y1uq19WdztCaiVXFaigrrnM24=; b=C6G6k8OOB3f8K8JXEt7hth4TJCrowWUH9JgQz8beuMoWPEjEvTMfTlhSWYW8LlNh02 nvH/gXaprJ1zgo7TY1T+PDzBSAoC5FfxnvW8tiCD6KWqR5VM5ezasm9Ks4R2w3ZXk6uD bHEzS8RucMk6hmVB8m66+FYNy3u8LhNHM8NtdRLnKaKSZ2gsW+W3jxXzWu9CeekYUUSu sDIUt0ZFN6xlfkiPYezWkdBYoHjOFK8MMCZ9GconaJk0F5jrFK+VHVKXiRh7A6EJAOMM 9YYpXOWnXEXzTQwUqVRzKk1UXVGOmkyEuAXubs5WLNmN8tzgqApDsM0HaSaF/1jqlFhT hkNw== 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; bh=QMawvA+QVTrmAaI0M5Y1uq19WdztCaiVXFaigrrnM24=; b=K/HCN6DBZj8gqT0MFHyfIbeW93GVJyWDpI7ygpOeEa5r/bfZWeq6t1Bv/3+6fRphgg noAKqxaoks4tdSBpmdlf/Uax0tGvkJ6msLv6jUigANECqjerMqpsGTlKBgOYunN74q+I tZmUGODOa/Tx2oR0kJmFTg9n27KYZS2K87fT+4+qI8W/d08TR0kqGz+ih2MVVH0bXlHy svvlWEyJPg+Z6bCpLYLz8QVVcmo4HhWpF/HYTPvN1Ldlr+6loYpy+KEpIh3984gMTR1F xpxa5hCAtpm1b8V4QW4jCOHM51fwM6DmtKr/oV8jZiw0oGs0RUlbA5Dn/OiHAP4QXxV+ D1og== X-Gm-Message-State: ALoCoQlV4GpoDP59ORCo+ledrGyXAgs8NjRV4UsPrZwpko0jFOFSO1mlBtGWbgaFi7xtbJRdO93K X-Received: by 10.28.9.138 with SMTP id 132mr1287810wmj.19.1447751581744; Tue, 17 Nov 2015 01:13:01 -0800 (PST) Received: from localhost.localdomain (host-92-13-246-184.as43234.net. [92.13.246.184]) by smtp.gmail.com with ESMTPSA id jt9sm38872065wjc.24.2015.11.17.01.13.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 17 Nov 2015 01:13:01 -0800 (PST) From: Srinivas Kandagatla To: Greg Kroah-Hartman Cc: Srinivas Kandagatla , Maxime Ripard , linux-kernel@vger.kernel.org, ariel@vanguardiasur.com.ar Subject: [PATCH] nvmem: core: return error for non word aligned access Date: Tue, 17 Nov 2015 09:12:41 +0000 Message-Id: <1447751561-22080-1-git-send-email-srinivas.kandagatla@linaro.org> X-Mailer: git-send-email 1.9.1 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 --- Hi Greg, Can you please queue this for next rc. Thanks, srini 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;