Received: by 2002:ac0:950e:0:0:0:0:0 with SMTP id f14csp1209738imc; Sun, 17 Mar 2019 07:14:49 -0700 (PDT) X-Google-Smtp-Source: APXvYqy270EUkPLoDEwqfwwKb6+rzyFOdJokYpJq+0HqrxL8Hk4IBVLXaCpjQ4hzgZumoMBioWbW X-Received: by 2002:a62:ee0e:: with SMTP id e14mr14320867pfi.201.1552832089040; Sun, 17 Mar 2019 07:14:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552832089; cv=none; d=google.com; s=arc-20160816; b=TCQZvvvFmEIXi5Mjavm6N+L9xMTpQWCU1XkMF3opvczvZWzQY1ZNf7wxtJstiZL5jV IdTn03oPsdoPnjUPob8Cu8S/yBoV+07V/OMMDQ/yHhOMSaw050DrBGWJCVOhPnWfBmq6 YUqx2yHuEe5L5K3XmZcRnMuvSKaEQjLZZ6Gz8b7IPkoNpfvafz8xwO0wU/aRTfCknd65 JdKdwhN8pkaI3PhiR3PD1WdxQOo4ymrKl/MNGr0AH09WhcOUySIRYNFBYhZhn4weojbm NBs5z4C5Pf/vMzI9awTwDr48GmEQC9u/W8b6Hk3SLM3zN0xieiPkCgJ4wYSk2l8MIvrT Bmyg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from; bh=uYvg31QB3ekL7dbChqemdlX8Ss1BlzCZqZPNbY6IKm4=; b=XgBShl87kBaRZ60g0LH8FpjDIdhJ72lK/Jch0qYRuIXi4ykz1JBkiPfxmxvXaaY6KE LlqAvrAOc7n33xJfhm/cqcXO8hCeTVXO16G7s3fLQ7NUO7Nz7EUA3IHPCqpUsVsEGAwh tCe3Ik2BRQP9Gf2AAKWWThttZ6CaS3HIic7pltMzHSpRf3ZHqzYW8Mz/Ct8FhTw63dui QRjbSLfPlb7lC33rAb7QCp9SS+yVPT7TqIWEcXDrhI4aJQx6KT/q4pZE0KIuvhbyBGVb 7kw08yHxLB2w3NpUD0Qi919k40h+tLFhizSZAbJK2xTTKs4DY1XOzc67ryNM+4jTWQQG ENAw== ARC-Authentication-Results: i=1; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 13si6637432pgm.311.2019.03.17.07.14.33; Sun, 17 Mar 2019 07:14:49 -0700 (PDT) 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727229AbfCQOM2 (ORCPT + 99 others); Sun, 17 Mar 2019 10:12:28 -0400 Received: from alexa-out-blr-02.qualcomm.com ([103.229.18.198]:49034 "EHLO alexa-out-blr.qualcomm.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726782AbfCQOM2 (ORCPT ); Sun, 17 Mar 2019 10:12:28 -0400 X-IronPort-AV: E=Sophos;i="5.58,489,1544466600"; d="scan'208";a="382997" Received: from ironmsg02-blr.qualcomm.com ([10.86.208.131]) by alexa-out-blr.qualcomm.com with ESMTP/TLS/AES256-SHA; 17 Mar 2019 19:42:25 +0530 X-IronPort-AV: E=McAfee;i="5900,7806,9197"; a="7216260" Received: from gkohli-linux.qualcomm.com ([10.204.78.26]) by ironmsg02-blr.qualcomm.com with ESMTP; 17 Mar 2019 19:42:25 +0530 Received: by gkohli-linux.qualcomm.com (Postfix, from userid 427023) id A394E3B22; Sun, 17 Mar 2019 19:42:23 +0530 (IST) From: Gaurav Kohli To: srinivas.kandagatla@linaro.org, linux-kernel@vger.kernel.org Cc: linux-arm-msm@vger.kernel.org, Gaurav Kohli Subject: [PATCH v2] nvmem: core: Set no-read-write provider to avoid userspace read/write Date: Sun, 17 Mar 2019 19:42:20 +0530 Message-Id: <1552831940-7327-1-git-send-email-gkohli@codeaurora.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 Current nvmem framework allows user space to read all register space populated by nvmem binary file, In case we don't want to expose value of registers to userspace and only want kernel space to read cell value from nvmem_cell_read_u32. To protect the same, Add no-read-write property to prevent read from userspace. Signed-off-by: Gaurav Kohli --- v2: Fix build error v1: Fix no_read_write update condition diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index f24008b..f1c44fc 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -27,6 +27,7 @@ struct nvmem_device { struct kref refcnt; size_t size; bool read_only; + bool no_read_write; int flags; enum nvmem_type type; struct bin_attribute eeprom; @@ -120,6 +121,10 @@ static ssize_t bin_attr_nvmem_read(struct file *filp, struct kobject *kobj, dev = container_of(kobj, struct device, kobj); nvmem = to_nvmem_device(dev); + /* if no-read-write, then stop from reading */ + if (nvmem->no_read_write) + return -EPERM; + /* Stop the user from reading */ if (pos >= nvmem->size) return 0; @@ -154,6 +159,10 @@ static ssize_t bin_attr_nvmem_write(struct file *filp, struct kobject *kobj, dev = container_of(kobj, struct device, kobj); nvmem = to_nvmem_device(dev); + /* if no-read-write, then stop from writing */ + if (nvmem->no_read_write) + return -EPERM; + /* Stop the user from writing */ if (pos >= nvmem->size) return -EFBIG; @@ -651,6 +660,9 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config) nvmem->read_only = device_property_present(config->dev, "read-only") || config->read_only || !nvmem->reg_write; + nvmem->no_read_write = device_property_present(config->dev, + "no-read-write"); + if (config->root_only) nvmem->dev.groups = nvmem->read_only ? nvmem_ro_root_dev_groups : -- Qualcomm India Private Limited, on behalf of Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project.