[Devel,RHEL7,COMMIT] ve/fs: Fix invalid dereference in proc_sys_getattr()

Submitted by Konstantin Khorenko on April 3, 2017, 10:04 a.m.

Details

Message ID 201704031004.v33A4780018872@finist_cl7.x64_64.work.ct
State New
Series "fs: Fix invalid dereference in proc_sys_getattr()"
Headers show

Commit Message

Konstantin Khorenko April 3, 2017, 10:04 a.m.
The commit is pushed to "branch-rh7-3.10.0-514.10.2.vz7.29.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh7-3.10.0-514.10.2.vz7.29.10
------>
commit 533f4b631ec240560362671d16d0daa2bbeaf118
Author: Kirill Tkhai <ktkhai@virtuozzo.com>
Date:   Mon Apr 3 14:04:07 2017 +0400

    ve/fs: Fix invalid dereference in proc_sys_getattr()
    
    grab_header() may return -ENOENT. In this case root in the below
    
            struct ctl_table_header *head = grab_header(inode);
    	struct ctl_table_root *root = head->root;
    
    dereferences (void *)-ENOENT, that leads to page fault and crash.
    Fix that.
    
    https://jira.sw.ru/browse/PSBM-56704
    
    Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
    
    Fixes (to merge): ac555dd ("VE/PROC/SYSCTL: show real permissions in stat")
    + hunk from 95c9cb3 ("SYSCTL: fix compilation")
---
 fs/proc/proc_sysctl.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Patch hide | download patch | download mbox

diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
index 1727eab..3c05a55 100644
--- a/fs/proc/proc_sysctl.c
+++ b/fs/proc/proc_sysctl.c
@@ -758,12 +758,14 @@  static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
 {
 	struct inode *inode = dentry->d_inode;
 	struct ctl_table_header *head = grab_header(inode);
-	struct ctl_table_root *root = head->root;
 	struct ctl_table *table = PROC_I(inode)->sysctl_entry;
+	struct ctl_table_root *root;
 
 	if (IS_ERR(head))
 		return PTR_ERR(head);
 
+	root = head->root;
+
 	generic_fillattr(inode, stat);
 
 	if (table) {