Whamcloud - gitweb
LU-9278 quota: avoid crash when access failed quota proc file 77/26277/4
authorWang Shilong <wshilong@ddn.com>
Fri, 31 Mar 2017 02:50:44 +0000 (10:50 +0800)
committerOleg Drokin <oleg.drokin@intel.com>
Thu, 13 Apr 2017 18:45:00 +0000 (18:45 +0000)
If quota dose not have accounting objects because of failing to
load or unsupported type, @lqp_obj will be NULL, we could not access
directly, add proper handling to avoid following crash

[<ffffffffa0c60730>] ? lprocfs_quota_seq_show+0x460/0x460 [lquota]
[<ffffffff8126bd8f>] proc_reg_open+0x6f/0x100
[<ffffffff811fbfb7>] do_dentry_open+0x1a7/0x2e0
[<ffffffff812a8bfc>] ? security_inode_permission+0x1c/0x30
[<ffffffff8126bd20>] ? proc_reg_release+0x70/0x70
[<ffffffff811fc18f>] vfs_open+0x5f/0xe0
[<ffffffff81209b58>] ? may_open+0x68/0x110
[<ffffffff8120ccfd>] do_last+0x1ed/0x12a0
[<ffffffff8120de72>] path_openat+0xc2/0x490
[<ffffffff8118075b>] ? unlock_page+0x2b/0x30
[<ffffffff8120ffeb>] do_filp_open+0x4b/0xb0
[<ffffffff8121cc77>] ? __alloc_fd+0xa7/0x130
[<ffffffff811fd4f3>] do_sys_open+0xf3/0x1f0
[<ffffffff811fd60e>] SyS_open+0x1e/0x20
[<ffffffff81696d49>] system_call_fastpath+0x16/0x1b

Signed-off-by: Wang Shilong <wshilong@ddn.com>
Change-Id: I8dfc2b35c1f38416ed0f933296bdaa455e117926
Reviewed-on: https://review.whamcloud.com/26277
Tested-by: Jenkins
Reviewed-by: Niu Yawei <yawei.niu@intel.com>
Reviewed-by: Li Xi <lixi@ddn.com>
Tested-by: Maloo <hpdd-maloo@intel.com>
Reviewed-by: Andreas Dilger <andreas.dilger@intel.com>
lustre/quota/lproc_quota.c

index ecee4a9..4ecbaa7 100644 (file)
@@ -308,6 +308,11 @@ static int lprocfs_quota_seq_open(struct inode *inode, struct file *file)
        if (rc)
                goto out_env;
 
+       if (!lqp->lqp_obj) {
+               lqp->lqp_it = NULL;
+               goto out_seq;
+       }
+
        /* initialize iterator */
        iops = &lqp->lqp_obj->do_index_ops->dio_it;
        it = iops->init(&lqp->lqp_env, lqp->lqp_obj, 0);
@@ -322,6 +327,7 @@ static int lprocfs_quota_seq_open(struct inode *inode, struct file *file)
        lqp->lqp_it = it;
        lqp->lqp_cookie = 0;
 
+out_seq:
        seq = file->private_data;
        seq->private = lqp;
        return 0;
@@ -340,9 +346,10 @@ static int lprocfs_quota_seq_release(struct inode *inode, struct file *file)
        const struct dt_it_ops  *iops;
 
        LASSERT(lqp);
-       iops = &lqp->lqp_obj->do_index_ops->dio_it;
-       if (lqp->lqp_it != NULL)
+       if (lqp->lqp_it != NULL) {
+               iops = &lqp->lqp_obj->do_index_ops->dio_it;
                iops->fini(&lqp->lqp_env, lqp->lqp_it);
+       }
        lu_env_fini(&lqp->lqp_env);
        OBD_FREE_PTR(lqp);