mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@suse.de>
To: linux-kernel@vger.kernel.org
Cc: "Eric W. Biederman" <ebiederm@aristanetworks.com>,
	Greg Kroah-Hartman <gregkh@suse.de>
Subject: [PATCH 21/31] sysfs: only access bin file vm_ops with the active lock
Date: Fri, 22 Oct 2010 11:25:06 -0700	[thread overview]
Message-ID: <1287771916-15016-21-git-send-email-gregkh@suse.de> (raw)
In-Reply-To: <20101022175107.GB13489@kroah.com>

From: Eric W. Biederman <ebiederm@aristanetworks.com>

bb->vm_ops is a cached copy of the vm_ops of the underlying
sysfs bin file, which means that after sysfs_bin_remove_file
completes it is only longer valid to deference bb->vm_ops.

So move all of the tests of bb->vm_ops inside of where
we hold the sysfs active lock.

Signed-off-by: Eric W. Biederman <ebiederm@aristanetworks.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
---
 fs/sysfs/bin.c |   42 ++++++++++++++++++++++++++----------------
 1 files changed, 26 insertions(+), 16 deletions(-)

diff --git a/fs/sysfs/bin.c b/fs/sysfs/bin.c
index d31d7b7..a475983 100644
--- a/fs/sysfs/bin.c
+++ b/fs/sysfs/bin.c
@@ -179,13 +179,14 @@ static void bin_vma_open(struct vm_area_struct *vma)
 	struct bin_buffer *bb = file->private_data;
 	struct sysfs_dirent *attr_sd = file->f_path.dentry->d_fsdata;
 
-	if (!bb->vm_ops || !bb->vm_ops->open)
+	if (!bb->vm_ops)
 		return;
 
 	if (!sysfs_get_active(attr_sd))
 		return;
 
-	bb->vm_ops->open(vma);
+	if (bb->vm_ops->open)
+		bb->vm_ops->open(vma);
 
 	sysfs_put_active(attr_sd);
 }
@@ -197,13 +198,15 @@ static int bin_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
 	struct sysfs_dirent *attr_sd = file->f_path.dentry->d_fsdata;
 	int ret;
 
-	if (!bb->vm_ops || !bb->vm_ops->fault)
+	if (!bb->vm_ops)
 		return VM_FAULT_SIGBUS;
 
 	if (!sysfs_get_active(attr_sd))
 		return VM_FAULT_SIGBUS;
 
-	ret = bb->vm_ops->fault(vma, vmf);
+	ret = VM_FAULT_SIGBUS;
+	if (bb->vm_ops->fault)
+		ret = bb->vm_ops->fault(vma, vmf);
 
 	sysfs_put_active(attr_sd);
 	return ret;
@@ -219,13 +222,12 @@ static int bin_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf)
 	if (!bb->vm_ops)
 		return VM_FAULT_SIGBUS;
 
-	if (!bb->vm_ops->page_mkwrite)
-		return 0;
-
 	if (!sysfs_get_active(attr_sd))
 		return VM_FAULT_SIGBUS;
 
-	ret = bb->vm_ops->page_mkwrite(vma, vmf);
+	ret = 0;
+	if (bb->vm_ops->page_mkwrite)
+		ret = bb->vm_ops->page_mkwrite(vma, vmf);
 
 	sysfs_put_active(attr_sd);
 	return ret;
@@ -239,13 +241,15 @@ static int bin_access(struct vm_area_struct *vma, unsigned long addr,
 	struct sysfs_dirent *attr_sd = file->f_path.dentry->d_fsdata;
 	int ret;
 
-	if (!bb->vm_ops || !bb->vm_ops->access)
+	if (!bb->vm_ops)
 		return -EINVAL;
 
 	if (!sysfs_get_active(attr_sd))
 		return -EINVAL;
 
-	ret = bb->vm_ops->access(vma, addr, buf, len, write);
+	ret = -EINVAL;
+	if (bb->vm_ops->access)
+		ret = bb->vm_ops->access(vma, addr, buf, len, write);
 
 	sysfs_put_active(attr_sd);
 	return ret;
@@ -259,13 +263,15 @@ static int bin_set_policy(struct vm_area_struct *vma, struct mempolicy *new)
 	struct sysfs_dirent *attr_sd = file->f_path.dentry->d_fsdata;
 	int ret;
 
-	if (!bb->vm_ops || !bb->vm_ops->set_policy)
+	if (!bb->vm_ops)
 		return 0;
 
 	if (!sysfs_get_active(attr_sd))
 		return -EINVAL;
 
-	ret = bb->vm_ops->set_policy(vma, new);
+	ret = 0;
+	if (bb->vm_ops->set_policy)
+		ret = bb->vm_ops->set_policy(vma, new);
 
 	sysfs_put_active(attr_sd);
 	return ret;
@@ -279,13 +285,15 @@ static struct mempolicy *bin_get_policy(struct vm_area_struct *vma,
 	struct sysfs_dirent *attr_sd = file->f_path.dentry->d_fsdata;
 	struct mempolicy *pol;
 
-	if (!bb->vm_ops || !bb->vm_ops->get_policy)
+	if (!bb->vm_ops)
 		return vma->vm_policy;
 
 	if (!sysfs_get_active(attr_sd))
 		return vma->vm_policy;
 
-	pol = bb->vm_ops->get_policy(vma, addr);
+	pol = vma->vm_policy;
+	if (bb->vm_ops->get_policy)
+		pol = bb->vm_ops->get_policy(vma, addr);
 
 	sysfs_put_active(attr_sd);
 	return pol;
@@ -299,13 +307,15 @@ static int bin_migrate(struct vm_area_struct *vma, const nodemask_t *from,
 	struct sysfs_dirent *attr_sd = file->f_path.dentry->d_fsdata;
 	int ret;
 
-	if (!bb->vm_ops || !bb->vm_ops->migrate)
+	if (!bb->vm_ops)
 		return 0;
 
 	if (!sysfs_get_active(attr_sd))
 		return 0;
 
-	ret = bb->vm_ops->migrate(vma, from, to, flags);
+	ret = 0;
+	if (bb->vm_ops->migrate)
+		ret = bb->vm_ops->migrate(vma, from, to, flags);
 
 	sysfs_put_active(attr_sd);
 	return ret;
-- 
1.7.2


  parent reply	other threads:[~2010-10-22 18:25 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-10-22 17:51 [GIT PATCH] driver core merge for .37-rc1 Greg KH
2010-10-22 18:24 ` [PATCH 01/31] Dynamic Debug: Split out query string parsing/setup from proc_write Greg Kroah-Hartman
2010-10-22 18:24 ` [PATCH 02/31] Dynamic Debug: Introduce ddebug_query= boot parameter Greg Kroah-Hartman
2010-10-22 18:24 ` [PATCH 03/31] Dynamic Debug: Initialize dynamic debug earlier via arch_initcall Greg Kroah-Hartman
2010-10-22 18:24 ` [PATCH 04/31] driver core: platform: Use drv->driver.bus instead of assuming platform_bus_type Greg Kroah-Hartman
2010-10-22 18:24 ` [PATCH 05/31] uio: do not use PCI resources before pci_enable_device() Greg Kroah-Hartman
2010-10-22 18:24 ` [PATCH 06/31] driver core: platform_bus: allow runtime override of dev_pm_ops Greg Kroah-Hartman
2010-10-22 18:24 ` [PATCH 07/31] add Packet hub driver for Topcliff Platform controller hub Greg Kroah-Hartman
2010-10-22 18:24 ` [PATCH 08/31] pch_phub: fix build warnings Greg Kroah-Hartman
2010-10-22 18:24 ` [PATCH 09/31] debugfs: mark me as the maintainer Greg Kroah-Hartman
2010-10-22 18:24 ` [PATCH 10/31] base/platform: Safe handling for NULL platform data and resources Greg Kroah-Hartman
2010-10-22 18:24 ` [PATCH 11/31] base/platform: Simplifications for NULL platform data/resources handling Greg Kroah-Hartman
2010-10-22 18:24 ` [PATCH 12/31] driver core: remove CONFIG_SYSFS_DEPRECATED_V2 but keep it for block devices Greg Kroah-Hartman
2010-10-22 18:24 ` [PATCH 13/31] SYSFS: Allow boot time switching between deprecated and modern sysfs layout Greg Kroah-Hartman
2010-10-22 18:24 ` [PATCH 14/31] uio: Fix lack of locking in init_uio_class Greg Kroah-Hartman
2010-10-22 18:25 ` [PATCH 15/31] uio: Don't clear driver data Greg Kroah-Hartman
2010-10-22 18:25 ` [PATCH 16/31] uio: Cleanup irq handling Greg Kroah-Hartman
2010-10-22 18:25 ` [PATCH 17/31] uio: Support 2^MINOR_BITS minors Greg Kroah-Hartman
2010-10-22 18:25 ` [PATCH 18/31] uio: Statically allocate uio_class and use class .dev_attrs Greg Kroah-Hartman
2010-10-22 18:25 ` [PATCH 19/31] FW_LOADER: fix kconfig dependency warning on HOTPLUG Greg Kroah-Hartman
2010-10-22 18:25 ` [PATCH 20/31] sysfs: Fail bin file mmap if vma close is implemented Greg Kroah-Hartman
2010-10-22 18:25 ` Greg Kroah-Hartman [this message]
2010-10-22 18:25 ` [PATCH 22/31] driver-core: base: change to new flag variable Greg Kroah-Hartman
2010-10-22 18:25 ` [PATCH 23/31] driver core: fix build for CONFIG_BLOCK not enabled Greg Kroah-Hartman
2010-10-22 18:25 ` [PATCH 24/31] kobject: Introduce kset_find_obj_hinted Greg Kroah-Hartman
2010-10-22 18:25 ` [PATCH 25/31] driver core: Introduce find_memory_block_hinted which utilizes kset_find_obj_hinted Greg Kroah-Hartman
2010-10-22 18:25 ` [PATCH 26/31] driver core: Convert link_mem_sections to use find_memory_block_hinted Greg Kroah-Hartman
2010-10-22 18:25 ` [PATCH 27/31] hpilo: Despecificate driver from iLO generation Greg Kroah-Hartman
2010-10-22 18:25 ` [PATCH 28/31] Driver core: Move find_memory_block routine Greg Kroah-Hartman
2010-10-22 18:25 ` [PATCH 29/31] Driver core: Add mutex for adding/removing memory blocks Greg Kroah-Hartman
2010-10-22 18:25 ` [PATCH 30/31] Driver core: Add section count to memory_block struct Greg Kroah-Hartman
2010-10-22 18:25 ` [PATCH 31/31] driver core: Display error codes when class suspend fails Greg Kroah-Hartman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1287771916-15016-21-git-send-email-gregkh@suse.de \
    --to=gregkh@suse.de \
    --cc=ebiederm@aristanetworks.com \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome