From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932178AbbJMBJ4 (ORCPT ); Mon, 12 Oct 2015 21:09:56 -0400 Received: from smtp.codeaurora.org ([198.145.29.96]:43547 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752827AbbJMBJP (ORCPT ); Mon, 12 Oct 2015 21:09:15 -0400 From: Stephen Boyd To: Greg Kroah-Hartman Cc: linux-kernel@vger.kernel.org, Viresh Kumar Subject: [PATCH 4/4] debugfs: Add read-only/write-only bool file ops Date: Mon, 12 Oct 2015 18:09:12 -0700 Message-Id: <1444698552-12369-5-git-send-email-sboyd@codeaurora.org> X-Mailer: git-send-email 2.6.1.134.g26caae2 In-Reply-To: <1444698552-12369-1-git-send-email-sboyd@codeaurora.org> References: <1444698552-12369-1-git-send-email-sboyd@codeaurora.org> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org There aren't any read-only or write-only bool file ops, but there is a caller of debugfs_create_bool() that calls it with mode equal to 0400. This leads to the possibility of userspace modifying the file, so let's use the newly created debugfs_create_mode() helper here to fix this. Signed-off-by: Stephen Boyd --- fs/debugfs/file.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/fs/debugfs/file.c b/fs/debugfs/file.c index e8e73aebe6b8..8450549d54a9 100644 --- a/fs/debugfs/file.c +++ b/fs/debugfs/file.c @@ -450,6 +450,18 @@ static const struct file_operations fops_bool = { .llseek = default_llseek, }; +static const struct file_operations fops_bool_ro = { + .read = debugfs_read_file_bool, + .open = simple_open, + .llseek = default_llseek, +}; + +static const struct file_operations fops_bool_wo = { + .write = debugfs_write_file_bool, + .open = simple_open, + .llseek = default_llseek, +}; + /** * debugfs_create_bool - create a debugfs file that is used to read and write a boolean value * @name: a pointer to a string containing the name of the file to create. @@ -477,7 +489,8 @@ static const struct file_operations fops_bool = { struct dentry *debugfs_create_bool(const char *name, umode_t mode, struct dentry *parent, bool *value) { - return debugfs_create_file(name, mode, parent, value, &fops_bool); + return debugfs_create_mode(name, mode, parent, value, &fops_bool, + &fops_bool_ro, &fops_bool_wo); } EXPORT_SYMBOL_GPL(debugfs_create_bool); -- The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project